feat: cypress testing (#40)
This commit is contained in:
Родитель
a491ca1692
Коммит
c5ad632408
|
@ -21,3 +21,4 @@ jobs:
|
|||
npm install
|
||||
npm run test
|
||||
npm run build
|
||||
npm run test:e2e
|
||||
|
|
|
@ -33,3 +33,7 @@ yarn-error.log*
|
|||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# cypress
|
||||
cypress/videos/
|
||||
cypress/screenshots/
|
||||
|
|
17
README.md
17
README.md
|
@ -46,6 +46,23 @@ yarn build
|
|||
|
||||
This will create an `out` folder in the repository root with the static files.
|
||||
|
||||
### Run tests
|
||||
|
||||
#### Using the UI
|
||||
|
||||
```
|
||||
yarn run cypress open
|
||||
```
|
||||
|
||||
#### Using the CLI
|
||||
|
||||
|
||||
Stop the app if you already have it running
|
||||
|
||||
```
|
||||
npm run build && npm run test:e2e
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
See the [contributing guide](CONTRIBUTING.md) for more details.
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
const { defineConfig } = require('cypress')
|
||||
const cucumber = require('cypress-cucumber-preprocessor').default
|
||||
|
||||
module.exports = defineConfig({
|
||||
e2e: {
|
||||
specPattern: 'cypress/integration/**/*.{feature, features, js}',
|
||||
setupNodeEvents(on, config) {
|
||||
// implement node event listeners here
|
||||
on('file:preprocessor', cucumber())
|
||||
},
|
||||
},
|
||||
})
|
|
@ -0,0 +1,5 @@
|
|||
describe('spec.cy.js', () => {
|
||||
it('should visit', () => {
|
||||
cy.visit('/')
|
||||
})
|
||||
})
|
|
@ -0,0 +1,33 @@
|
|||
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
|
||||
|
||||
Given('I open {string} page', (uri) => {
|
||||
const baseUrl = 'http://localhost:3000'
|
||||
let path = ''
|
||||
switch (uri) {
|
||||
case 'home':
|
||||
path = '/'
|
||||
break
|
||||
case 'schedule':
|
||||
path = '/schedule'
|
||||
break
|
||||
default:
|
||||
path = uri
|
||||
}
|
||||
cy.visit(baseUrl + path)
|
||||
})
|
||||
|
||||
When(`I click on {string}`, (path) => {
|
||||
cy.get(`a[href*="/${path}"]`).click()
|
||||
})
|
||||
|
||||
When(`I click on {string} in section {string}`, (path, section) => {
|
||||
cy.get(`${section} a[href*="/${path}"]`).click()
|
||||
})
|
||||
|
||||
Then(`I should see {string} in the url`, (text) => {
|
||||
cy.url().should('include', text)
|
||||
})
|
||||
|
||||
Then(`I see {string} text in section {string}`, (text, location) => {
|
||||
cy.get(location).should('contain', text)
|
||||
})
|
|
@ -0,0 +1,7 @@
|
|||
Feature: Maintainer Month homepage
|
||||
|
||||
I want check the homepage loads
|
||||
|
||||
Scenario: Opening the homepage
|
||||
Given I open "home" page
|
||||
Then I see "June 2022" text in section ".hero"
|
|
@ -0,0 +1,18 @@
|
|||
Feature: Schedule page
|
||||
|
||||
I want check the schedule page loads the data correctly
|
||||
|
||||
Scenario: Navigating to the schedule page
|
||||
Given I open "home" page
|
||||
When I click on "schedule" in section ".header"
|
||||
Then I should see "schedule" in the url
|
||||
Then I see "Jun 2" text in section ".events-list"
|
||||
Then I see "Jun 3" text in section ".events-list"
|
||||
|
||||
Scenario: Opening the schedule page directly
|
||||
Given I open "/schedule" page
|
||||
Then I see "Jun 2" text in section ".events-list"
|
||||
|
||||
Scenario: Check data is loaded correctly
|
||||
Given I open "schedule" page
|
||||
Then I see "Maintainer Twitter Space" text in section ".events-list"
|
|
@ -0,0 +1,25 @@
|
|||
// ***********************************************
|
||||
// This example commands.js 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) => { ... })
|
|
@ -0,0 +1,20 @@
|
|||
// ***********************************************************
|
||||
// This example support/e2e.js 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')
|
11
package.json
11
package.json
|
@ -7,7 +7,10 @@
|
|||
"build": "NODE_ENV=production next build && next export",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"test": "jest"
|
||||
"test": "jest",
|
||||
"cypress:open": "cypress open",
|
||||
"cypress:run": "cypress run",
|
||||
"test:e2e": "concurrently -k --success first \"npm run cypress:run\" \"npm run start\""
|
||||
},
|
||||
"dependencies": {
|
||||
"clsx": "^1.1.1",
|
||||
|
@ -25,11 +28,17 @@
|
|||
"@testing-library/jest-dom": "^5.16.4",
|
||||
"@testing-library/react": "^13.0.0",
|
||||
"babel-jest": "^27.5.1",
|
||||
"concurrently": "^7.2.1",
|
||||
"cypress": "^10.0.2",
|
||||
"cypress-cucumber-preprocessor": "^4.3.1",
|
||||
"eslint": "8.11.0",
|
||||
"eslint-config-next": "12.1.0",
|
||||
"jest": "^27.5.1",
|
||||
"jest-css-modules": "^2.1.0",
|
||||
"sass": "^1.49.9",
|
||||
"sass-loader": "^12.6.0"
|
||||
},
|
||||
"cypress-cucumber-preprocessor": {
|
||||
"nonGlobalStepDefinitions": true
|
||||
}
|
||||
}
|
||||
|
|
10303
yarn.lock
10303
yarn.lock
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче