Repository navigation
Conversation
Native frames from stack-utils parse without a `file` path. Calling normalizeFile(undefined) threw TypeError and hid the original test failure during error serialization. Fixes avajs#3483
| t.test('Node.js internal stack locations are stable across runtime releases', t => { | ||
| for (const location of ['318:16', '319:16', '346:16', '355:16']) { | ||
| t.equal( | ||
| report.sanitizers.nodeInternalLineNumbers(`compileSourceTextModule (node:internal/modules/esm/utils:${location})`), | ||
| 'compileSourceTextModule (node:internal/modules/esm/utils)', | ||
| ); | ||
| } | ||
|
|
||
| const applicationFrame = 'test (file:///project/test.js:3:1)'; | ||
| t.equal(report.sanitizers.nodeInternalLineNumbers(applicationFrame), applicationFrame); | ||
| t.end(); | ||
| }); |
There was a problem hiding this comment.
I'm cool with not having the line numbers in the logs (unrelated though it is to what this PR fixes), but this test adds no value.
| t.test('Node.js internal stack locations are stable across runtime releases', t => { | |
| for (const location of ['318:16', '319:16', '346:16', '355:16']) { | |
| t.equal( | |
| report.sanitizers.nodeInternalLineNumbers(`compileSourceTextModule (node:internal/modules/esm/utils:${location})`), | |
| 'compileSourceTextModule (node:internal/modules/esm/utils)', | |
| ); | |
| } | |
| const applicationFrame = 'test (file:///project/test.js:3:1)'; | |
| t.equal(report.sanitizers.nodeInternalLineNumbers(applicationFrame), applicationFrame); | |
| t.end(); | |
| }); |
There was a problem hiding this comment.
Dropped the reporter sanitizer and the edge-case log refreshes in 7216266 — they were unrelated to the serialize-error fix. The PR is now only lib/serialize-error.js + test/serialize-error.js.
| import path from 'node:path'; | ||
| import {pathToFileURL} from 'node:url'; | ||
|
|
||
| import {test} from 'tap'; |
There was a problem hiding this comment.
New tests should be under test/.
There was a problem hiding this comment.
Moved in the earlier follow-up — coverage now lives in test/serialize-error.js (and the old test-tap/serialize-error.js path is gone).
Move serialization regressions to test/ and remove the redundant internal stack-location test. Preserve the accepted reporter normalization while resolving upstream snapshot changes. Validated with npm test on Node.js 24.21.0.
Keep the PR focused on extractSource skipping file-less frames. Reporter line-number sanitizing belonged elsewhere and was called out in review.
|
It struck me that this PR manually constructs the stack trace. The original issue doesn't give a source for such a stack trace either. Copilot is very confident no such traces exist in the supported Node.js versions. Happy to reconsider when we have a test against a real stack trace, not a fabricated one. |
This relates to...
Fixes #3483
Rationale
When AVA serializes a failed test error,
extractSourcewalks the stack withstack-utils. Native frames parse to a truthy call site whosefileisundefined. CallingnormalizeFile(undefined)then throwsTypeError: Cannot read properties of undefined (reading 'startsWith'), which crashes error serialization and hides the original failure.Changes
Features
N/A
Bug Fixes
filepath before callingnormalizeFile.<anonymous>file path that must not match the test file.Breaking Changes and Deprecations
N/A
Status
Test plan
npx xo lib/serialize-error.js test-tap/serialize-error.jsnpx tap test-tap/serialize-error.js test-tap/assert.js(846 passed)AI assistance was used while preparing this change.