2023-02-09 18:08:48 +01:00
const {
2023-02-10 18:36:14 +01:00
EXCLUDE _E2E _TESTS _REGEX ,
2023-02-09 18:08:48 +01:00
filterDiffAdditions ,
filterDiffByFilePath ,
hasNumberOfCodeBlocksIncreased ,
} = require ( './shared' ) ;
function checkMochaSyntax ( diff ) {
const ruleHeading = 'favor-jest-instead-of-mocha' ;
const codeBlocks = [
"import { strict as assert } from 'assert';" ,
'assert.deepEqual' ,
'assert.equal' ,
'assert.rejects' ,
'assert.strictEqual' ,
'sinon.' ,
] ;
2023-02-10 18:36:14 +01:00
console . log ( ` \n Checking ${ ruleHeading } ... ` ) ;
2023-02-09 18:08:48 +01:00
2023-02-10 18:36:14 +01:00
const diffByFilePath = filterDiffByFilePath ( diff , EXCLUDE _E2E _TESTS _REGEX ) ;
2023-02-09 18:08:48 +01:00
const diffAdditions = filterDiffAdditions ( diffByFilePath ) ;
const hashmap = hasNumberOfCodeBlocksIncreased ( diffAdditions , codeBlocks ) ;
Object . keys ( hashmap ) . forEach ( ( key ) => {
if ( hashmap [ key ] ) {
console . error ( ` Number of occurences of " ${ key } " have increased. ` ) ;
}
} ) ;
if ( Object . values ( hashmap ) . includes ( true ) ) {
console . error (
2023-02-10 18:36:14 +01:00
` ...changes have not been accepted by the fitness function. \n For more info, see: https://github.com/MetaMask/metamask-extension/blob/develop/docs/testing.md# ${ ruleHeading } ` ,
2023-02-09 18:08:48 +01:00
) ;
process . exit ( 1 ) ;
} else {
console . log (
` ...number of occurences has not increased for any code block. ` ,
) ;
process . exit ( 0 ) ;
}
}
module . exports = { checkMochaSyntax } ;