-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node): handle dependency stack traces with external source maps in non-browser mode #9047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
iclectic
wants to merge
7
commits into
vitest-dev:main
from
iclectic:fix/non-browser-external-sourcemaps
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
795fc05
fix(browser): map dependency stack frames using external source maps …
iclectic c202fac
chore: trigger CI re-run
iclectic cda1bc7
fix(node): handle dependency stack traces with external source maps i…
iclectic a3e8540
fix: remove unused stdout variable
iclectic 42f47ee
chore: trigger CI re-run
iclectic bc62d43
refactor: extract retrieveSourceMapURL to shared utils
iclectic 6d8617c
chore: trigger CI
iclectic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import { expect, test } from 'vitest' | ||
| import { runInlineTests } from '../../test-utils' | ||
|
|
||
| test('should load external source maps for bundled dependencies', async () => { | ||
| const { stderr } = await runInlineTests( | ||
| { | ||
| 'bundled-dep.js': ` | ||
| // Simulated bundled code (transformed) | ||
| function __bundled__throwError() { | ||
| throw new Error('Error from bundled dependency'); | ||
| } | ||
| export function callError() { | ||
| __bundled__throwError(); | ||
| } | ||
| //# sourceMappingURL=bundled-dep.js.map | ||
| `, | ||
| 'bundled-dep.js.map': JSON.stringify({ | ||
| version: 3, | ||
| file: 'bundled-dep.js', | ||
| sources: ['original-source.ts'], | ||
| sourcesContent: [ | ||
| `// Original source before bundling | ||
| function throwError() { | ||
| throw new Error('Error from bundled dependency'); | ||
| } | ||
| export function callError() { | ||
| throwError(); | ||
| } | ||
| `, | ||
| ], | ||
| names: [], | ||
| mappings: ';;AACA,SAAS,UAAU,GAAG;AACpB,QAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC;AACnD;AACA,OAAO,SAAS,SAAS,GAAG;AAC1B,YAAU,EAAE;AACd', | ||
| }), | ||
| 'test.spec.ts': ` | ||
| import { test, expect } from 'vitest'; | ||
| import { callError } from './bundled-dep.js'; | ||
|
|
||
| test('error with external source map', () => { | ||
| try { | ||
| callError(); | ||
| expect.fail('Should have thrown an error'); | ||
| } catch (error) { | ||
| // The error should reference the original source file | ||
| expect(error.message).toBe('Error from bundled dependency'); | ||
| // Stack trace should be parsed with source maps | ||
| expect(error.stack).toBeTruthy(); | ||
| } | ||
| }); | ||
| `, | ||
| }, | ||
| { | ||
| pool: 'threads', | ||
| }, | ||
| ) | ||
|
|
||
| // The test should pass, meaning source maps were loaded | ||
| expect(stderr).not.toContain('FAIL') | ||
| }) | ||
|
|
||
| test('should handle missing external source maps gracefully', async () => { | ||
| const { stderr } = await runInlineTests( | ||
| { | ||
| 'bundled-dep-no-map.js': ` | ||
| // Bundled code with source map reference but no actual map file | ||
| function __bundled__throwError() { | ||
| throw new Error('Error without source map'); | ||
| } | ||
| export function callError() { | ||
| __bundled__throwError(); | ||
| } | ||
| //# sourceMappingURL=non-existent.js.map | ||
| `, | ||
| 'test.spec.ts': ` | ||
| import { test, expect } from 'vitest'; | ||
| import { callError } from './bundled-dep-no-map.js'; | ||
|
|
||
| test('error without external source map', () => { | ||
| try { | ||
| callError(); | ||
| expect.fail('Should have thrown an error'); | ||
| } catch (error) { | ||
| // Should still work even without source map | ||
| expect(error.message).toBe('Error without source map'); | ||
| expect(error.stack).toBeTruthy(); | ||
| } | ||
| }); | ||
| `, | ||
| }, | ||
| { | ||
| pool: 'threads', | ||
| }, | ||
| ) | ||
|
|
||
| // The test should still pass even without source map | ||
| expect(stderr).not.toContain('FAIL') | ||
| }) | ||
|
|
||
| test('should parse stack traces with external source maps in error output', async () => { | ||
| const result = await runInlineTests( | ||
| { | ||
| 'bundled-lib.js': ` | ||
| // Simulated bundled library code | ||
| export function deepFunction() { | ||
| throw new Error('Deep error in bundled code'); | ||
| } | ||
| export function middleFunction() { | ||
| deepFunction(); | ||
| } | ||
| export function topFunction() { | ||
| middleFunction(); | ||
| } | ||
| //# sourceMappingURL=bundled-lib.js.map | ||
| `, | ||
| 'bundled-lib.js.map': JSON.stringify({ | ||
| version: 3, | ||
| file: 'bundled-lib.js', | ||
| sources: ['src/lib.ts'], | ||
| sourcesContent: [ | ||
| `// Original library source | ||
| export function deepFunction() { | ||
| throw new Error('Deep error in bundled code'); | ||
| } | ||
| export function middleFunction() { | ||
| deepFunction(); | ||
| } | ||
| export function topFunction() { | ||
| middleFunction(); | ||
| } | ||
| `, | ||
| ], | ||
| names: [], | ||
| mappings: ';;AACA,OAAO,SAAS,YAAY,GAAG;AAC7B,QAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC;AAC/C;AACA,OAAO,SAAS,cAAc,GAAG;AAC/B,cAAY,EAAE;AAChB;AACA,OAAO,SAAS,WAAW,GAAG;AAC5B,gBAAc,EAAE;AAClB', | ||
| }), | ||
| 'test.spec.ts': ` | ||
| import { test, expect } from 'vitest'; | ||
| import { topFunction } from './bundled-lib.js'; | ||
|
|
||
| test('should show original source in stack trace', () => { | ||
| expect(() => topFunction()).toThrow('Deep error in bundled code'); | ||
| }); | ||
| `, | ||
| }, | ||
| { | ||
| pool: 'threads', | ||
| }, | ||
| ) | ||
|
|
||
| // The test itself should pass - this verifies source maps work | ||
| expect(result.stderr).not.toContain('FAIL') | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain how this test case is testing external library's source map? It looks like it's importing as user's file via
import './bundled-lib.js'.