-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
js-sourcemap.spec.ts
72 lines (66 loc) · 1.92 KB
/
js-sourcemap.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { URL } from 'node:url'
import { describe, expect, test } from 'vitest'
import {
extractSourcemap,
findAssetFile,
formatSourcemapForSnapshot,
isBuild,
page,
serverLogs,
} from '~utils'
if (!isBuild) {
test('js', async () => {
const res = await page.request.get(new URL('./foo.js', page.url()).href)
const js = await res.text()
const lines = js.split('\n')
expect(lines[lines.length - 1].includes('//')).toBe(false) // expect no sourcemap
})
test('ts', async () => {
const res = await page.request.get(new URL('./bar.ts', page.url()).href)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
{
"mappings": "AAAO,aAAM,MAAM;",
"sourceRoot": "/root/",
"sources": [
"bar.ts",
],
"sourcesContent": [
"export const bar = 'bar'
",
],
"version": 3,
}
`)
})
test('should not output missing source file warning', () => {
serverLogs.forEach((log) => {
expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/)
})
})
}
describe.runIf(isBuild)('build tests', () => {
test('should not output sourcemap warning (#4939)', () => {
serverLogs.forEach((log) => {
expect(log).not.toMatch('Sourcemap is likely to be incorrect')
})
})
test('sourcemap is correct when preload information is injected', async () => {
const map = findAssetFile(/after-preload-dynamic.*\.js\.map/)
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
{
"mappings": "stBAAAA,aAAO,2BAAuB,EAAC,sEAE/B,QAAQ,IAAI,uBAAuB",
"sources": [
"../../after-preload-dynamic.js",
],
"sourcesContent": [
"import('./dynamic/dynamic-foo')
console.log('after preload dynamic')
",
],
"version": 3,
}
`)
})
})