From 8f923574f19d5cbc931e0d571b6e4d1619af2aa5 Mon Sep 17 00:00:00 2001 From: Eric Ferraiuolo Date: Mon, 31 Oct 2016 16:41:27 -0400 Subject: [PATCH] Switch to Jest for running tests --- .eslintrc | 2 +- .gitignore | 1 - package.json | 43 ++++++++++++++++--------- src/.babelrc | 9 +----- test/functional/index.js | 13 ++++---- test/functional/locale-data.js | 3 +- test/functional/{ => support}/build.js | 2 +- test/functional/{ => support}/format.js | 0 test/unit/components/provider.js | 4 +-- 9 files changed, 41 insertions(+), 36 deletions(-) rename test/functional/{ => support}/build.js (91%) rename test/functional/{ => support}/format.js (100%) diff --git a/.eslintrc b/.eslintrc index bb22a0f0fd..d1e9731324 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,7 @@ "es6": true, "node": true, "browser": true, - "mocha": true + "jest": true }, "plugins": [ "react" diff --git a/.gitignore b/.gitignore index f20d920041..9136ad065b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.nyc_output/ coverage/ dist/ lib/ diff --git a/package.json b/package.json index bbb13208c0..34ef5ea41b 100644 --- a/package.json +++ b/package.json @@ -39,12 +39,29 @@ "browserify-shim": { "react": "global:React" }, - "nyc": { - "exclude": [ - "src/en.js" + "jest": { + "testRegex": "/test/(unit|functional)/.*\\.js", + "testPathIgnorePatterns": [ + "/test/functional/support/" ], - "instrument": false, - "sourceMap": false + "collectCoverageFrom": [ + "src/**/*.js", + "!src/en.js" + ], + "coverageReporters": [ + "lcov", + "text", + "text-summary", + "html" + ], + "coverageThreshold": { + "global": { + "branches": 85, + "functions": 100, + "lines": 95, + "statements": 95 + } + } }, "dependencies": { "intl-format-cache": "^2.0.5", @@ -58,7 +75,7 @@ "devDependencies": { "babel-cli": "^6.2.0", "babel-eslint": "^6.1.2", - "babel-plugin-istanbul": "^2.0.0", + "babel-jest": "^16.0.0", "babel-plugin-react-intl": "^2.0.0", "babel-plugin-transform-class-properties": "^6.11.5", "babel-plugin-transform-es2015-modules-commonjs": "^6.4.0", @@ -70,13 +87,11 @@ "babel-preset-es2015": "^6.1.18", "babel-preset-es2015-rollup": "^1.1.1", "babel-preset-react": "^6.1.18", - "babel-register": "^6.2.0", "babelify": "^7.2.0", "benchmark": "^2.1.0", "browserify": "^13.0.0", "browserify-shim": "^3.8.11", "cross-env": "^2.0.0", - "es6-promise": "^4.0.3", "eslint": "^2.13.1", "eslint-plugin-react": "^6.2.0", "expect": "^1.9.0", @@ -86,9 +101,8 @@ "glob": "^7.0.0", "intl": "^1.2.1", "intl-messageformat-parser": "^1.2.0", + "jest": "^16.0.2", "mkdirp": "^0.5.1", - "mocha": "^3.0.2", - "nyc": "^8.1.0", "react": "^15.0.0", "react-addons-test-utils": "^15.0.0", "react-dom": "^15.0.0", @@ -118,12 +132,11 @@ "react:15": "npm run react:clean && npm i react@^15 react-dom@^15 react-addons-test-utils@^15", "lint": "eslint .", "lint:fix": "eslint . --fix", - "test": "mocha --require babel-polyfill --require intl --require babel-register --recursive test/unit/ test/functional/", - "test:cov": "cross-env NODE_ENV=test nyc --reporter text --reporter text-summary --reporter html npm test", - "posttest:cov": "nyc check-coverage --statements 95 --branches 85 --functions 100 --lines 95", - "test:react": "npm run react:14 && npm run test -- --reporter dot && npm run react:15 && npm run test -- --reporter dot", + "test": "jest --verbose", + "test:cov": "npm test -- --coverage", + "test:react": "npm run react:14 && npm run test -- --verbose false && npm run react:15 && npm run test -- --verbose false", "test:all": "npm run lint && npm run test:cov && npm run test:react", - "test:watch": "npm run test -- --watch --reporter min", + "test:watch": "npm run test -- --watch --verbose false", "test:perf": "cross-env NODE_ENV=production babel-node test/perf", "preversion": "npm run clean && npm run build && npm run test:all", "postversion": "echo 'Uninstall react-router to fix npm issue' && npm uninstall react-router", diff --git a/src/.babelrc b/src/.babelrc index c6a220eeb6..95ac9f4cf6 100644 --- a/src/.babelrc +++ b/src/.babelrc @@ -9,12 +9,5 @@ "transform-es3-member-expression-literals", "transform-es3-property-literals", ["transform-react-remove-prop-types", {"mode": "wrap"}] - ], - "env": { - "test": { - "plugins": [ - "istanbul" - ] - } - } + ] } diff --git a/test/functional/index.js b/test/functional/index.js index cebc9501cb..55b1cac3c8 100644 --- a/test/functional/index.js +++ b/test/functional/index.js @@ -1,11 +1,12 @@ -import buildTests from './build'; -import formatTests from './format'; +import * as p from 'path'; +import buildTests from './support/build'; +import formatTests from './support/format'; const builds = { - 'ES' : '../../lib/index.es.js', - 'CJS' : '../../lib/index.js', - 'UMD-dev' : '../../dist/react-intl.js', - 'UMD-prod': '../../dist/react-intl.min.js', + 'ES' : p.resolve('lib/index.es.js'), + 'CJS' : p.resolve('lib/index.js'), + 'UMD-dev' : p.resolve('dist/react-intl.js'), + 'UMD-prod': p.resolve('dist/react-intl.min.js'), }; Object.keys(builds).forEach((name) => { diff --git a/test/functional/locale-data.js b/test/functional/locale-data.js index 36f2c8269b..9806f03b4f 100644 --- a/test/functional/locale-data.js +++ b/test/functional/locale-data.js @@ -3,8 +3,7 @@ import expect from 'expect'; import {sync as globSync} from 'glob'; describe('locale data', () => { - it('has generated locale data modules with correct shape', function () { - this.timeout(5000); + it('has generated locale data modules with correct shape', () => { const localeDataFiles = globSync('./locale-data/*.js'); expect(localeDataFiles.length).toBeGreaterThan(0); diff --git a/test/functional/build.js b/test/functional/support/build.js similarity index 91% rename from test/functional/build.js rename to test/functional/support/build.js index 6ee3dce522..02d12965fc 100644 --- a/test/functional/build.js +++ b/test/functional/support/build.js @@ -1,5 +1,5 @@ import expect from 'expect'; -import * as ReactIntl from '../../src/'; +import * as ReactIntl from '../../../src/'; export default function (buildPath) { describe('build', () => { diff --git a/test/functional/format.js b/test/functional/support/format.js similarity index 100% rename from test/functional/format.js rename to test/functional/support/format.js diff --git a/test/unit/components/provider.js b/test/unit/components/provider.js index bcc3e69ee5..e48087c91f 100644 --- a/test/unit/components/provider.js +++ b/test/unit/components/provider.js @@ -16,7 +16,7 @@ const skipWhen = (shouldSkip, callback) => { }; describe('', () => { - let immutableIntl; + let immutableIntl = false; try { global.Intl = global.Intl; } catch (e) { @@ -77,7 +77,7 @@ describe('', () => { // If global.Intl is immutable, then skip this test. skipWhen(immutableIntl, (it) => { it('throws when `Intl` is missing from runtime', () => { - delete global.Intl; + global.Intl = undefined; expect(() => renderer.render()).toThrow( '[React Intl] The `Intl` APIs must be available in the runtime, and do not appear to be built-in. An `Intl` polyfill should be loaded.' );