Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: fix async callback in describe not awaited #48856

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
ObjectSeal,
PromisePrototypeThen,
PromiseResolve,
SafePromisePrototypeFinally,
ReflectApply,
RegExpPrototypeExec,
SafeMap,
Expand Down Expand Up @@ -783,17 +784,23 @@ class Suite extends Test {
const { ctx, args } = this.getRunArgs();
const runArgs = [this.fn, ctx];
ArrayPrototypePushApply(runArgs, args);
this.buildSuite = PromisePrototypeThen(
PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)),
undefined,
(err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
});
this.buildSuite = SafePromisePrototypeFinally(
PromisePrototypeThen(
PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)),
undefined,
(err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}),
() => {
this.buildPhaseFinished = true;
},
);
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));

this.buildPhaseFinished = true;
}
this.fn = () => {};
this.buildPhaseFinished = true;
}

getRunArgs() {
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/test-runner/output/describe_it.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,22 @@ describe('rejected thenable', () => {
},
};
});

describe("async describe function", async () => {
await null;

await it("it inside describe 1", async () => {
await null
});
await it("it inside describe 2", async () => {
await null;
});

describe("inner describe", async () => {
await null;

it("it inside inner describe", async () => {
await null;
});
});
});
39 changes: 34 additions & 5 deletions test/fixtures/test-runner/output/describe_it.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,37 @@ not ok 59 - rejected thenable
stack: |-
*
...
# Subtest: async describe function
# Subtest: it inside describe 1
ok 1 - it inside describe 1
---
duration_ms: *
...
# Subtest: it inside describe 2
ok 2 - it inside describe 2
---
duration_ms: *
...
# Subtest: inner describe
# Subtest: it inside inner describe
ok 1 - it inside inner describe
---
duration_ms: *
...
1..1
ok 3 - inner describe
---
duration_ms: *
type: 'suite'
...
1..3
ok 60 - async describe function
---
duration_ms: *
type: 'suite'
...
# Subtest: invalid subtest fail
not ok 60 - invalid subtest fail
not ok 61 - invalid subtest fail
---
duration_ms: *
failureType: 'parentAlreadyFinished'
Expand All @@ -645,16 +674,16 @@ not ok 60 - invalid subtest fail
stack: |-
*
...
1..60
1..61
# Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
# Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
# Warning: Test "immediate throw - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from immediate throw fail" and would have caused the test to fail, but instead triggered an uncaughtException event.
# Warning: Test "immediate reject - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from immediate reject fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
# Warning: Test "callback called twice in different ticks" generated asynchronous activity after the test ended. This activity created the error "Error [ERR_TEST_FAILURE]: callback invoked multiple times" and would have caused the test to fail, but instead triggered an uncaughtException event.
# Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event.
# tests 67
# suites 9
# pass 29
# tests 70
# suites 11
# pass 32
# fail 19
# cancelled 4
# skipped 10
Expand Down