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

Update: Migrate tests to Jest #199

Merged
merged 5 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
19 changes: 7 additions & 12 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Configuration for Babel transpilation
{
"presets": [
["es2015", { "modules": false }],
Expand All @@ -21,17 +20,13 @@
},
"test": {
"plugins": [
["istanbul", {
"exclude": [
"src/polyfill.js",
"**/*-test.js",
"build/**",
"docs/**",
"lib'**"
]
}],
["babel-plugin-transform-require-ignore", { "extensions": [".scss"] }]
"transform-es2015-modules-commonjs",
[
"babel-plugin-transform-require-ignore", {
"extensions": [".scss", ".css"]
}
]
]
},
}
}
}
10 changes: 6 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
"es6": true,
"browser": true,
"mocha": true,
"commonjs": true
"commonjs": true,
"jest": true
},
"globals": {
"after": false,
"afterAll": false,
"afterEach": false,
"before": false,
"beforeAll": false,
"beforeEach": false,
"describe": false,
"expect": false,
Expand All @@ -27,7 +28,8 @@
"Feature": false,
"Before": false,
"After": false,
"Scenario": false
"Scenario": false,
"jest": false
},
"rules": {
"quotes": [
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Install the following plugins in your preferred editor

* `yarn run build` to generate resource bundles and JS webpack bundles.
* `yarn run watch` to only generate JS webpack bundles on file changes.
* `yarn run test` launches karma tests with PhantomJS.
* `yarn run test` launches jest tests with PhantomJS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does jest also use phantom? I only see it being removed in configs/ package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove it!

* `yarn run test -- --src=PATH/TO/SRC/FILENAME` launches test only for `src/PATH/TO/SRC/__tests__/FILENAME-test.js` instead of all tests. For example, `yarn run test -- --src=doc/DocAnnotator` launches tests for `src/doc/__tests__/DocAnnotator-test.js`. This also works for directories, e.g. `yarn run test -- --src=doc/`.
* `yarn run debug` launches karma tests with PhantomJS for debugging. Open the URL mentioned in the console.
* `yarn run debug` launches jest tests with PhantomJS for debugging. Open the URL mentioned in the console.
* `yarn run debug -- --src=path/to/src/FILENAME` launches debugging for `src/path/to/src/__tests__/FILENAME-test.js` instead of all tests. Open the URL mentioned in the console.

For more script commands see `package.json`. Test coverage reports are available under reports/coverage.
Expand Down
117 changes: 0 additions & 117 deletions build/karma.conf.js

This file was deleted.

15 changes: 0 additions & 15 deletions build/webpack.karma.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions docs/dev-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Install the following plugins in your preferred editor

* `yarn run build` to generate resource bundles and JS webpack bundles.
* `yarn run watch` to only generate JS webpack bundles on file changes.
* `yarn run test` launches karma tests with PhantomJS.
* `yarn run test` launches jest tests with PhantomJS.
* `yarn run test -- --src=PATH/TO/SRC/FILENAME` launches test only for `src/PATH/TO/SRC/__tests__/FILENAME-test.js` instead of all tests. For example, `yarn run test -- --src=doc/DocAnnotator` launches tests for `src/doc/__tests__/DocAnnotator-test.js`. This also works for directories, e.g. `yarn run test -- --src=doc/`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest can filter by default right? We can remove all of this -- --src business

* `yarn run debug` launches karma tests with PhantomJS for debugging. Open the URL mentioned in the console.
* `yarn run debug` launches jest tests with PhantomJS for debugging. Open the URL mentioned in the console.
* `yarn run debug -- --src=path/to/src/FILENAME` launches debugging for `src/path/to/src/__tests__/FILENAME-test.js` instead of all tests. Open the URL mentioned in the console.

For more script commands see `package.json`. Test coverage reports are available under reports/coverage.
49 changes: 30 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.3",
"babel-jest": "^23.4.2",
"babel-loader": "^7.1.2",
"babel-plugin-istanbul": "^4.1.6",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
Expand All @@ -38,6 +38,7 @@
"conventional-github-releaser": "^2.0.0",
"css-loader": "^0.28.7",
"cssnano-cli": "^1.0.5",
"enzyme-to-json": "^3.3.4",
"eslint": "^4.12.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.9.0",
Expand All @@ -50,22 +51,8 @@
"fetch-mock": "^6.0.0",
"fetch-mock-forwarder": "^1.0.0",
"husky": "^0.14.3",
"karma": "^2.0.0",
"karma-chai": "^0.1.0",
"karma-chai-dom": "^1.1.0",
"karma-chai-sinon": "^0.1.5",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-fixture": "^0.2.6",
"karma-html2js-preprocessor": "^1.1.0",
"karma-junit-reporter": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sinon": "^1.0.5",
"karma-sinon-stub-promise": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.6",
"jest": "^23.5.0",
"jest-canvas-mock": "^1.1.0",
"lint-staged": "^7.0.4",
"mocha": "^5.1.1",
"node-noop": "^1.0.0",
Expand Down Expand Up @@ -94,8 +81,8 @@
"scripts": {
"build": "yarn install && BABEL_ENV=production NODE_ENV=production CI=1 node --max_old_space_size=4096 ./node_modules/webpack/bin/webpack.js -p --progress --colors --config build/webpack.config.js",
"watch": "yarn install && BABEL_ENV=dev NODE_ENV=dev ./node_modules/.bin/webpack --watch --progress --colors --config build/webpack.config.js",
"test": "yarn install && NODE_ENV=test ./node_modules/.bin/karma start build/karma.conf.js",
"debug": "yarn install && NODE_ENV=test ./node_modules/.bin/karma start build/karma.conf.js --no-single-run --auto-watch",
"test": "yarn install && NODE_ENV=test yarn run jest",
"debug": "yarn install && NODE_ENV=test yarn run jest --watch",
"setup-travis": "cd functional-tests && yarn install && node app.js",
"selenium-build": "BABEL_ENV=production NODE_ENV=production CI=1 node --max_old_space_size=4096 ./node_modules/webpack/bin/webpack.js -p --progress --colors --config build/webpack.selenium.config.js",
"functional-tests": "node functional-tests/app.js & node ./node_modules/codeceptjs/bin/codecept.js run --steps",
Expand All @@ -120,5 +107,29 @@
"prettier-eslint --print-width 120 --single-quote --tab-width 4 --write",
"git add"
]
},
"jest": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to break this out in a separate config file like we did for karma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this actually needs to be in package.json

"clearMocks": true,
"globals": {
"__NAME__": "name",
"__VERSION__": "version"
},
"setupFiles": [
"jest-canvas-mock"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test-utils/fileMock.js",
"\\.(css|less|html)$": "<rootDir>/test-utils/styleMock.js"
},
"transformIgnorePatterns": [
"node_modules/(?!(box-react-ui)/)"
],
"collectCoverage": false,
"coverageDirectory": "<rootDir>/reports",
"collectCoverageFrom": [
"src/**/*.js",
"!**/node_modules/**",
"!**/__tests__/**"
]
}
}
7 changes: 0 additions & 7 deletions src/__tests__/AnnotationDialog-test.html

This file was deleted.

Loading