Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
feat(filter improvements): test.each support and properly removing al…
Browse files Browse the repository at this point in the history
…l docBlock "\t"s
  • Loading branch information
ryparker committed Jul 21, 2020
1 parent 6d323e6 commit 1b0f7b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -14,8 +14,8 @@
"postinstall": "patch-package",
"build": "yarn clean && tsc",
"test": "yarn build && jest",
"lint": "xo .",
"fix": "xo . --fix",
"lint": "xo src",
"fix": "xo src --fix",
"clean": "rimraf dist"
},
"jest": {
Expand Down
18 changes: 11 additions & 7 deletions src/filter-by-pragma.ts
Expand Up @@ -7,7 +7,7 @@ export type TestBlock = {
pragmas: string;
};

const TEST_BLOCK_REGEX = /(fit|it|xit|test|xtest)\(("|')(?<testName>[\S ]*)("|'),\s*\(\)\s*=>\s*{\s*(?<docBlock>\/\*\*?(.|\r?\n)*?\*\/)/gm;
const TEST_BLOCK_REGEX = /(fit|it|xit|test|xtest)(.each\(\S*\))?\(\s*(["'`])(?<testName>[\S ]*)(["'`]),\s*(async\s*)?\((\S*)?\)\s*=>\s*{\s*(?<docBlock>\/\*\*?(.|\r?\n)*?\*\/)/gm;

export const filterByPragma = (testFiles: JestTest[], pragmasToMatch: Record<string, string[]>) => {
if (testFiles.length === 0) {
Expand All @@ -31,7 +31,7 @@ function _filterFileTestCasesByPragma(testFiles: JestTest[], pragmasToMatch: Rec

const matchingTestBlocks = testBlocks.filter(testBlock => _doPragmasHaveMatchingValues(testBlock.pragmas, pragmasToMatch));

if (matchingTestBlocks) {
if (matchingTestBlocks.length > 0) {
const testNamePattern = matchingTestBlocks.map(testBlock => testBlock.name).join('|');

/** @privateRemarks
Expand All @@ -50,8 +50,6 @@ function _filterFileTestCasesByPragma(testFiles: JestTest[], pragmasToMatch: Rec
}
});
}

console.debug({matchingTestBlocks});
}

return matchingTestFiles;
Expand All @@ -66,8 +64,8 @@ function _findTestBlocksWithPragmas(source: string) {
if (match) {
const group = {...match.groups};
const name = group?.testName;
const docBlock = group?.docBlock.replace('\t', '');
const pragmas = parseDocBlockPragmas(docBlock);
const docBlock = group?.docBlock.replace(/\t/g, '');
const pragmas = {...parseDocBlockPragmas(docBlock)};

if (pragmas !== {}) {
groups.push({
Expand All @@ -89,7 +87,13 @@ function _doPragmasHaveMatchingValues(pragmas: Record<string, string | string[]>
const pragma = pragmas[pragmaKeyToMatch];
const pragmaToMatch = pragmasToMatch[pragmaKeyToMatch];

if (pragma && pragmaToMatch.some(valuesToMatch => pragma.includes(valuesToMatch))) {
if (!pragma) {
return false;
}

const hasMatchingPragmaValue = pragmaToMatch.some(valuesToMatch => pragma.includes(valuesToMatch));

if (hasMatchingPragmaValue) {
return true;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/runner.ts
Expand Up @@ -25,8 +25,6 @@ export default class AllureTestRunner extends TestRunner {

const cliArgs = process.argv.slice(2);
this._userArgs = this._extractArgs(cliArgs);

console.debug('User arguments:', this._userArgs);
}

async runTests(
Expand Down

0 comments on commit 1b0f7b6

Please sign in to comment.