Skip to content

Build your personal knowledge base with Trilium Notes

ci: emit repo-root-relative lcov paths so Codecov attributes coverage correctly

Elian Doran26c078a12d12
diff --git a/apps/client/vite.config.mts b/apps/client/vite.config.mts
index c2dd6445f1..98735a5636 100644
--- a/apps/client/vite.config.mts
+++ b/apps/client/vite.config.mts
@@ -134,7 +134,12 @@ export default defineConfig(() => ({
coverage: {
reportsDirectory: "./test-output/vitest/coverage",
provider: "v8" as const,
- reporter: ["text", "html", "lcov"],
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list.
+ // Vitest defaults the lcov reporter's `projectRoot` to the Vite `root`, which would
+ // emit app-relative paths (`src/…`); the shallow ones are ambiguous in this monorepo
+ // and get attributed to whichever project wins the match. Anchor to the repo root so
+ // every path is unambiguous.
+ reporter: ["text", "html", ["lcov", { projectRoot: join(__dirname, "../..") }]],
include: ["src/**/*.{ts,tsx}"],
exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts"]
},
diff --git a/apps/desktop/vitest.config.mts b/apps/desktop/vitest.config.mts
index 0e34e2027e..663b56bf8f 100644
--- a/apps/desktop/vitest.config.mts
+++ b/apps/desktop/vitest.config.mts
@@ -1,4 +1,6 @@
/// <reference types='vitest' />
+import { resolve } from "node:path";
+
import { defineConfig } from "vite";
export default defineConfig(() => ({
@@ -32,7 +34,12 @@ export default defineConfig(() => ({
coverage: {
reportsDirectory: "./test-output/vitest/coverage",
provider: "v8" as const,
- reporter: ["text", "html", "lcov"],
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list.
+ // Vitest defaults the lcov reporter's `projectRoot` to the Vite `root`, which would
+ // emit app-relative paths (`src/…`); the shallow ones are ambiguous in this monorepo
+ // and get attributed to whichever project wins the match. Anchor to the repo root so
+ // every path is unambiguous.
+ reporter: ["text", "html", ["lcov", { projectRoot: resolve(__dirname, "../..") }]],
include: ["src/**/*.{ts,tsx}"],
exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts"]
}
diff --git a/apps/server/vite.config.mts b/apps/server/vite.config.mts
index 0649380357..a69a3609cf 100644
--- a/apps/server/vite.config.mts
+++ b/apps/server/vite.config.mts
@@ -1,4 +1,5 @@
/// <reference types='vitest' />
+import { resolve } from 'node:path';
import { defineConfig } from 'vite';
export default defineConfig(() => ({
@@ -39,7 +40,12 @@ export default defineConfig(() => ({
coverage: {
reportsDirectory: './test-output/vitest/coverage',
provider: 'v8' as const,
- reporter: [ "text", "html", "lcov" ],
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list. Vitest
+ // defaults the lcov reporter's `projectRoot` to the Vite `root`, which would emit paths
+ // relative to this app (`src/…`, `../../packages/trilium-core/src/…`); the shallow ones are
+ // ambiguous in this monorepo and get attributed to whichever project wins the match. Anchor
+ // to the repo root so every path is unambiguous.
+ reporter: [ "text", "html", ["lcov", { projectRoot: resolve(__dirname, '../..') }] ],
allowExternal: true,
include: ["src/**/*.{ts,tsx}", "../../packages/trilium-core/src/**/*.{ts,tsx}"],
exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts"]
diff --git a/apps/standalone/vite.config.mts b/apps/standalone/vite.config.mts
index 9d83b97cdb..65dceb7526 100644
--- a/apps/standalone/vite.config.mts
+++ b/apps/standalone/vite.config.mts
@@ -358,7 +358,12 @@ export default defineConfig(() => ({
// core initialization; it is exercised by the Playwright e2e suite instead.
"**/local-server-worker.ts"
],
- reporter: ["text", "html", "lcov"]
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list.
+ // Vitest defaults the lcov reporter's `projectRoot` to the Vite `root` — here `src`,
+ // so paths would emit as bare `main.ts` / `../../../packages/trilium-core/src/…`,
+ // which are ambiguous in this monorepo and get attributed to whichever project wins
+ // the match. Anchor to the repo root so every path is unambiguous.
+ reporter: ["text", "html", ["lcov", { projectRoot: join(__dirname, "../..") }]]
},
server: {
deps: {
diff --git a/codecov.yml b/codecov.yml
index abfd49f628..8d8045d78b 100644
--- a/codecov.yml
+++ b/codecov.yml
@@ -9,14 +9,10 @@ coverage:
target: 80%
threshold: 5%
-# trilium-core has no test runner of its own; its specs run *through* the server
-# and standalone suites. Vitest's v8 provider emits those external files with
-# paths relative to each suite's project root, so they arrive as `../../packages/…`
-# (server, root = apps/server) and `../../../packages/…` (standalone, root = apps/standalone/src).
-# Strip the leading `../` segments so the paths resolve to the repo-root tree.
-fixes:
- - "../../../packages/::packages/"
- - "../../packages/::packages/"
+# No `fixes:` needed: every suite pins the lcov reporter's `projectRoot` to the repo root, so
+# `SF:` paths already arrive repo-root-relative. Leaving them project-relative would make the
+# shallow ones (`src/index.ts`, `src/utils.ts`) ambiguous across the monorepo, and Codecov would
+# attribute their coverage to whichever project won the match.
flags:
client:
diff --git a/packages/ckeditor5-utils/vitest.config.ts b/packages/ckeditor5-utils/vitest.config.ts
index 08e0a8c7ff..a4b6529bb7 100644
--- a/packages/ckeditor5-utils/vitest.config.ts
+++ b/packages/ckeditor5-utils/vitest.config.ts
@@ -1,3 +1,5 @@
+import { resolve } from "node:path";
+
import { webdriverio } from "@vitest/browser-webdriverio";
import { defineConfig } from "vitest/config";
@@ -26,7 +28,11 @@ export default defineConfig({
allowExternal: false,
include: ["src/**/*.{ts,tsx}"],
exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts", "**/node_modules/**"],
- reporter: ["text", "lcov"]
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list, so
+ // the package-relative paths istanbul emits by default (`src/index.ts`, relative to
+ // cwd) are ambiguous in this monorepo and get attributed to whichever package wins the
+ // match. Emit repo-root-relative paths instead.
+ reporter: ["text", ["lcov", { projectRoot: resolve(__dirname, "../..") }]]
}
}
});
diff --git a/packages/ckeditor5/vitest.config.ts b/packages/ckeditor5/vitest.config.ts
index a576ead55f..4c1d8de98e 100644
--- a/packages/ckeditor5/vitest.config.ts
+++ b/packages/ckeditor5/vitest.config.ts
@@ -1,3 +1,5 @@
+import { resolve } from "node:path";
+
import { webdriverio } from "@vitest/browser-webdriverio";
import { defineConfig } from "vitest/config";
@@ -30,7 +32,11 @@ export default defineConfig({
allowExternal: false,
include: ["src/**/*.{ts,tsx}"],
exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts", "**/node_modules/**", "**/ckeditor5-*/**"],
- reporter: ["text", "lcov"]
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list, so
+ // the package-relative paths istanbul emits by default (`src/utils.ts`, relative to
+ // cwd) are ambiguous in this monorepo and get attributed to whichever package wins the
+ // match. Emit repo-root-relative paths instead.
+ reporter: ["text", ["lcov", { projectRoot: resolve(__dirname, "../..") }]]
}
}
});
diff --git a/packages/codemirror/vite.config.ts b/packages/codemirror/vite.config.ts
index 57f2212265..43901fba98 100644
--- a/packages/codemirror/vite.config.ts
+++ b/packages/codemirror/vite.config.ts
@@ -1,4 +1,5 @@
+import { resolve } from 'node:path';
import { defineConfig } from 'vite';
export default defineConfig(() => ({
@@ -39,7 +40,11 @@ export default defineConfig(() => ({
provider: 'v8',
include: ['src/**/*.{ts,tsx}'],
exclude: ['**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}', '**/*.d.ts'],
- reporter: ['text', 'lcov'],
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list, so the
+ // package-relative paths istanbul emits by default (`src/index.ts`, relative to cwd) are
+ // ambiguous in this monorepo and get attributed to whichever package wins the match. Emit
+ // repo-root-relative paths instead.
+ reporter: ['text', ['lcov', { projectRoot: resolve(__dirname, '../..') }]],
reportsDirectory: './test-output/vitest/coverage'
}
},
diff --git a/packages/commons/vite.config.ts b/packages/commons/vite.config.ts
index 7c874ad8ca..b693ce20bb 100644
--- a/packages/commons/vite.config.ts
+++ b/packages/commons/vite.config.ts
@@ -1,4 +1,5 @@
+import { resolve } from 'node:path';
import { defineConfig } from 'vite';
export default defineConfig(() => ({
@@ -17,7 +18,11 @@ export default defineConfig(() => ({
'coverage': {
'reportsDirectory': './test-output/vitest/coverage',
'provider': 'v8' as const,
- 'reporter': ['text', 'html', 'lcov'],
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list, so
+ // the package-relative paths istanbul emits by default (`src/lib/utils.ts`, relative
+ // to cwd) are ambiguous in this monorepo and get attributed to whichever package wins
+ // the match. Emit repo-root-relative paths instead.
+ 'reporter': ['text', 'html', ['lcov', { projectRoot: resolve(__dirname, '../..') }]],
'include': ['src/**/*.ts'],
'exclude': ['src/**/*.spec.ts'],
}
diff --git a/packages/express-partial-content/vite.config.ts b/packages/express-partial-content/vite.config.ts
index ef9c8abe32..d6065cc07a 100644
--- a/packages/express-partial-content/vite.config.ts
+++ b/packages/express-partial-content/vite.config.ts
@@ -1,4 +1,5 @@
/// <reference types='vitest' />
+import { resolve } from 'node:path';
import { defineConfig } from 'vite';
export default defineConfig(() => ({
@@ -25,7 +26,11 @@ export default defineConfig(() => ({
provider: 'v8' as const,
include: ['src/**/*.{ts,tsx}'],
exclude: ['**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}', '**/*.d.ts'],
- reporter: ['text', 'lcov'],
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list, so the
+ // package-relative paths istanbul emits by default (`src/utils.ts`, relative to cwd) are
+ // ambiguous in this monorepo and get attributed to whichever package wins the match. Emit
+ // repo-root-relative paths instead.
+ reporter: ['text', ['lcov', { projectRoot: resolve(__dirname, '../..') }]],
}
},
}));
diff --git a/packages/highlightjs/vite.config.ts b/packages/highlightjs/vite.config.ts
index c3bce83e5a..1d249df93f 100644
--- a/packages/highlightjs/vite.config.ts
+++ b/packages/highlightjs/vite.config.ts
@@ -1,4 +1,5 @@
+import { resolve } from 'node:path';
import { defineConfig } from 'vite';
export default defineConfig(() => ({
@@ -46,7 +47,11 @@ export default defineConfig(() => ({
'provider': 'v8' as const,
'include': ["src/**/*.{ts,tsx}"],
'exclude': ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts"],
- 'reporter': ["text", "lcov"],
+ // Codecov resolves an lcov `SF:` path by matching it against the repo's file list, so
+ // the package-relative paths istanbul emits by default (`src/index.ts`, relative to
+ // cwd) are ambiguous in this monorepo and get attributed to whichever package wins the
+ // match. Emit repo-root-relative paths instead.
+ 'reporter': ["text", ["lcov", { projectRoot: resolve(__dirname, "../..") }]],
}
},
}));