-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Test reporter #56438
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
Test reporter #56438
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5167a85
test: add error only reporter for node:test
cjihrig f71e6d8
temp - add a failure
cjihrig d004f46
apply to GHA
cjihrig d34f649
fixup! test: add error only reporter for node:test
Ceres6 0e1ecd1
remove example test fail
Ceres6 63c7fac
Apply suggestions from code review
Ceres6 01f7d09
apply to GHA
cjihrig 0ce6e5c
test: use unusual chars in the path to ensure our tests are robust
aduh95 d2f1d56
apply to GHA
cjihrig 4547f09
fixup! apply to GHA
Ceres6 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
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
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,41 @@ | ||
| 'use strict'; | ||
| const { relative } = require('node:path'); | ||
| const { inspect } = require('node:util'); | ||
| const cwd = process.cwd(); | ||
|
|
||
| module.exports = async function* errorReporter(source) { | ||
| for await (const event of source) { | ||
| if (event.type === 'test:fail') { | ||
| const { name, details, line, column, file } = event.data; | ||
| let { error } = details; | ||
|
|
||
| if (error?.failureType === 'subtestsFailed') { | ||
| // In the interest of keeping things concise, skip failures that are | ||
| // only due to nested failures. | ||
| continue; | ||
| } | ||
|
|
||
| if (error?.code === 'ERR_TEST_FAILURE') { | ||
| error = error.cause; | ||
| } | ||
|
|
||
| const output = [ | ||
| `Test failure: '${name}'`, | ||
| ]; | ||
|
|
||
| if (file) { | ||
| output.push(`Location: ${relative(cwd, file)}:${line}:${column}`); | ||
| } | ||
|
|
||
| output.push(inspect(error)); | ||
| output.push('\n'); | ||
| yield output.join('\n'); | ||
|
|
||
| if (process.env.FAIL_FAST) { | ||
| yield `\n\u001b[31m✖ Bailing on failed test: ${event.data.name}\u001b[0m\n`; | ||
| process.exitCode = 1; | ||
| process.emit('SIGINT'); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
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,6 @@ | ||
| const assert = require('node:assert'); | ||
| const { test } = require('node:test'); | ||
|
|
||
| test('fail', () => { | ||
| assert.fail('a.mjs fail'); | ||
| }); |
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,6 @@ | ||
| const assert = require('node:assert'); | ||
| const { test } = require('node:test'); | ||
|
|
||
| test('fail', () => { | ||
| assert.fail('b.mjs fail'); | ||
| }); |
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,33 @@ | ||
| 'use strict'; | ||
|
|
||
| require('../common'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const assert = require('node:assert'); | ||
| const { spawnSync } = require('node:child_process'); | ||
| const { test } = require('node:test'); | ||
| const cwd = fixtures.path('test-runner', 'error-reporter-fail-fast'); | ||
| const env = { ...process.env }; | ||
|
|
||
| test('all tests failures reported without FAIL_FAST flag', async () => { | ||
| const args = [ | ||
| '--test-reporter=./test/common/test-error-reporter.js', | ||
| '--test-concurrency=1', | ||
| '--test', | ||
| `${cwd}/*.mjs`, | ||
| ]; | ||
| const cp = spawnSync(process.execPath, args, { env }); | ||
Ceres6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const failureCount = (cp.stdout.toString().match(/Test failure:/g) || []).length; | ||
| assert.strictEqual(failureCount, 2); | ||
| }); | ||
|
|
||
| test('FAIL_FAST stops test execution after first failure', async () => { | ||
| const args = [ | ||
| '--test-reporter=./test/common/test-error-reporter.js', | ||
| '--test-concurrency=1', | ||
| '--test', | ||
| `${cwd}/*.mjs`, | ||
| ]; | ||
| const cp = spawnSync(process.execPath, args, { env: { ...env, FAIL_FAST: 'true' } }); | ||
Ceres6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const failureCount = (cp.stdout.toString().match(/Test failure:/g) || []).length; | ||
| assert.strictEqual(failureCount, 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.