|
| 1 | +import { browserLogs, findAssetFile, getColor, getEl, getText, isBuild } from '~utils'; |
| 2 | +import { expect } from 'vitest'; |
| 3 | + |
| 4 | +test('should not have failed requests', async () => { |
| 5 | + browserLogs.forEach((msg) => { |
| 6 | + expect(msg).not.toMatch('404'); |
| 7 | + }); |
| 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 | + |
| 22 | +test('should not render unused components', async () => { |
| 23 | + expect(await getEl('#b')).toBeNull(); |
| 24 | + expect(await getEl('#c')).toBeNull(); |
| 25 | +}); |
| 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 |
| 31 | + }); |
| 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'); |
| 36 | + }); |
| 37 | +} |
0 commit comments