Skip to content

Commit

Permalink
test_runner: refactor TestPlan constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarchini committed Feb 2, 2025
1 parent cf3c2d3 commit d9a7124
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function lazyAssertObject(harness) {
return assertObj;
}

function stopTest(timeout, signal, reason) {
function stopTest(timeout, signal) {
const deferred = PromiseWithResolvers();
const abortListener = addAbortListener(signal, deferred.resolve);
let timer;
Expand All @@ -141,7 +141,7 @@ function stopTest(timeout, signal, reason) {
writable: true,
value: PromisePrototypeThen(deferred.promise, () => {
throw new ERR_TEST_FAILURE(
reason || `test timed out after ${timeout}ms`,
`test timed out after ${timeout}ms`,
kTestTimeoutFailure,
);
}),
Expand Down Expand Up @@ -181,31 +181,20 @@ class TestPlan {
#timeoutId = null;

constructor(count, options = kEmptyObject) {
this.#validateConstructorArgs(count, options);
this.expected = count;
this.actual = 0;
this.#setWaitOption(options);
}

#validateConstructorArgs(count, options) {
validateUint32(count, 'count');
validateObject(options, 'options');
}
this.expected = count;
this.actual = 0;

#setWaitOption(options) {
switch (typeof options.wait) {
case 'boolean':
this.wait = options.wait;
this.#waitIndefinitely = options.wait;
break;
case 'number':
validateNumber(options.wait, 'options.wait', 0, TIMEOUT_MAX);
this.wait = options.wait;
break;
default:
if (options.wait !== undefined) {
throw new ERR_INVALID_ARG_TYPE('options.wait', ['boolean', 'number'], options.wait);
}
const { wait } = options;
if (typeof wait === 'boolean') {
this.wait = wait;
this.#waitIndefinitely = wait;
} else if (typeof wait === 'number') {
validateNumber(wait, 'options.wait', 0, TIMEOUT_MAX);
this.wait = wait;
} else if (wait !== undefined) {
throw new ERR_INVALID_ARG_TYPE('options.wait', ['boolean', 'number'], wait);
}
}

Expand Down Expand Up @@ -513,8 +502,6 @@ class Test extends AsyncResource {
super('Test');

let { fn, name, parent } = options;
// TODO(pmarchini): The plan has additional options that a user can set via t.plan.
// We should allow users to set these options via the options object for consistency.
const { concurrency, entryFile, loc, only, timeout, todo, skip, signal, plan } = options;

if (typeof fn !== 'function') {
Expand Down

0 comments on commit d9a7124

Please sign in to comment.