Skip to content

Commit

Permalink
feat(OHIFv3):Add static e2e data (#2665)
Browse files Browse the repository at this point in the history
This change wraps the E2E test data into a github repository, which is then included in the test builds as static data.
That makes running the e2e tests as simple as:
yarn test:e2e:server
yarn test:e2e

without any need to have docker etc installed/running.
  • Loading branch information
wayfarer3130 authored Jan 31, 2022
1 parent 72bb074 commit 0e2c319
Show file tree
Hide file tree
Showing 14 changed files with 887 additions and 107 deletions.
18 changes: 8 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ executors:
# Custom executor to override Cypress config
deploy-to-prod-executor:
docker:
- image: 'cypress/browsers:node14.15.0-chrome86-ff82'
- image: cimg/node:14.18
environment:
CYPRESS_BASE_URL: https://ohif-staging.netlify.com/
chrome-and-pacs:
docker:
# Primary container image where all steps run.
- image: 'cypress/browsers:node14.15.0-chrome86-ff82'
- image: 'ohif/viewer-testdata:0.1-test'

defaults: &defaults
docker:
- image: circleci/node:14.15.0
- image: cimg/node:14.18-browsers
environment:
TERM: xterm # Enable colors in term
QUICK_BUILD: true
Expand Down Expand Up @@ -335,15 +334,14 @@ workflows:
browser: chrome
pre-steps:
- run: |
# Clear yarn cache; update to latest
# Clear yarn cache; use yarn from image (update image to update yarn)
rm -rf ~/.yarn
npm i -g yarn
yarn -v
yarn: true
record: true
store_artifacts: true
working_directory: platform/viewer
build: npx cross-env QUICK_BUILD=true APP_CONFIG=config/dicomweb-server.js yarn run build
build: yarn test:data
start: yarn run test:e2e:serve
spec: 'cypress/integration/**/*'
wait-on: 'http://localhost:3000'
Expand All @@ -369,12 +367,12 @@ workflows:
executor: cypress/browsers-chrome76
browser: chrome
pre-steps:
- run: 'rm -rf ~/.yarn && npm i -g yarn && yarn -v && yarn global
add wait-on' # Use yarn latest
- run: 'rm -rf ~/.yarn && yarn -v && yarn global
add wait-on'
yarn: true
store_artifacts: false
working_directory: platform/viewer
build: npx cross-env QUICK_BUILD=true APP_CONFIG=config/dicomweb-server.js yarn run build
build: yarn test:data && npx cross-env QUICK_BUILD=true APP_CONFIG=config/dicomweb-server.js yarn run build
# start server --> verify running --> percy + chrome + cypress
command: yarn run test:e2e:dist
cache-key: 'yarn-packages-{{ checksum "yarn.lock" }}'
Expand Down Expand Up @@ -436,7 +434,7 @@ workflows:
yarn: true
store_artifacts: false
working_directory: platform/viewer
build: npx cross-env QUICK_BUILD=true APP_CONFIG=config/dicomweb-server.js yarn run build
build: npx cross-env QUICK_BUILD=true APP_CONFIG=config/e2e.js yarn run build
# start server --> verify running --> percy + chrome + cypress
command: yarn run test:e2e:dist
cache-key: 'yarn-packages-{{ checksum "yarn.lock" }}'
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "testdata"]
path = testdata
url = https://github.com/OHIF/viewer-testdata-dicomweb.git
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.18.0
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class StaticWadoClient extends api.DICOMwebClient {
"StudyDescription": "00081030",
"StudyDate": "00080020",
"ModalitiesInStudy": "00080061",
AccessionNumber: "00080050",
};

constructor(qidoConfig) {
Expand Down Expand Up @@ -66,7 +67,16 @@ export default class StaticWadoClient extends api.DICOMwebClient {
actual = actual.Alphabetic;
}
if (typeof (actual) == 'string') {
return actual.indexOf(desired) != -1;
if (actual.length === 0) return true;
if (desired.length === 0 || desired === '*') return true;
if (desired[0] === '*' && desired[desired.length - 1] === '*') {
console.log(`Comparing ${actual} to ${desired.substring(1, desired.length - 1)}`)
return actual.indexOf(desired.substring(1, desired.length - 1)) != -1;
} else if (desired[desired.length - 1] === '*') {
return actual.indexOf(desired.substring(0, desired.length - 1)) != -1;
} else if (desired[0] === '*') {
return actual.indexOf(desired.substring(1)) === actual.length - desired.length + 1;
}
}
return desired === actual;
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
"orthanc:up": "docker-compose -f .docker/Nginx-Orthanc/docker-compose.yml up",
"start": "yarn run dev",
"test": "yarn run test:unit",
"test:data": "git submodule update --init",
"test-watch": "jest --collectCoverage --watchAll",
"test:unit": "jest --collectCoverage",
"test:unit:ci": "lerna run test:unit:ci --parallel --stream",
"test:e2e": "lerna run test:e2e --stream",
"test:e2e:ci": "lerna run test:e2e:ci --stream",
"test:e2e:dist": "lerna run test:e2e:dist --stream",
"test:e2e:serve": "lerna run test:e2e:serve --stream",
"test:e2e:serve": "yarn test:data && lerna run test:e2e:serve --stream",
"see-changed": "lerna changed",
"docs:preview": "lerna run docs:preview --stream",
"docs:publish": "chmod +x ./build-and-publish-docs.sh && ./build-and-publish-docs.sh",
Expand Down Expand Up @@ -115,7 +116,7 @@
"unused-webpack-plugin": "2.4.0",
"webpack": "^5.50.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2",
"webpack-dev-server": "4.7.3",
"webpack-hot-middleware": "^2.25.0",
"webpack-merge": "^5.7.3",
"workbox-webpack-plugin": "^6.1.5",
Expand Down
41 changes: 25 additions & 16 deletions platform/docs/docs/development/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,14 @@ Running unit test will generate a report at the end showing the successful and
unsuccessful tests with detailed explanations.

## End-to-end test

For running the OHIF e2e test you need to run the following steps:

- Create a mini-pacs for OHIF to access the images for testing. We download and
run our lightweight implementation which provides a collection of DICOM
studies ([source code][mini-pacs]).

```bash
docker run -p 5985:5985 -p 5984:5984 -e USE_POUCHDB=true -e DB_SERVER=http://0.0.0.0 ohif/viewer-testdata:0.1-test
```

Successful execution should be

![](../assets/img/docker-pacs.png)

- Open a new terminal, navigate to the OHIF project, and run OHIF with the
dicom-server config
e2e config. The test:data only needs to be run once and checks the data out.

```bash
APP_CONFIG=config/dicomweb-server.js yarn start
yarn test:data
APP_CONFIG=config/e2e.js yarn start
```

You should be able to see test studies in the study list
Expand All @@ -53,7 +41,7 @@ For running the OHIF e2e test you need to run the following steps:
- Open a new terminal inside the OHIF project, and run the e2e cypress test

```bash
yarn run test:e2e
yarn test:e2e
```

You should be able to see the cypress window open
Expand All @@ -67,6 +55,27 @@ For running the OHIF e2e test you need to run the following steps:

![e2e-cypress-final](../assets/img/e2e-cypress-final.png)

## Test Data
The testing data is stored in two OHIF repositories. The first contains the
binary DICOM data, at [viewer-testdata](https://github.com/OHIF/viewer-testdata.git)
while the second module contains data in the DICOMweb format, installed as a submodule
into OHIF in the `testdata` directory. This is retrieved via the command
```bash
yarn test:data
```
or the equivalent command `git submodule update --init`
When adding new data, run:
```
npm install -g dicomp10-to-dicomweb
mkdicomweb -d dicomweb dcm
```
to update the local dicomweb submodule in viewer-testdata. Then, commit
that data and update the submodules used in OHIF and in the viewer-testdata
parent modules.

All data MUST be fully anonymized and allowed to be used for open access.
Any attributions should be included in the DCM directory.

## Testing Philosophy

> Testing is an opinionated topic. Here is a rough overview of our testing
Expand Down
41 changes: 37 additions & 4 deletions platform/viewer/.webpack/webpack.pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ const PROXY_DOMAIN = process.env.PROXY_DOMAIN;
const ENTRY_TARGET = process.env.ENTRY_TARGET || `${SRC_DIR}/index.js`;
const Dotenv = require('dotenv-webpack');

const setHeaders = (res, path) => {
res.setHeader('Content-Type', 'text/plain')
if (path.indexOf('.gz') !== -1) {
res.setHeader('Content-Encoding', 'gzip')
} else if (path.indexOf('.br') !== -1) {
res.setHeader('Content-Encoding', 'br')
}
}

module.exports = (env, argv) => {
const baseConfig = webpackBase(env, argv, { SRC_DIR, DIST_DIR });
const isProdBuild = process.env.NODE_ENV === 'production';
Expand All @@ -36,7 +45,7 @@ module.exports = (env, argv) => {
path: DIST_DIR,
filename: isProdBuild ? '[name].bundle.[chunkhash].js' : '[name].js',
publicPath: PUBLIC_URL, // Used by HtmlWebPackPlugin for asset prefix
devtoolModuleFilenameTemplate: function(info) {
devtoolModuleFilenameTemplate: function (info) {
if (isProdBuild) {
return `webpack:///${info.resourcePath}`;
} else {
Expand Down Expand Up @@ -110,8 +119,32 @@ module.exports = (env, argv) => {
hot: true,
open: true,
port: 3000,
host: '0.0.0.0',
public: 'http://localhost:' + 3000,
client: {
overlay: { errors: true, warnings: false },
},
'static': [
{
directory: path.join(require('os').homedir(), 'dicomweb'),
staticOptions: {
extensions: ['gz', 'br'],
index: "index.json.gz",
redirect: true,
setHeaders,
},
publicPath: '/dicomweb',
},
{
directory: '../../testdata',
staticOptions: {
extensions: ['gz', 'br'],
index: "index.json.gz",
redirect: true,
setHeaders,
},
publicPath: '/viewer-testdata',
},
],
//public: 'http://localhost:' + 3000,
//writeToDisk: true,
historyApiFallback: {
disableDotRule: true,
Expand All @@ -124,7 +157,7 @@ module.exports = (env, argv) => {
});

if (hasProxy) {
mergedConfig.devServer.proxy = {};
mergedConfig.devServer.proxy = mergedConfig.devServer.proxy || {};
mergedConfig.devServer.proxy[PROXY_TARGET] = PROXY_DOMAIN;
}

Expand Down
15 changes: 11 additions & 4 deletions platform/viewer/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,17 @@ Cypress.Commands.add('waitDicomImage', (timeout = 50000) => {

element.addEventListener('cornerstoneimagerendered', onEvent);
};
$cornerstone.events.addEventListener(
'cornerstoneelementenabled',
onEnabled
);
const enabledElements = $cornerstone.getEnabledElements();
if (enabledElements && enabledElements.length && !enabledElements[0].invalid) {
// Sometimes the page finishes rendering before this gets run,
// if so, just resolve immediately.
resolve();
} else {
$cornerstone.events.addEventListener(
'cornerstoneelementenabled',
onEnabled
);
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion platform/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"test:e2e:ci": "percy exec -- cypress run --config video=false --record --browser chrome --spec 'cypress/integration/visual-regression/**/*'",
"test:e2e:local": "cypress run --config video=false --browser chrome --spec 'cypress/integration/common/**/*,cypress/integration/pwa/**/*'",
"test:e2e:dist": "start-server-and-test test:e2e:serve http://localhost:3000 test:e2e:ci",
"test:e2e:serve": "serve -n -l 3000 -s dist",
"test:e2e:serve": "cross-env APP_CONFIG=config/e2e.js yarn start",
"test:unit": "jest --watchAll",
"test:unit:ci": "jest --ci --runInBand --collectCoverage",
"ci:generateSuccessVersion": "node -p -e \"require('./package.json').version\" > success_version.txt"
Expand Down
Loading

0 comments on commit 0e2c319

Please sign in to comment.