Skip to content

Commit a38e16e

Browse files
committed
Fix go/node coverage path normalization
1 parent 92488e7 commit a38e16e

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.github/workflows/build-go.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ jobs:
3434
./native/build.sh
3535
cd go
3636
go test ./... -coverprofile=coverage.out
37+
- name: Normalize coverage paths
38+
if: steps.detect.outputs.present == 'true'
39+
run: |
40+
python - <<'PY'
41+
from pathlib import Path
42+
path = Path("go/coverage.out")
43+
if path.exists():
44+
text = path.read_text()
45+
path.write_text(text.replace("github.com/cuihairu/epoch/", ""))
46+
PY
3747
- name: Upload coverage
3848
if: steps.detect.outputs.present == 'true'
3949
uses: codecov/codecov-action@v4

node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"packageManager": "[email protected]",
88
"scripts": {
99
"build": "tsc -p tsconfig.json",
10-
"test": "tsc -p tsconfig.json && c8 --reporter=lcov --reporter=text node --test"
10+
"test": "tsc -p tsconfig.json && c8 --cwd .. --reporter=lcov --reporter=text node --test && node scripts/normalize-coverage.js"
1111
},
1212
"dependencies": {
1313
"koffi": "2.15.0"

node/scripts/normalize-coverage.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require("node:fs");
2+
const path = require("node:path");
3+
4+
const lcovPath = path.join(__dirname, "..", "coverage", "lcov.info");
5+
if (!fs.existsSync(lcovPath)) {
6+
process.exit(0);
7+
}
8+
9+
const lines = fs.readFileSync(lcovPath, "utf8").split(/\r?\n/);
10+
const rewritten = lines.map((line) => {
11+
if (!line.startsWith("SF:")) {
12+
return line;
13+
}
14+
const filePath = line.slice(3);
15+
if (filePath.startsWith("/") || filePath.startsWith("node/")) {
16+
return line;
17+
}
18+
return `SF:node/${filePath}`;
19+
});
20+
fs.writeFileSync(lcovPath, rewritten.join("\n"));

node/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"rootDir": "src",
66
"outDir": "dist",
77
"declaration": true,
8+
"sourceMap": true,
9+
"inlineSources": true,
810
"strict": true,
911
"esModuleInterop": false,
1012
"forceConsistentCasingInFileNames": true,

0 commit comments

Comments
 (0)