|
1 |
| -import { browserLogs, findAssetFile, getColor, getEl, getText, isBuild } from '~utils'; |
| 1 | +import { |
| 2 | + browserLogs, |
| 3 | + findAssetFile, |
| 4 | + getColor, |
| 5 | + getEl, |
| 6 | + getText, |
| 7 | + IS_SVELTE_BASELINE, |
| 8 | + isBuild |
| 9 | +} from '~utils'; |
2 | 10 | import { expect } from 'vitest';
|
3 | 11 |
|
4 |
| -test('should not have failed requests', async () => { |
5 |
| - browserLogs.forEach((msg) => { |
6 |
| - expect(msg).not.toMatch('404'); |
| 12 | +// support for treeshaking css was added after 5.0.0 |
| 13 | +describe.skipIf(IS_SVELTE_BASELINE)('css-treeshake', () => { |
| 14 | + test('should not have failed requests', async () => { |
| 15 | + browserLogs.forEach((msg) => { |
| 16 | + expect(msg).not.toMatch('404'); |
| 17 | + }); |
7 | 18 | });
|
8 |
| -}); |
9 |
| - |
10 |
| -test('should apply css from used components', async () => { |
11 |
| - expect(await getText('#app')).toBe('App'); |
12 |
| - expect(await getColor('#app')).toBe('blue'); |
13 |
| - expect(await getText('#a')).toBe('A'); |
14 |
| - expect(await getColor('#a')).toBe('red'); |
15 |
| -}); |
16 |
| - |
17 |
| -test('should apply css from unused components that contain global styles', async () => { |
18 |
| - expect(await getEl('head style[src]')); |
19 |
| - expect(await getColor('#test')).toBe('green'); // from B.svelte |
20 |
| -}); |
21 | 19 |
|
22 |
| -test('should not render unused components', async () => { |
23 |
| - expect(await getEl('#b')).toBeNull(); |
24 |
| - expect(await getEl('#c')).toBeNull(); |
25 |
| -}); |
| 20 | + test('should apply css from used components', async () => { |
| 21 | + expect(await getText('#app')).toBe('App'); |
| 22 | + expect(await getColor('#app')).toBe('blue'); |
| 23 | + expect(await getText('#a')).toBe('A'); |
| 24 | + expect(await getColor('#a')).toBe('red'); |
| 25 | + }); |
26 | 26 |
|
27 |
| -if (isBuild) { |
28 |
| - test('should include unscoped global styles from unused components', async () => { |
29 |
| - const cssOutput = findAssetFile(/index-.*\.css/); |
30 |
| - expect(cssOutput).toContain('#test{color:green}'); // from B.svelte |
| 27 | + test('should apply css from unused components that contain global styles', async () => { |
| 28 | + expect(await getEl('head style[src]')); |
| 29 | + expect(await getColor('#test')).toBe('green'); // from B.svelte |
31 | 30 | });
|
32 |
| - test('should not include scoped styles from unused components', async () => { |
33 |
| - const cssOutput = findAssetFile(/index-.*\.css/); |
34 |
| - // from C.svelte |
35 |
| - expect(cssOutput).not.toContain('.unused'); |
| 31 | + |
| 32 | + test('should not render unused components', async () => { |
| 33 | + expect(await getEl('#b')).toBeNull(); |
| 34 | + expect(await getEl('#c')).toBeNull(); |
36 | 35 | });
|
37 |
| -} |
| 36 | + |
| 37 | + if (isBuild) { |
| 38 | + test('should include unscoped global styles from unused components', async () => { |
| 39 | + const cssOutput = findAssetFile(/index-.*\.css/); |
| 40 | + expect(cssOutput).toContain('#test{color:green}'); // from B.svelte |
| 41 | + }); |
| 42 | + test('should not include scoped styles from unused components', async () => { |
| 43 | + const cssOutput = findAssetFile(/index-.*\.css/); |
| 44 | + // from C.svelte |
| 45 | + expect(cssOutput).not.toContain('.unused'); |
| 46 | + }); |
| 47 | + } |
| 48 | +}); |
0 commit comments