Skip to content

Commit dd49bec

Browse files
committed
Try using ESM
1 parent 4be62a4 commit dd49bec

File tree

3 files changed

+9
-40
lines changed

3 files changed

+9
-40
lines changed

lib/vitest-reporter/build/coverage-reporter.cjs renamed to lib/vitest-reporter/build/coverage-reporter.js

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,6 @@
1-
"use strict";
2-
var __create = Object.create;
3-
var __defProp = Object.defineProperty;
4-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5-
var __getOwnPropNames = Object.getOwnPropertyNames;
6-
var __getProtoOf = Object.getPrototypeOf;
7-
var __hasOwnProp = Object.prototype.hasOwnProperty;
8-
var __export = (target, all) => {
9-
for (var name in all)
10-
__defProp(target, name, { get: all[name], enumerable: true });
11-
};
12-
var __copyProps = (to, from, except, desc) => {
13-
if (from && typeof from === "object" || typeof from === "function") {
14-
for (let key of __getOwnPropNames(from))
15-
if (!__hasOwnProp.call(to, key) && key !== except)
16-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17-
}
18-
return to;
19-
};
20-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21-
// If the importer is in node compatibility mode or this is not an ESM
22-
// file that has been converted to a CommonJS file using a Babel-
23-
// compatible transform (i.e. "__esModule" has not been set), then set
24-
// "default" to the CommonJS "module.exports" for node compatibility.
25-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26-
mod
27-
));
28-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29-
301
// src/coverage-reporter.ts
31-
var coverage_reporter_exports = {};
32-
__export(coverage_reporter_exports, {
33-
default: () => GithubActionsCoverageReporter
34-
});
35-
module.exports = __toCommonJS(coverage_reporter_exports);
36-
var import_fs = __toESM(require("fs"), 1);
37-
var import_istanbul_lib_report = require("istanbul-lib-report");
2+
import fs from "fs";
3+
import { ReportBase } from "istanbul-lib-report";
384
function isFull(metrics) {
395
return metrics.statements.pct === 100 && metrics.branches.pct === 100 && metrics.functions.pct === 100 && metrics.lines.pct === 100;
406
}
@@ -71,7 +37,7 @@ function getUncoveredLines(node) {
7137
return ranges;
7238
}
7339
var headers = ["Statements", "Branches", "Functions", "Lines"];
74-
var GithubActionsCoverageReporter = class extends import_istanbul_lib_report.ReportBase {
40+
var GithubActionsCoverageReporter = class extends ReportBase {
7541
skipEmpty;
7642
skipFull;
7743
results = {};
@@ -87,7 +53,7 @@ var GithubActionsCoverageReporter = class extends import_istanbul_lib_report.Rep
8753
console.log("Reporter not being executed in Github Actions environment");
8854
return;
8955
}
90-
this.cw = import_fs.default.createWriteStream(process.env.GITHUB_STEP_SUMMARY, { encoding: "utf-8", flags: "a" });
56+
this.cw = fs.createWriteStream(process.env.GITHUB_STEP_SUMMARY, { encoding: "utf-8", flags: "a" });
9157
this.watermarks = context.watermarks;
9258
this.cw.write("<h2>Test Coverage</h2>");
9359
this.cw.write("<table><thead><tr>");
@@ -157,3 +123,6 @@ var GithubActionsCoverageReporter = class extends import_istanbul_lib_report.Rep
157123
this.cw.close();
158124
}
159125
};
126+
export {
127+
GithubActionsCoverageReporter as default
128+
};

lib/vitest-reporter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"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.ts",
22+
"build:coverage-reporter": "esbuild --outfile=./build/coverage-reporter.js --format=esm --bundle=true --minify=false --external:\"istanbul-lib-report\" --platform=node src/coverage-reporter.ts",
2323
"build:test-reporter": "esbuild --outfile=./build/test-reporter.js --format=esm --bundle=true --minify --external:\"vitest*\" --platform=node src/test-reporter.ts",
2424
"test": "vitest"
2525
}

vitest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const coverageReporters = ['text'];
1212
const testReporters = ['default'];
1313

1414
if (process.env.GITHUB_ACTIONS) {
15-
const reporter = pathlib.resolve(import.meta.dirname, './lib/vitest-reporter/build/coverage-reporter.cjs');
15+
const reporter = pathlib.resolve(import.meta.dirname, './lib/vitest-reporter/build/coverage-reporter.js');
1616
coverageReporters.push(reporter);
1717
testReporters.push(new GithubActionsSummaryReporter());
1818
} else {

0 commit comments

Comments
 (0)