Skip to content

Commit 5cebe91

Browse files
MoLowjuliangruber
authored andcommitted
test_runner: allow nesting test within describe
PR-URL: nodejs/node#46544 Fixes: nodejs/node#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> (cherry picked from commit 2787e2dfc2e10c584259ff34d7aad565447a84d9)
1 parent f131a8c commit 5cebe91

File tree

4 files changed

+76
-62
lines changed

4 files changed

+76
-62
lines changed

lib/internal/test_runner/harness.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ function getGlobalRoot () {
129129
}
130130

131131
function test (name, options, fn) {
132-
const subtest = getGlobalRoot().createSubtest(Test, name, options, fn)
132+
const parent = testResources.get(executionAsyncId()) || getGlobalRoot()
133+
const subtest = parent.createSubtest(Test, name, options, fn)
133134
return subtest.start()
134135
}
135136

test/message/test_runner_desctibe_it.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'use strict'
44
require('../common')
55
const assert = require('node:assert')
6-
const { describe, it } = require('#node:test')
6+
const { describe, it, test } = require('node:test')
77
const util = require('util')
88

99
it.todo('sync pass todo', () => {
@@ -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
@@ -308,12 +311,12 @@ describe('describe async throw fails', async () => {
308311
describe('timeouts', () => {
309312
it('timed out async test', { timeout: 5 }, async () => {
310313
return new Promise((resolve) => {
311-
setTimeout(resolve, 1000)
314+
setTimeout(resolve, 100)
312315
})
313316
})
314317

315318
it('timed out callback test', { timeout: 5 }, (done) => {
316-
setTimeout(done, 1000)
319+
setTimeout(done, 100)
317320
})
318321

319322
it('large timeout async test is ok', { timeout: 30_000_000 }, async () => {

0 commit comments

Comments
 (0)