Skip to content

Commit

Permalink
test: add test for vitejs#18150
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Sep 20, 2024
1 parent b529b6f commit ef3433c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* You can rebuild this with:
* - rm -f ./dist.js ./dist.js.map
* - npx esbuild --bundle entrypoint.js --outfile=dist.js --sourcemap --format=esm
*/

import nested from './nested-directory/nested-file'

export function entrypoint() {
console.log(nested)
throw new Error('Hello world')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'Nested file will trigger edge case that used to break sourcemaps'
25 changes: 25 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,31 @@ test('sourcemap with multiple sources', async () => {
}
})

test('sourcemap with multiple sources and nested paths', async () => {
const code = readFixture('dist.js')
const map = readFixture('dist.js.map')

const result = await ssrTransform(code, JSON.parse(map), '', code)
assert(result?.map)

const { sources } = result.map as SourceMap
expect(sources).toMatchInlineSnapshot(`
[
"nested-directory/nested-file.js",
"entrypoint.js",
]
`)

function readFixture(filename: string) {
const url = new URL(
`./fixtures/multi-source-sourcemaps/${filename}`,
import.meta.url,
)

return readFileSync(fileURLToPath(url), 'utf8')
}
})

test('overwrite bindings', async () => {
expect(
await ssrTransformSimpleCode(
Expand Down

0 comments on commit ef3433c

Please sign in to comment.