Skip to content

Commit 3f67aa9

Browse files
committed
Add basic Cypress end-to-end testing
1 parent bcfdc6f commit 3f67aa9

17 files changed

Lines changed: 2073 additions & 13 deletions

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ module.exports = {
4242
'plugin:vue/vue3-strongly-recommended', // Priority B: Strongly Recommended (Improving Readability)
4343
// 'plugin:vue/vue3-recommended', // Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead)
4444

45+
'plugin:cypress/recommended',
46+
4547
'standard'
4648

4749
],

.github/workflows/test.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ jobs:
2424
- name: Run unit tests
2525
run: npm run test:unit:ci
2626

27-
27+
cypress:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v2
31+
with:
32+
ref: ${{ github.head_ref }}
33+
- name: Cypress run
34+
uses: cypress-io/github-action@v4
35+
with:
36+
start: npm run dev
37+
wait-on: 'http://localhost:8080/cff-initializer-javascript/#'

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ yarn-error.log*
3232
*.njsproj
3333
*.sln
3434
node_modules
35+
36+
# Cypress
37+
cypress/downloads
38+
cypress/screenshots
39+
cypress/videos

README.dev.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ npm run build
5151

5252
## Tests
5353

54+
### Unit tests
55+
5456
We use `Jest` for unit tests. The unit tests can be found under `test/jest/__tests__/` folder.
5557

5658
You can run the test with
@@ -65,6 +67,20 @@ You can also use the Majestic web interface to run the unit tests in your browse
6567
npm run test:unit:ui
6668
```
6769

70+
### End-to-end tests
71+
72+
We use [Cypress](https://cypress.io) for end-to-end tests. These tests can be found under the `cypress/e2e` folder.
73+
74+
You can start Cypress with
75+
76+
```shell
77+
npm run cypress:open
78+
```
79+
80+
Select "E2E Testing", which should be configured already and select the desired browser and click the start button.
81+
82+
A browser will open with the list of tests, which can be explored.
83+
6884
## Linting and formatting
6985

7086
```shell

cypress.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
e2e: {
5+
baseUrl: 'http://localhost:8080/cff-initializer-javascript/#'
6+
}
7+
})

cypress/e2e/spec.cy.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const minimumCff = '# This CITATION.cff file was generated with cffinit.\n# Visit https://bit.ly/cffinit to generate yours today!\n\ncff-version: 1.2.0\ntitle: My Title\nmessage: >-\n If you use this software, please cite it using the\n metadata from this file.\ntype: software\nauthors:\n - {}\n'
2+
3+
describe('Minimum usage', () => {
4+
it('Visit site, fill minimum information and download', () => {
5+
// Main screen
6+
cy.visit('/')
7+
cy.contains('Generate your citation metadata files with ease')
8+
cy.get('[data-cy="btn-create"]')
9+
.click()
10+
11+
// Start screen
12+
cy.url().should('include', '/start')
13+
cy.get('[data-cy="input-title"]')
14+
.type('My Title')
15+
.should('have.value', 'My Title')
16+
cy.get('[data-cy="input-message"]')
17+
.should('have.value', 'If you use this software, please cite it using the metadata from this file.')
18+
cy.get('[data-cy="btn-next"]')
19+
.click()
20+
21+
// Author screen
22+
cy.url().should('include', '/authors')
23+
cy.get('[data-cy="btn-add-author"]')
24+
.click()
25+
cy.get('[data-cy="btn-done"]')
26+
.click()
27+
cy.get('[data-cy="btn-next"]')
28+
.click()
29+
30+
// Finish Minimum screen
31+
cy.url().should('include', '/finish-minimum')
32+
cy.get('[data-cy="btn-download"]')
33+
.click()
34+
const downloadsFolder = Cypress.config('downloadsFolder')
35+
const cfffile = `${downloadsFolder}/CITATION.cff`
36+
37+
cy.readFile(cfffile, 'binary', { timeout: 400 })
38+
.should(buffer => expect(buffer).to.be.equal(minimumCff))
39+
})
40+
})

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/support/commands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

cypress/support/e2e.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
// import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
require('./commands')

0 commit comments

Comments
 (0)