Skip to content

Commit

Permalink
fix: fix top level describe queuing
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#43998
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
(cherry picked from commit a3e110820ff98702e1761831e7beaf0f5f1f75e7)
  • Loading branch information
MoLow authored and aduh95 committed Jul 29, 2022
1 parent 4071052 commit c6f554c
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 94 deletions.
19 changes: 8 additions & 11 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/60da0a1b364efdd84870269d23b39faa12fb46d8/lib/internal/test_runner/test.js
// https://github.com/nodejs/node/blob/a3e110820ff98702e1761831e7beaf0f5f1f75e7/lib/internal/test_runner/test.js

'use strict'

Expand Down Expand Up @@ -562,25 +562,22 @@ class Suite extends Test {

try {
const context = { signal: this.signal }
this.buildSuite = this.runInAsyncScope(this.fn, context, [context])
this.buildSuite = PromisePrototypeThen(
PromiseResolve(this.runInAsyncScope(this.fn, context, [context])),
undefined,
(err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
})
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
}
this.fn = () => {}
this.buildPhaseFinished = true
}

start () {
return this.run()
}

async run () {
try {
await this.buildSuite
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure))
}
this.parent.activeSubtests++
await this.buildSuite
this.startTime = hrtime()

if (this[kShouldAbort]()) {
Expand Down
58 changes: 45 additions & 13 deletions test/message/test_runner_desctibe_it.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/389b7e138e89a339fabe4ad628bf09cd9748f957/test/message/test_runner_desctibe_it.js
// https://github.com/nodejs/node/blob/a3e110820ff98702e1761831e7beaf0f5f1f75e7/test/message/test_runner_desctibe_it.js
// Flags: --no-warnings
'use strict'
require('../common')
Expand Down Expand Up @@ -149,18 +149,6 @@ describe('level 0a', { concurrency: 4 }, () => {
return p0a
})

describe('top level', { concurrency: 2 }, () => {
it('+long running', async () => {
return new Promise((resolve, reject) => {
setTimeout(resolve, 3000).unref()
})
})

describe('+short running', async () => {
it('++short running', async () => {})
})
})

describe('invalid subtest - pass but subtest fails', () => {
setImmediate(() => {
it('invalid subtest fail', () => {
Expand Down Expand Up @@ -338,3 +326,47 @@ describe('timeouts', () => {
setTimeout(done, 10)
})
})

describe('successful thenable', () => {
it('successful thenable', () => {
let thenCalled = false
return {
get then () {
if (thenCalled) throw new Error()
thenCalled = true
return (successHandler) => successHandler()
}
}
})

it('rejected thenable', () => {
let thenCalled = false
return {
get then () {
if (thenCalled) throw new Error()
thenCalled = true
return (_, errorHandler) => errorHandler(new Error('custom error'))
}
}
})

let thenCalled = false
return {
get then () {
if (thenCalled) throw new Error()
thenCalled = true
return (successHandler) => successHandler()
}
}
})

describe('rejected thenable', () => {
let thenCalled = false
return {
get then () {
if (thenCalled) throw new Error()
thenCalled = true
return (_, errorHandler) => errorHandler(new Error('custom error'))
}
}
})
Loading

0 comments on commit c6f554c

Please sign in to comment.