Commit 79494d2c authored by Will Binns-Smith's avatar Will Binns-Smith Committed by Will Binns-Smith

add test

parent 4d4dbf2e
// hmr-trigger: 0
export default function Page() {
throw new Error('hmr-sourcemap-test-error')
}
...@@ -127,4 +127,31 @@ describe('server-hmr', () => { ...@@ -127,4 +127,31 @@ describe('server-hmr', () => {
} }
) )
}) })
describe('source maps', () => {
itTurbopackDev(
"stack frames from eval'd HMR modules point to original source locations",
async () => {
await next.fetch('/sourcemaps').catch(() => {})
await next.patchFile('app/sourcemaps/page.tsx', (content) =>
content.replace('hmr-trigger: 0', 'hmr-trigger: 1')
)
const outputLengthBeforeFetch = next.cliOutput.length
await next.fetch('/sourcemaps').catch(() => {})
await retry(async () => {
expect(next.cliOutput.slice(outputLengthBeforeFetch)).toContain(
'hmr-sourcemap-test-error'
)
})
const outputAfterHmr = next.cliOutput.slice(outputLengthBeforeFetch)
// Without proper sourcemaps, the stack frame doesn't include the accurate file number
expect(outputAfterHmr).toMatch(/page\.tsx:6:/)
}
)
})
}) })
...@@ -18,7 +18,7 @@ type NodeJsHmrPayload = { ...@@ -18,7 +18,7 @@ type NodeJsHmrPayload = {
* that Node.js can resolve stack frames from `eval`ed server HMR modules back to * that Node.js can resolve stack frames from `eval`ed server HMR modules back to
* their original source files. Mirrors the browser's _eval in dev-backend-dom.ts. * their original source files. Mirrors the browser's _eval in dev-backend-dom.ts.
*/ */
function maybeInlineSourcemaps(entry: EcmascriptModuleEntry): string { function inlineSourcemaps(entry: EcmascriptModuleEntry): string {
const [chunkPath, moduleId] = entry.url.split('?', 2) const [chunkPath, moduleId] = entry.url.split('?', 2)
const absolutePath = path.resolve(RUNTIME_ROOT, chunkPath) const absolutePath = path.resolve(RUNTIME_ROOT, chunkPath)
const fileHref = url.pathToFileURL(absolutePath).href const fileHref = url.pathToFileURL(absolutePath).href
...@@ -96,7 +96,7 @@ function handleNodejsUpdate( ...@@ -96,7 +96,7 @@ function handleNodejsUpdate(
const evalModuleEntry = (entry: EcmascriptModuleEntry) => { const evalModuleEntry = (entry: EcmascriptModuleEntry) => {
// eslint-disable-next-line no-eval // eslint-disable-next-line no-eval
return (0, eval)(maybeInlineSourcemaps(entry)) return (0, eval)(entry.map ? inlineSourcemaps(entry) : entry.code)
} }
const { added, modified } = computeChangedModules( const { added, modified } = computeChangedModules(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment