Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Jun 4, 2024
1 parent 8bc57f9 commit fb82a11
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
SafeSet,
StringPrototypeIncludes,
StringPrototypeLocaleCompare,
StringPrototypeRepeat,
StringPrototypeStartsWith,
} = primordials;
const {
Expand All @@ -37,14 +36,14 @@ const kLineSplitRegex = /(?<=\r?\n)/u;
const kStatusRegex = /\/\* node:coverage (?<status>enable|disable) \*\//;

class CoverageLine {
constructor(line, src, startOffset) {
const newlineLength =
constructor(line, startOffset, src, length = src?.length) {
const newlineLength = src == null ? 0 :
RegExpPrototypeExec(kLineEndingRegex, src)?.[0].length ?? 0;

this.line = line;
this.src = src;
this.startOffset = startOffset;
this.endOffset = startOffset + src.length - newlineLength;
this.endOffset = startOffset + length - newlineLength;
this.ignore = false;
this.count = this.startOffset === this.endOffset ? 1 : 0;
}
Expand Down Expand Up @@ -84,7 +83,7 @@ class TestCoverage {

const lines = ArrayPrototypeMap(linesWithBreaks, (line, i) => {
const startOffset = offset;
const coverageLine = new CoverageLine(i + 1, line, startOffset);
const coverageLine = new CoverageLine(i + 1, startOffset, line);

offset += line.length;

Expand Down Expand Up @@ -339,8 +338,7 @@ class TestCoverage {
const { data, lineLengths } = sourceMapCache[url];
let offset = 0;
const executedLines = ArrayPrototypeMap(lineLengths, (length, i) => {
const startOffset = offset;
const coverageLine = new CoverageLine(i + 1, StringPrototypeRepeat('.', length), startOffset);
const coverageLine = new CoverageLine(i + 1, offset, null, length);
offset += length;
return coverageLine;
});
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-runner/coverage-loader/hooks.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const sources = {
// Virtual file. dosent exist on disk
// Virtual file. Dosen't exist on disk
"virtual.js": `
import { test } from 'node:test';
test('test', async () => {});
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-runner/coverage-loader/sum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sum } from './sum'

describe('sum', () => {
it('should sum two numbers', () => {
assert.deepStrictEqual(sum(1,2), 3)
assert.deepStrictEqual(sum(1, 2), 3)
})

it('should error out if one is not a number', () => {
Expand Down

0 comments on commit fb82a11

Please sign in to comment.