Skip to content

Commit

Permalink
Merge pull request #948 from GeotrekCE/Setup-cyrpress
Browse files Browse the repository at this point in the history
Setup cypress
  • Loading branch information
submarcos authored Jan 15, 2024
2 parents 713ac61 + b02f675 commit 09b62cc
Show file tree
Hide file tree
Showing 15 changed files with 523 additions and 597 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "npm"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
21 changes: 18 additions & 3 deletions .github/workflows/action-intall-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
name: Install and test

on: [pull_request]
on:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CYPRESS_INSTALL_BINARY: 0

jobs:
install-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup node
id: cache-node-modules
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: ./frontend/.nvmrc
cache: "yarn"
cache-dependency-path: "**/yarn.lock"

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
working-directory: ./frontend

- name: Check types
run: yarn tsc
working-directory: ./frontend

- name: Run tests
run: yarn test:coverage
working-directory: ./frontend

- name: Check linter
run: yarn lint
working-directory: ./frontend
44 changes: 44 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: E2E tests

on:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
e2e:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup node
id: cache-node-modules
uses: actions/setup-node@v4
with:
node-version-file: ./frontend/.nvmrc
cache: "yarn"
cache-dependency-path: "**/yarn.lock"

- name: Install dependencies
run: yarn install --frozen-lockfile
working-directory: ./frontend

- name: Cypress run
uses: cypress-io/github-action@v6
with:
start: yarn dev
working-directory: ./frontend

- name: Archive results as artifacts
uses: actions/upload-artifact@v3
with:
name: cypress
path: |
/home/runner/work/Geotrek-rando-v3/Geotrek-rando-v3/frontend/cypress/videos/*.mp4
/home/runner/work/Geotrek-rando-v3/Geotrek-rando-v3/frontend/cypress/screenshots/*.png
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Installation in development:
- Use nvm and then:

```bash
nvm use 18
nvm use
```

Install yarn
Expand Down
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules

# testing
/coverage
**/public/*@cypress

# production
/build
Expand Down
12 changes: 12 additions & 0 deletions frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://rando.localhost:3000",
retries: {
runMode: 3,
},
viewportHeight: 1080,
viewportWidth: 1920,
},
});
7 changes: 0 additions & 7 deletions frontend/cypress.json

This file was deleted.

5 changes: 5 additions & 0 deletions frontend/cypress/e2e/homePage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('template spec', () => {
it('Visits homepage', () => {
cy.visit('/')
})
})
36 changes: 0 additions & 36 deletions frontend/cypress/integration/login.spec.js

This file was deleted.

37 changes: 37 additions & 0 deletions frontend/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>
// }
// }
// }
20 changes: 20 additions & 0 deletions frontend/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// 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'

// Alternatively you can use CommonJS syntax:
// require('./commands')
8 changes: 8 additions & 0 deletions frontend/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"],
},
"include": ["**/*.ts"],
}
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"autoprefixer": "^10.4.14",
"axios": "0.25.0",
"compression": "^1.7.4",
"cypress": "^4.12.1",
"cypress": "^12.17.2",
"debounce": "^1.2.1",
"deepmerge": "^4.3.1",
"diacritics": "^1.3.0",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
"**/*.tsx",
"cypress.config.ts"
]
}
Loading

0 comments on commit 09b62cc

Please sign in to comment.