Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e testing with Cypress #283

Merged
merged 48 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1ecea65
Start adding some cypress tests
dariober Aug 14, 2023
2b32d1a
Start adding some cypress tests
dariober Aug 14, 2023
5ee49be
Add tests and refactor
dariober Aug 22, 2023
5067f28
Merge branch 'cypress' of https://github.com/GMOD/Apollo3 into cypress
dariober Aug 22, 2023
80cdc7d
Start adding some cypress tests
dariober Aug 14, 2023
eb5170c
Add tests and refactor
dariober Aug 22, 2023
5e8ca09
Start adding some cypress tests
dariober Aug 14, 2023
26a23d5
Several edit to cypress tests
dariober Aug 30, 2023
2155cb9
Work in progress mostly on feature resizing
dariober Sep 4, 2023
9638e6b
Merge branch 'cypress' of https://github.com/GMOD/Apollo3 into cypress
dariober Sep 4, 2023
79b480a
Remove old test files
dariober Sep 7, 2023
f9848d9
Test cypress-mongodb
dariober Sep 11, 2023
a57fdd4
Lower packageExtensions bson version
garrettjstevens Sep 11, 2023
b9203d8
Replace mongosh with cypress-mongo
dariober Sep 12, 2023
b86ab3c
Fix linter
dariober Sep 12, 2023
89f0111
Minor tidying up
dariober Sep 12, 2023
fd1bfbf
Start adding some cypress tests
dariober Aug 14, 2023
3abaa75
Add tests and refactor
dariober Aug 22, 2023
8c4d8a6
Start adding some cypress tests
dariober Aug 14, 2023
445cdd8
Several edit to cypress tests
dariober Aug 30, 2023
a1f0f82
Work in progress mostly on feature resizing
dariober Sep 4, 2023
ae67749
Start adding some cypress tests
dariober Aug 14, 2023
6ea1b09
Add tests and refactor
dariober Aug 22, 2023
44b8171
Start adding some cypress tests
dariober Aug 14, 2023
040395e
Remove old test files
dariober Sep 7, 2023
e4134d3
Test cypress-mongodb
dariober Sep 11, 2023
a97f05c
Lower packageExtensions bson version
garrettjstevens Sep 11, 2023
53bd318
Replace mongosh with cypress-mongo
dariober Sep 12, 2023
19ae883
Fix linter
dariober Sep 12, 2023
f555324
Minor tidying up
dariober Sep 12, 2023
54e20d6
Delete template
dariober Sep 18, 2023
1be5797
Edits tests and add workflow
dariober Sep 19, 2023
ef49f0f
Update script; Fix linter
dariober Sep 19, 2023
06a1244
Minor edits to variable names
dariober Sep 19, 2023
d6fc05a
Try setting viewport size; Fix assembly name
dariober Sep 19, 2023
407e6fe
Set viewport in config; Set log level and trigger in workflow
dariober Sep 21, 2023
d3da898
Merge branch 'main' into cypress
dariober Sep 21, 2023
e4ff48c
Tweaks to tests. Add downloads to gitignore
dariober Sep 21, 2023
c18f1e2
Simplify grep
dariober Sep 21, 2023
fdcf244
Add test:ci
dariober Sep 21, 2023
618da78
Replace system call with cypress/ts code. Wait for download
dariober Sep 21, 2023
832c606
Remove unsused import
dariober Sep 21, 2023
75ca64e
Allow retries to reduce false alarms (not ideal)
dariober Sep 21, 2023
ce0a495
Merge feature with end coordinate fixed
dariober Sep 22, 2023
58f04f6
Fix test by simplifing input file and increase waiting
dariober Sep 25, 2023
d41de13
Small cleanups
garrettjstevens Sep 21, 2023
46c10a2
Update Cypress file linting
garrettjstevens Sep 22, 2023
218abaa
Rearrange tests a bit
garrettjstevens Sep 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 7 additions & 45 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,63 +113,25 @@ module.exports = {
],
},
},
// Lint non-src files (e.g. jest.config.js) using a separate tsconfig
// Lint non-src JS files (e.g. jest.config.js) using a separate tsconfig
{
files: ['./packages/jbrowse-plugin-apollo/*.js'],
parserOptions: {
project: 'packages/jbrowse-plugin-apollo/tsconfig.eslint.json',
},
env: { node: true },
},
// Specify Node env for cypress testing files
// Specify Node env and tsconfig for cypress testing and config files
{
files: ['./packages/jbrowse-plugin-apollo/cypress/**/*.js'],
env: { node: true },
},
// Specify Node env for apollo-collaboration-server/
{
files: ['./packages/apollo-collaboration-server/**/*.ts'],
env: { node: true },
},
// Don't enforce tsdoc syntax in JS files
{
files: ['./packages/jbrowse-plugin-apollo/**/*.{ts,tsx}'],
env: { browser: true },
extends: [
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
files: [
'./packages/jbrowse-plugin-apollo/cypress.config.js',
'./packages/jbrowse-plugin-apollo/cypress/**/*.{j,t}s',
],
settings: {
// These settings are from eslint-plugin-react
react: {
// React version. "detect" automatically picks the version you have installed.
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// It will default to "latest" and warn if missing, and to "detect" in the future
version: 'detect',
},
componentWrapperFunctions: [
// The name of any function used to wrap components, e.g. Mobx `observer` function. If this isn't set, components wrapped by these functions will be skipped.
'observer', // `property`
{ property: 'styled' }, // `object` is optional
{ property: 'observer', object: 'Mobx' },
{ property: 'observer', object: '<pragma>' }, // sets `object` to whatever value `settings.react.pragma` is set to
],
},
},
// Lint non-src files (e.g. jest.config.js) using a separate tsconfig
{
files: ['./packages/jbrowse-plugin-apollo/*.js'],
parserOptions: {
project: 'packages/jbrowse-plugin-apollo/tsconfig.eslint.json',
project: 'packages/jbrowse-plugin-apollo/cypress/tsconfig.json',
},
env: { node: true },
},
// Specify Node env for cypress testing files
{
files: ['./packages/jbrowse-plugin-apollo/cypress/**/*.js'],
env: { node: true },
},
// Specify Node env for apollo-collaboration-server/
{
files: ['./packages/apollo-collaboration-server/**/*.ts'],
Expand All @@ -183,4 +145,4 @@ module.exports = {
},
},
],
};
}
42 changes: 42 additions & 0 deletions .github/workflows/cypress_debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Cypress debug
on: workflow_dispatch

jobs:
build:
name: End-to-end test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

- name: Install
run: yarn --immutable

- name: Get latest JBrowse
working-directory: packages/jbrowse-plugin-apollo
run: yarn run jbrowse create --nightly .jbrowse

- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 7
mongodb-replica-set: test-rs

- name: Run tests
working-directory: packages/jbrowse-plugin-apollo
env:
GUEST_USER_ROLE: admin
MONGODB_URI: mongodb://localhost:27017/apolloTestDb
LOG_LEVELS: error,warn,log
run: yarn run test:e2e:debug

- name: Archive test results
if: '!cancelled()'
uses: actions/upload-artifact@v3
with:
name: cypress_results
path: packages/jbrowse-plugin-apollo/cypress
17 changes: 16 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ jobs:
working-directory: packages/apollo-shared
- name: Lint codebase
run: yarn eslint --report-unused-disable-directives --max-warnings 0 --ext .js,.ts,.jsx,.tsx .
- name: Test codebase
- name: Run Jest tests
run: yarn test
- name: Get latest JBrowse
working-directory: packages/jbrowse-plugin-apollo
run: yarn run jbrowse create --nightly .jbrowse
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 7
mongodb-replica-set: test-rs
- name: Run Cypress tests
working-directory: packages/jbrowse-plugin-apollo
env:
GUEST_USER_ROLE: admin
MONGODB_URI: mongodb://localhost:27017/apolloTestDb
LOG_LEVELS: error,warn,log
run: yarn run test:e2e
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ packageExtensions:
dependencies:
"#ansi-styles": "npm:[email protected]"
"#supports-color": "npm:[email protected]"
cypress-mongodb@*:
dependencies:
bson: "^4"
material-ui-popup-state@*:
peerDependencies:
"@emotion/react": "*"
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo-collaboration-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"cypress:start": "GUEST_USER_ROLE=admin MONGODB_URI=mongodb://localhost:27017/apolloTestDb yarn start"
},
"dependencies": {
"@emotion/react": "^11.10.6",
Expand Down
1 change: 1 addition & 0 deletions packages/jbrowse-plugin-apollo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# Cypress specific files
cypress/videos
cypress/screenshots
cypress/downloads
62 changes: 62 additions & 0 deletions packages/jbrowse-plugin-apollo/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
# jbrowse-plugin-apollo

## Testing with cypress

These notes setup cypress and run tests. These notes are likely to change.

- One time step: **Outside** the Apollo dev container
[install cypress](https://docs.cypress.io/guides/getting-started/installing-cypress).
E.g. on your OS terminal (not vscode) run:

```
yarn --cwd packages/jbrowse-plugin-apollo add cypress --dev
yarn --cwd packages/jbrowse-plugin-apollo add cypress-mongodb --dev
```

Add these lines to the `packageExtensions` section of `.yarnrc.yml`:

```
cypress-mongodb@*:
dependencies:
bson: "*"
```

Then run `yarn` again.

---

- Start [jbrowse](https://github.com/GMOD/jbrowse-components): You may want to
pull the latest code to be consistent with the GitHub workflow

```
cd /path/to/jbrowse-components
git pull
yarn --cwd products/jbrowse-web start
```

- Start Apollo server. Within the docker container (_i.e_ within vscode) and in
distinct terminals run:

```
yarn --cwd packages/apollo-shared start
```

```
yarn --cwd packages/apollo-collaboration-server run cypress:start
```

```
yarn --cwd packages/jbrowse-plugin-apollo start
```

If above you change the name fo the test database (`apolloTestDb`), change
accordingly in `commands.ts`

- Open cypress in the testing directory, _i.e._ where yo have the relevant
`package.json`. Typically (again outside the dev container/vscode):

```
yarn --cwd packages/jbrowse-plugin-apollo run cypress open
```

- For end-to-end testing, click "E2E Testing" `->` Chrome `->`
`Start E2E Testing`. Click on one of the available test scripts.
37 changes: 33 additions & 4 deletions packages/jbrowse-plugin-apollo/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
module.exports = {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { defineConfig } = require('cypress')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { configurePlugin } = require('cypress-mongodb')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('node:fs')

module.exports = defineConfig({
// Make viewport long and thin to avoid the scrollbar on the right intefere
// with the coordinates
viewportHeight: 2000,
viewportWidth: 1000,
retries: {
runMode: 2,
},
env: {
mongodb: {
uri: 'mongodb://localhost:27017/?directConnection=true',
database: 'apolloTestDb',
},
},
screenshotOnRunFailure: false,
video: false,
e2e: {
setupNodeEvents(_on, _config) {
// implement node event listeners here
baseUrl: 'http://localhost:8999',
setupNodeEvents(on, config) {
configurePlugin(on)
on('task', {
readdirSync(path) {
return fs.readdirSync(path)
},
})
return config
},
},
}
})
46 changes: 46 additions & 0 deletions packages/jbrowse-plugin-apollo/cypress/e2e/addAssembly.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
describe('Add Assembly', () => {
beforeEach(() => {
cy.deleteAssemblies()
cy.loginAsGuest()
})

it('Can add assembly from fasta', () => {
cy.contains('Apollo').click()
cy.contains('Add Assembly').click()
cy.get('input[type="TextField"]').type('volvox_deleteme')
cy.get('input[value="text/x-fasta"]').check()
cy.get('input[type="file"]').selectFile('test_data/volvox.fa')

cy.intercept('/changes').as('changes')
cy.contains('Submit').click()
cy.contains('is being added', { timeout: 10_000 })
cy.wait('@changes').its('response.statusCode').should('match', /2../)
})

it('Can add assembly from gff3 with fasta', () => {
cy.contains('Apollo').click()
cy.contains('Add Assembly').click()
cy.get('input[type="TextField"]').type('volvox_deleteme')
cy.get('input[value="text/x-gff3"]').check()
cy.get('input[type="file"]').selectFile('test_data/volvox.fasta.gff3')

cy.intercept('/changes').as('changes')
cy.contains('Submit').click()
cy.contains('is being added', { timeout: 10_000 })
cy.wait('@changes').its('response.statusCode').should('match', /2../)
})

it('FIXME: Can add assembly from 2bit', () => {
cy.contains('Apollo').click()
cy.contains('Add Assembly').click()
cy.get('input[type="TextField"]').type('volvox_deleteme')
cy.get('input[value="text/x-fasta"]').check()
cy.get('input[type="file"]').selectFile('test_data/volvox.2bit')

cy.intercept('/changes').as('changes')
cy.contains('Submit').click()
cy.contains('is being added', { timeout: 10_000 })
// Should match /2../ instead
cy.wait('@changes').its('response.statusCode').should('match', /4../)
})
})
16 changes: 0 additions & 16 deletions packages/jbrowse-plugin-apollo/cypress/e2e/apollo.cy.ts

This file was deleted.

40 changes: 40 additions & 0 deletions packages/jbrowse-plugin-apollo/cypress/e2e/downloadGff.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
describe('Download GFF', () => {
beforeEach(() => {
cy.exec(`rm ${Cypress.config('downloadsFolder')}/*_apollo.gff3`, {
failOnNonZeroExit: false,
}).then((result) => {
cy.log(result.stderr)
})
cy.deleteAssemblies()
cy.loginAsGuest()
})

it('Can download gff', () => {
cy.addAssemblyFromGff('volvox.fasta.gff3', 'test_data/volvox.fasta.gff3')
cy.get('button[data-testid="dropDownMenuButton"]')
.contains('Apollo')
.click()
cy.contains('Download GFF3').click()
cy.focused()
.contains('Select assembly')
.parent()
.within(() => {
cy.get('input').parent().click()
})
cy.contains('volvox.fasta.gff3').click()
cy.get('button').contains('Download').click()

// We don't know when the download is done
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(4000)
cy.task('readdirSync', Cypress.config('downloadsFolder')).then((out) => {
const gff = out as string
cy.readFile(`${Cypress.config('downloadsFolder')}/${gff[0]}`).then(
(x: string) => {
const lines: string[] = x.trim().split('\n')
expect(lines.length).eq(247)
},
)
})
})
})
Loading
Loading