Skip to content

Commit 52e1a67

Browse files
committed
FIx the typescript errors with the coverage reporter
1 parent 758ff97 commit 52e1a67

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

lib/vitest-reporter/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"devDependencies": {
1111
"@types/istanbul-lib-report": "^3.0.3",
1212
"@types/node": "^22.15.30",
13+
"@vitest/coverage-v8": "^3.2.3",
1314
"esbuild": "^0.25.8",
1415
"typescript": "^5.8.2"
1516
},
@@ -19,7 +20,7 @@
1920
},
2021
"scripts": {
2122
"build": "yarn build:coverage-reporter && yarn build:test-reporter",
22-
"build:coverage-reporter": "esbuild --outfile=./build/coverage-reporter.cjs --format=cjs --bundle=true --minify=false --external:\"istanbul-lib-report\" --platform=node src/coverage-reporter.cts",
23+
"build:coverage-reporter": "esbuild --outfile=./build/coverage-reporter.cjs --format=cjs --bundle=true --minify --external:\"istanbul-lib-report\" --platform=node src/coverage-reporter.cts",
2324
"build:test-reporter": "esbuild --outfile=./build/test-reporter.js --format=esm --bundle=true --minify --external:\"vitest*\" --platform=node src/test-reporter.ts",
2425
"test": "vitest"
2526
}

lib/vitest-reporter/src/__tests__/coverage.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import fs from 'fs';
22
import { describe, expect, it as baseIt, vi } from 'vitest';
3-
import CoverageReporter from '../coverage-reporter.cjs'
3+
import reporter from '../coverage-reporter.cjs'
4+
5+
// I really don't know why importing from a CJS module doesn't work here
6+
// so that's why this line is here
7+
const CoverageReporter = reporter as any
48

59
vi.spyOn(fs, 'createWriteStream').mockReturnValue({
610
write: () => true,

lib/vitest-reporter/src/coverage-reporter.cts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Heavily based on the default text reporter
66
*/
77

8+
// This is some weird typescript only syntax that allows us to continue to have
9+
// the type information even though we're using CJS imports
810
import fs = require('fs')
911
import report = require('istanbul-lib-report');
1012
import type { CoverageSummary } from 'istanbul-lib-coverage';

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,6 +4112,7 @@ __metadata:
41124112
dependencies:
41134113
"@types/istanbul-lib-report": "npm:^3.0.3"
41144114
"@types/node": "npm:^22.15.30"
4115+
"@vitest/coverage-v8": "npm:^3.2.3"
41154116
esbuild: "npm:^0.25.8"
41164117
istanbul-lib-report: "npm:^3.0.1"
41174118
typescript: "npm:^5.8.2"

0 commit comments

Comments
 (0)