| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d147c08 commit b064ddc
100 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,13 +4,17 @@ const path = require('node:path'); | |||
| 4 | 4 | const test = require('node:test'); | |
| 5 | 5 | const fs = require('node:fs/promises'); | |
| 6 | 6 | const assert = require('node:assert/strict'); | |
| 7 | + const { pathToFileURL } = require('node:url'); | ||
| 7 | 8 | const { hostname } = require('node:os'); | |
| 8 | 9 | ||
| 9 | 10 | const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; | |
| 10 | 11 | const windowNewlineRegexp = /\r/g; | |
| 11 | 12 | ||
| 13 | + // Replaces the current Node.js executable version strings with a | ||
| 14 | + // placeholder. This could commonly present in an unhandled exception | ||
| 15 | + // output. | ||
| 12 | 16 | function replaceNodeVersion(str) { | |
| 13 | - return str.replaceAll(process.version, '*'); | ||
| 17 | + return str.replaceAll(process.version, '<node-version>'); | ||
| 14 | 18 | } | |
| 15 | 19 | ||
| 16 | 20 | function replaceStackTrace(str, replacement = '$1*$7$8\n') { | |
@@ -23,18 +27,49 @@ function replaceInternalStackTrace(str) { | |||
| 23 | 27 | return str.replaceAll(/(\W+).*[(\s]node:.*/g, '$1*'); | |
| 24 | 28 | } | |
| 25 | 29 | ||
| 30 | + // Replaces Windows line endings with posix line endings for unified snapshots | ||
| 31 | + // across platforms. | ||
| 26 | 32 | function replaceWindowsLineEndings(str) { | |
| 27 | 33 | return str.replace(windowNewlineRegexp, ''); | |
| 28 | 34 | } | |
| 29 | 35 | ||
| 36 | + // Replaces all Windows path separators with posix separators for unified snapshots | ||
| 37 | + // across platforms. | ||
| 30 | 38 | function replaceWindowsPaths(str) { | |
| 31 | 39 | return common.isWindows ? str.replaceAll(path.win32.sep, path.posix.sep) : str; | |
| 32 | 40 | } | |
| 33 | 41 | ||
| 34 | - function transformProjectRoot(replacement = '') { | ||
| 42 | + // Removes line trailing white spaces. | ||
| 43 | + function replaceTrailingSpaces(str) { | ||
| 44 | + return str.replaceAll(/[\t ]+\n/g, '\n'); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + // Replaces customized or platform specific executable names to be `<node-exe>`. | ||
| 48 | + function generalizeExeName(str) { | ||
| 49 | + const baseName = path.basename(process.argv0 || 'node', '.exe'); | ||
| 50 | + return str.replaceAll(`${baseName} --`, '<node-exe> --'); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + // Replaces the pids in warning messages with a placeholder. | ||
| 54 | + function replaceWarningPid(str) { | ||
| 55 | + return str.replaceAll(/\(node:\d+\)/g, '(node:<pid>)'); | ||
| 56 | + } | ||
| 57 | + | ||
| 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>') { | ||
| 35 | 62 | const projectRoot = path.resolve(__dirname, '../..'); | |
| 63 | + // Handles output already processed by `replaceWindowsPaths`. | ||
| 64 | + const winPath = replaceWindowsPaths(projectRoot); | ||
| 65 | + // Handles URL encoded project root in file URL strings as well. | ||
| 66 | + const urlEncoded = pathToFileURL(projectRoot).pathname; | ||
| 36 | 67 | return (str) => { | |
| 37 | - return str.replaceAll('\\\'', "'").replaceAll(projectRoot, replacement); | ||
| 68 | + return str.replaceAll('\\\'', "'") | ||
| 69 | + // Replace fileUrl first as `winPath` could be a substring of the fileUrl. | ||
| 70 | + .replaceAll(urlEncoded, replacement) | ||
| 71 | + .replaceAll(projectRoot, replacement) | ||
| 72 | + .replaceAll(winPath, replacement); | ||
| 38 | 73 | }; | |
| 39 | 74 | } | |
| 40 | 75 | ||
@@ -152,32 +187,41 @@ function pickTestFileFromLcov(str) { | |||
| 152 | 187 | ); | |
| 153 | 188 | } | |
| 154 | 189 | ||
| 155 | - const defaultTransform = transform( | ||
| 190 | + // Transforms basic patterns like: | ||
| 191 | + // - platform specific path and line endings, | ||
| 192 | + // - line trailing spaces, | ||
| 193 | + // - executable specific path and versions. | ||
| 194 | + const basicTransform = transform( | ||
| 156 | 195 | replaceWindowsLineEndings, | |
| 157 | - replaceStackTrace, | ||
| 196 | + replaceTrailingSpaces, | ||
| 158 | 197 | removeWindowsPathEscaping, | |
| 159 | - transformProjectRoot(), | ||
| 160 | 198 | replaceWindowsPaths, | |
| 199 | + replaceNodeVersion, | ||
| 200 | + generalizeExeName, | ||
| 201 | + replaceWarningPid, | ||
| 202 | + ); | ||
| 203 | + | ||
| 204 | + const defaultTransform = transform( | ||
| 205 | + basicTransform, | ||
| 206 | + replaceStackTrace, | ||
| 207 | + transformProjectRoot(), | ||
| 161 | 208 | replaceTestDuration, | |
| 162 | 209 | replaceTestLocationLine, | |
| 163 | 210 | ); | |
| 164 | 211 | const specTransform = transform( | |
| 165 | 212 | replaceSpecDuration, | |
| 166 | - replaceWindowsLineEndings, | ||
| 213 | + basicTransform, | ||
| 167 | 214 | replaceStackTrace, | |
| 168 | - replaceWindowsPaths, | ||
| 169 | 215 | ); | |
| 170 | 216 | const junitTransform = transform( | |
| 171 | 217 | replaceJunitDuration, | |
| 172 | - replaceWindowsLineEndings, | ||
| 218 | + basicTransform, | ||
| 173 | 219 | replaceStackTrace, | |
| 174 | - replaceWindowsPaths, | ||
| 175 | 220 | ); | |
| 176 | 221 | const lcovTransform = transform( | |
| 177 | - replaceWindowsLineEndings, | ||
| 222 | + basicTransform, | ||
| 178 | 223 | replaceStackTrace, | |
| 179 | 224 | transformProjectRoot(), | |
| 180 | - replaceWindowsPaths, | ||
| 181 | 225 | pickTestFileFromLcov, | |
| 182 | 226 | ); | |
| 183 | 227 | ||
@@ -204,6 +248,7 @@ module.exports = { | |||
| 204 | 248 | transform, | |
| 205 | 249 | transformProjectRoot, | |
| 206 | 250 | replaceTestDuration, | |
| 251 | + basicTransform, | ||
| 207 | 252 | defaultTransform, | |
| 208 | 253 | specTransform, | |
| 209 | 254 | junitTransform, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,8 @@ | |||
| 1 | 1 | before | |
| 2 | - *test*fixtures*console*stack_overflow.js:* | ||
| 2 | + <project-root>/test/fixtures/console/stack_overflow.js:* | ||
| 3 | 3 | JSON.stringify(array); | |
| 4 | 4 | ^ | |
| 5 | 5 | ||
| 6 | 6 | [RangeError: Maximum call stack size exceeded] | |
| 7 | 7 | ||
| 8 | - Node.js * | ||
| 8 | + Node.js <node-version> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | 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) | ||
| 7 | 7 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | Error: test | |
| 2 | - at one (*fixtures*async-error.js:4:9) | ||
| 3 | - at two (*fixtures*async-error.js:17:9) | ||
| 4 | - at async three (*fixtures*async-error.js:20:3) | ||
| 5 | - at async four (*fixtures*async-error.js:24:3) | ||
| 6 | - at async main (*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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | Error: test | |
| 2 | - at one (*fixtures*async-error.js:4:9) | ||
| 3 | - at two (*fixtures*async-error.js:17:9) | ||
| 4 | - at process.processTicksAndRejections (node:internal*process*task_queues:104:5) | ||
| 5 | - at async three (*fixtures*async-error.js:20:3) | ||
| 6 | - at async four (*fixtures*async-error.js:24:3) | ||
| 7 | - at async main (*async_error_nexttick_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 process.processTicksAndRejections (node:internal/process/task_queues:104: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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | Error: test | |
| 2 | - at one (*fixtures*async-error.js:4:9) | ||
| 3 | - at two (*fixtures*async-error.js:17:9) | ||
| 4 | - at async three (*fixtures*async-error.js:20:3) | ||
| 5 | - at async four (*fixtures*async-error.js:24:3) | ||
| 6 | - at async main (file:*/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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | Error: test | |
| 2 | - at one (*fixtures*async-error.js:4:9) | ||
| 3 | - at two (*fixtures*async-error.js:17:9) | ||
| 4 | - at async three (*fixtures*async-error.js:20:3) | ||
| 5 | - at async four (*fixtures*async-error.js:24:3) | ||
| 6 | - at async main (*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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,6 @@ node:punycode:54 | |||
| 5 | 5 | RangeError: Invalid input | |
| 6 | 6 | at error (node:punycode:54:8) | |
| 7 | 7 | at Object.decode (node:punycode:247:5) | |
| 8 | - at Object.<anonymous> (*core_line_numbers.js:13:10) | ||
| 8 | + at Object.<anonymous> (<project-root>/test/fixtures/errors/core_line_numbers.js:13:10) | ||
| 9 | 9 | ||
| 10 | - Node.js * | ||
| 10 | + Node.js <node-version> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,20 +1,20 @@ | |||
| 1 | - *error_aggregateTwoErrors.js:* | ||
| 1 | + <project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:* | ||
| 2 | 2 | throw aggregateTwoErrors(err, originalError); | |
| 3 | 3 | ^ | |
| 4 | 4 | ||
| 5 | 5 | AggregateError: original | |
| 6 | - at Object.<anonymous> (*error_aggregateTwoErrors.js:*:*) { | ||
| 6 | + at Object.<anonymous> (<project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) { | ||
| 7 | 7 | code: 'ERR0', | |
| 8 | 8 | [errors]: [ | |
| 9 | 9 | Error: original | |
| 10 | - at Object.<anonymous> (*error_aggregateTwoErrors.js:*:*) { | ||
| 10 | + at Object.<anonymous> (<project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) { | ||
| 11 | 11 | code: 'ERR0' | |
| 12 | 12 | }, | |
| 13 | 13 | Error: second error | |
| 14 | - at Object.<anonymous> (*error_aggregateTwoErrors.js:*:*) { | ||
| 14 | + at Object.<anonymous> (<project-root>/test/fixtures/errors/error_aggregateTwoErrors.js:*:*) { | ||
| 15 | 15 | code: 'ERR1' | |
| 16 | 16 | } | |
| 17 | 17 | ] | |
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | - Node.js * | ||
| 20 | + Node.js <node-version> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: | |||
| 7 | 7 | ||
| 8 | 8 | 1 !== 2 | |
| 9 | 9 | ||
| 10 | - at Object.<anonymous> (*error_exit.js:*:*) { | ||
| 10 | + at Object.<anonymous> (<project-root>/test/fixtures/errors/error_exit.js:*:*) { | ||
| 11 | 11 | generatedMessage: true, | |
| 12 | 12 | code: 'ERR_ASSERTION', | |
| 13 | 13 | actual: 1, | |
@@ -16,4 +16,4 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: | |||
| 16 | 16 | diff: 'simple' | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | - Node.js * | ||
| 19 | + Node.js <node-version> | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments