
Pendant longtemps, j'ai examinĂ© le cadre de test Jest, qui contient une Ă©norme quantitĂ© de toutes sortes de puces savoureuses, dont l'une est l'exĂ©cution de tests multi-thread. A condition d'avoir un projet de 5000 tests unitaires, la migration s'annonçait extrĂȘmement utile. Ensuite, je dĂ©crirai 14 Ă©tapes simples pour lesquelles j'ai rĂ©ussi Ă migrer - bien qu'avec quelques rĂ©serves - et ce que nous avons obtenu en consĂ©quence. Spoiler - tout s'est avĂ©rĂ© trĂšs cool.
Référence
â , , . â â . , , 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 , â , .
Oui, si c'est le cas, voici un lien vers mon moka de coureur de fourche .
Vous pouvez le mettre avec la commande
npm install --save-dev @kernel-panic/jest-runner-mocha
Et dans le registre de configuration comment
runner: '@kernel-panic/jest-runner-mocha',