Skip to content

Commit 7335f25

Browse files
committed
fix tests
1 parent b120a68 commit 7335f25

3 files changed

Lines changed: 37 additions & 18 deletions

File tree

src/lib/components/coverage/Coverage.spec.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,21 @@ test.describe('loading example file', () => {
4343
let size_column = header.getByRole('columnheader').nth(1)
4444
await expect.soft(size_column).toHaveAccessibleName('Total size')
4545
await expect.soft(size_column).not.toHaveAttribute('aria-sort')
46-
let coverage_column = header.getByRole('columnheader').nth(2)
46+
let line_count_column = header.getByRole('columnheader').nth(2)
47+
await expect.soft(line_count_column).toHaveAccessibleName('Lines')
48+
await expect.soft(line_count_column).not.toHaveAttribute('aria-sort')
49+
let coverage_column = header.getByRole('columnheader').nth(3)
4750
await expect.soft(coverage_column).toHaveAccessibleName('Coverage')
4851
await expect.soft(coverage_column).not.toHaveAttribute('aria-sort')
4952

5053
// Row contents:
5154
let first_row = table.getByRole('row').nth(1)
52-
await expect.soft(first_row.getByRole('cell').nth(0)).toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/0.BBE7cspC.css')
55+
await expect
56+
.soft(first_row.getByRole('cell').nth(0))
57+
.toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/0.BBE7cspC.css')
5358
await expect.soft(first_row.getByRole('cell').nth(1)).toHaveAccessibleName('38 kB')
54-
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('72.16%')
59+
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('2,619')
60+
await expect.soft(first_row.getByRole('cell').nth(3)).toHaveAccessibleName('72.16%')
5561

5662
// Elements in correct state:
5763
await expect.soft(table.getByRole('row').nth(1)).toHaveAttribute('aria-selected', 'true')
@@ -87,19 +93,23 @@ test.describe('loading example file', () => {
8793
await expect.soft(url_header).toHaveAttribute('aria-sort', 'descending')
8894
let first_row = table.getByRole('row').nth(1)
8995
await expect.soft(first_row).toHaveAttribute('aria-selected', 'true')
90-
await expect.soft(first_row.getByRole('cell').nth(0)).toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/Textarea.D3Oc5lUl.css')
96+
await expect
97+
.soft(first_row.getByRole('cell').nth(0))
98+
.toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/Textarea.D3Oc5lUl.css')
9199
await expect.soft(first_row.getByRole('cell').nth(1)).toHaveAccessibleName('238 B')
92-
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('100%')
100+
await expect.soft(first_row.getByRole('cell').nth(3)).toHaveAccessibleName('100%')
93101
let css_content = await page.getByTestId('pre-css').textContent()
94102
expect.soft(css_content).toContain('textarea.svelte-g7hyhb {')
95103

96104
// Click the same column again to reverse the sort
97105
await url_header.click()
98106
await expect.soft(url_header).toHaveAttribute('aria-sort', 'ascending')
99107
await expect.soft(first_row).toHaveAttribute('aria-selected', 'true')
100-
await expect.soft(first_row.getByRole('cell').nth(0)).toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/0.BBE7cspC.css')
108+
await expect
109+
.soft(first_row.getByRole('cell').nth(0))
110+
.toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/0.BBE7cspC.css')
101111
await expect.soft(first_row.getByRole('cell').nth(1)).toHaveAccessibleName('38 kB')
102-
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('72.16%')
112+
await expect.soft(first_row.getByRole('cell').nth(3)).toHaveAccessibleName('72.16%')
103113
})
104114

105115
test('sorting by total size', async ({ page }) => {
@@ -109,44 +119,52 @@ test.describe('loading example file', () => {
109119
await expect.soft(size_header).toHaveAttribute('aria-sort', 'descending')
110120
let first_row = table.getByRole('row').nth(1)
111121
await expect.soft(first_row).toHaveAttribute('aria-selected', 'true')
112-
await expect.soft(first_row.getByRole('cell').nth(0)).toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/0.BBE7cspC.css')
122+
await expect
123+
.soft(first_row.getByRole('cell').nth(0))
124+
.toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/0.BBE7cspC.css')
113125
await expect.soft(first_row.getByRole('cell').nth(1)).toHaveAccessibleName('38 kB')
114-
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('72.16%')
126+
await expect.soft(first_row.getByRole('cell').nth(3)).toHaveAccessibleName('72.16%')
115127
let css_content = await page.getByTestId('pre-css').textContent()
116128
expect.soft(css_content).toContain('.logo.svelte-1jiwtxp {')
117129

118130
// Click the same column again to reverse the sort
119131
await size_header.click()
120132
await expect.soft(size_header).toHaveAttribute('aria-sort', 'ascending')
121133
await expect.soft(first_row).toHaveAttribute('aria-selected', 'true')
122-
await expect.soft(first_row.getByRole('cell').nth(0)).toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/FormattedDate.JHv9Zh3p.css')
134+
await expect
135+
.soft(first_row.getByRole('cell').nth(0))
136+
.toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/FormattedDate.JHv9Zh3p.css')
123137
await expect.soft(first_row.getByRole('cell').nth(1)).toHaveAccessibleName('69 B')
124-
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('100%')
138+
await expect.soft(first_row.getByRole('cell').nth(3)).toHaveAccessibleName('100%')
125139
css_content = await page.getByTestId('pre-css').textContent()
126140
expect.soft(css_content).toContain('time.svelte-60ldmz {')
127141
})
128142

129143
test('sorting by coverage', async ({ page }) => {
130144
let header = table.getByRole('row').first()
131-
let coverage_header = header.getByRole('columnheader').nth(2)
145+
let coverage_header = header.getByRole('columnheader').nth(3)
132146
await coverage_header.click()
133147
await expect.soft(coverage_header).toHaveAttribute('aria-sort', 'descending')
134148
let first_row = table.getByRole('row').nth(1)
135149
await expect.soft(first_row).toHaveAttribute('aria-selected', 'true')
136-
await expect.soft(first_row.getByRole('cell').nth(0)).toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/23.lTvFD_l9.css')
150+
await expect
151+
.soft(first_row.getByRole('cell').nth(0))
152+
.toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/23.lTvFD_l9.css')
137153
await expect.soft(first_row.getByRole('cell').nth(1)).toHaveAccessibleName('405 B')
138-
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('100%')
154+
await expect.soft(first_row.getByRole('cell').nth(3)).toHaveAccessibleName('100%')
139155
let css_content = await page.getByTestId('pre-css').textContent()
140156
expect.soft(css_content).toContain('.form.svelte-148ca8f {')
141157

142158
// Click the same column again to reverse the sort
143159
await coverage_header.click()
144160
await expect.soft(coverage_header).toHaveAttribute('aria-sort', 'ascending')
145161
await expect.soft(first_row).toHaveAttribute('aria-selected', 'true')
146-
await expect.soft(first_row.getByRole('cell').nth(0)).toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/25.C4edrrKC.css')
162+
await expect
163+
.soft(first_row.getByRole('cell').nth(0))
164+
.toHaveAccessibleName('https://www.projectwallace.com/_app/immutable/assets/25.C4edrrKC.css')
147165
await expect.soft(first_row.getByRole('cell').nth(1)).toHaveAccessibleName('780 B')
148-
await expect.soft(first_row.getByRole('cell').nth(2)).toHaveAccessibleName('0%')
166+
await expect.soft(first_row.getByRole('cell').nth(3)).toHaveAccessibleName('0%')
149167
css_content = await page.getByTestId('pre-css').textContent()
150168
expect.soft(css_content).toContain('.page.svelte-1b1m7j9 {')
151169
})
152-
})
170+
})

src/lib/components/coverage/calculate-coverage.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ describe('calculates coverage', () => {
164164
expect.soft(sheet.total_lines).toBe(11)
165165
expect.soft(sheet.covered_lines).toBe(7)
166166
expect.soft(sheet.uncovered_lines).toBe(4)
167+
expect.soft(sheet.coverage_ratio).toBe(7 / 11)
167168
expect.soft(sheet.line_coverage).toEqual(new Uint8Array([1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1]))
168169
})
169170
})

src/lib/components/coverage/calculate-coverage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export function calculate_coverage(browser_coverage: Coverage[], parse_html: Htm
191191

192192
let trimmed_line = line.trim()
193193
let is_empty = trimmed_line.length === 0
194-
let is_closing_brace = trimmed_line === '}'
194+
let is_closing_brace = !is_empty && trimmed_line === '}'
195195
let prev_is_covered = index > 0 ? line_coverage[index - 1] === 1 : false
196196

197197
if (is_in_range && !is_closing_brace && !is_empty) {

0 commit comments

Comments
 (0)