
Lange habe ich mir das Scherz-Test-Framework angesehen, das eine große Menge aller Arten von leckeren Chips enthält, von denen einer die Multithread-Testausführung ist. Vorausgesetzt, ich hatte ein Projekt für 5000 Komponententests, versprach die Migration äußerst nützlich zu sein. Als nächstes werde ich 14 einfache Schritte beschreiben, für die ich - wenn auch mit einigen Vorbehalten - migrieren konnte, und was wir als Ergebnis erhalten haben. Spoiler - alles ist sehr cool geworden.
Basislinie
— , , . — — . , , 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 , — , .
Ja, wenn das so ist, hier ist ein Link zu meinem Gabelläufer Mokka .
Sie können es mit dem Befehl setzen
npm install --save-dev @kernel-panic/jest-runner-mocha
Und in der Konfiguration registrieren, wie
runner: '@kernel-panic/jest-runner-mocha',