|
9 | 9 | cssUrlRE, |
10 | 10 | getEmptyChunkReplacer, |
11 | 11 | hoistAtRules, |
| 12 | + preprocessCSS, |
12 | 13 | } from '../../plugins/css' |
13 | 14 |
|
14 | 15 | describe('search css url function', () => { |
@@ -65,6 +66,7 @@ background: #f0f; |
65 | 66 | }`, |
66 | 67 | }, |
67 | 68 | { |
| 69 | + configFile: false, |
68 | 70 | resolve: { |
69 | 71 | alias: [ |
70 | 72 | { |
@@ -101,6 +103,7 @@ position: fixed; |
101 | 103 |
|
102 | 104 | test('custom generateScopedName', async () => { |
103 | 105 | const { transform, resetMock } = await createCssPluginTransform(undefined, { |
| 106 | + configFile: false, |
104 | 107 | css: { |
105 | 108 | modules: { |
106 | 109 | generateScopedName: 'custom__[hash:base64:5]', |
@@ -338,3 +341,50 @@ require("other-module");` |
338 | 341 | ) |
339 | 342 | }) |
340 | 343 | }) |
| 344 | + |
| 345 | +describe('preprocessCSS', () => { |
| 346 | + test('works', async () => { |
| 347 | + const resolvedConfig = await resolveConfig({ configFile: false }, 'serve') |
| 348 | + const result = await preprocessCSS( |
| 349 | + `\ |
| 350 | +.foo { |
| 351 | + color:red; |
| 352 | + background: url(./foo.png); |
| 353 | +}`, |
| 354 | + 'foo.css', |
| 355 | + resolvedConfig, |
| 356 | + ) |
| 357 | + expect(result.code).toMatchInlineSnapshot(` |
| 358 | + ".foo { |
| 359 | + color:red; |
| 360 | + background: url(./foo.png); |
| 361 | + }" |
| 362 | + `) |
| 363 | + }) |
| 364 | + |
| 365 | + test('works with lightningcss', async () => { |
| 366 | + const resolvedConfig = await resolveConfig( |
| 367 | + { |
| 368 | + configFile: false, |
| 369 | + css: { transformer: 'lightningcss' }, |
| 370 | + }, |
| 371 | + 'serve', |
| 372 | + ) |
| 373 | + const result = await preprocessCSS( |
| 374 | + `\ |
| 375 | +.foo { |
| 376 | + color: red; |
| 377 | + background: url(./foo.png); |
| 378 | +}`, |
| 379 | + 'foo.css', |
| 380 | + resolvedConfig, |
| 381 | + ) |
| 382 | + expect(result.code).toMatchInlineSnapshot(` |
| 383 | + ".foo { |
| 384 | + color: red; |
| 385 | + background: url("./foo.png"); |
| 386 | + } |
| 387 | + " |
| 388 | + `) |
| 389 | + }) |
| 390 | +}) |
0 commit comments