forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourcemap-inline.spec.ts
47 lines (41 loc) · 1.57 KB
/
sourcemap-inline.spec.ts
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
import fs from 'fs'
import path from 'path'
import { untilUpdated, isBuild, testDir } from '../../../testUtils'
import { Page } from 'playwright-chromium'
if (isBuild) {
// assert correct files
test('inlined sourcemap generation for web workers', async () => {
const assetsDir = path.resolve(testDir, 'dist/iife-sourcemap-inline/assets')
const files = fs.readdirSync(assetsDir)
const index = files.find((f) => f.includes('main-classic'))
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
const indexSourcemap = getSourceMapUrl(content)
const worker = files.find((f) => f.includes('my-worker'))
const workerContent = fs.readFileSync(
path.resolve(assetsDir, worker),
'utf-8'
)
const workerSourcemap = getSourceMapUrl(workerContent)
const sharedWorker = files.find((f) => f.includes('my-shared-worker'))
const sharedWorkerContent = fs.readFileSync(
path.resolve(assetsDir, sharedWorker),
'utf-8'
)
const sharedWorkerSourcemap = getSourceMapUrl(sharedWorkerContent)
// sourcemap should exist and have a data URL
expect(indexSourcemap).toMatch(/^data:application\/json;/)
expect(workerSourcemap).toMatch(/^data:application\/json;/)
expect(sharedWorkerSourcemap).toMatch(/^data:application\/json;/)
})
}
test('true', () => {
expect(true).toBe(true)
})
function getSourceMapUrl(code: string): string {
const regex = /\/\/[#@]\s(?:source(?:Mapping)?URL)=\s*(\S+)/g
const results = regex.exec(code)
if (results && results.length >= 2) {
return results[1]
}
return null
}