1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Fix mocha syntax fitness function (#17712)

This commit is contained in:
Pedro Figueiredo 2023-02-10 17:36:14 +00:00 committed by GitHub
parent 9b0e71f27f
commit 18a1b80524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 9 deletions

View File

@ -25,4 +25,4 @@ jobs:
git fetch origin $HEAD_REF git fetch origin $HEAD_REF
git fetch origin $BASE_REF git fetch origin $BASE_REF
git diff origin/$BASE_REF origin/$HEAD_REF -- . ':(exclude)development/fitness-functions/*' > diff git diff origin/$BASE_REF origin/$HEAD_REF -- . ':(exclude)development/fitness-functions/*' > diff
# npm run fitness-functions -- "ci" "./diff" npm run fitness-functions -- "ci" "./diff"

View File

@ -6,10 +6,10 @@
// subset of files to check against these targets. // subset of files to check against these targets.
module.exports = { module.exports = {
global: { global: {
lines: 62.25, lines: 63,
branches: 50.5, branches: 51,
statements: 61.5, statements: 62.5,
functions: 55, functions: 55.5,
}, },
transforms: { transforms: {
branches: 100, branches: 100,

View File

@ -1,4 +1,5 @@
const { const {
EXCLUDE_E2E_TESTS_REGEX,
filterDiffAdditions, filterDiffAdditions,
filterDiffByFilePath, filterDiffByFilePath,
hasNumberOfCodeBlocksIncreased, hasNumberOfCodeBlocksIncreased,
@ -15,10 +16,9 @@ function checkMochaSyntax(diff) {
'sinon.', 'sinon.',
]; ];
console.log(`Checking ${ruleHeading}...`); console.log(`\nChecking ${ruleHeading}...`);
const jsFilesExcludingE2ETests = '^(?!.*/test/e2e/).*.(js|ts|jsx)$'; const diffByFilePath = filterDiffByFilePath(diff, EXCLUDE_E2E_TESTS_REGEX);
const diffByFilePath = filterDiffByFilePath(diff, jsFilesExcludingE2ETests);
const diffAdditions = filterDiffAdditions(diffByFilePath); const diffAdditions = filterDiffAdditions(diffByFilePath);
const hashmap = hasNumberOfCodeBlocksIncreased(diffAdditions, codeBlocks); const hashmap = hasNumberOfCodeBlocksIncreased(diffAdditions, codeBlocks);
@ -30,7 +30,7 @@ function checkMochaSyntax(diff) {
if (Object.values(hashmap).includes(true)) { if (Object.values(hashmap).includes(true)) {
console.error( console.error(
`...changes have not been committed.\nFor more info, see: https://github.com/MetaMask/metamask-extension/blob/develop/docs/testing.md#${ruleHeading}`, `...changes have not been accepted by the fitness function.\nFor more info, see: https://github.com/MetaMask/metamask-extension/blob/develop/docs/testing.md#${ruleHeading}`,
); );
process.exit(1); process.exit(1);
} else { } else {

View File

@ -1,3 +1,5 @@
const EXCLUDE_E2E_TESTS_REGEX = '^(?!test/e2e/).*.(js|ts|jsx)$';
function filterDiffByFilePath(diff, regex) { function filterDiffByFilePath(diff, regex) {
// split by `diff --git` and remove the first element which is empty // split by `diff --git` and remove the first element which is empty
const diffBlocks = diff.split(`diff --git`).slice(1); const diffBlocks = diff.split(`diff --git`).slice(1);
@ -64,6 +66,7 @@ function hasNumberOfCodeBlocksIncreased(diffFragment, codeBlocks) {
} }
module.exports = { module.exports = {
EXCLUDE_E2E_TESTS_REGEX,
filterDiffByFilePath, filterDiffByFilePath,
filterDiffAdditions, filterDiffAdditions,
hasNumberOfCodeBlocksIncreased, hasNumberOfCodeBlocksIncreased,

View File

@ -1,4 +1,5 @@
const { const {
EXCLUDE_E2E_TESTS_REGEX,
filterDiffAdditions, filterDiffAdditions,
hasNumberOfCodeBlocksIncreased, hasNumberOfCodeBlocksIncreased,
filterDiffByFilePath, filterDiffByFilePath,
@ -156,3 +157,51 @@ describe('filterDiffByFilePath()', () => {
`); `);
}); });
}); });
describe(`EXCLUDE_E2E_TESTS_REGEX "${EXCLUDE_E2E_TESTS_REGEX}"`, () => {
const PATHS_IT_SHOULD_MATCH = [
'file.js',
'path/file.js',
'much/longer/path/file.js',
'file.ts',
'path/file.ts',
'much/longer/path/file.ts',
'file.jsx',
'path/file.jsx',
'much/longer/path/file.jsx',
];
const PATHS_IT_SHOULD_NOT_MATCH = [
'test/e2e/file',
'test/e2e/file.extension',
'test/e2e/path/file.extension',
'test/e2e/much/longer/path/file.extension',
'test/e2e/file.js',
'test/e2e/path/file.ts',
'test/e2e/much/longer/path/file.jsx',
'file',
'file.extension',
'path/file.extension',
'much/longer/path/file.extension',
];
describe('included paths', () => {
PATHS_IT_SHOULD_MATCH.forEach((path) => {
it(`should match "${path}"`, () => {
const result = new RegExp(EXCLUDE_E2E_TESTS_REGEX, 'u').test(path);
expect(result).toStrictEqual(true);
});
});
});
describe('excluded paths', () => {
PATHS_IT_SHOULD_NOT_MATCH.forEach((path) => {
it(`should not match "${path}"`, () => {
const result = new RegExp(EXCLUDE_E2E_TESTS_REGEX, 'u').test(path);
expect(result).toStrictEqual(false);
});
});
});
});