Skip to content

Commit

Permalink
test_runner: fix typescript coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Aug 30, 2023
1 parent 9848352 commit 2a9c0ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function mapRangeToLines(range, lines) {
mid = MathFloor((start + end) / 2);
let line = lines[mid];

if (startOffset >= line.startOffset && startOffset <= line.endOffset) {
if (startOffset >= line?.startOffset && startOffset <= line?.endOffset) {
while (endOffset > line?.startOffset) {
// If the range is not covered, and the range covers the entire line,
// then mark that line as not covered.
Expand All @@ -333,7 +333,7 @@ function mapRangeToLines(range, lines) {
}

break;
} else if (startOffset >= line.endOffset) {
} else if (startOffset >= line?.endOffset) {
start = mid + 1;
} else {
end = mid - 1;
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ class Test extends AsyncResource {
this.reported = true;
reporter.plan(nesting, loc, harness.counters.topLevel);

const coverage = harness.coverage(); // Call this before printing diagnostics, since failure to collect coverage is a diagnostic.

Check failure on line 740 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

This line has a length of 135. Maximum allowed is 120
for (let i = 0; i < diagnostics.length; i++) {
reporter.diagnostic(nesting, loc, diagnostics[i]);
}
Expand All @@ -750,8 +751,6 @@ class Test extends AsyncResource {
reporter.diagnostic(nesting, loc, `todo ${harness.counters.todo}`);
reporter.diagnostic(nesting, loc, `duration_ms ${this.duration()}`);

const coverage = harness.coverage();

if (coverage) {
reporter.coverage(nesting, loc, coverage);
}
Expand Down

0 comments on commit 2a9c0ed

Please sign in to comment.