Skip to content

Commit 1f76732

Browse files
committed
fixup! test: unify assertSnapshot common patterns
1 parent f67151d commit 1f76732

File tree

72 files changed

+386
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+386
-374
lines changed

test/common/assertSnapshot.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const { hostname } = require('node:os');
1010
const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g;
1111
const windowNewlineRegexp = /\r/g;
1212

13+
// Replaces the current Node.js executable version strings with a
14+
// placeholder. This could commonly present in an unhandled exception
15+
// output.
1316
function replaceNodeVersion(str) {
1417
return str.replaceAll(process.version, '<node-version>');
1518
}
@@ -24,29 +27,38 @@ function replaceInternalStackTrace(str) {
2427
return str.replaceAll(/(\W+).*[(\s]node:.*/g, '$1*');
2528
}
2629

30+
// Replaces Windows line endings with posix line endings for unified snapshots
31+
// across platforms.
2732
function replaceWindowsLineEndings(str) {
2833
return str.replace(windowNewlineRegexp, '');
2934
}
3035

36+
// Replaces all Windows path separators with posix separators for unified snapshots
37+
// across platforms.
3138
function replaceWindowsPaths(str) {
3239
return common.isWindows ? str.replaceAll(path.win32.sep, path.posix.sep) : str;
3340
}
3441

42+
// Removes line trailing white spaces.
3543
function replaceTrailingSpaces(str) {
3644
return str.replaceAll(/[\t ]+\n/g, '\n');
3745
}
3846

39-
// Replaces customized or platform specific executable names to be `node`.
47+
// Replaces customized or platform specific executable names to be `<node-exe>`.
4048
function generalizeExeName(str) {
4149
const baseName = path.basename(process.argv0 || 'node', '.exe');
42-
return str.replaceAll(`${baseName} --`, 'node --');
50+
return str.replaceAll(`${baseName} --`, '<node-exe> --');
4351
}
4452

53+
// Replaces the pids in warning messages with a placeholder.
4554
function replaceWarningPid(str) {
4655
return str.replaceAll(/\(node:\d+\)/g, '(node:<pid>)');
4756
}
4857

49-
function transformProjectRoot(replacement = '') {
58+
// Replaces path strings representing the nodejs/node repo full project root with
59+
// `<project-root>`. Also replaces file URLs containing the full project root path.
60+
// The project root path may contain unicode characters.
61+
function transformProjectRoot(replacement = '<project-root>') {
5062
const projectRoot = path.resolve(__dirname, '../..');
5163
// Handles URL encoded project root in file URL strings as well.
5264
const urlEncoded = pathToFileURL(projectRoot).pathname;

test/fixtures/console/stack_overflow.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
before
2-
/test/fixtures/console/stack_overflow.js:*
2+
<project-root>/test/fixtures/console/stack_overflow.js:*
33
JSON.stringify(array);
44
^
55

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Error: test
2-
at one (file:///[eval1]:2:9)
3-
at two (file:///[eval1]:15:9)
4-
at async three (file:///[eval1]:18:3)
5-
at async four (file:///[eval1]:22:3)
6-
at async main (file:///[eval1]:28:5)
2+
at one (file://<project-root>/[eval1]:2:9)
3+
at two (file://<project-root>/[eval1]:15:9)
4+
at async three (file://<project-root>/[eval1]:18:3)
5+
at async four (file://<project-root>/[eval1]:22:3)
6+
at async main (file://<project-root>/[eval1]:28:5)
77

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Error: test
2-
at one (/test/fixtures/async-error.js:4:9)
3-
at two (/test/fixtures/async-error.js:17:9)
4-
at async three (/test/fixtures/async-error.js:20:3)
5-
at async four (/test/fixtures/async-error.js:24:3)
6-
at async main (/test/fixtures/errors/async_error_microtask_main.js:7:5)
2+
at one (<project-root>/test/fixtures/async-error.js:4:9)
3+
at two (<project-root>/test/fixtures/async-error.js:17:9)
4+
at async three (<project-root>/test/fixtures/async-error.js:20:3)
5+
at async four (<project-root>/test/fixtures/async-error.js:24:3)
6+
at async main (<project-root>/test/fixtures/errors/async_error_microtask_main.js:7:5)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Error: test
2-
at one (/test/fixtures/async-error.js:4:9)
3-
at two (/test/fixtures/async-error.js:17:9)
2+
at one (<project-root>/test/fixtures/async-error.js:4:9)
3+
at two (<project-root>/test/fixtures/async-error.js:17:9)
44
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
5-
at async three (/test/fixtures/async-error.js:20:3)
6-
at async four (/test/fixtures/async-error.js:24:3)
7-
at async main (/test/fixtures/errors/async_error_nexttick_main.js:7:5)
5+
at async three (<project-root>/test/fixtures/async-error.js:20:3)
6+
at async four (<project-root>/test/fixtures/async-error.js:24:3)
7+
at async main (<project-root>/test/fixtures/errors/async_error_nexttick_main.js:7:5)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Error: test
2-
at one (/test/fixtures/async-error.js:4:9)
3-
at two (/test/fixtures/async-error.js:17:9)
4-
at async three (/test/fixtures/async-error.js:20:3)
5-
at async four (/test/fixtures/async-error.js:24:3)
6-
at async main (file:///test/fixtures/errors/async_error_sync_esm.mjs:6:5)
2+
at one (<project-root>/test/fixtures/async-error.js:4:9)
3+
at two (<project-root>/test/fixtures/async-error.js:17:9)
4+
at async three (<project-root>/test/fixtures/async-error.js:20:3)
5+
at async four (<project-root>/test/fixtures/async-error.js:24:3)
6+
at async main (file://<project-root>/test/fixtures/errors/async_error_sync_esm.mjs:6:5)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Error: test
2-
at one (/test/fixtures/async-error.js:4:9)
3-
at two (/test/fixtures/async-error.js:17:9)
4-
at async three (/test/fixtures/async-error.js:20:3)
5-
at async four (/test/fixtures/async-error.js:24:3)
6-
at async main (/test/fixtures/errors/async_error_sync_main.js:7:5)
2+
at one (<project-root>/test/fixtures/async-error.js:4:9)
3+
at two (<project-root>/test/fixtures/async-error.js:17:9)
4+
at async three (<project-root>/test/fixtures/async-error.js:20:3)
5+
at async four (<project-root>/test/fixtures/async-error.js:24:3)
6+
at async main (<project-root>/test/fixtures/errors/async_error_sync_main.js:7:5)

test/fixtures/errors/core_line_numbers.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ node:punycode:54
55
RangeError: Invalid input
66
at error (node:punycode:54:8)
77
at Object.decode (node:punycode:247:5)
8-
at Object.<anonymous> (/test/fixtures/errors/core_line_numbers.js:13:10)
8+
at Object.<anonymous> (<project-root>/test/fixtures/errors/core_line_numbers.js:13:10)
99

1010
Node.js <node-version>

test/fixtures/errors/error_aggregateTwoErrors.snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/test/fixtures/errors/error_aggregateTwoErrors.js:*
1+
<project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:*
22
throw aggregateTwoErrors(err, originalError);
33
^
44

55
AggregateError: original
6-
at Object.<anonymous> (/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) {
6+
at Object.<anonymous> (<project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) {
77
code: 'ERR0',
88
[errors]: [
99
Error: original
10-
at Object.<anonymous> (/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) {
10+
at Object.<anonymous> (<project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) {
1111
code: 'ERR0'
1212
},
1313
Error: second error
14-
at Object.<anonymous> (/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) {
14+
at Object.<anonymous> (<project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) {
1515
code: 'ERR1'
1616
}
1717
]

test/fixtures/errors/error_exit.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
77

88
1 !== 2
99

10-
at Object.<anonymous> (/test/fixtures/errors/error_exit.js:*:*) {
10+
at Object.<anonymous> (<project-root>/test/fixtures/errors/error_exit.js:*:*) {
1111
generatedMessage: true,
1212
code: 'ERR_ASSERTION',
1313
actual: 1,

0 commit comments

Comments
 (0)