-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
Copy pathvue.spec.ts
186 lines (160 loc) · 5.82 KB
/
vue.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { editFile, getBg, getColor, isBuild, untilUpdated } from 'testUtils'
test('should render', async () => {
expect(await page.textContent('h1')).toMatch('Vue SFCs')
})
test('should update', async () => {
expect(await page.textContent('.hmr-inc')).toMatch('count is 0')
await page.click('.hmr-inc')
expect(await page.textContent('.hmr-inc')).toMatch('count is 1')
})
test('template/script latest syntax support', async () => {
expect(await page.textContent('.syntax')).toBe('baz')
})
test('should remove comments in prod', async () => {
expect(await page.innerHTML('.comments')).toBe(isBuild ? `` : `<!--hello-->`)
})
test(':slotted', async () => {
expect(await getColor('.slotted')).toBe('red')
})
test('scan deps from <script setup lang="ts">', async () => {
expect(await page.textContent('.scan')).toBe('ok')
})
describe('pre-processors', () => {
test('pug', async () => {
expect(await page.textContent('p.pug')).toMatch(
`This is rendered from <template lang="pug">`
)
// #1383 pug default doctype
expect(await page.textContent('.pug-slot')).toMatch(`slot content`)
editFile('PreProcessors.vue', (code) =>
code.replace('Pre-Processors', 'Updated')
)
await untilUpdated(() => page.textContent('h2.pre-processors'), 'Updated')
})
test('scss', async () => {
const el = await page.$('p.pug')
expect(await getColor(el)).toBe('magenta')
editFile('PreProcessors.vue', (code) =>
code.replace('$color: magenta;', '$color: red;')
)
await untilUpdated(() => getColor(el), 'red')
})
test('less + scoped', async () => {
const el = await page.$('p.pug-less')
expect(await getColor(el)).toBe('green')
editFile('PreProcessors.vue', (code) =>
code.replace('@color: green;', '@color: blue;')
)
await untilUpdated(() => getColor(el), 'blue')
})
})
describe('css modules', () => {
test('basic', async () => {
expect(await getColor('.sfc-css-modules')).toBe('blue')
editFile('CssModules.vue', (code) =>
code.replace('color: blue;', 'color: red;')
)
await untilUpdated(() => getColor('.sfc-css-modules'), 'red')
})
test('with preprocessor + name', async () => {
expect(await getColor('.sfc-css-modules-with-pre')).toBe('orange')
editFile('CssModules.vue', (code) =>
code.replace('color: orange;', 'color: blue;')
)
await untilUpdated(() => getColor('.sfc-css-modules-with-pre'), 'blue')
})
})
describe('asset reference', () => {
const assetMatch = isBuild
? /\/assets\/asset\.\w{8}\.png/
: '/assets/asset.png'
test('should not 404', () => {
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('404')
})
})
test('relative import', async () => {
const el = await page.$('img.relative-import')
expect(await el.evaluate((el) => (el as HTMLImageElement).src)).toMatch(
assetMatch
)
})
test('absolute import', async () => {
const el = await page.$('img.relative-import')
expect(await el.evaluate((el) => (el as HTMLImageElement).src)).toMatch(
assetMatch
)
})
test('absolute import from public dir', async () => {
const el = await page.$('img.public-import')
expect(await el.evaluate((el) => (el as HTMLImageElement).src)).toMatch(
`/icon.png`
)
})
test('svg fragment', async () => {
const img = await page.$('.svg-frag')
expect(await img.getAttribute('src')).toMatch(
isBuild ? /svg%3e#icon-heart-view$/ : /svg#icon-heart-view$/
)
})
test('relative url from <style>', async () => {
const assetMatch = isBuild
? /\/assets\/asset\.\w{8}\.png/
: '/assets/asset.png'
expect(await getBg('.relative-style-url')).toMatch(assetMatch)
})
})
describe('hmr', () => {
test('should re-render and preserve state when template is edited', async () => {
editFile('Hmr.vue', (code) => code.replace('HMR', 'HMR updated'))
await untilUpdated(() => page.textContent('h2.hmr'), 'HMR updated')
expect(await page.textContent('.hmr-inc')).toMatch('count is 1')
})
test('should update style and preserve state when style is edited', async () => {
expect(await getColor('.hmr-inc')).toBe('red')
editFile('Hmr.vue', (code) => code.replace('color: red;', 'color: blue;'))
await untilUpdated(() => getColor('.hmr-inc'), 'blue')
expect(await page.textContent('.hmr-inc')).toMatch('count is 1')
})
test('should reload and reset state when script is edited', async () => {
editFile('Hmr.vue', (code) =>
code.replace('let foo: number = 0', 'let foo: number = 100')
)
await untilUpdated(() => page.textContent('.hmr-inc'), 'count is 100')
})
test('should re-render when template is emptied', async () => {
editFile('Hmr.vue', () => '')
await untilUpdated(() => page.innerHTML('.hmr-block'), '<!---->')
})
})
describe('src imports', () => {
test('script src with ts', async () => {
expect(await page.textContent('.src-imports-script')).toMatch(
'hello from script src'
)
editFile('src-import/script.ts', (code) =>
code.replace('hello from script src', 'updated')
)
await untilUpdated(() => page.textContent('.src-imports-script'), 'updated')
})
test('style src', async () => {
const el = await page.$('.src-imports-style')
expect(await getColor(el)).toBe('tan')
editFile('src-import/style.css', (code) =>
code.replace('color: tan', 'color: red')
)
await untilUpdated(() => getColor(el), 'red')
})
test('tempalte src import hmr', async () => {
const el = await page.$('.src-imports-style')
editFile('src-import/template.html', (code) =>
code.replace('should be tan', 'should be red')
)
await untilUpdated(() => el.textContent(), 'should be red')
})
})
describe('custom blocks', () => {
test('should work', async () => {
expect(await page.textContent('.custom-block')).toMatch('こんにちは')
})
})