|
9 | 9 | findAssetFile, |
10 | 10 | formatSourcemapForSnapshot, |
11 | 11 | isBuild, |
| 12 | + listAssets, |
12 | 13 | page, |
| 14 | + readFile, |
13 | 15 | serverLogs, |
14 | 16 | } from '~utils' |
15 | 17 |
|
@@ -139,6 +141,7 @@ describe.runIf(isBuild)('build tests', () => { |
139 | 141 | const map = findAssetFile(/after-preload-dynamic-[-\w]{8}\.js\.map/) |
140 | 142 | expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(` |
141 | 143 | { |
| 144 | + "debugId": "c3dabf82-954a-4c41-ba03-767350e274b5", |
142 | 145 | "ignoreList": [], |
143 | 146 | "mappings": ";+8BAAA,OAAO,2BAAuB,0BAE9B,QAAQ,IAAI,uBAAuB", |
144 | 147 | "sources": [ |
@@ -177,6 +180,7 @@ describe.runIf(isBuild)('build tests', () => { |
177 | 180 | const map = findAssetFile(/with-define-object.*\.js\.map/) |
178 | 181 | expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(` |
179 | 182 | { |
| 183 | + "debugId": "bd3962fc-edb5-4a6d-a5da-f27a1e5f3268", |
180 | 184 | "mappings": "qBAEA,SAASA,GAAO,CACJC,EAAA,CACZ,CAEA,SAASA,GAAY,CAEX,QAAA,MAAM,qBAAsBC,CAAkB,CACxD,CAEAF,EAAK", |
181 | 185 | "sources": [ |
182 | 186 | "../../with-define-object.ts", |
@@ -207,4 +211,34 @@ describe.runIf(isBuild)('build tests', () => { |
207 | 211 | cwd: fileURLToPath(new URL('..', import.meta.url)), |
208 | 212 | }) |
209 | 213 | }) |
| 214 | + |
| 215 | + test('source and sourcemap contain matching debug IDs', () => { |
| 216 | + function getDebugIdFromString(input: string): string | undefined { |
| 217 | + const match = input.match(/\/\/# debugId=([a-fA-F0-9-]+)/) |
| 218 | + return match ? match[1] : undefined |
| 219 | + } |
| 220 | + |
| 221 | + const assets = listAssets().map((asset) => `dist/assets/${asset}`) |
| 222 | + const jsAssets = assets.filter((asset) => asset.endsWith('.js')) |
| 223 | + |
| 224 | + for (const jsAsset of jsAssets) { |
| 225 | + const jsContent = readFile(jsAsset) |
| 226 | + const sourceDebugId = getDebugIdFromString(jsContent) |
| 227 | + expect( |
| 228 | + sourceDebugId, |
| 229 | + `Asset '${jsAsset}' did not contain a debug ID`, |
| 230 | + ).toBeDefined() |
| 231 | + |
| 232 | + const mapFile = jsAsset + '.map' |
| 233 | + const mapContent = readFile(mapFile) |
| 234 | + |
| 235 | + const mapObj = JSON.parse(mapContent) |
| 236 | + const mapDebugId = mapObj.debugId |
| 237 | + |
| 238 | + expect( |
| 239 | + sourceDebugId, |
| 240 | + 'Debug ID in source didnt match debug ID in sourcemap', |
| 241 | + ).toEqual(mapDebugId) |
| 242 | + } |
| 243 | + }) |
210 | 244 | }) |
0 commit comments