Skip to content

Commit

Permalink
Chore: Replace karma with Jest for testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Aug 15, 2018
1 parent a71ecb6 commit 36cd579
Show file tree
Hide file tree
Showing 9 changed files with 916 additions and 1,534 deletions.
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.
* `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
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/`.
* `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.
45 changes: 26 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,7 @@
"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",
"lint-staged": "^7.0.4",
"mocha": "^5.1.1",
"node-noop": "^1.0.0",
Expand Down Expand Up @@ -94,8 +80,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 +106,26 @@
"prettier-eslint --print-width 120 --single-quote --tab-width 4 --write",
"git add"
]
},
"jest": {
"clearMocks": true,
"globals": {
"__NAME__": "name",
"__VERSION__": "version"
},
"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)$": "<rootDir>/test-utils/styleMock.js"
},
"transformIgnorePatterns": [
"node_modules/(?!(box-react-ui)/)"
],
"collectCoverage": false,
"coverageDirectory": "<rootDir>/reports",
"collectCoverageFrom": [
"src/**/*.js",
"!**/node_modules/**",
"!**/__tests__/**"
]
}
}
7 changes: 7 additions & 0 deletions test-utils/enzyme-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'raf/polyfill';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
3 changes: 3 additions & 0 deletions test-utils/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// __mocks__/fileMock.js

module.exports = 'test-file-stub';
3 changes: 3 additions & 0 deletions test-utils/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// __mocks__/styleMock.js

module.exports = {};
Loading

0 comments on commit 36cd579

Please sign in to comment.