Skip to content

Commit

Permalink
feat(poku): add fail-fast option (#226)
Browse files Browse the repository at this point in the history
* feat: add fast-fail feature

* chore: fastFail running in parallel
  • Loading branch information
rodrigo-militao authored May 11, 2024
1 parent 5f80fa3 commit c204c5d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/@types/poku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export type Configs = {
* @default 'node'
*/
platform?: 'node' | 'bun' | 'deno';
/**
* By setting `true` the tests will stop at the first failure.
*
* @default false
*/
fastFail?: boolean;
/**
* You can use this option to run a **callback** or a **file** before each test file on your suite.
*
Expand Down
2 changes: 2 additions & 0 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const exclude = getArg('exclude');
const parallel = hasArg('parallel');
const quiet = hasArg('quiet');
const debug = hasArg('debug');
const fastFail = hasArg('fastFail');

if (hasArg('log-success'))
console.log(
Expand All @@ -30,5 +31,6 @@ poku(dirs, {
parallel,
quiet,
debug,
fastFail,
});
/* c8 ignore stop */
32 changes: 21 additions & 11 deletions src/services/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const runTests = async (
showLogs &&
console.log(`${indentation.test}${format.fail('✘')} ${log}`, nextLine);
passed = false;

if (configs?.fastFail) return passed;
}
}

Expand All @@ -80,20 +82,28 @@ export const runTestsParallel = async (
const testDir = path.join(cwd, dir);
const files = IS_FILE(dir) ? [dir] : listFiles(testDir, undefined, configs);

const promises = files.map(async (filePath) => {
const testPassed = await runTestFile(filePath, configs);
try {
const promises = files.map(async (filePath) => {
const testPassed = await runTestFile(filePath, configs);

if (!testPassed) {
++results.fail;
return false;
}
if (!testPassed) {
++results.fail;

++results.success;
if (configs?.fastFail)
throw new Error('Test failed with fastFail enabled');

return true;
});
return false;
}

const concurrency = await Promise.all(promises);
++results.success;

return true;
});

return concurrency.every((result) => result);
const concurrency = await Promise.all(promises);

return concurrency.every((result) => result);
} catch {
return false;
}
};

0 comments on commit c204c5d

Please sign in to comment.