|
1 | | -import process from 'node:process' |
2 | 1 | import fs from 'fs-extra' |
3 | 2 | import { resolve } from 'pathe' |
4 | 3 | import { afterAll, beforeAll, describe, expect, it } from 'vitest' |
@@ -98,31 +97,6 @@ describe('cli', () => { |
98 | 97 | expect(transform).toMatchSnapshot() |
99 | 98 | }) |
100 | 99 |
|
101 | | - it.skipIf(process.version.startsWith('v20'))('uno.css exclude initialized class after changing file', async () => { |
102 | | - const { output, testDir } = await runCli({ |
103 | | - 'views/index.html': '<div class="bg-blue"></div>', |
104 | | - }, { args: ['--preset', 'wind3', '-w'] }) |
105 | | - |
106 | | - expect(output).toContain('.bg-blue') |
107 | | - |
108 | | - const changedContent = '<div class="bg-red"></div>' |
109 | | - const absolutePathOfFile = resolve(testDir!, 'views/index.html') |
110 | | - await fs.writeFile(absolutePathOfFile, changedContent) |
111 | | - |
112 | | - // polling until update |
113 | | - |
114 | | - while (true) { |
115 | | - await sleep(100) |
116 | | - const output = await readFile(testDir!) |
117 | | - if (output.includes('.bg-red')) { |
118 | | - expect(output).toContain('.bg-red') |
119 | | - break |
120 | | - } |
121 | | - } |
122 | | - |
123 | | - (await getWatcher()).close() |
124 | | - }) |
125 | | - |
126 | 100 | it('supports unocss.config.js cli options', async () => { |
127 | 101 | const testDir = getTestDir() |
128 | 102 | const outFiles = ['./uno1.css', './test/uno2.css'] |
@@ -173,7 +147,73 @@ describe('cli', () => { |
173 | 147 | expect(output2).toContain('.bg-red') |
174 | 148 | }) |
175 | 149 |
|
176 | | - it.skipIf(process.version.startsWith('v20'))('supports uno.config.ts changed rebuild', async () => { |
| 150 | + it('should correctly deduplicate files of different types containing @media', async () => { |
| 151 | + const { output, transform } = await runCli( |
| 152 | + { |
| 153 | + 'views/index1.html': '<div class="lg:p-8"></div>', |
| 154 | + 'views/index2.html': '<div class="md:p-4"></div>', |
| 155 | + 'views/index3.html': '<div class="box"></div>', |
| 156 | + 'views/index.css': '.box { @apply pd-6 sm:p-2; }', |
| 157 | + 'unocss.config.js': ` |
| 158 | + import { defineConfig, presetWind3, transformerDirectives } from 'unocss' |
| 159 | + export default defineConfig({ |
| 160 | + presets: [presetWind3()], |
| 161 | + transformers: [transformerDirectives()] |
| 162 | + }) |
| 163 | + `.trim(), |
| 164 | + }, |
| 165 | + { transformFile: 'views/index.css', args: ['--rewrite'] }, |
| 166 | + ) |
| 167 | + |
| 168 | + expect(output).toMatchSnapshot() |
| 169 | + expect(transform).toMatchSnapshot() |
| 170 | + }) |
| 171 | + |
| 172 | + it('@unocss-skip uno.css', async () => { |
| 173 | + const { output } = await runCli({ |
| 174 | + 'views/index.html': ` |
| 175 | + <div class="p-4"></div> |
| 176 | + // @unocss-skip-start |
| 177 | + <div class="bg-red text-white"></div> |
| 178 | + // @unocss-skip-end |
| 179 | + <div className="w-10"></div> |
| 180 | + `, |
| 181 | + }) |
| 182 | + |
| 183 | + expect(output).toContain('.p-4') |
| 184 | + expect(output).toContain('.w-10') |
| 185 | + expect(output).not.toContain('.bg-red') |
| 186 | + expect(output).not.toContain('.text-white') |
| 187 | + }) |
| 188 | +}) |
| 189 | + |
| 190 | +describe.skipIf(process.version.startsWith('v20'))('cli watch mode', () => { |
| 191 | + it('uno.css exclude initialized class after changing file', async () => { |
| 192 | + const { output, testDir } = await runCli({ |
| 193 | + 'views/index.html': '<div class="bg-blue"></div>', |
| 194 | + }, { args: ['-w'] }) |
| 195 | + |
| 196 | + expect(output).toContain('.bg-blue') |
| 197 | + |
| 198 | + const changedContent = '<div class="bg-red"></div>' |
| 199 | + const absolutePathOfFile = resolve(testDir!, 'views/index.html') |
| 200 | + await fs.writeFile(absolutePathOfFile, changedContent) |
| 201 | + |
| 202 | + // polling until update |
| 203 | + |
| 204 | + while (true) { |
| 205 | + await sleep(100) |
| 206 | + const output = await readFile(testDir!) |
| 207 | + if (output.includes('.bg-red')) { |
| 208 | + expect(output).toContain('.bg-red') |
| 209 | + break |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + (await getWatcher()).close() |
| 214 | + }) |
| 215 | + |
| 216 | + it('supports uno.config.ts changed rebuild', async () => { |
177 | 217 | const { output, testDir } = await runCli({ |
178 | 218 | 'views/index.html': '<div class="bg-foo"></div>', |
179 | 219 | 'uno.config.ts': ` |
@@ -213,43 +253,4 @@ describe('cli', () => { |
213 | 253 |
|
214 | 254 | (await getWatcher()).close() |
215 | 255 | }) |
216 | | - |
217 | | - it('should correctly deduplicate files of different types containing @media', async () => { |
218 | | - const { output, transform } = await runCli( |
219 | | - { |
220 | | - 'views/index1.html': '<div class="lg:p-8"></div>', |
221 | | - 'views/index2.html': '<div class="md:p-4"></div>', |
222 | | - 'views/index3.html': '<div class="box"></div>', |
223 | | - 'views/index.css': '.box { @apply pd-6 sm:p-2; }', |
224 | | - 'unocss.config.js': ` |
225 | | - import { defineConfig, presetWind3, transformerDirectives } from 'unocss' |
226 | | - export default defineConfig({ |
227 | | - presets: [presetWind3()], |
228 | | - transformers: [transformerDirectives()] |
229 | | - }) |
230 | | - `.trim(), |
231 | | - }, |
232 | | - { transformFile: 'views/index.css', args: ['--rewrite'] }, |
233 | | - ) |
234 | | - |
235 | | - expect(output).toMatchSnapshot() |
236 | | - expect(transform).toMatchSnapshot() |
237 | | - }) |
238 | | - |
239 | | - it('@unocss-skip uno.css', async () => { |
240 | | - const { output } = await runCli({ |
241 | | - 'views/index.html': ` |
242 | | - <div class="p-4"></div> |
243 | | - // @unocss-skip-start |
244 | | - <div class="bg-red text-white"></div> |
245 | | - // @unocss-skip-end |
246 | | - <div className="w-10"></div> |
247 | | - `, |
248 | | - }) |
249 | | - |
250 | | - expect(output).toContain('.p-4') |
251 | | - expect(output).toContain('.w-10') |
252 | | - expect(output).not.toContain('.bg-red') |
253 | | - expect(output).not.toContain('.text-white') |
254 | | - }) |
255 | 256 | }) |
0 commit comments