Skip to content

Commit

Permalink
test_runner: fixed test shorthands return type
Browse files Browse the repository at this point in the history
`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: nodejs#48557
PR-URL: nodejs#48555
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
shockerqt authored and Ceres6 committed Aug 14, 2023
1 parent a4ae309 commit 2fa5531
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
36 changes: 36 additions & 0 deletions test/parallel/test-runner-typechecking.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 2fa5531

Please sign in to comment.