|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | +import { calculate_coverage } from '.' |
| 3 | +import { DOMParser } from 'linkedom' |
| 4 | + |
| 5 | +function parse_html(html: string) { |
| 6 | + return new DOMParser().parseFromString(html, 'text/html') |
| 7 | +} |
| 8 | + |
| 9 | +test('proejctw wallace Container', () => { |
| 10 | + const coverage = [ |
| 11 | + { |
| 12 | + url: 'http://localhost:4173/_app/immutable/assets/Container.n-2BXq6O.css', |
| 13 | + text: '.container.svelte-1ginl5v{margin-inline:auto;padding-inline:var(--space-2)}@media (min-width: 44rem){.container.svelte-1ginl5v{padding-inline:var(--space-4)}}@media (min-width: 66rem){.container.svelte-1ginl5v{padding-inline:var(--space-8)}}.size-auto.svelte-1ginl5v{max-width:120rem}.size-sm.svelte-1ginl5v{max-width:28rem}.size-md.svelte-1ginl5v{max-width:32rem}.size-lg.svelte-1ginl5v{max-width:36rem}.size-xl.svelte-1ginl5v{max-width:48rem}.size-2xl.svelte-1ginl5v{max-width:64rem}.size-3xl.svelte-1ginl5v{max-width:80rem}\n', |
| 14 | + ranges: [ |
| 15 | + { start: 0, end: 75 }, |
| 16 | + { start: 82, end: 157 }, |
| 17 | + { start: 165, end: 240 }, |
| 18 | + { start: 241, end: 284 }, |
| 19 | + { start: 485, end: 526 }, |
| 20 | + ], |
| 21 | + }, |
| 22 | + ] |
| 23 | + let result = calculate_coverage(coverage, parse_html) |
| 24 | + let sheet = result.coverage_per_stylesheet.at(0)! |
| 25 | + |
| 26 | + expect.soft(sheet.total_lines).toBe(44) |
| 27 | + expect.soft(sheet.chunks).toHaveLength(3) |
| 28 | + |
| 29 | + let [chunk1, chunk2, chunk3] = sheet.chunks |
| 30 | + |
| 31 | + expect.soft(chunk1?.start_line).toEqual(1) |
| 32 | + expect.soft(chunk1?.end_line).toEqual(21) |
| 33 | + expect.soft(chunk1?.total_lines).toEqual(21) |
| 34 | + |
| 35 | + expect.soft(chunk2?.start_line).toEqual(22) |
| 36 | + expect.soft(chunk2?.end_line).toEqual(40) |
| 37 | + expect.soft(chunk2?.total_lines).toEqual(19) |
| 38 | + |
| 39 | + expect.soft(chunk3?.start_line).toEqual(41) |
| 40 | + expect.soft(chunk3?.end_line).toEqual(44) |
| 41 | + expect.soft(chunk3?.total_lines).toEqual(4) |
| 42 | +}) |
0 commit comments