diff --git a/playground/worker/__tests__/iife/iife-worker.spec.ts b/playground/worker/__tests__/iife/iife-worker.spec.ts index 737c4b1f22361c..96aaae6ef22e66 100644 --- a/playground/worker/__tests__/iife/iife-worker.spec.ts +++ b/playground/worker/__tests__/iife/iife-worker.spec.ts @@ -1,7 +1,15 @@ import fs from 'node:fs' import path from 'node:path' import { describe, expect, test } from 'vitest' -import { isBuild, page, readManifest, testDir, untilUpdated } from '~utils' +import { + isBuild, + isServe, + page, + readManifest, + testDir, + untilUpdated, + viteTestUrl, +} from '~utils' test('normal', async () => { await untilUpdated(() => page.textContent('.pong'), 'pong') @@ -143,3 +151,23 @@ test('import.meta.glob eager in worker', async () => { '["', ) }) + +test.runIf(isServe)('sourcemap boundary', async () => { + const response = page.waitForResponse(/my-worker.ts\?type=module&worker_file/) + await page.goto(viteTestUrl) + const content = await (await response).text() + const { mappings } = decodeSourceMapUrl(content) + expect(mappings.startsWith(';')).toBeTruthy() + expect(mappings.endsWith(';')).toBeFalsy() +}) + +function decodeSourceMapUrl(content: string) { + return JSON.parse( + Buffer.from( + content.match( + /\/\/[#@]\ssourceMappingURL=\s*data:application\/json;base64,(\S+)/, + )?.[1], + 'base64', + ).toString(), + ) +}