-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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: wait for stream finish when --test-force-exit #54953
Closed
+293
−6
Closed
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 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 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 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 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
24 changes: 24 additions & 0 deletions
24
test/fixtures/test-runner/output/test-runner-force-exit-dot.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,24 @@ | ||
X.X | ||
|
||
Failed tests: | ||
|
||
✖ Failing test (*ms) | ||
AssertionError [ERR_ASSERTION]: Failed | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
at new Promise (<anonymous>) | ||
* | ||
* | ||
at Array.map (<anonymous>) { | ||
generatedMessage: true, | ||
code: 'ERR_ASSERTION', | ||
actual: undefined, | ||
expected: undefined, | ||
operator: 'fail' | ||
} | ||
✖ Suite (*ms) | ||
'1 subtest failed' |
41 changes: 41 additions & 0 deletions
41
test/fixtures/test-runner/output/test-runner-force-exit-junit.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,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<testsuites> | ||
<testsuite name="Suite" time="*" disabled="0" errors="0" tests="2" failures="1" skipped="0" hostname="HOSTNAME"> | ||
<testcase name="Failing test" time="*" classname="test" failure="Failed"> | ||
<failure type="testCodeFailure" message="Failed"> | ||
Error [ERR_TEST_FAILURE]: Failed | ||
at new Promise (<anonymous>) | ||
at Array.map (<anonymous>) { | ||
code: 'ERR_TEST_FAILURE', | ||
failureType: 'testCodeFailure', | ||
cause: AssertionError [ERR_ASSERTION]: Failed | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
at new Promise (<anonymous>) | ||
* | ||
* | ||
at Array.map (<anonymous>) { | ||
generatedMessage: true, | ||
code: 'ERR_ASSERTION', | ||
actual: undefined, | ||
expected: undefined, | ||
operator: 'fail' | ||
} | ||
} | ||
</failure> | ||
</testcase> | ||
<testcase name="Passing test" time="*" classname="test"/> | ||
</testsuite> | ||
<!-- tests 2 --> | ||
<!-- suites 1 --> | ||
<!-- pass 1 --> | ||
<!-- fail 1 --> | ||
<!-- cancelled 0 --> | ||
<!-- skipped 0 --> | ||
<!-- todo 0 --> | ||
<!-- duration_ms * --> | ||
</testsuites> |
52 changes: 52 additions & 0 deletions
52
test/fixtures/test-runner/output/test-runner-force-exit-spec.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,52 @@ | ||
▶ Suite | ||
✖ Failing test (*ms) | ||
AssertionError [ERR_ASSERTION]: Failed | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
at new Promise (<anonymous>) | ||
* | ||
* | ||
at Array.map (<anonymous>) { | ||
generatedMessage: true, | ||
code: 'ERR_ASSERTION', | ||
actual: undefined, | ||
expected: undefined, | ||
operator: 'fail' | ||
} | ||
|
||
✔ Passing test (*ms) | ||
▶ Suite (*ms) | ||
ℹ tests 2 | ||
ℹ suites 1 | ||
ℹ pass 1 | ||
ℹ fail 1 | ||
ℹ cancelled 0 | ||
ℹ skipped 0 | ||
ℹ todo 0 | ||
ℹ duration_ms * | ||
|
||
✖ failing tests: | ||
|
||
* | ||
✖ Failing test (*ms) | ||
AssertionError [ERR_ASSERTION]: Failed | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
at new Promise (<anonymous>) | ||
* | ||
* | ||
at Array.map (<anonymous>) { | ||
generatedMessage: true, | ||
code: 'ERR_ASSERTION', | ||
actual: undefined, | ||
expected: undefined, | ||
operator: 'fail' | ||
} |
48 changes: 48 additions & 0 deletions
48
test/fixtures/test-runner/output/test-runner-force-exit-tap.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,48 @@ | ||
TAP version 13 | ||
# Subtest: Suite | ||
# Subtest: Failing test | ||
not ok 1 - Failing test | ||
--- | ||
duration_ms: * | ||
location: '/test/fixtures/test-runner/output/test-runner-force-exit.js:(LINE):5' | ||
failureType: 'testCodeFailure' | ||
error: 'Failed' | ||
code: 'ERR_ASSERTION' | ||
name: 'AssertionError' | ||
operator: 'fail' | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
new Promise (<anonymous>) | ||
* | ||
* | ||
Array.map (<anonymous>) | ||
... | ||
# Subtest: Passing test | ||
ok 2 - Passing test | ||
--- | ||
duration_ms: * | ||
... | ||
1..2 | ||
not ok 1 - Suite | ||
--- | ||
duration_ms: * | ||
type: 'suite' | ||
location: '/test/fixtures/test-runner/output/test-runner-force-exit.js:(LINE):1' | ||
failureType: 'subtestsFailed' | ||
error: '1 subtest failed' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
1..1 | ||
# tests 2 | ||
# suites 1 | ||
# pass 1 | ||
# fail 1 | ||
# cancelled 0 | ||
# skipped 0 | ||
# todo 0 | ||
# duration_ms * |
12 changes: 12 additions & 0 deletions
12
test/fixtures/test-runner/output/test-runner-force-exit.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,12 @@ | ||
const { describe, test } = require('node:test'); | ||
const assert = require('node:assert'); | ||
|
||
describe('Suite', () => { | ||
test('Failing test', () => { | ||
assert.fail() | ||
}) | ||
|
||
test('Passing test', () => { | ||
assert.ok(true) | ||
}) | ||
}); |
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,97 @@ | ||
import * as common from '../common/index.mjs'; | ||
import * as tmpdir from '../common/tmpdir.js'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import * as snapshot from '../common/assertSnapshot.js'; | ||
import { describe, it } from 'node:test'; | ||
import { hostname } from 'node:os'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { readFile } from 'node:fs/promises'; | ||
|
||
function replaceTestDuration(str) { | ||
return str | ||
.replaceAll(/duration_ms: [0-9.]+/g, 'duration_ms: *') | ||
.replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *'); | ||
} | ||
|
||
const root = fileURLToPath(new URL('../..', import.meta.url)).slice(0, -1); | ||
|
||
const color = '(\\[\\d+m)'; | ||
const stackTraceBasePath = new RegExp(`${color}\\(${root.replaceAll(/[\\^$*+?.()|[\]{}]/g, '\\$&')}/?${color}(.*)${color}\\)`, 'g'); | ||
|
||
function replaceSpecDuration(str) { | ||
return str | ||
.replaceAll(/[0-9.]+ms/g, '*ms') | ||
.replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *') | ||
.replace(stackTraceBasePath, '$3'); | ||
} | ||
|
||
function replaceJunitDuration(str) { | ||
return str | ||
.replaceAll(/time="[0-9.]+"/g, 'time="*"') | ||
.replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *') | ||
.replaceAll(hostname(), 'HOSTNAME') | ||
.replace(stackTraceBasePath, '$3'); | ||
} | ||
|
||
function removeWindowsPathEscaping(str) { | ||
return common.isWindows ? str.replaceAll(/\\\\/g, '\\') : str; | ||
} | ||
|
||
function replaceTestLocationLine(str) { | ||
return str.replaceAll(/(js:)(\d+)(:\d+)/g, '$1(LINE)$3'); | ||
} | ||
|
||
const defaultTransform = snapshot.transform( | ||
snapshot.replaceWindowsLineEndings, | ||
snapshot.replaceStackTrace, | ||
removeWindowsPathEscaping, | ||
snapshot.replaceFullPaths, | ||
snapshot.replaceWindowsPaths, | ||
replaceTestDuration, | ||
replaceTestLocationLine, | ||
); | ||
|
||
const transformers = { | ||
junit: snapshot.transform( | ||
replaceJunitDuration, | ||
snapshot.replaceWindowsLineEndings, | ||
snapshot.replaceStackTrace, | ||
snapshot.replaceWindowsPaths, | ||
), | ||
spec: snapshot.transform( | ||
replaceSpecDuration, | ||
snapshot.replaceWindowsLineEndings, | ||
snapshot.replaceStackTrace, | ||
snapshot.replaceWindowsPaths, | ||
), | ||
dot: snapshot.transform( | ||
replaceSpecDuration, | ||
snapshot.replaceWindowsLineEndings, | ||
snapshot.replaceStackTrace, | ||
snapshot.replaceWindowsPaths, | ||
), | ||
}; | ||
|
||
describe('test runner output', { concurrency: true }, async () => { | ||
tmpdir.refresh(); | ||
for (const reporter of ['dot', 'junit', 'spec', 'tap']) { | ||
await it(reporter, async (t) => { | ||
const output = tmpdir.resolve(`${reporter}.out`); | ||
const spawned = await common.spawnPromisified( | ||
process.execPath, | ||
[ | ||
'--test', | ||
'--test-force-exit', | ||
`--test-reporter=${reporter}`, | ||
`--test-reporter-destination=${output}`, | ||
fixtures.path('test-runner/output/test-runner-force-exit.js'), | ||
], | ||
); | ||
t.assert.deepStrictEqual(spawned, { code: 1, signal: null, stderr: '', stdout: '' }); | ||
const transformer = transformers[reporter] || defaultTransform; | ||
const outputData = await readFile(output, 'utf-8'); | ||
await snapshot.assertSnapshot(transformer(outputData), fixtures.path(`test-runner/output/test-runner-force-exit-${reporter}.output`)); | ||
}); | ||
} | ||
tmpdir.refresh(); | ||
}); |
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.
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.
@cjihrig the issue was that I was originally appending
stream
, notdestination
.