Skip to content

Commit 0177557

Browse files
authored
Merge pull request #638 from citation-file-format/610-cypress
2 parents 69ed9ee + 966ddf9 commit 0177557

14 files changed

Lines changed: 2025 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: 29 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,33 @@ 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+
It should look like this:
84+
85+
<figure style="text-align: center; width=80%;">
86+
<img alt="Cypress E2E specs list" src="https://docs.cypress.io/_nuxt/img/spec-list-with-new-spec.61d015d.png">
87+
<caption>
88+
Cypress E2E specs list. Image is from https://docs.cypress.io/guides/end-to-end-testing/writing-your-first-end-to-end-test
89+
</caption>
90+
</figure>
91+
92+
Click on the spec file.
93+
The next screen will show the tests being executed.
94+
If anything goes wrong, you will see it in red.
95+
For more information, check <https://docs.cypress.io/guides/end-to-end-testing/testing-your-app#What-you-ll-learn>.
96+
6897
## Linting and formatting
6998

7099
```shell

cypress.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
e2e: {
5+
baseUrl: 'http://localhost:8080/cff-initializer-javascript/#',
6+
supportFile: false // If the support/e2e.ts or support/commands.ts files are reinstated, delete this line
7+
}
8+
})

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+
})

0 commit comments

Comments
 (0)