forked from vitejs/vite
/
tailwind.spec.ts
89 lines (67 loc) · 2.27 KB
/
tailwind.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
import { expect, test } from 'vitest'
import {
browserLogs,
editFile,
getBgColor,
getColor,
isBuild,
page,
untilUpdated
} from '~utils'
test('should render', async () => {
expect(await page.textContent('#pagetitle')).toBe('|Page title|')
})
if (!isBuild) {
test('regenerate CSS and HMR (glob pattern)', async () => {
browserLogs.length = 0
const el = await page.$('#pagetitle')
const el2 = await page.$('#helloroot')
expect(await getColor(el)).toBe('rgb(11, 22, 33)')
editFile('src/views/Page.vue', (code) =>
code.replace('|Page title|', '|Page title updated|')
)
await untilUpdated(() => el.textContent(), '|Page title updated|')
expect(browserLogs).toMatchObject([
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/views/Page.vue'
])
browserLogs.length = 0
editFile('src/components/HelloWorld.vue', (code) =>
code.replace('text-gray-800', 'text-[rgb(10,20,30)]')
)
await untilUpdated(() => getColor(el2), 'rgb(10, 20, 30)')
expect(browserLogs).toMatchObject([
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/components/HelloWorld.vue'
])
browserLogs.length = 0
})
test('regenerate CSS and HMR (relative path)', async () => {
browserLogs.length = 0
const el = await page.$('h1')
expect(await getColor(el)).toBe('black')
editFile('src/App.vue', (code) =>
code.replace('text-black', 'text-[rgb(11,22,33)]')
)
await untilUpdated(() => getColor(el), 'rgb(11, 22, 33)')
expect(browserLogs).toMatchObject([
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/App.vue'
])
browserLogs.length = 0
})
test('regenerate CSS and HMR (pug template)', async () => {
browserLogs.length = 0
const el = await page.$('.pug')
expect(await getBgColor(el)).toBe('rgb(248, 113, 113)')
editFile('src/components/PugTemplate.vue', (code) =>
code.replace('bg-red-400', 'bg-red-600')
)
await untilUpdated(() => getBgColor(el), 'rgb(220, 38, 38)')
expect(browserLogs).toContain('[vite] css hot updated: /index.css')
expect(browserLogs).toContain(
'[vite] hot updated: /src/components/PugTemplate.vue?vue&type=template&lang.js'
)
browserLogs.length = 0
})
}