Skip to content
Open
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
48 changes: 29 additions & 19 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@
const { concurrency, entryFile, expectFailure, loc, only, timeout, todo, skip, signal, plan } = options;
const rawTags = options.tags;

const isTodo = fn === undefined;

if (typeof fn !== 'function') {
fn = noop;
}
Expand Down Expand Up @@ -744,7 +746,9 @@
this.cancelled = false;
this.expectFailure = parseExpectFailure(expectFailure) || this.parent?.expectFailure;
this.skipped = skip !== undefined && skip !== false;
this.isTodo = (todo !== undefined && todo !== false) || this.parent?.isTodo;
this.isTodo = isTodo ||
(todo !== undefined && todo !== false) ||
this.parent?.isTodo;
this.startTime = null;
this.endTime = null;
this.passed = false;
Expand Down Expand Up @@ -871,8 +875,8 @@

if (this.root.harness.isFilteringByOnly && !this.only && !this.hasOnlyTests) {
if (this.parent.runOnlySubtests ||
this.parent.hasOnlyTests ||
this.only === false) {
this.parent.hasOnlyTests ||
this.only === false) {
this.filtered = true;
return;
}
Expand Down Expand Up @@ -985,7 +989,7 @@
this.readySubtests.set(subtest.reportOrder, subtest);

if (this.unfinishedSubtests.delete(subtest) &&
this.unfinishedSubtests.size === 0) {
this.unfinishedSubtests.size === 0) {
this.subtestsPromise.resolve();
}
}
Expand Down Expand Up @@ -1138,7 +1142,7 @@

if (this.expectFailure) {
if (typeof this.expectFailure === 'object' &&
this.expectFailure.match !== undefined) {
this.expectFailure.match !== undefined) {
const { match: validation } = this.expectFailure;
try {
const errorToCheck = (
Expand Down Expand Up @@ -1215,7 +1219,7 @@
log(message, data) {
validateString(message, 'message');
this.reporter.log(this.nesting, this.loc, message, data,
this.name, this.testId, this.parent?.testId);
this.name, this.testId, this.parent?.testId);

Check failure on line 1222 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 22 spaces but found 6
}

start() {
Expand All @@ -1234,7 +1238,7 @@
// pending for later execution.
this.parent.unfinishedSubtests.add(this);
this.reporter.enqueue(this.nesting, this.loc, this.name, this.reportedType,
this.testId, this.parent?.testId, this.tags);
this.testId, this.parent?.testId, this.tags);

Check failure on line 1241 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 26 spaces but found 6
if (this.root.harness.buildPromise || !this.parent.hasConcurrency()) {
const deferred = PromiseWithResolvers();

Expand All @@ -1258,7 +1262,7 @@

this.parent.assignReportOrder(this);
this.reporter.dequeue(this.nesting, this.loc, this.name, this.reportedType,
this.testId, this.parent?.testId, this.tags);
this.testId, this.parent?.testId, this.tags);

Check failure on line 1265 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 26 spaces but found 6
return this.run();
}

Expand Down Expand Up @@ -1571,14 +1575,20 @@

if (coverage) {
const coverages = [
{ __proto__: null, actual: coverage.totals.coveredLinePercent,
threshold: this.config.lineCoverage, name: 'line' },

{ __proto__: null, actual: coverage.totals.coveredBranchPercent,
threshold: this.config.branchCoverage, name: 'branch' },

{ __proto__: null, actual: coverage.totals.coveredFunctionPercent,
threshold: this.config.functionCoverage, name: 'function' },
{
__proto__: null, actual: coverage.totals.coveredLinePercent,
threshold: this.config.lineCoverage, name: 'line'

Check failure on line 1580 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
},

{
__proto__: null, actual: coverage.totals.coveredBranchPercent,
threshold: this.config.branchCoverage, name: 'branch'

Check failure on line 1585 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
},

{
__proto__: null, actual: coverage.totals.coveredFunctionPercent,
threshold: this.config.functionCoverage, name: 'function'

Check failure on line 1590 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
},
];

for (let i = 0; i < coverages.length; i++) {
Expand Down Expand Up @@ -1631,7 +1641,7 @@
this.finished = true;

if (this.parent === this.root &&
this.root.waitingOn > this.root.subtests.length) {
this.root.waitingOn > this.root.subtests.length) {
// At this point all of the tests have finished running. However, there
// might be ref'ed handles keeping the event loop alive. This gives the
// global after() hook a chance to clean them up. The user may also
Expand Down Expand Up @@ -1795,8 +1805,8 @@
}

if (this.config.testNamePatterns !== null &&
this.config.testSkipPatterns !== null &&
!options.skip) {
this.config.testSkipPatterns !== null &&
!options.skip) {
this.fn = options.fn || this.fn;
this.skipped = false;
}
Expand Down
16 changes: 12 additions & 4 deletions test/parallel/test-runner-todo-skip-tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

const common = require('../common');
const assert = require('node:assert');
const { run, suite, test } = require('node:test');
Expand All @@ -7,10 +8,15 @@
const stream = run({ files: [__filename] });

stream.on('test:fail', common.mustNotCall());

stream.on('test:pass', common.mustCall((event) => {
assert.strictEqual(event.skip, true);
assert.strictEqual(event.todo, undefined);
}, 4));
if (event.name === 'test with no callback') {
assert.strictEqual(event.todo, true);
} else {
assert.strictEqual(event.skip, true);
assert.strictEqual(event.todo, undefined);
}
}, 5));
} else {
test('test options only', { skip: true, todo: true }, common.mustNotCall());

Expand All @@ -23,10 +29,12 @@
t.skip();
}));

test('test with no callback');

// Note - there is no test for the skip option and t.todo() because the skip
// option prevents the test from running at all. This is verified by other
// tests.

// Suites don't have the context methods, so only test the options combination.
suite('suite options only', { skip: true, todo: true }, common.mustNotCall());
}
}

Check failure on line 40 in test/parallel/test-runner-todo-skip-tests.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Newline required at end of file but not found
Loading