Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2c56835

Browse filesBrowse files
shockerqtRafaelGSS
authored andcommitted
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: #48557 PR-URL: #48555 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 6d00c2e commit 2c56835
Copy full SHA for 2c56835

File tree

Expand file treeCollapse file tree

2 files changed

+37
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/test_runner/harness.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,7 @@ function runInParentContext(Factory) {
216216

217217
const test = (name, options, fn) => run(name, options, fn);
218218
ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => {
219-
test[keyword] = (name, options, fn) => {
220-
run(name, options, fn, { [keyword]: true });
221-
};
219+
test[keyword] = (name, options, fn) => run(name, options, fn, { [keyword]: true });
222220
});
223221
return test;
224222
}
Collapse file
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
require('../common');
3+
4+
// Return type of shorthands should be consistent
5+
// with the return type of test
6+
7+
const assert = require('assert');
8+
const { test, describe, it } = require('node:test');
9+
const { isPromise } = require('util/types');
10+
11+
const testOnly = test('only test', { only: true });
12+
const testTodo = test('todo test', { todo: true });
13+
const testSkip = test('skip test', { skip: true });
14+
const testOnlyShorthand = test.only('only test shorthand');
15+
const testTodoShorthand = test.todo('todo test shorthand');
16+
const testSkipShorthand = test.skip('skip test shorthand');
17+
18+
describe('\'node:test\' and its shorthands should return the same', () => {
19+
it('should return a Promise', () => {
20+
assert(isPromise(testOnly));
21+
assert(isPromise(testTodo));
22+
assert(isPromise(testSkip));
23+
assert(isPromise(testOnlyShorthand));
24+
assert(isPromise(testTodoShorthand));
25+
assert(isPromise(testSkipShorthand));
26+
});
27+
28+
it('should resolve undefined', async () => {
29+
assert.strictEqual(await testOnly, undefined);
30+
assert.strictEqual(await testTodo, undefined);
31+
assert.strictEqual(await testSkip, undefined);
32+
assert.strictEqual(await testOnlyShorthand, undefined);
33+
assert.strictEqual(await testTodoShorthand, undefined);
34+
assert.strictEqual(await testSkipShorthand, undefined);
35+
});
36+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.