|
| 1 | +import { browserLogs, getColor, 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 compiled from scss', async () => { |
| 11 | + expect(await getText('#test')).toBe('red'); |
| 12 | + expect(await getColor('#test')).toBe('red'); |
| 13 | + expect(await getText('.foo')).toBe('magenta'); |
| 14 | + expect(await getColor('.foo')).toBe('magenta'); |
| 15 | +}); |
| 16 | + |
| 17 | +if (!isBuild) { |
| 18 | + test('should generate sourcemap', async () => { |
| 19 | + const style = await getText('style'); |
| 20 | + const lines = style.split(`\n`).map((l) => l.trim()); |
| 21 | + const css = lines[0]; |
| 22 | + const mapComment = lines[1]; |
| 23 | + expect(css).toBe( |
| 24 | + '.foo.s-XsEmFtvddWTw{color:magenta}#test.s-XsEmFtvddWTw{color:red}.s-XsEmFtvddWTw{}' |
| 25 | + ); |
| 26 | + const b64start = '/*# sourceMappingURL=data:application/json;base64,'; |
| 27 | + const b64end = ' */'; |
| 28 | + expect(mapComment.startsWith(b64start)); |
| 29 | + expect(mapComment.endsWith(b64end)); |
| 30 | + const map = JSON.parse( |
| 31 | + Buffer.from(mapComment.slice(b64start.length, -1 * b64end.length), 'base64').toString('utf-8') |
| 32 | + ); |
| 33 | + expect(map.sources).toStrictEqual(['foo.scss', 'App.svelte']); |
| 34 | + expect(map.file).toBe('App.svelte'); |
| 35 | + // we are not testing the quality of the mapping here, just that it exists. |
| 36 | + expect(map.mappings).toBeDefined(); |
| 37 | + }); |
| 38 | +} |
0 commit comments