Skip to content

Commit

Permalink
test: fix edge snapshot stack traces
Browse files Browse the repository at this point in the history
PR-URL: #49659
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
  • Loading branch information
GeoffreyBooth authored and codebytere committed Oct 18, 2023
1 parent a0e60c1 commit 57814ae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
5 changes: 5 additions & 0 deletions test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const assert = require('node:assert/strict');
const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g;
const windowNewlineRegexp = /\r/g;

function replaceNodeVersion(str) {
return str.replaceAll(process.version, '*');
}

function replaceStackTrace(str, replacement = '$1*$7$8\n') {
return str.replace(stackFramesRegexp, replacement);
}
Expand Down Expand Up @@ -69,6 +73,7 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ...
module.exports = {
assertSnapshot,
getSnapshotPath,
replaceNodeVersion,
replaceStackTrace,
replaceWindowsLineEndings,
replaceWindowsPaths,
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/errors/force_colors.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ throw new Error('Should include grayed stack trace')

Error: Should include grayed stack trace
at Object.<anonymous> (/test*force_colors.js:1:7)
 at Module._compile (node:internal*modules*cjs*loader:1256:14)
 at Module._extensions..js (node:internal*modules*cjs*loader:1310:10)
 at Module.load (node:internal*modules*cjs*loader:1119:32)
 at Module._load (node:internal*modules*cjs*loader:960:12)
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:86:12)
 at node:internal*main*run_main_module:23:47
 at *
 at *
 at *
 at *
 at *
 at *

Node.js *
21 changes: 13 additions & 8 deletions test/parallel/test-node-output-errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ const skipForceColors =
(common.isWindows && (Number(os.release().split('.')[0]) !== 10 || Number(os.release().split('.')[2]) < 14393)); // See https://github.com/nodejs/node/pull/33132


function replaceNodeVersion(str) {
return str.replaceAll(process.version, '*');
}

function replaceStackTrace(str) {
return snapshot.replaceStackTrace(str, '$1at *$7\n');
}

function replaceForceColorsStackTrace(str) {
// eslint-disable-next-line no-control-regex
return str.replaceAll(/(\[90m\W+)at .*node:.*/g, '$1at *');
}

describe('errors output', { concurrency: true }, () => {
function normalize(str) {
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*errors*', '*').replaceAll('file:**', 'file:*/');
Expand All @@ -28,9 +29,12 @@ describe('errors output', { concurrency: true }, () => {
}
const common = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths);
const defaultTransform = snapshot.transform(common, normalize, replaceNodeVersion);
const errTransform = snapshot.transform(common, normalizeNoNumbers, replaceNodeVersion);
const promiseTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers, replaceNodeVersion);
const defaultTransform = snapshot.transform(common, normalize, snapshot.replaceNodeVersion);
const errTransform = snapshot.transform(common, normalizeNoNumbers, snapshot.replaceNodeVersion);
const promiseTransform = snapshot.transform(common, replaceStackTrace,
normalizeNoNumbers, snapshot.replaceNodeVersion);
const forceColorsTransform = snapshot.transform(common, normalize,
replaceForceColorsStackTrace, snapshot.replaceNodeVersion);

const tests = [
{ name: 'errors/async_error_eval_cjs.js' },
Expand All @@ -50,7 +54,8 @@ describe('errors output', { concurrency: true }, () => {
{ name: 'errors/throw_in_line_with_tabs.js', transform: errTransform },
{ name: 'errors/throw_non_error.js', transform: errTransform },
{ name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform },
!skipForceColors ? { name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } } : null,
!skipForceColors ? { name: 'errors/force_colors.js', transform: forceColorsTransform,
env: { FORCE_COLOR: 1 } } : null,

Check failure on line 58 in test/parallel/test-node-output-errors.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 25 spaces but found 4
].filter(Boolean);
for (const { name, transform, env } of tests) {
it(name, async () => {
Expand Down
10 changes: 4 additions & 6 deletions test/parallel/test-node-output-sourcemaps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import * as snapshot from '../common/assertSnapshot.js';
import * as path from 'node:path';
import { describe, it } from 'node:test';

function replaceNodeVersion(str) {
return str.replaceAll(process.version, '*');
}

describe('sourcemaps output', { concurrency: true }, () => {
function normalize(str) {
const result = str
Expand All @@ -16,7 +12,8 @@ describe('sourcemaps output', { concurrency: true }, () => {
.replaceAll('/Users/bencoe/oss/coffee-script-test', '')
.replaceAll(/\/(\w)/g, '*$1')
.replaceAll('*test*', '*')
.replaceAll('*fixtures*source-map*', '*');
.replaceAll('*fixtures*source-map*', '*')
.replaceAll(/(\W+).*node:internal\*modules.*/g, '$1*');
if (common.isWindows) {
const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi');
Expand All @@ -25,7 +22,8 @@ describe('sourcemaps output', { concurrency: true }, () => {
return result;
}
const defaultTransform = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize, replaceNodeVersion);
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths,
normalize, snapshot.replaceNodeVersion);

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

0 comments on commit 57814ae

Please sign in to comment.