Skip to content

Commit ef3433c

Browse files
committed
test: add test for vitejs#18150
1 parent b529b6f commit ef3433c

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

packages/vite/src/node/ssr/__tests__/fixtures/multi-source-sourcemaps/dist.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/vite/src/node/ssr/__tests__/fixtures/multi-source-sourcemaps/dist.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* You can rebuild this with:
3+
* - rm -f ./dist.js ./dist.js.map
4+
* - npx esbuild --bundle entrypoint.js --outfile=dist.js --sourcemap --format=esm
5+
*/
6+
7+
import nested from './nested-directory/nested-file'
8+
9+
export function entrypoint() {
10+
console.log(nested)
11+
throw new Error('Hello world')
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'Nested file will trigger edge case that used to break sourcemaps'

packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,31 @@ test('sourcemap with multiple sources', async () => {
441441
}
442442
})
443443

444+
test('sourcemap with multiple sources and nested paths', async () => {
445+
const code = readFixture('dist.js')
446+
const map = readFixture('dist.js.map')
447+
448+
const result = await ssrTransform(code, JSON.parse(map), '', code)
449+
assert(result?.map)
450+
451+
const { sources } = result.map as SourceMap
452+
expect(sources).toMatchInlineSnapshot(`
453+
[
454+
"nested-directory/nested-file.js",
455+
"entrypoint.js",
456+
]
457+
`)
458+
459+
function readFixture(filename: string) {
460+
const url = new URL(
461+
`./fixtures/multi-source-sourcemaps/${filename}`,
462+
import.meta.url,
463+
)
464+
465+
return readFileSync(fileURLToPath(url), 'utf8')
466+
}
467+
})
468+
444469
test('overwrite bindings', async () => {
445470
expect(
446471
await ssrTransformSimpleCode(

0 commit comments

Comments
 (0)