test_runner: fix global before not called when no global test exists#48877
Conversation
|
Review requested:
|
| 'global after', | ||
| ]); | ||
| } catch (e) { | ||
| // TODO(rluvaton): remove the try catch after #48867 is fixed |
There was a problem hiding this comment.
because of #48867 we must use process.exit as otherwise, it won't fail the test
| 'describe afterEach', | ||
| 'describe nested afterEach', |
There was a problem hiding this comment.
it seems really weird that we executing top describe afterEach before the nested one...
There was a problem hiding this comment.
I see #48736 (comment) also talked about afterEach...
lib/internal/test_runner/test.js
Outdated
| } | ||
|
|
||
| if (this.parent?.hooks.before.length > 0) { | ||
| await this.parent.runHook('before', this.parent?.getRunArgs()); |
There was a problem hiding this comment.
If we reach here this.parent will have a value (and we already call runHook without the optional chaining)
| await this.parent.runHook('before', this.parent?.getRunArgs()); | |
| await this.parent.runHook('before', this.parent.getRunArgs()); |
There was a problem hiding this comment.
I would expect this to replace the call to this.runHook('before', hookArgs);, and also for the same implementation for beforeEach, afterEach and after
There was a problem hiding this comment.
We can't for after as if there are multiple describe we only need to run for the last one after all test completes
There was a problem hiding this comment.
Why did you expect that? Current describe hooks have different hookArgs that the parent (which I think is why some tests are failing when I run with the current tests args)
There was a problem hiding this comment.
I guess It is just surprising that the before and after hooks are not "symmetric"
There was a problem hiding this comment.
It is, the first describe should run the before and the last describe should run the after...
There was a problem hiding this comment.
I would simply expect to also see this.parent.runHook('after') - but I guess I am missing something
There was a problem hiding this comment.
let's take this test for example:
const {describe, it, before, after} = require("node:test");
describe('top desc', () => {
before(() => {
console.log('before top desc');
});
after(() => {
console.log('after top desc');
});
describe('inner describe 1', () => {
before(() => {
console.log('before inner 1 desc');
});
after(() => {
console.log('after inner 1 desc');
});
it('inner it 1', () => {
console.log('inner it 1');
});
});
describe('inner describe 2', () => {
before(() => {
console.log('before inner 2 desc');
});
after(() => {
console.log('after inner 2 desc');
});
it('inner it 1', () => {
console.log('inner it 2');
});
});
});the expected log is:
before top desc
before inner 1 desc
inner it 1
after inner 1 desc
before inner 2 desc
inner it 2
after inner 2 desc
after top desc <-----
if I add this.parent.runHook('after') as well the output will be:
before top desc
before inner 1 desc
inner it 1
after top desc <-----
after inner 1 desc
before inner 2 desc
inner it 2
after inner 2 desc
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
MoLow
left a comment
There was a problem hiding this comment.
LGTM. I think afterEach and beforeEach might need the same fix, but that can be handled by another PR
|
There is no need as we concat the before and after each in the constructor |
|
Landed in a0f3ed8 |
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: #48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
|
This commit didn't land cleanly on v20.x-staging. Could you please open a manual backport? Reference: https://github.com/nodejs/node/blob/main/doc/contributing/backporting-to-release-lines.md |
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: #48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: #48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs/node#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
PR-URL: nodejs/node#48877 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
fix #48844