Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per-test timeout option #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/supertape/lib/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ const notSkip = ({skip}) => !skip;

const getInitOperators = async () => await import('./operators.mjs');

const {SUPERTAPE_TIMEOUT = 3000} = process.env;
const DEBUG_TIME = 3000 * 1000;

const timeout = (time, value) => {
const doTimeout = (time, value) => {
let stop;

if (isDebug)
Expand Down Expand Up @@ -95,6 +94,7 @@ async function runTests(tests, {formatter, operators, skiped, isStop}) {
incPassed,
getValidationMessage,
validations,
timeout,

extensions: {
...operators,
Expand All @@ -118,7 +118,7 @@ async function runTests(tests, {formatter, operators, skiped, isStop}) {
};
}

async function runOneTest({message, at, fn, extensions, formatter, count, total, failed, incCount, incPassed, incFailed, getValidationMessage, validations}) {
async function runOneTest({message, at, fn, extensions, formatter, count, total, failed, incCount, incPassed, incFailed, getValidationMessage, validations, timeout}) {
const isReturn = fullstore(false);
const assertionsCount = fullstore(0);
const isEnded = fullstore(false);
Expand All @@ -145,7 +145,7 @@ async function runOneTest({message, at, fn, extensions, formatter, count, total,
});

if (!isReturn()) {
const [timer, stopTimer] = timeout(SUPERTAPE_TIMEOUT, ['timeout']);
const [timer, stopTimer] = doTimeout(timeout, ['timeout']);
const [error] = await Promise.race([tryToCatch(fn, t), timer]);

stopTimer();
Expand Down
1 change: 1 addition & 0 deletions packages/supertape/lib/supertape.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type TestOptions = {
checkAssertionsCount?: boolean;
checkScopes?: boolean;
checkDuplicates?: boolean;
timeout?: number;
};

declare function test(message: string, fn: (t: Test) => void, options?: TestOptions): void;
Expand Down
6 changes: 5 additions & 1 deletion packages/supertape/lib/supertape.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ const defaultOptions = {
checkIfEnded: true,
checkAssertionsCount: true,
checkScopes: true,
timeout: process.env.SUPERTAPE_TIMEOUT || 3000
};

function _createEmitter({quiet, stream = stdout, format, getOperators, isStop, readyFormatter, workerFormatter}) {
const tests = [];
const emitter = new EventEmitter();

emitter.on('test', (message, fn, {skip, only, extensions, at, validations}) => {
emitter.on('test', (message, fn, {skip, only, extensions, at, validations, timeout}) => {
tests.push({
message,
fn,
Expand All @@ -59,6 +60,7 @@ function _createEmitter({quiet, stream = stdout, format, getOperators, isStop, r
extensions,
at,
validations,
timeout,
});
});

Expand Down Expand Up @@ -154,6 +156,7 @@ function test(message, fn, options = {}) {
checkAssertionsCount,
checkIfEnded,
workerFormatter,
timeout
} = {
...defaultOptions,
...initedOptions,
Expand Down Expand Up @@ -186,6 +189,7 @@ function test(message, fn, options = {}) {
extensions,
at,
validations,
timeout,
});

if (run)
Expand Down
Loading