Skip to content

Commit

Permalink
test(worker): correct sourcemap boundary after injecting env (#14277)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day committed Sep 8, 2023
1 parent 4fb617f commit ab5c421
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion playground/worker/__tests__/iife/iife-worker.spec.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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(),
)
}

0 comments on commit ab5c421

Please sign in to comment.