Unverified Commit 6bf43020 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

test: read server chunk map sources with source-map

Use Next.js's bundled source-map@0.6.1 SourceMapConsumer to enumerate sources, which handles index maps, instead of a hand-rolled helper.

<!-- NEXT_JS_LLM -->
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 2c9e7c10
...@@ -2,6 +2,7 @@ import * as fs from 'fs' ...@@ -2,6 +2,7 @@ import * as fs from 'fs'
import * as path from 'path' import * as path from 'path'
import * as url from 'url' import * as url from 'url'
import { SourceMap } from 'module' import { SourceMap } from 'module'
import sourceMapLib from 'next/dist/compiled/source-map'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
import WebSocket from 'ws' import WebSocket from 'ws'
...@@ -68,19 +69,6 @@ function scriptURLToFileURL(scriptURL: string): string { ...@@ -68,19 +69,6 @@ function scriptURLToFileURL(scriptURL: string): string {
: url.pathToFileURL(scriptURL).href : url.pathToFileURL(scriptURL).href
} }
/**
* The `sources` of a source map. Index maps list theirs in `sections`, and the
* top-level `sources` of an index map isn't meaningful.
*/
function sourceMapSources(sourceMap: any): string[] {
if (Array.isArray(sourceMap.sections)) {
return sourceMap.sections.flatMap((section: any) =>
sourceMapSources(section.map)
)
}
return sourceMap.sources ?? []
}
/** /**
* Debugger frontends cannot be assumed to fetch arbitrary http(s) URLs * Debugger frontends cannot be assumed to fetch arbitrary http(s) URLs
* themselves (the dedicated Chrome DevTools frontend for Node.js targets * themselves (the dedicated Chrome DevTools frontend for Node.js targets
...@@ -438,7 +426,9 @@ describe('app-dir - server source maps - fake frame source maps', () => { ...@@ -438,7 +426,9 @@ describe('app-dir - server source maps - fake frame source maps', () => {
script.sourceMapURL, script.sourceMapURL,
scriptURLToFileURL(script.url) scriptURLToFileURL(script.url)
) )
for (const source of sourceMapSources(sourceMap)) { // Handles index maps, whose sources are listed in `sections`.
const consumer = new sourceMapLib.SourceMapConsumer(sourceMap)
for (const source of consumer.sources) {
const resolved = new URL(source, mapURL).href const resolved = new URL(source, mapURL).href
expectWellFormedSource(resolved) expectWellFormedSource(resolved)
resolvedSources.add(resolved) resolvedSources.add(resolved)
......
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