-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 global before not called when no global test exists #48877
Merged
nodejs-github-bot
merged 5 commits into
nodejs:main
from
rluvaton:global-before-not-run-if-no-global-test
Jul 24, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2969867
test_runner: fix global before not called when no global test exists
rluvaton 99786ae
add test
rluvaton 5b2c5d6
remove ?.
rluvaton 6c5a5af
Update test/fixtures/test-runner/output/hooks-with-no-global-test.js
rluvaton f2c551c
remove ?.
rluvaton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
test/fixtures/test-runner/output/hooks-with-no-global-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict'; | ||
const { test, describe, it, before, after, beforeEach, afterEach } = require('node:test'); | ||
const assert = require("assert"); | ||
|
||
// This file should not have any global tests to reproduce bug #48844 | ||
const testArr = []; | ||
|
||
before(() => testArr.push('global before')); | ||
after(() => { | ||
testArr.push('global after'); | ||
|
||
try { | ||
assert.deepStrictEqual(testArr, [ | ||
'global before', | ||
'describe before', | ||
|
||
'describe beforeEach', | ||
'describe it 1', | ||
'describe afterEach', | ||
|
||
'describe beforeEach', | ||
'describe test 2', | ||
'describe afterEach', | ||
|
||
'describe nested before', | ||
|
||
'describe beforeEach', | ||
'describe nested beforeEach', | ||
'describe nested it 1', | ||
'describe afterEach', | ||
'describe nested afterEach', | ||
|
||
'describe beforeEach', | ||
'describe nested beforeEach', | ||
'describe nested test 2', | ||
'describe afterEach', | ||
'describe nested afterEach', | ||
|
||
'describe nested after', | ||
'describe after', | ||
'global after', | ||
]); | ||
} catch (e) { | ||
// TODO(rluvaton): remove the try catch after #48867 is fixed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because of #48867 we must use |
||
console.error(e); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
describe('describe hooks with no global tests', () => { | ||
before(() => { | ||
testArr.push('describe before'); | ||
}); | ||
after(()=> { | ||
testArr.push('describe after'); | ||
}); | ||
beforeEach(() => { | ||
testArr.push('describe beforeEach'); | ||
}); | ||
afterEach(() => { | ||
testArr.push('describe afterEach'); | ||
}); | ||
|
||
it('1', () => testArr.push('describe it 1')); | ||
test('2', () => testArr.push('describe test 2')); | ||
|
||
describe('nested', () => { | ||
before(() => { | ||
testArr.push('describe nested before') | ||
}); | ||
after(() => { | ||
testArr.push('describe nested after') | ||
}); | ||
beforeEach(() => { | ||
testArr.push('describe nested beforeEach') | ||
}); | ||
afterEach(() => { | ||
testArr.push('describe nested afterEach') | ||
}); | ||
|
||
it('nested 1', () => testArr.push('describe nested it 1')); | ||
test('nested 2', () => testArr.push('describe nested test 2')); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
test/fixtures/test-runner/output/hooks-with-no-global-test.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
TAP version 13 | ||
# Subtest: describe hooks with no global tests | ||
# Subtest: 1 | ||
ok 1 - 1 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: 2 | ||
ok 2 - 2 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: nested | ||
# Subtest: nested 1 | ||
ok 1 - nested 1 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: nested 2 | ||
ok 2 - nested 2 | ||
--- | ||
duration_ms: * | ||
... | ||
1..2 | ||
ok 3 - nested | ||
--- | ||
duration_ms: * | ||
type: 'suite' | ||
... | ||
1..3 | ||
ok 1 - describe hooks with no global tests | ||
--- | ||
duration_ms: * | ||
type: 'suite' | ||
... | ||
1..1 | ||
# tests 4 | ||
# suites 2 | ||
# pass 4 | ||
# fail 0 | ||
# cancelled 0 | ||
# skipped 0 | ||
# todo 0 | ||
# duration_ms * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems really weird that we executing top describe
afterEach
before the nested one...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see #48736 (comment) also talked about
afterEach
...