Skip to content

Add Jest #12

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/containers/LanguageProvider/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { translationMessages } from '../../../i18n';
describe('<LanguageProvider />', () => {
let store;

before(() => {
beforeAll(() => {
store = configureStore({}, browserHistory);
});

Expand Down
2 changes: 1 addition & 1 deletion app/containers/LocaleToggle/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { translationMessages } from '../../../i18n';
describe('<LocaleToggle />', () => {
let store;

before(() => {
beforeAll(() => {
store = configureStore({}, browserHistory);
});

Expand Down
4 changes: 2 additions & 2 deletions app/utils/tests/asyncInjectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('asyncInjectors', () => {
let store;

describe('getAsyncInjectors', () => {
before(() => {
beforeAll(() => {
store = configureStore({}, createMemoryHistory);
});

Expand Down Expand Up @@ -72,7 +72,7 @@ describe('asyncInjectors', () => {
});

describe('helpers', () => {
before(() => {
beforeAll(() => {
store = configureStore({}, createMemoryHistory);
});

Expand Down
1 change: 1 addition & 0 deletions internals/mocks/cssModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'CSS_MODULE';
1 change: 1 addition & 0 deletions internals/mocks/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'IMAGE_MOCK';
23 changes: 23 additions & 0 deletions internals/testing/preprocessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const tsc = require('typescript');
const tsConfig = require('../../tsconfig.json');
const babelJest = require('babel-jest');

module.exports = {
process(src, path) {
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
return tsc.transpile(
src,
Object.assign({}, tsConfig.compilerOptions, {
module: tsc.ModuleKind.CommonJS,
jsx: tsc.JsxEmit.React,
}),
path,
[]
);
}
if (path.endsWith('.js') || path.endsWith('.jsx')) {
return babelJest.process(src, path);
}
return src;
},
};
9 changes: 9 additions & 0 deletions internals/testing/test-bundler.jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// needed for regenerator-runtime
// (ES7 generator support is required by redux-saga)
import 'babel-polyfill';

// If we need to use Chai, we'll have already chaiEnzyme loaded
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';
chai.use(chaiEnzyme());

63 changes: 60 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"test:firefox": "npm run test -- --browsers Firefox",
"test:safari": "npm run test -- --browsers Safari",
"test:ie": "npm run test -- --browsers IE",
"test:jest": "cross-env NODE_ENV=test jest --coverage",
"test:jest:watch": "cross-env NODE_ENV=test jest --watchAll",
"coveralls": "cat ./coverage/lcov/lcov.info | coveralls"
},
"lint-staged": {
Expand All @@ -70,9 +72,11 @@
"babel": {
"presets": [
[
"es2015",
"latest",
{
"modules": false
"es2015": {
"modules": false
}
}
],
"react",
Expand All @@ -91,7 +95,9 @@
},
"test": {
"plugins": [
"istanbul"
"istanbul",
"transform-es2015-modules-commonjs",
"dynamic-import-node"
]
}
}
Expand All @@ -103,6 +109,7 @@
"browser": true,
"node": true,
"mocha": true,
"jest": true,
"es6": true
},
"plugins": [
Expand Down Expand Up @@ -222,6 +229,49 @@
"eventsource-polyfill"
]
},
"jest": {
"collectCoverageFrom": [
"app/**/*.{js,jsx,ts,tsx}",
"!app/**/*.d.ts",
"!app/**/*.test.{js,jsx,ts,tsx}",
"!app/*/RbGenerated*/*.{js,jsx,ts,tsx}",
"!app/app.tsx",
"!app/routes.tsx"
],
"coverageThreshold": {
"global": {
"statements": 98,
"branches": 91,
"functions": 98,
"lines": 98
}
},
"moduleDirectories": [
"node_modules",
"app"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"modulePaths": [
"<rootDir>"
],
"moduleNameMapper": {
".*\\.(css|less|styl|scss|sass)$": "<rootDir>/internals/mocks/cssModule.js",
".*\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/internals/mocks/image.js"
},
"setupTestFrameworkScriptFile": "<rootDir>/internals/testing/test-bundler.jest.js",
"transform": {
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/internals/testing/preprocessor.js"
},
"testMatch": [
"**/tests/*.test.{ts,tsx,js,jsx}"
]
},
"dependencies": {
"babel-polyfill": "^6.22.0",
"chalk": "1.1.3",
Expand Down Expand Up @@ -261,6 +311,7 @@
"@types/express": "^4.0.35",
"@types/fontfaceobserver": "0.0.5",
"@types/invariant": "^2.2.28",
"@types/jest": "^19.2.2",
"@types/lodash": "^4.14.61",
"@types/mocha": "^2.2.40",
"@types/react": "^15.0.21",
Expand All @@ -283,14 +334,18 @@
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-eslint": "^7.1.1",
"babel-jest": "^19.0.0",
"babel-loader": "^6.4.1",
"babel-plugin-dynamic-import-node": "^1.0.1",
"babel-plugin-istanbul": "^4.1.1",
"babel-plugin-react-intl": "^2.3.1",
"babel-plugin-react-transform": "2.0.2",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-plugin-transform-react-constant-elements": "^6.23.0",
"babel-plugin-transform-react-inline-elements": "^6.22.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-react-hmre": "1.1.1",
"babel-preset-stage-0": "^6.24.1",
Expand Down Expand Up @@ -318,6 +373,7 @@
"html-webpack-plugin": "^2.28.0",
"image-webpack-loader": "^3.3.0",
"imports-loader": "^0.7.1",
"jest-cli": "^19.0.2",
"json-loader": "0.5.4",
"karma": "^1.6.0",
"karma-chrome-launcher": "2.0.0",
Expand All @@ -343,6 +399,7 @@
"psi": "^3.0.0",
"react-addons-test-utils": "~15.4.2",
"react-hot-loader": "^1.3.0",
"react-test-renderer": "15.4.2",
"rimraf": "^2.6.1",
"shelljs": "^0.7.7",
"sinon": "^2.1.0",
Expand Down
Loading