11/**
2- * For whatever reason, this reporter doesn't really work if its compiled to ESM
3- * so its compiled to CJS
2+ * For whatever reason, this reporter doesn't really work if its written in ESM
3+ * so its written in and compiled to CJS
44 *
55 * Heavily based on the default text reporter
66 */
7- import fs from 'fs' ;
7+
8+ import fs = require( 'fs' )
9+ import report = require( 'istanbul-lib-report' ) ;
810import type { CoverageSummary } from 'istanbul-lib-coverage' ;
9- import { ReportBase , type ContextOptions , type ReportNode , type Watermarks } from 'istanbul-lib-report' ;
1011
1112/**
1213 * Determines if the coverage summary has full coverage
@@ -23,7 +24,7 @@ function isFull(metrics: CoverageSummary) {
2324/**
2425 * Determines the uncovered lines
2526 */
26- function getUncoveredLines ( node : ReportNode ) {
27+ function getUncoveredLines ( node : report . ReportNode ) {
2728 if ( node . isSummary ( ) ) {
2829 return [ ] ;
2930 }
@@ -77,12 +78,12 @@ interface ResultObject {
7778/**
7879 * A Vitest coverage reporter that writes to the Github Actions summary
7980 */
80- export default class GithubActionsCoverageReporter extends ReportBase {
81+ module . exports = class GithubActionsCoverageReporter extends report . ReportBase {
8182 private readonly skipEmpty : boolean ;
8283 private readonly skipFull : boolean ;
8384 private readonly results : Record < string , ResultObject > = { } ;
8485 private cw : fs . WriteStream | null = null ;
85- private watermarks : Partial < Watermarks > | null = null ;
86+ private watermarks : Partial < report . Watermarks > = { } ;
8687
8788 constructor ( opts : any ) {
8889 super ( opts ) ;
@@ -91,7 +92,7 @@ export default class GithubActionsCoverageReporter extends ReportBase {
9192 this . skipFull = Boolean ( opts . skipFull ) ;
9293 }
9394
94- onStart ( _node : any , context : ContextOptions ) {
95+ onStart ( _node : any , context : report . ContextOptions ) {
9596 if ( ! process . env . GITHUB_STEP_SUMMARY ) {
9697 console . log ( 'Reporter not being executed in Github Actions environment' ) ;
9798 return ;
@@ -108,7 +109,7 @@ export default class GithubActionsCoverageReporter extends ReportBase {
108109 this . cw . write ( '</tr></thead><tbody>' ) ;
109110 }
110111
111- onSummary ( node : ReportNode ) {
112+ onSummary ( node : report . ReportNode ) {
112113 const nodeName = node . getRelativeName ( ) || 'All Files' ;
113114 const rawMetrics = node . getCoverageSummary ( false ) ;
114115 const isEmpty = rawMetrics . isEmpty ( ) ;
@@ -129,12 +130,12 @@ export default class GithubActionsCoverageReporter extends ReportBase {
129130 } ;
130131 }
131132
132- onDetail ( node : ReportNode ) {
133+ onDetail ( node : report . ReportNode ) {
133134 return this . onSummary ( node ) ;
134135 }
135136
136- private formatter ( pct : number , watermark : keyof Watermarks ) {
137- if ( ! this . watermarks || this . watermarks [ watermark ] === undefined ) return `<td>${ pct } %</td>` ;
137+ private formatter ( pct : number , watermark : keyof report . Watermarks ) {
138+ if ( this . watermarks [ watermark ] === undefined ) return `<td>${ pct } %</td>` ;
138139 const [ low , high ] = this . watermarks [ watermark ] ;
139140
140141 if ( pct < low ) {
0 commit comments