-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
- Loading branch information
Showing
37 changed files
with
432 additions
and
318 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'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; | ||
|
||
function replaceStackTrace(str) { | ||
return str.replace(stackFramesRegexp, '$1*$7\n'); | ||
} | ||
|
||
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); | ||
const expected = process.env.NODE_REGENERATE_SHANPSHOTS ? actual : await fs.readFile(snapshot, 'utf8'); | ||
if (process.env.NODE_REGENERATE_SHANPSHOTS) { | ||
await fs.writeFile(snapshot, actual); | ||
} | ||
assert.strictEqual(actual, expected); | ||
} | ||
|
||
async function spawnAndAssert(filename, transform = (x) => x) { | ||
const flags = common.parseTestFlags(filename); | ||
const { stderr, stdout } = await common.spawnPromisified(process.execPath, [...flags, filename]); | ||
await assertSnapshot(transform(`${stdout}${stderr}`), filename); | ||
} | ||
|
||
module.exports = { | ||
assertSnapshot, | ||
getSnapshotPath, | ||
replaceStackTrace, | ||
spawnAndAssert, | ||
transform, | ||
}; |
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.
2 changes: 1 addition & 1 deletion
2
test/message/test_runner_hooks.js β test/fixtures/test-runner/output/hooks.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
Oops, something went wrong.