Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a71e3a6

Browse filesBrowse files
test: fix edge snapshot stack traces
PR-URL: #49659 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 7e12d0e commit a71e3a6
Copy full SHA for a71e3a6

File tree

Expand file treeCollapse file tree

5 files changed

+29
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+29
-21
lines changed
Open diff view settings
Collapse file

‎test/common/assertSnapshot.js‎

Copy file name to clipboardExpand all lines: test/common/assertSnapshot.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const assert = require('node:assert/strict');
88
const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g;
99
const windowNewlineRegexp = /\r/g;
1010

11+
function replaceNodeVersion(str) {
12+
return str.replaceAll(process.version, '*');
13+
}
14+
1115
function replaceStackTrace(str, replacement = '$1*$7$8\n') {
1216
return str.replace(stackFramesRegexp, replacement);
1317
}
@@ -84,6 +88,7 @@ module.exports = {
8488
assertSnapshot,
8589
getSnapshotPath,
8690
replaceFullPaths,
91+
replaceNodeVersion,
8792
replaceStackTrace,
8893
replaceWindowsLineEndings,
8994
replaceWindowsPaths,
Collapse file

‎test/fixtures/errors/force_colors.snapshot‎

Copy file name to clipboardExpand all lines: test/fixtures/errors/force_colors.snapshot
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ throw new Error('Should include grayed stack trace')
44

55
Error: Should include grayed stack trace
66
at Object.<anonymous> (/test*force_colors.js:1:7)
7-
 at Module._compile (node:internal*modules*cjs*loader:1264:14)
8-
 at Module._extensions..js (node:internal*modules*cjs*loader:1318:10)
9-
 at Module.load (node:internal*modules*cjs*loader:1113:32)
10-
 at Module._load (node:internal*modules*cjs*loader:954:12)
11-
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:80:12)
12-
 at node:internal*main*run_main_module:23:47
7+
 at *
8+
 at *
9+
 at *
10+
 at *
11+
 at *
12+
 at *
1313

1414
Node.js *
Collapse file
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Error: an exception.
22
at Object.<anonymous> (*typescript-sourcemapping_url_string.ts:3:7)
3-
at Module._compile (node:internal*modules*cjs*loader:1264:14)
3+
*
Collapse file

‎test/parallel/test-node-output-errors.mjs‎

Copy file name to clipboardExpand all lines: test/parallel/test-node-output-errors.mjs
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ const skipForceColors =
1111
(common.isWindows && (Number(os.release().split('.')[0]) !== 10 || Number(os.release().split('.')[2]) < 14393)); // See https://github.com/nodejs/node/pull/33132
1212

1313

14-
function replaceNodeVersion(str) {
15-
return str.replaceAll(process.version, '*');
16-
}
17-
1814
function replaceStackTrace(str) {
1915
return snapshot.replaceStackTrace(str, '$1at *$7\n');
2016
}
2117

18+
function replaceForceColorsStackTrace(str) {
19+
// eslint-disable-next-line no-control-regex
20+
return str.replaceAll(/(\[90m\W+)at .*node:.*/g, '$1at *');
21+
}
22+
2223
describe('errors output', { concurrency: true }, () => {
2324
function normalize(str) {
2425
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
@@ -35,9 +36,12 @@ describe('errors output', { concurrency: true }, () => {
3536
}
3637
const common = snapshot
3738
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths);
38-
const defaultTransform = snapshot.transform(common, normalize, replaceNodeVersion);
39-
const errTransform = snapshot.transform(common, normalizeNoNumbers, replaceNodeVersion);
40-
const promiseTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers, replaceNodeVersion);
39+
const defaultTransform = snapshot.transform(common, normalize, snapshot.replaceNodeVersion);
40+
const errTransform = snapshot.transform(common, normalizeNoNumbers, snapshot.replaceNodeVersion);
41+
const promiseTransform = snapshot.transform(common, replaceStackTrace,
42+
normalizeNoNumbers, snapshot.replaceNodeVersion);
43+
const forceColorsTransform = snapshot.transform(common, normalize,
44+
replaceForceColorsStackTrace, snapshot.replaceNodeVersion);
4145

4246
const tests = [
4347
{ name: 'errors/async_error_eval_cjs.js' },
@@ -57,7 +61,8 @@ describe('errors output', { concurrency: true }, () => {
5761
{ name: 'errors/throw_in_line_with_tabs.js', transform: errTransform },
5862
{ name: 'errors/throw_non_error.js', transform: errTransform },
5963
{ name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform },
60-
{ skip: skipForceColors, name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } },
64+
{ skip: skipForceColors, name: 'errors/force_colors.js',
65+
transform: forceColorsTransform, env: { FORCE_COLOR: 1 } },
6166
];
6267
for (const { name, transform = defaultTransform, env, skip = false } of tests) {
6368
it(name, { skip }, async () => {
Collapse file

‎test/parallel/test-node-output-sourcemaps.mjs‎

Copy file name to clipboardExpand all lines: test/parallel/test-node-output-sourcemaps.mjs
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import * as snapshot from '../common/assertSnapshot.js';
44
import * as path from 'node:path';
55
import { describe, it } from 'node:test';
66

7-
function replaceNodeVersion(str) {
8-
return str.replaceAll(process.version, '*');
9-
}
10-
117
describe('sourcemaps output', { concurrency: true }, () => {
128
function normalize(str) {
139
const result = str
@@ -16,7 +12,8 @@ describe('sourcemaps output', { concurrency: true }, () => {
1612
.replaceAll('/Users/bencoe/oss/coffee-script-test', '')
1713
.replaceAll(/\/(\w)/g, '*$1')
1814
.replaceAll('*test*', '*')
19-
.replaceAll('*fixtures*source-map*', '*');
15+
.replaceAll('*fixtures*source-map*', '*')
16+
.replaceAll(/(\W+).*node:internal\*modules.*/g, '$1*');
2017
if (common.isWindows) {
2118
const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
2219
const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi');
@@ -25,7 +22,8 @@ describe('sourcemaps output', { concurrency: true }, () => {
2522
return result;
2623
}
2724
const defaultTransform = snapshot
28-
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize, replaceNodeVersion);
25+
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths,
26+
normalize, snapshot.replaceNodeVersion);
2927

3028
const tests = [
3129
{ name: 'source-map/output/source_map_disabled_by_api.js' },

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.