
For a long time I looked at the jest testing framework, which has a huge amount of all kinds of tasty chips, one of which is multi-threaded test execution. Provided that I had a project for 5000 unit tests, migration promised to be extremely useful. Next, I will describe 14 simple steps for which I managed to migrate - albeit with some reservations - and what we got as a result. Spoiler - everything turned out very cool.
Baseline
β , , . β β . , , 5000 β .
mocha, chai, sinon, rewire, nock, nyc β , . , :
1) sandbox, , sinon.sandbox.
2) - β . , .
3) sinon.useFakeTimers. . .
4) 13 . , , 13 .
, Jest , . puppeteer , ( ) β β , . β . , β , .
- mocha β , , . , mocha-parallel-tests , . β , , . , .
jest-codemods β , , β sinon β 5000 . .
!
1.
awesome-jest, jest-runner-mocha. " !" β , , .
.
npm install --save-dev jest jest-runner-mocha
jest-test.config.js
module.exports = {
runner: 'jest-runner-mocha',
testRegex: 'tests/.*test_.*\\.js$',
maxWorkers: 3
};
node --use_strict ./node_modules/.bin/jest --no-cache --config jest-test.config.js
, , .
, β jest. β .
β β 90% , ! , β , .
2.
, , . , , β , . , , . jest-dot-reporter β progress bar , β .
CLI config:
reporters: ['jest-dot-reporter'],
, awesome-jest - . β .
3. mocha
β , . jest-runner-mocha. , mocha 3.5. β 7. , Node 4. ,
- Node 4 mocha jest, yarn,
- Node 8 End Of Life
- ,
- mocha peerDependency,
. . . peerDependency β , .
4. clearMocks
, . β β . β , β , .
, , clearMocks . , β , . jasmine2. β .
β setupFilesAfterEnv
, β clearMocks
β . , . , clearMocks jest β sinon, jest .
:
setupFilesAfterEnv: [ 'lib/clearMocks.js'],
clearMocks: true,
lib/clearMocks.js
// const jest = require('jest-mock');
const sinon = require('sinon');
module.exports = {
clearMocks: () => {
// jest.clearAllMocks(); , ,
sinon.sandbox.restore();
}
};
.
. , β .
5.
, - . , , ( ). . , . β ! , ? , !
6.
, process
500 exit
. - .
process.on('exit', () => process.exit());
, , β¦ , , β¦ slowpoke.jpg.
7.
, , , process
unCaughtException
. , , β 7.0.0 7.0.1.
8.
, β , . jest-runner-mocha, jest . , β β . β , , yarn.
9.
, postinstall hook jest-runner-mocha:
> core-js@3.6.4 postinstall
> node -e "try{require('./postinstall')}catch(e){}"
Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock
Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
, , . . β c 23,528,407 , β , , , . , 57 , . . . 12 . , . . . . , , .
β .
10.
, β . CI , , , . - esprint β , .
jest-runner-eslint β , , . , . , β .
, , β . Jest , grunt gulp. , , , . Jest , ...
11. CI
CI , - . , , , . β !
12.
- , . - , β¦ , yarn, yarn.lock. . .
. yarn β yarn . . ? , β .
? , yarn package-lock.json, npm-shrinkwrap.json ( ). β , shrinkwrap β , shrinkwrap. , , . , , . npm prune --production
.
, . , , . , . - . , . ?
, β . , . , jest , . , .
14.
, , , β , . , .
15.
. , . !
?
- CI 3 3 . , , .
- . β . , .
- jest , .
ToDo
:
- , . , . , mocha , .
- jest β . β , .
- , jest-codemods , β , .
Yes, if that, here is a link to my fork runner mocha .
You can put it with the command
npm install --save-dev @kernel-panic/jest-runner-mocha
And in the config register how
runner: '@kernel-panic/jest-runner-mocha',