Skip to content

Commit c6f554c

Browse files
MoLowaduh95
authored andcommitted
fix: fix top level describe queuing
PR-URL: nodejs/node#43998 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> (cherry picked from commit a3e110820ff98702e1761831e7beaf0f5f1f75e7)
1 parent 4071052 commit c6f554c

File tree

6 files changed

+212
-94
lines changed

6 files changed

+212
-94
lines changed

lib/internal/test_runner/test.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/60da0a1b364efdd84870269d23b39faa12fb46d8/lib/internal/test_runner/test.js
1+
// https://github.com/nodejs/node/blob/a3e110820ff98702e1761831e7beaf0f5f1f75e7/lib/internal/test_runner/test.js
22

33
'use strict'
44

@@ -562,25 +562,22 @@ class Suite extends Test {
562562

563563
try {
564564
const context = { signal: this.signal }
565-
this.buildSuite = this.runInAsyncScope(this.fn, context, [context])
565+
this.buildSuite = PromisePrototypeThen(
566+
PromiseResolve(this.runInAsyncScope(this.fn, context, [context])),
567+
undefined,
568+
(err) => {
569+
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
570+
})
566571
} catch (err) {
567572
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
568573
}
569574
this.fn = () => {}
570575
this.buildPhaseFinished = true
571576
}
572577

573-
start () {
574-
return this.run()
575-
}
576-
577578
async run () {
578-
try {
579-
await this.buildSuite
580-
} catch (err) {
581-
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
582-
}
583579
this.parent.activeSubtests++
580+
await this.buildSuite
584581
this.startTime = hrtime()
585582

586583
if (this[kShouldAbort]()) {

test/message/test_runner_desctibe_it.js

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/389b7e138e89a339fabe4ad628bf09cd9748f957/test/message/test_runner_desctibe_it.js
1+
// https://github.com/nodejs/node/blob/a3e110820ff98702e1761831e7beaf0f5f1f75e7/test/message/test_runner_desctibe_it.js
22
// Flags: --no-warnings
33
'use strict'
44
require('../common')
@@ -149,18 +149,6 @@ describe('level 0a', { concurrency: 4 }, () => {
149149
return p0a
150150
})
151151

152-
describe('top level', { concurrency: 2 }, () => {
153-
it('+long running', async () => {
154-
return new Promise((resolve, reject) => {
155-
setTimeout(resolve, 3000).unref()
156-
})
157-
})
158-
159-
describe('+short running', async () => {
160-
it('++short running', async () => {})
161-
})
162-
})
163-
164152
describe('invalid subtest - pass but subtest fails', () => {
165153
setImmediate(() => {
166154
it('invalid subtest fail', () => {
@@ -338,3 +326,47 @@ describe('timeouts', () => {
338326
setTimeout(done, 10)
339327
})
340328
})
329+
330+
describe('successful thenable', () => {
331+
it('successful thenable', () => {
332+
let thenCalled = false
333+
return {
334+
get then () {
335+
if (thenCalled) throw new Error()
336+
thenCalled = true
337+
return (successHandler) => successHandler()
338+
}
339+
}
340+
})
341+
342+
it('rejected thenable', () => {
343+
let thenCalled = false
344+
return {
345+
get then () {
346+
if (thenCalled) throw new Error()
347+
thenCalled = true
348+
return (_, errorHandler) => errorHandler(new Error('custom error'))
349+
}
350+
}
351+
})
352+
353+
let thenCalled = false
354+
return {
355+
get then () {
356+
if (thenCalled) throw new Error()
357+
thenCalled = true
358+
return (successHandler) => successHandler()
359+
}
360+
}
361+
})
362+
363+
describe('rejected thenable', () => {
364+
let thenCalled = false
365+
return {
366+
get then () {
367+
if (thenCalled) throw new Error()
368+
thenCalled = true
369+
return (_, errorHandler) => errorHandler(new Error('custom error'))
370+
}
371+
}
372+
})

0 commit comments

Comments
 (0)