Skip to content

Commit

Permalink
e2e: improve local setup
Browse files Browse the repository at this point in the history
  • Loading branch information
karolina-siemieniuk-morawska committed Jan 30, 2024
1 parent 818565a commit 7b55463
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 52 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,17 @@ Note that `jest` automatically run tests that changed files (unstaged) affect.

### cypress (e2e)

Runs everything from scratch, identical to CI

```bash
$ sh cypress-tests.sh # runs everything from scratch, identical to CI
$ sh cypress-tests-chrome.sh
$ sh cypress-tests-firefox.sh
```

Opens cypress runner GUI runs them against local dev server (localhost:8080)
```bash
$ cd e2e
$ yarn test:dev # open cypress runner GUI runs them against local dev server (localhost:3000)
$ yarn test:dev
$ yarn test:dev --env inspirehep_url=<any url that serves inspirehep ui>
```

Expand All @@ -308,12 +314,9 @@ If required, tests can run against `localhost:3000` by simply modifying `--host`

#### working with (visual) tests more efficiently

(TODO: improve DX)

You may not always need to run tests exactly like on the CI environment.

- To run specific suite, just change `test` script in `e2e/package.json` temporarily to `cypress run --spec cypress/integration/<spec.test.js>`
- To enable mounting `backend` code and live update, just use `e2e/docker-compose.cypress.dev.yml` instead.

## How to import records

Expand Down
12 changes: 12 additions & 0 deletions cypress-tests-setup.sh → cypress-tests-chrome.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rc=0
files="-f docker-compose.yml -f ./e2e/docker-compose.cypress.yml"

(docker-compose $files build --parallel) &
Expand All @@ -18,3 +19,14 @@ wait %1
wait %2
wait %3
wait %4

# import data
docker-compose $files exec hep-web ./scripts/setup
docker-compose $files exec next-web inspirehep db create
docker-compose $files exec hep-web inspirehep importer demo-records

# run tests
docker-compose $files run -w "/tests" --rm cypress bash -c "yarn && yarn test --browser chrome --headless --env inspirehep_url=http://ui:8080" || rc=$?
docker-compose $files logs --no-color > cypress-containers.log

exit $rc
5 changes: 0 additions & 5 deletions cypress-tests-data.sh

This file was deleted.

32 changes: 32 additions & 0 deletions cypress-tests-firefox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
rc=0
files="-f docker-compose.yml -f ./e2e/docker-compose.cypress.yml"

(docker-compose $files build --parallel) &

# run installs sequantially until we move different cache foreach
# https://github.com/yarnpkg/yarn/issues/7087#issuecomment-719434163
(cd ui && yarn install)
(cd record-editor && yarn install)

(cd ui && yarn build) &
(cd record-editor && yarn build) &

wait %1 # wait for docker-compose build before up
docker-compose $files up -d --force-recreate &

# wait for everything
wait %1
wait %2
wait %3
wait %4

# import data
docker-compose $files exec hep-web ./scripts/setup
docker-compose $files exec next-web inspirehep db create
docker-compose $files exec hep-web inspirehep importer demo-records

# run tests
docker-compose $files run -w "/tests" --rm cypress bash -c "yarn && yarn test --browser firefox --headless --env inspirehep_url=http://ui:8080" || rc=$?
docker-compose $files logs --no-color > cypress-containers.log

exit $rc
7 changes: 0 additions & 7 deletions cypress-tests-run-chrome.sh

This file was deleted.

7 changes: 0 additions & 7 deletions cypress-tests-run-firefox.sh

This file was deleted.

3 changes: 0 additions & 3 deletions cypress-tests.sh

This file was deleted.

4 changes: 1 addition & 3 deletions e2e/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = defineConfig({
videosFolder: 'cypress/__videos__',
screenshotsFolder: 'cypress/__screenshots__',
env: {
inspirehep_url: 'localhost:3000',
inspirehep_url: 'localhost:8080',
mobile_viewport_width: 375,
mobile_viewport_height: 667,
},
Expand All @@ -20,7 +20,5 @@ module.exports = defineConfig({
},
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
experimentalRunAllSpecs: true,
experimentalMemoryManagement: true,
numTestsKeptInMemory: 0
},
})
5 changes: 0 additions & 5 deletions e2e/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ const {

module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, launchOptions) => {
if (browser.name == 'chrome') {
launchOptions.args.push('--disable-gpu')
launchOptions.args.push('--disable-dev-shm-usage');
launchOptions.args.push('--js-flags="--max_old_space_size=8192 --max_semi_space_size=8192"');
}
return launchOptions
}),
addMatchImageSnapshotPlugin(on, config);
Expand Down
14 changes: 0 additions & 14 deletions e2e/docker-compose.cypress.dev.yml

This file was deleted.

4 changes: 2 additions & 2 deletions e2e/docker-compose.cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2.1'

services:
cypress:
image: cypress/included:12.17.0
image: cypress/included:13.0.0
volumes:
- ./e2e:/tests
environment:
Expand All @@ -19,7 +19,7 @@ services:
ports:
- '8080:8080'
volumes:
- ./ui/docker/nginx/config/e2e.conf:/etc/nginx/conf.d/default.conf
- ./ui/docker/nginx/config/local.conf:/etc/nginx/conf.d/default.conf
depends_on:
- hep-web
- next-web
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test:dev": "cypress open",
"test": "cypress run",
"test": "cypress run --browser chrome",
"cypress": "cypress"
},
"author": "",
Expand Down

0 comments on commit 7b55463

Please sign in to comment.