From 60684039cc778a8dbe28a2e1bcad7d9bedfbec3a Mon Sep 17 00:00:00 2001 From: Shocker <43253032+shockerqt@users.noreply.github.com> Date: Sun, 25 Jun 2023 23:47:06 -0400 Subject: [PATCH 1/3] 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 --- lib/internal/test_runner/harness.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index f150a8f5ed85c2..246620f6628d88 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -216,9 +216,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; } From 6ce6729f0709bd151f05a7348c3fe7aba799c061 Mon Sep 17 00:00:00 2001 From: shocker Date: Mon, 26 Jun 2023 07:20:14 -0400 Subject: [PATCH 2/3] test_runner: added tests for test shorthands Added test to check that the return type of the `todo`, `only` and `skip` shorthands are consistent with the return type of `test`. --- test/parallel/test-runner-typechecking.js | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/parallel/test-runner-typechecking.js diff --git a/test/parallel/test-runner-typechecking.js b/test/parallel/test-runner-typechecking.js new file mode 100644 index 00000000000000..03c75733a17509 --- /dev/null +++ b/test/parallel/test-runner-typechecking.js @@ -0,0 +1,34 @@ +'use strict'; +const common = require('../common'); + +// Return type of shorthands should be consistent +// with the return type of test + +const assert = require('assert'); +const test = require('node:test'); +const { isPromise } = require('util/types'); + +const testOnly = test({ only: true }); +const testTodo = test({ todo: true }); +const testSkip = test({ skip: true }); +const testOnlyShorthand = test.only(); +const testTodoShorthand = test.todo(); +const testSkipShorthand = test.skip(); + +// return Promise +assert(isPromise(testOnly)); +assert(isPromise(testTodo)); +assert(isPromise(testSkip)); +assert(isPromise(testOnlyShorthand)); +assert(isPromise(testTodoShorthand)); +assert(isPromise(testSkipShorthand)); + +// resolve to 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); +})().then(common.mustCall()); From cf59fa00fb6c4d6c60b97a2ce07ec73149d8bed3 Mon Sep 17 00:00:00 2001 From: shocker Date: Mon, 26 Jun 2023 21:07:55 -0400 Subject: [PATCH 3/3] test_runner: change tests to use `describe/it` --- test/parallel/test-runner-typechecking.js | 50 ++++++++++++----------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/test/parallel/test-runner-typechecking.js b/test/parallel/test-runner-typechecking.js index 03c75733a17509..e96761b1a054bd 100644 --- a/test/parallel/test-runner-typechecking.js +++ b/test/parallel/test-runner-typechecking.js @@ -1,34 +1,36 @@ 'use strict'; -const common = require('../common'); +require('../common'); // Return type of shorthands should be consistent // with the return type of test const assert = require('assert'); -const test = require('node:test'); +const { test, describe, it } = require('node:test'); const { isPromise } = require('util/types'); -const testOnly = test({ only: true }); -const testTodo = test({ todo: true }); -const testSkip = test({ skip: true }); -const testOnlyShorthand = test.only(); -const testTodoShorthand = test.todo(); -const testSkipShorthand = test.skip(); +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'); -// return Promise -assert(isPromise(testOnly)); -assert(isPromise(testTodo)); -assert(isPromise(testSkip)); -assert(isPromise(testOnlyShorthand)); -assert(isPromise(testTodoShorthand)); -assert(isPromise(testSkipShorthand)); +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)); + }); -// resolve to 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); -})().then(common.mustCall()); + 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); + }); +});