-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate test runner message tests to snapshot
PR-URL: #47392 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
Showing
41 changed files
with
460 additions
and
331 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules β¦
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
const common = require('.'); | ||
const path = require('node:path'); | ||
const fs = require('node:fs/promises'); | ||
const assert = require('node:assert/strict'); | ||
|
||
|
||
const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\n|$)/g; | ||
const windowNewlineRegexp = /\r/g; | ||
|
||
function replaceStackTrace(str) { | ||
return str.replace(stackFramesRegexp, '$1*$7\n'); | ||
} | ||
|
||
function replaceWindowsLineEndings(str) { | ||
return str.replace(windowNewlineRegexp, ''); | ||
} | ||
|
||
function transform(...args) { | ||
return (str) => args.reduce((acc, fn) => fn(acc), str); | ||
} | ||
|
||
function getSnapshotPath(filename) { | ||
const { name, dir } = path.parse(filename); | ||
return path.resolve(dir, `${name}.snapshot`); | ||
} | ||
|
||
async function assertSnapshot(actual, filename = process.argv[1]) { | ||
const snapshot = getSnapshotPath(filename); | ||
if (process.env.NODE_REGENERATE_SNAPSHOTS) { | ||
await fs.writeFile(snapshot, actual); | ||
} else { | ||
const expected = await fs.readFile(snapshot, 'utf8'); | ||
assert.strictEqual(actual, replaceWindowsLineEndings(expected)); | ||
} | ||
} | ||
|
||
async function spawnAndAssert(filename, transform = (x) => x) { | ||
// TODO: Add an option to this function to alternatively or additionally compare stderr. | ||
// For now, tests that want to check stderr or both stdout and stderr can use spawnPromisified. | ||
const flags = common.parseTestFlags(filename); | ||
const { stdout } = await common.spawnPromisified(process.execPath, [...flags, filename]); | ||
await assertSnapshot(transform(stdout), filename); | ||
} | ||
|
||
module.exports = { | ||
assertSnapshot, | ||
getSnapshotPath, | ||
replaceStackTrace, | ||
replaceWindowsLineEndings, | ||
spawnAndAssert, | ||
transform, | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
test/message/test_runner_abort.js β test/fixtures/test-runner/output/abort.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
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
2 changes: 1 addition & 1 deletion
2
test/message/test_runner_abort_suite.js β ...ixtures/test-runner/output/abort_suite.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
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
2 changes: 1 addition & 1 deletion
2
test/message/test_runner_describe_it.js β ...ixtures/test-runner/output/describe_it.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
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
2 changes: 1 addition & 1 deletion
2
test/message/test_runner_describe_nested.js β ...res/test-runner/output/describe_nested.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
File renamed without changes.
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,8 @@ | ||
// Flags: --no-warnings | ||
'use strict'; | ||
require('../../../common'); | ||
const fixtures = require('../../../common/fixtures'); | ||
const spawn = require('node:child_process').spawn; | ||
|
||
spawn(process.execPath, | ||
['--no-warnings', '--test-reporter', 'dot', fixtures.path('test-runner/output/output.js')], { stdio: 'inherit' }); |
File renamed without changes.
Oops, something went wrong.