-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
test_runner: add testId to test events
#62772
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,21 @@ | ||
| 'use strict'; | ||
| const { describe, it } = require('node:test'); | ||
| const assert = require('node:assert'); | ||
|
|
||
| // Factory that creates subtests at the SAME source location. | ||
| // Multiple concurrent `it` blocks calling this will have subtests | ||
| // sharing file:line:column — but each should get a distinct testId. | ||
| function makeSubtest(shouldFail) { | ||
| return async function(t) { | ||
| await t.test('e2e', async () => { | ||
| if (shouldFail) assert.fail('intentional'); | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| describe('suite', { concurrency: 10_000 }, () => { | ||
| it('test-A (passes)', makeSubtest(false)); | ||
| it('test-B (passes)', makeSubtest(false)); | ||
| it('test-C (fails)', makeSubtest(true)); | ||
| it('test-D (passes)', makeSubtest(false)); | ||
| }); |
This file contains hidden or 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,76 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const assert = require('node:assert'); | ||
| const { run } = require('node:test'); | ||
| const fixtures = require('../common/fixtures'); | ||
|
|
||
| async function collectEvents() { | ||
| const events = []; | ||
| const stream = run({ | ||
| files: [fixtures.path('test-runner/test-id-fixture.js')], | ||
| isolation: 'none', | ||
| }); | ||
| for await (const event of stream) { | ||
| events.push(event); | ||
| } | ||
| return events; | ||
| } | ||
|
|
||
| async function main() { | ||
| const events = await collectEvents(); | ||
|
|
||
| // 1. Every per-test event should have a numeric testId. | ||
| const perTestTypes = new Set([ | ||
| 'test:start', 'test:complete', 'test:fail', | ||
| 'test:pass', 'test:enqueue', 'test:dequeue', | ||
| ]); | ||
| for (const event of events) { | ||
| if (perTestTypes.has(event.type)) { | ||
| assert.strictEqual(typeof event.data.testId, 'number', | ||
| `${event.type} for "${event.data.name}" should have numeric testId`); | ||
| } | ||
| } | ||
|
|
||
| // 2. test:start and test:fail for the same instance should share testId. | ||
| const failEvent = events.find( | ||
| (e) => e.type === 'test:fail' && e.data.name === 'e2e', | ||
| ); | ||
| assert.ok(failEvent, 'should have a test:fail for "e2e"'); | ||
|
|
||
| const startEvent = events.find( | ||
| (e) => e.type === 'test:start' && | ||
| e.data.testId === failEvent.data.testId, | ||
| ); | ||
| assert.ok(startEvent, 'should have a test:start with matching testId'); | ||
| assert.strictEqual(startEvent.data.name, 'e2e'); | ||
|
|
||
| // 3. Concurrent instances at the same source location get distinct testIds. | ||
| const e2eStarts = events.filter( | ||
| (e) => e.type === 'test:start' && e.data.name === 'e2e', | ||
| ); | ||
| assert.strictEqual(e2eStarts.length, 4); | ||
|
|
||
| const testIds = e2eStarts.map((e) => e.data.testId); | ||
| const uniqueIds = new Set(testIds); | ||
| assert.strictEqual(uniqueIds.size, 4, | ||
| `all 4 "e2e" instances should have distinct testIds, got: ${testIds}`); | ||
|
|
||
| // 4. test:complete for the same instance shares testId with test:start. | ||
| const completeEvents = events.filter( | ||
| (e) => e.type === 'test:complete' && e.data.name === 'e2e', | ||
| ); | ||
| for (const complete of completeEvents) { | ||
| const matchingStart = e2eStarts.find( | ||
| (s) => s.data.testId === complete.data.testId, | ||
| ); | ||
| assert.ok(matchingStart, | ||
| `test:complete (testId=${complete.data.testId}) should match a test:start`); | ||
| } | ||
|
|
||
| console.log('All testId assertions passed'); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.