forked from vitejs/vite
/
vue-jsx.spec.ts
105 lines (90 loc) · 3.63 KB
/
vue-jsx.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
import { editFile, isBuild, untilUpdated } from 'testUtils'
test('should render', async () => {
expect(await page.textContent('.named')).toMatch('0')
expect(await page.textContent('.named-specifier')).toMatch('1')
expect(await page.textContent('.default')).toMatch('2')
expect(await page.textContent('.default-tsx')).toMatch('3')
expect(await page.textContent('.script')).toMatch('4')
expect(await page.textContent('.src-import')).toMatch('5')
expect(await page.textContent('.other-ext')).toMatch('Other Ext')
})
test('should update', async () => {
await page.click('.named')
expect(await page.textContent('.named')).toMatch('1')
await page.click('.named-specifier')
expect(await page.textContent('.named-specifier')).toMatch('2')
await page.click('.default')
expect(await page.textContent('.default')).toMatch('3')
await page.click('.default-tsx')
expect(await page.textContent('.default-tsx')).toMatch('4')
await page.click('.script')
expect(await page.textContent('.script')).toMatch('5')
await page.click('.src-import')
expect(await page.textContent('.src-import')).toMatch('6')
})
if (!isBuild) {
test('hmr: named export', async () => {
editFile('Comps.jsx', (code) =>
code.replace('named {count', 'named updated {count')
)
await untilUpdated(() => page.textContent('.named'), 'named updated 0')
// affect all components in same file
expect(await page.textContent('.named-specifier')).toMatch('1')
expect(await page.textContent('.default')).toMatch('2')
// should not affect other components from different file
expect(await page.textContent('.default-tsx')).toMatch('4')
})
test('hmr: named export via specifier', async () => {
editFile('Comps.jsx', (code) =>
code.replace('named specifier {count', 'named specifier updated {count')
)
await untilUpdated(
() => page.textContent('.named-specifier'),
'named specifier updated 1'
)
// affect all components in same file
expect(await page.textContent('.default')).toMatch('2')
// should not affect other components on the page
expect(await page.textContent('.default-tsx')).toMatch('4')
})
test('hmr: default export', async () => {
editFile('Comps.jsx', (code) =>
code.replace('default {count', 'default updated {count')
)
await untilUpdated(() => page.textContent('.default'), 'default updated 2')
// should not affect other components on the page
expect(await page.textContent('.default-tsx')).toMatch('4')
})
test('hmr: named export via specifier', async () => {
// update another component
await page.click('.named')
expect(await page.textContent('.named')).toMatch('1')
editFile('Comp.tsx', (code) =>
code.replace('default tsx {count', 'default tsx updated {count')
)
await untilUpdated(
() => page.textContent('.default-tsx'),
'default tsx updated 3'
)
// should not affect other components on the page
expect(await page.textContent('.named')).toMatch('1')
})
test('hmr: script in .vue', async () => {
editFile('Script.vue', (code) =>
code.replace('script {count', 'script updated {count')
)
await untilUpdated(() => page.textContent('.script'), 'script updated 4')
expect(await page.textContent('.src-import')).toMatch('6')
})
test('hmr: src import in .vue', async () => {
await page.click('.script')
editFile('SrcImport.jsx', (code) =>
code.replace('src import {count', 'src import updated {count')
)
await untilUpdated(
() => page.textContent('.src-import'),
'src import updated 5'
)
expect(await page.textContent('.script')).toMatch('5')
})
}