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 e97e796

Browse filesBrowse files
MoLowMylesBorins
authored andcommitted
test_runner: allow nesting test within describe
PR-URL: #46544 Fixes: #46478 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7392cd0 commit e97e796
Copy full SHA for e97e796

File tree

Expand file treeCollapse file tree

4 files changed

+76
-62
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+76
-62
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
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ function getGlobalRoot() {
167167
}
168168

169169
function test(name, options, fn) {
170-
const subtest = getGlobalRoot().createSubtest(Test, name, options, fn);
170+
const parent = testResources.get(executionAsyncId()) || getGlobalRoot();
171+
const subtest = parent.createSubtest(Test, name, options, fn);
171172
return subtest.start();
172173
}
173174

Collapse file

‎test/message/test_runner_describe_it.js‎

Copy file name to clipboardExpand all lines: test/message/test_runner_describe_it.js
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33
require('../common');
44
const assert = require('node:assert');
5-
const { describe, it } = require('node:test');
5+
const { describe, it, test } = require('node:test');
66
const util = require('util');
77

88

@@ -41,6 +41,8 @@ it('async pass', async () => {
4141

4242
});
4343

44+
test('mixing describe/it and test should work', () => {});
45+
4446
it('async throw fail', async () => {
4547
throw new Error('thrown from async throw fail');
4648
});
@@ -95,6 +97,7 @@ describe('subtest sync throw fail', () => {
9597
it('+sync throw fail', () => {
9698
throw new Error('thrown from subtest sync throw fail');
9799
});
100+
test('mixing describe/it and test should work', () => {});
98101
});
99102

100103
it('sync throw non-error fail', async () => {
@@ -106,7 +109,7 @@ describe('level 0a', { concurrency: 4 }, () => {
106109
const p1a = new Promise((resolve) => {
107110
setTimeout(() => {
108111
resolve();
109-
}, 1000);
112+
}, 100);
110113
});
111114

112115
return p1a;
@@ -124,7 +127,7 @@ describe('level 0a', { concurrency: 4 }, () => {
124127
const p1c = new Promise((resolve) => {
125128
setTimeout(() => {
126129
resolve();
127-
}, 2000);
130+
}, 200);
128131
});
129132

130133
return p1c;
@@ -134,7 +137,7 @@ describe('level 0a', { concurrency: 4 }, () => {
134137
const p1c = new Promise((resolve) => {
135138
setTimeout(() => {
136139
resolve();
137-
}, 1500);
140+
}, 150);
138141
});
139142

140143
return p1c;
@@ -143,7 +146,7 @@ describe('level 0a', { concurrency: 4 }, () => {
143146
const p0a = new Promise((resolve) => {
144147
setTimeout(() => {
145148
resolve();
146-
}, 3000);
149+
}, 300);
147150
});
148151

149152
return p0a;
@@ -309,12 +312,12 @@ describe('describe async throw fails', async () => {
309312
describe('timeouts', () => {
310313
it('timed out async test', { timeout: 5 }, async () => {
311314
return new Promise((resolve) => {
312-
setTimeout(resolve, 1000);
315+
setTimeout(resolve, 100);
313316
});
314317
});
315318

316319
it('timed out callback test', { timeout: 5 }, (done) => {
317-
setTimeout(done, 1000);
320+
setTimeout(done, 100);
318321
});
319322

320323

0 commit comments

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