From f5494fa1b0c27a1cea8498005e9539cbd8e8b74e Mon Sep 17 00:00:00 2001 From: Shocker <43253032+shockerqt@users.noreply.github.com> Date: Mon, 3 Jul 2023 05:04:11 -0400 Subject: [PATCH] test_runner: fixed `test` shorthands return type `test.todo`, `test.only` and `test.skip` are expected to return the same as `test`. This commit corrects the inconsistent behavior of these shorthands. Fixes: https://github.com/nodejs/node/issues/48557 PR-URL: https://github.com/nodejs/node/pull/48555 Reviewed-By: Moshe Atlow --- lib/internal/test_runner/harness.js | 4 +-- test/parallel/test-runner-typechecking.js | 36 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-runner-typechecking.js diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index 29b4d597b799aa..f29d5c95cc6084 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -214,9 +214,7 @@ function runInParentContext(Factory) { const test = (name, options, fn) => run(name, options, fn); ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => { - test[keyword] = (name, options, fn) => { - run(name, options, fn, { [keyword]: true }); - }; + test[keyword] = (name, options, fn) => run(name, options, fn, { [keyword]: true }); }); return test; } diff --git a/test/parallel/test-runner-typechecking.js b/test/parallel/test-runner-typechecking.js new file mode 100644 index 00000000000000..e96761b1a054bd --- /dev/null +++ b/test/parallel/test-runner-typechecking.js @@ -0,0 +1,36 @@ +'use strict'; +require('../common'); + +// Return type of shorthands should be consistent +// with the return type of test + +const assert = require('assert'); +const { test, describe, it } = require('node:test'); +const { isPromise } = require('util/types'); + +const testOnly = test('only test', { only: true }); +const testTodo = test('todo test', { todo: true }); +const testSkip = test('skip test', { skip: true }); +const testOnlyShorthand = test.only('only test shorthand'); +const testTodoShorthand = test.todo('todo test shorthand'); +const testSkipShorthand = test.skip('skip test shorthand'); + +describe('\'node:test\' and its shorthands should return the same', () => { + it('should return a Promise', () => { + assert(isPromise(testOnly)); + assert(isPromise(testTodo)); + assert(isPromise(testSkip)); + assert(isPromise(testOnlyShorthand)); + assert(isPromise(testTodoShorthand)); + assert(isPromise(testSkipShorthand)); + }); + + it('should resolve undefined', async () => { + assert.strictEqual(await testOnly, undefined); + assert.strictEqual(await testTodo, undefined); + assert.strictEqual(await testSkip, undefined); + assert.strictEqual(await testOnlyShorthand, undefined); + assert.strictEqual(await testTodoShorthand, undefined); + assert.strictEqual(await testSkipShorthand, undefined); + }); +});