-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathcss-treeshake.spec.ts
37 lines (32 loc) · 1.23 KB
/
css-treeshake.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
import { browserLogs, findAssetFile, getColor, getEl, getText, isBuild } from '~utils';
import { expect } from 'vitest';
test('should not have failed requests', async () => {
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('404');
});
});
test('should apply css from used components', async () => {
expect(await getText('#app')).toBe('App');
expect(await getColor('#app')).toBe('blue');
expect(await getText('#a')).toBe('A');
expect(await getColor('#a')).toBe('red');
});
test('should apply css from unused components that contain global styles', async () => {
expect(await getEl('head style[src]'));
expect(await getColor('#test')).toBe('green'); // from B.svelte
});
test('should not render unused components', async () => {
expect(await getEl('#b')).toBeNull();
expect(await getEl('#c')).toBeNull();
});
if (isBuild) {
test('should include unscoped global styles from unused components', async () => {
const cssOutput = findAssetFile(/index-.*\.css/);
expect(cssOutput).toContain('#test{color:green}'); // from B.svelte
});
test('should not include scoped styles from unused components', async () => {
const cssOutput = findAssetFile(/index-.*\.css/);
// from C.svelte
expect(cssOutput).not.toContain('.unused');
});
}