forked from vitejs/vite
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tailwind.spec.ts
82 lines (74 loc) · 2.24 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
import { expect, test } from 'vitest'
import {
editFile,
getColor,
isServe,
page,
untilBrowserLogAfter,
untilUpdated,
} from '~utils'
test('should render', async () => {
expect(await page.textContent('#pagetitle')).toBe('Page title')
})
test.runIf(isServe)('regenerate CSS and HMR (glob pattern)', async () => {
const el = page.locator('#view1-text')
expect(await getColor(el)).toBe('rgb(22, 163, 74)')
await untilBrowserLogAfter(
() =>
editFile('src/views/view1.js', (code) =>
code.replace('|view1|', '|view1 updated|'),
),
[
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/views/view1.js via /src/main.js',
],
false,
)
await untilUpdated(() => el.textContent(), '|view1 updated|')
await untilBrowserLogAfter(
() =>
editFile('src/views/view1.js', (code) =>
code.replace('text-green-600', 'text-orange-600'),
),
[
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/views/view1.js via /src/main.js',
],
false,
)
// await new Promise(resolve => setTimeout(resolve, 10))
await untilUpdated(async () => getColor(el), 'rgb(234, 88, 12)')
})
test.runIf(isServe)(
'same file duplicated in module graph (#4267)',
async () => {
const el = page.locator('#component1')
expect(await getColor(el)).toBe('rgb(220, 38, 38)')
// when duplicated, page reload happens
await untilBrowserLogAfter(
() =>
editFile('src/components/component1.js', (code) =>
code.replace('text-red-600', 'text-blue-600'),
),
[
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/components/component1.js',
],
false,
)
await untilUpdated(() => getColor(el), 'rgb(37, 99, 235)')
},
)
test.runIf(isServe)('regenerate CSS and HMR (relative path)', async () => {
const el = page.locator('#pagetitle')
expect(await getColor(el)).toBe('rgb(124, 58, 237)')
await untilBrowserLogAfter(
() =>
editFile('src/main.js', (code) =>
code.replace('text-violet-600', 'text-cyan-600'),
),
['[vite] css hot updated: /index.css', '[vite] hot updated: /src/main.js'],
false,
)
await untilUpdated(() => getColor(el), 'rgb(8, 145, 178)')
})