File size: 4,695 Bytes
94786da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | diff --git a/test/e2e/app-dir/server-source-maps/fake-frame-source-maps.test.ts b/test/e2e/app-dir/server-source-maps/fake-frame-source-maps.test.ts
index be03cedc70..f59cd54945 100644
--- a/test/e2e/app-dir/server-source-maps/fake-frame-source-maps.test.ts
+++ b/test/e2e/app-dir/server-source-maps/fake-frame-source-maps.test.ts
@@ -229,6 +229,21 @@ describe('app-dir - server source maps - fake frame source maps', () => {
}).toEqual({ url: script.url, hasSourceMap: true })
}
+ if (isTurbopack) {
+ // The resolver silently falls back to inlining `data:` URLs, so a
+ // defect in the `file:` URL derivation keeps all behavior-based
+ // assertions green. Only this assertion catches it.
+ for (const script of fakeScripts) {
+ expect({
+ url: script.url,
+ sourceMapURL: script.sourceMapURL,
+ }).toEqual({
+ url: script.url,
+ sourceMapURL: expect.stringMatching(/^file:/),
+ })
+ }
+ }
+
// Resolve each source map like a debugger frontend and map the
// padded `_()` call position of each fake function back to its
// original source, like clicking the frame in a debugger would.
@@ -282,6 +297,88 @@ describe('app-dir - server source maps - fake frame source maps', () => {
session.close()
}
})
+
+ it('fake stack frames from nested Flight requests are resolvable by an attached debugger', async () => {
+ // Rendering this page produces fake frame scripts whose frame
+ // filenames are `file:` URLs rather than file paths.
+ await next.render('/rsc-error-throw-cached')
+
+ const target = await findServerInspectorTarget()
+ const session = await CDPSession.connect(target.webSocketDebuggerUrl)
+ try {
+ const evalScripts: {
+ scriptId: string
+ url: string
+ sourceMapURL: string
+ }[] = []
+ session.onEvent = (method, params) => {
+ if (method === 'Debugger.scriptParsed' && params.hasSourceURL) {
+ evalScripts.push({
+ scriptId: params.scriptId,
+ url: params.url,
+ sourceMapURL: params.sourceMapURL ?? '',
+ })
+ }
+ }
+ await session.send('Debugger.enable', { maxScriptsCacheSize: 1 })
+
+ await retry(async () => {
+ expect(
+ evalScripts.filter((script) =>
+ script.url.startsWith('about://React/Cache/')
+ ).length
+ ).toBeGreaterThan(0)
+ })
+
+ // React emits a fake frame script under `about://React/` with a
+ // source map, or, when no source map could be found for it, under
+ // the frame's raw filename without one.
+ const fakeScripts = evalScripts.filter(
+ (script) =>
+ script.url.startsWith('about://React/') ||
+ (script.url.startsWith('file:') && script.sourceMapURL === '')
+ )
+ const mappedSources = new Set<string>()
+ for (const script of fakeScripts) {
+ expect({
+ url: script.url,
+ hasSourceMap: script.sourceMapURL !== '',
+ }).toEqual({ url: script.url, hasSourceMap: true })
+
+ const { sourceMap, mapURL } = await resolveSourceMapLikeADebugger(
+ session,
+ script.url,
+ script.sourceMapURL
+ )
+ const { scriptSource } = await session.send(
+ 'Debugger.getScriptSource',
+ { scriptId: script.scriptId }
+ )
+ const callIndex = scriptSource.indexOf('_()')
+ if (callIndex === -1) continue
+ const line = scriptSource.slice(0, callIndex).split('\n').length
+ const column =
+ callIndex - (scriptSource.lastIndexOf('\n', callIndex) + 1)
+
+ const consumer = new SourceMap(sourceMap)
+ const original = consumer.findEntry(line - 1, column)
+ if (original.originalSource !== undefined) {
+ mappedSources.add(
+ mapURL === null
+ ? original.originalSource
+ : new URL(original.originalSource, mapURL).href
+ )
+ }
+ }
+
+ const testDirURL = url.pathToFileURL(fs.realpathSync(next.testDir))
+ expect([...mappedSources]).toContain(
+ `${testDirURL.href}/app/rsc-error-throw-cached/page.js`
+ )
+ } finally {
+ session.close()
+ }
+ })
} else {
it('server chunk source maps are resolvable by an attached debugger', async () => {
await next.render('/rsc-error-log')
|