Skip to content

Commit 2cf1e7c

Browse files
MoLowjuanarbol
authored andcommitted
test_runner: allow nesting test within describe
PR-URL: #46544 Backport-PR-URL: #46839 Fixes: #46478 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent aac7898 commit 2cf1e7c

File tree

4 files changed

+76
-62
lines changed

4 files changed

+76
-62
lines changed

lib/internal/test_runner/harness.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ function getGlobalRoot() {
165165
}
166166

167167
function test(name, options, fn) {
168-
const subtest = getGlobalRoot().createSubtest(Test, name, options, fn);
168+
const parent = testResources.get(executionAsyncId()) || getGlobalRoot();
169+
const subtest = parent.createSubtest(Test, name, options, fn);
169170
return subtest.start();
170171
}
171172

test/message/test_runner_describe_it.js

+10-7
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)