From 2b9c88579615b39f9218b906a71ccc4494c7410b Mon Sep 17 00:00:00 2001 From: jazelly Date: Sat, 7 Nov 2026 15:11:13 +1030 Subject: [PATCH] test_runner: treat falsy skip option as not skipped The `skip` option is documented as "If truthy, the test is skipped", but values such as `''`, `0`, `null` and `NaN` marked the test as skipped while its function still ran, because the function is only replaced with a noop when `skip` is truthy. Use a truthiness check for `skipped` so the reported result matches what actually runs. Co-authored-by: Vaishnavi J K Signed-off-by: jazelly --- lib/internal/test_runner/test.js | 2 +- test/parallel/test-runner-skip-falsy.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-runner-skip-falsy.js diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 1b0956e4253c..65847cd210b9 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -768,7 +768,7 @@ class Test extends AsyncResource { this.expectedAssertions = plan; this.cancelled = false; this.expectFailure = parseExpectFailure(expectFailure) || this.parent?.expectFailure; - this.skipped = skip !== undefined && skip !== false; + this.skipped = !!skip; this.isTodo = (todo !== undefined && todo !== false) || this.parent?.isTodo; this.startTime = null; this.endTime = null; diff --git a/test/parallel/test-runner-skip-falsy.js b/test/parallel/test-runner-skip-falsy.js new file mode 100644 index 000000000000..54c2b042122d --- /dev/null +++ b/test/parallel/test-runner-skip-falsy.js @@ -0,0 +1,22 @@ +'use strict'; +const common = require('../common'); +const assert = require('node:assert'); +const { run, suite, test } = require('node:test'); + +// The skip option is documented as a truthy check, so falsy values other than +// false and undefined must run the test and not report it as skipped. +const falsyValues = ['', 0, null, NaN]; + +if (!process.env.NODE_TEST_CONTEXT) { + const stream = run({ files: [__filename] }); + + stream.on('test:fail', common.mustNotCall()); + stream.on('test:pass', common.mustCall((event) => { + assert.strictEqual(event.skip, undefined); + }, falsyValues.length * 2)); +} else { + for (const value of falsyValues) { + test(`test skip: ${value}`, { skip: value }, common.mustCall()); + suite(`suite skip: ${value}`, { skip: value }, common.mustCall()); + } +}