-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathvue-sourcemap.spec.ts
129 lines (114 loc) · 4 KB
/
vue-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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { URL } from 'node:url'
import { describe, expect, test } from 'vitest'
import {
extractSourcemap,
formatSourcemapForSnapshot,
isBuild,
isServe,
page,
serverLogs,
} from '~utils'
describe.runIf(isServe)('serve:vue-sourcemap', () => {
const getStyleTagContentIncluding = async (content: string) => {
const styles = await page.$$('style')
for (const style of styles) {
const text = await style.textContent()
if (text.includes(content)) {
return text
}
}
throw new Error('Style not found: ' + content)
}
test('js', async () => {
const res = await page.request.get(new URL('./Js.vue', page.url()).href)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-js')
})
test('ts', async () => {
const res = await page.request.get(new URL('./Ts.vue', page.url()).href)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-ts')
})
test('css', async () => {
const css = await getStyleTagContentIncluding('.css ')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-css')
})
test('css module', async () => {
const css = await getStyleTagContentIncluding('._css-module_')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-css-module')
})
test('css scoped', async () => {
const css = await getStyleTagContentIncluding('.css-scoped[data-v-')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-css-scoped')
})
test('sass', async () => {
const css = await getStyleTagContentIncluding('.sass ')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-sass')
})
test('sass with import', async () => {
const css = await getStyleTagContentIncluding('.sass-with-import ')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot(
'serve-sass-with-import',
)
})
test('less with additionalData', async () => {
const css = await getStyleTagContentIncluding('.less ')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot(
'serve-less-with-additionalData',
)
})
test('src imported', async () => {
const css = await getStyleTagContentIncluding('.src-import[data-v-')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot(
'serve-src-imported',
)
})
test('src imported sass', async () => {
const css = await getStyleTagContentIncluding('.src-import-sass[data-v-')
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot(
'serve-src-imported-sass',
)
})
test('src imported html', async () => {
const res = await page.request.get(
new URL(
'./src-import-html/src-import.html?import&vue&type=template&src=true&lang.js',
page.url(),
).href,
)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-html')
})
test('no script', async () => {
const res = await page.request.get(
new URL('./NoScript.vue', page.url()).href,
)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-no-script')
})
test('no template', async () => {
const res = await page.request.get(
new URL('./NoTemplate.vue', page.url()).href,
)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-no-template')
})
})
test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => {
serverLogs.forEach((log) => {
expect(log).not.toMatch('Sourcemap is likely to be incorrect')
})
})