-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathmulti-root.test.ts
170 lines (158 loc) · 4.69 KB
/
multi-root.test.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
import { candidate, css, fetchStyles, html, json, retryAssertion, test, ts } from '../utils'
test(
`production build`,
{
fs: {
'package.json': json`
{
"type": "module",
"dependencies": {
"@tailwindcss/vite": "workspace:^",
"tailwindcss": "workspace:^"
},
"devDependencies": {
"vite": "^6"
}
}
`,
'vite.config.ts': ts`
import tailwindcss from '@tailwindcss/vite'
import path from 'node:path'
import { defineConfig } from 'vite'
export default defineConfig({
build: {
cssMinify: false,
rollupOptions: {
input: {
root1: path.resolve(__dirname, 'root1.html'),
root2: path.resolve(__dirname, 'root2.html'),
},
},
},
plugins: [tailwindcss()],
})
`,
'root1.html': html`
<head>
<link rel="stylesheet" href="./src/root1.css" />
</head>
<body>
<div class="one:underline two:underline">Hello, world!</div>
</body>
`,
'src/shared.css': css`
@reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
`,
'src/root1.css': css`
@import './shared.css';
@custom-variant one (&:is([data-root='1']));
`,
'root2.html': html`
<head>
<link rel="stylesheet" href="./src/root2.css" />
</head>
<body>
<div class="one:underline two:underline">Hello, world!</div>
</body>
`,
'src/root2.css': css`
@import './shared.css';
@custom-variant two (&:is([data-root='2']));
`,
},
},
async ({ fs, exec, expect }) => {
await exec('pnpm vite build')
let files = await fs.glob('dist/**/*.css')
expect(files).toHaveLength(2)
let root1 = files.find(([filename]) => filename.includes('root1'))
let root2 = files.find(([filename]) => filename.includes('root2'))
expect(root1).toBeDefined()
expect(root2).toBeDefined()
expect(root1![1]).toContain(candidate`one:underline`)
expect(root1![1]).not.toContain(candidate`two:underline`)
expect(root2![1]).not.toContain(candidate`one:underline`)
expect(root2![1]).toContain(candidate`two:underline`)
},
)
test(
'dev mode',
{
fs: {
'package.json': json`
{
"type": "module",
"dependencies": {
"@tailwindcss/vite": "workspace:^",
"tailwindcss": "workspace:^"
},
"devDependencies": {
"vite": "^6"
}
}
`,
'vite.config.ts': ts`
import tailwindcss from '@tailwindcss/vite'
import path from 'node:path'
import { defineConfig } from 'vite'
export default defineConfig({
build: { cssMinify: false },
plugins: [tailwindcss()],
})
`,
'root1.html': html`
<head>
<link rel="stylesheet" href="./src/root1.css" />
</head>
<body>
<div class="one:underline two:underline">Hello, world!</div>
</body>
`,
'src/shared.css': css`
@reference 'tailwindcss/theme';
@import 'tailwindcss/utilities';
`,
'src/root1.css': css`
@import './shared.css';
@custom-variant one (&:is([data-root='1']));
`,
'root2.html': html`
<head>
<link rel="stylesheet" href="./src/root2.css" />
</head>
<body>
<div class="one:underline two:underline">Hello, world!</div>
</body>
`,
'src/root2.css': css`
@import './shared.css';
@custom-variant two (&:is([data-root='2']));
`,
},
},
async ({ spawn, expect }) => {
let process = await spawn('pnpm vite dev')
await process.onStdout((m) => m.includes('ready in'))
let url = ''
await process.onStdout((m) => {
let match = /Local:\s*(http.*)\//.exec(m)
if (match) url = match[1]
return Boolean(url)
})
// Candidates are resolved lazily, so the first visit of index.html
// will only have candidates from this file.
await retryAssertion(async () => {
let styles = await fetchStyles(url, '/root1.html')
expect(styles).toContain(candidate`one:underline`)
expect(styles).not.toContain(candidate`two:underline`)
})
// Going to about.html will extend the candidate list to include
// candidates from about.html.
await retryAssertion(async () => {
let styles = await fetchStyles(url, '/root2.html')
expect(styles).not.toContain(candidate`one:underline`)
expect(styles).toContain(candidate`two:underline`)
})
},
)