Skip to content

Commit 47d4f17

Browse files
committed
fix chunks calc
1 parent 1b96fa9 commit 47d4f17

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,7 @@ on:
88
types: [created]
99

1010
jobs:
11-
test:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v5
15-
- uses: actions/setup-node@v5
16-
with:
17-
cache: 'npm'
18-
node-version: 22
19-
- run: npm ci --ignore-scripts --no-audit --no-fund
20-
- run: npm test
21-
2211
publish-npm:
23-
needs: test
2412
runs-on: ubuntu-latest
2513
steps:
2614
- uses: actions/checkout@v5
@@ -30,6 +18,8 @@ jobs:
3018
cache: 'npm'
3119
registry-url: https://registry.npmjs.org/
3220
- run: npm ci --ignore-scripts --no-audit --no-fund
21+
- run: npx playwright install chromium --only-shell
22+
- run: npm test -- --forbid-only
3323
- run: npm run build
3424
- run: npm publish --public
3525
env:

src/index.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ test.describe('from coverage data downloaded directly from the browser as JSON',
186186
1, 1, 1, 1,
187187
// comment + p {}
188188
0, 0, 0, 0,
189+
// newline
190+
1,
189191
// @media
190192
1,
191193
// h1 {
192-
1, 0,
194+
0,
193195
// color: green; }
194196
1, 1, 1,
195197
]),
@@ -200,10 +202,10 @@ test.describe('from coverage data downloaded directly from the browser as JSON',
200202
let result = calculate_coverage(coverage, html_parser)
201203
expect(result.coverage_per_stylesheet.at(0)?.chunks).toEqual([
202204
{ start_line: 1, is_covered: true, end_line: 4, total_lines: 4 },
203-
{ start_line: 4, is_covered: false, end_line: 8, total_lines: 5 },
204-
{ start_line: 8, is_covered: true, end_line: 10, total_lines: 3 },
205-
{ start_line: 10, is_covered: false, end_line: 11, total_lines: 2 },
206-
{ start_line: 11, is_covered: true, end_line: 14, total_lines: 4 },
205+
{ start_line: 5, is_covered: false, end_line: 8, total_lines: 4 },
206+
{ start_line: 9, is_covered: true, end_line: 10, total_lines: 2 },
207+
{ start_line: 11, is_covered: false, end_line: 11, total_lines: 1 },
208+
{ start_line: 12, is_covered: true, end_line: 14, total_lines: 3 },
207209
])
208210
})
209211

@@ -223,6 +225,7 @@ test.describe('from coverage data downloaded directly from the browser as JSON',
223225
],
224226
html_parser,
225227
)
228+
expect(result.coverage_per_stylesheet.at(0)?.text).toEqual('h1 {\n\tcolor: blue;\n}')
226229
expect(result.coverage_per_stylesheet.at(0)?.chunks).toEqual([
227230
{
228231
start_line: 1,

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,20 @@ export function calculate_coverage(coverage: Coverage[], parse_html?: Parser): C
128128
{
129129
start_line: 1,
130130
is_covered: line_coverage[0] === 1,
131-
end_line: 0,
132-
total_lines: 0,
131+
end_line: 1,
132+
total_lines: 1,
133133
},
134134
]
135135

136-
for (let index = 0; index < line_coverage.length; index++) {
136+
for (let index = 1; index < line_coverage.length; index++) {
137137
let is_covered = line_coverage[index]
138-
if (index > 0 && is_covered !== line_coverage[index - 1]) {
138+
if (is_covered !== line_coverage[index - 1]) {
139139
let last_chunk = chunks.at(-1)!
140140
last_chunk.end_line = index
141141
last_chunk.total_lines = index - last_chunk.start_line + 1
142142

143143
chunks.push({
144-
start_line: index,
144+
start_line: index + 1,
145145
is_covered: is_covered === 1,
146146
end_line: index,
147147
total_lines: 0,
@@ -150,7 +150,7 @@ export function calculate_coverage(coverage: Coverage[], parse_html?: Parser): C
150150
}
151151

152152
let last_chunk = chunks.at(-1)!
153-
last_chunk.total_lines = line_coverage.length - last_chunk.start_line + 1
153+
last_chunk.total_lines = line_coverage.length + 1 - last_chunk.start_line
154154
last_chunk.end_line = line_coverage.length
155155

156156
return {

0 commit comments

Comments
 (0)