Comment migrer du moka vers la plaisanterie en 15 Ă©tapes faciles - et pourquoi


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.


, . , , . , . - . , . ?


13.


, — . , . , jest , . , .


14.


, , , — , . , .


15.


. , . !



?


  1. CI 3 3 . , , .
  2. . — . , .
  3. jest , .

ToDo


:


  1. , . , . , mocha , .
  2. jest — . — , .
  3. , 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',

Source: https://habr.com/ru/post/undefined/


All Articles