mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
26f6ae4c7c
* Add testing documentation * Implement diff filtering by regex * change to relative import
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const {
|
|
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.',
|
|
];
|
|
|
|
console.log(`Checking ${ruleHeading}...`);
|
|
|
|
const jsFilesExcludingE2ETests = '^(?!.*/test/e2e/).*.(js|ts|jsx)$';
|
|
const diffByFilePath = filterDiffByFilePath(diff, jsFilesExcludingE2ETests);
|
|
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(
|
|
`...changes have not been committed.\nFor more info, see: https://github.com/MetaMask/metamask-extension/blob/develop/docs/testing.md#${ruleHeading}`,
|
|
);
|
|
process.exit(1);
|
|
} else {
|
|
console.log(
|
|
`...number of occurences has not increased for any code block.`,
|
|
);
|
|
process.exit(0);
|
|
}
|
|
}
|
|
|
|
module.exports = { checkMochaSyntax };
|