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: call {before,after}Each() on suites #45161

Merged
merged 1 commit into from Oct 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/internal/test_runner/test.js
Expand Up @@ -731,13 +731,24 @@ class Suite extends Test {
}

const hookArgs = this.getRunArgs();

if (this.parent?.hooks.beforeEach.length > 0) {
await this.parent[kRunHook]('beforeEach', hookArgs);
}

await this[kRunHook]('before', hookArgs);

const stopPromise = stopTest(this.timeout, this.signal);
const subtests = this.skipped || this.error ? [] : this.subtests;
const promise = SafePromiseAll(subtests, (subtests) => subtests.start());

await SafePromiseRace([promise, stopPromise]);
await this[kRunHook]('after', hookArgs);

if (this.parent?.hooks.afterEach.length > 0) {
await this.parent[kRunHook]('afterEach', hookArgs);
}

this.pass();
} catch (err) {
if (isTestFailureError(err)) {
Expand Down
2 changes: 2 additions & 0 deletions test/message/test_runner_hooks.js
Expand Up @@ -15,10 +15,12 @@ describe('describe hooks', () => {
'before describe hooks',
'beforeEach 1', '1', 'afterEach 1',
'beforeEach 2', '2', 'afterEach 2',
'beforeEach nested',
'before nested',
'beforeEach nested 1', 'nested 1', 'afterEach nested 1',
'beforeEach nested 2', 'nested 2', 'afterEach nested 2',
'after nested',
'afterEach nested',
'after describe hooks',
]);
});
Expand Down
4 changes: 2 additions & 2 deletions test/message/test_runner_test_name_pattern.js
Expand Up @@ -34,8 +34,8 @@ test('top level test enabled', common.mustCall(async (t) => {

describe('top level describe enabled', () => {
before(common.mustCall());
beforeEach(common.mustCall(2));
afterEach(common.mustCall(2));
beforeEach(common.mustCall(4));
afterEach(common.mustCall(4));
after(common.mustCall());

it('nested it disabled', common.mustNotCall());
Expand Down