Skip to content

Commit

Permalink
Merge pull request #6 from Parrit/add_cypress
Browse files Browse the repository at this point in the history
add cypress tests
  • Loading branch information
Pinwheeler authored Dec 30, 2024
2 parents 5cb86cb + 6ca469b commit dc336cd
Show file tree
Hide file tree
Showing 9 changed files with 2,240 additions and 99 deletions.
126 changes: 122 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,148 @@ on:
- main

jobs:
test:
setup:
runs-on: ubuntu-latest

outputs:
node_version: ${{ steps.nvmrc.outputs.NODE_VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Read Node.js version from .nvmrc
id: nvmrc
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV && echo "::set-output name=NODE_VERSION::$(cat .nvmrc)"

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
node-version: ${{ steps.nvmrc.outputs.NODE_VERSION }}

- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ steps.nvmrc.outputs.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.nvmrc.outputs.NODE_VERSION }}-
- name: Install dependencies
run: npm install

- name: Compress node_modules
run: tar -czf node_modules.tar.gz node_modules

- name: Save node_modules
uses: actions/upload-artifact@v3
with:
name: node-modules
path: node_modules.tar.gz

unit-tests:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Run unit tests
run: npm test

lint:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Lint code
run: npm run lint

build:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Build project
run: npm run build

cypress-tests:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Cache Cypress binary
uses: actions/cache@v4
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-cypress-
- name: Install Cypress binary if not cached
run: npx cypress install

- name: Wait for Netlify Deploy
uses: jakepartusch/wait-for-netlify-action@v1
id: netlify
with:
site_name: "parrit"

- name: Run Cypress tests
uses: cypress-io/github-action@v2
with:
command: npx cypress run
config: baseUrl=${{ steps.netlify.outputs.url }}
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: process.env.DEPLOY_URL,
setupNodeEvents(on, config) {

Check warning on line 6 in cypress.config.ts

View workflow job for this annotation

GitHub Actions / lint

'on' is defined but never used

Check warning on line 6 in cypress.config.ts

View workflow job for this annotation

GitHub Actions / lint

'config' is defined but never used
// implement node event listeners here
},
},
});
5 changes: 5 additions & 0 deletions cypress/e2e/basic.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("Basic Test", () => {
it("should visit the app", () => {
cy.visit(Cypress.config().baseUrl ?? "https://parrit.rurai.dev");
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
17 changes: 17 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
4 changes: 3 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ command = "npm run dev"
framework = "vite"

[[plugins]]
package = "@xata.io/netlify"
package = "netlify-plugin-cypress"
[plugins.inputs]
record = false

# Set immutable caching for static files, because they have fingerprinted filenames

Expand Down
Loading

0 comments on commit dc336cd

Please sign in to comment.