Skip to content

Build your personal knowledge base with Trilium Notes

test(core): not visible in code coverage

Elian Doran1d2a5b0038a2
diff --git a/.claude/skills/writing-unit-tests/SKILL.md b/.claude/skills/writing-unit-tests/SKILL.md
index 22695b8b10..53b118873f 100644
--- a/.claude/skills/writing-unit-tests/SKILL.md
+++ b/.claude/skills/writing-unit-tests/SKILL.md
@@ -50,7 +50,7 @@ coverage: {
- **Do NOT use `all: true`** — it was removed in Vitest 4 and is a type error; `include` already pulls in untested files.
- If a config sets Vite `root: "src"` (e.g. `apps/standalone`), coverage `include` globs resolve **relative to `src`**, so use `["**/*.{ts,tsx}"]`, not `["src/**/…"]`.
-- v8 does **not** traverse `../../` paths outside the project root; `trilium-core` coverage is measured *through* `apps/server` (and `apps/standalone`), which already list it in their `include`.
+- **Files outside the project `root` need `coverage.allowExternal: true`.** v8 defaults it to `false`, which **silently drops** every out-of-root file — so an `include` glob alone (e.g. `../../packages/trilium-core/src/**`) is ignored and contributes nothing. `trilium-core` has no runner of its own; its coverage is measured *through* `apps/server` and `apps/standalone`, and both **must** set `allowExternal: true` **plus** a core glob in `coverage.include` whose `../` depth matches that suite's `root`: `../../packages/trilium-core/src/**` for server (root `apps/server`), `../../../packages/trilium-core/src/**` for standalone (root `apps/standalone/src`). Without `allowExternal` core never reaches the lcov or Codecov. The lcov writes these as `../…/packages/…` paths; `codecov.yml`'s `fixes:` entries strip the `../` so they map onto the repo tree.
- For provably-unreachable defensive branches, mark them with `/* v8 ignore next */` / `/* v8 ignore start */…/* v8 ignore stop */` and a one-line reason — don't delete the guard or write a fake test.
## Universal gotchas
diff --git a/.claude/skills/writing-unit-tests/server-and-core.md b/.claude/skills/writing-unit-tests/server-and-core.md
index 23e5e033fd..d175f97274 100644
--- a/.claude/skills/writing-unit-tests/server-and-core.md
+++ b/.claude/skills/writing-unit-tests/server-and-core.md
@@ -2,7 +2,7 @@
`apps/server/spec/setup.ts` boots an **in-memory SQLite fixture** once per spec file: it loads `packages/trilium-core/src/test/fixtures/document.db` (password **`demo1234`**) and calls `initializeCore(...)`. With `pool: "forks"`, each spec file gets a fresh writable copy — **mutations isolate per file, not per `it()`**.
-`trilium-core` cannot run tests standalone (its `test` script just prints a note — it needs a host runtime's platform providers). Its specs run **through** `apps/server` (and `apps/standalone`), which already list `../../packages/trilium-core/src/**` in both their test `include` and `coverage.include`. Add core specs next to the core source or under `apps/server/spec` — both feed the same coverage number. A dedicated core vitest project is **not** needed.
+`trilium-core` cannot run tests standalone (its `test` script just prints a note — it needs a host runtime's platform providers). Its specs run **through** `apps/server` (and `apps/standalone`), which list `../../packages/trilium-core/src/**` in their test `include`. For that core code to actually count toward coverage, each host also sets `coverage.allowExternal: true` and lists core in `coverage.include` (v8 drops out-of-root files otherwise — see the coverage rules in `SKILL.md`). Add core specs next to the core source or under `apps/server/spec` — both feed the same coverage number, reported under the `server`/`standalone` Codecov flags. A dedicated core vitest project is **not** needed.
There are **two distinct HTTP code paths** — testing one does not cover the other:
- **ETAPI** (`apps/server/src/etapi/*`): basic-auth token, helpers in `spec/etapi/utils.ts`.
diff --git a/apps/server/vite.config.mts b/apps/server/vite.config.mts
index 4aaf436789..0649380357 100644
--- a/apps/server/vite.config.mts
+++ b/apps/server/vite.config.mts
@@ -40,6 +40,7 @@ export default defineConfig(() => ({
reportsDirectory: './test-output/vitest/coverage',
provider: 'v8' as const,
reporter: [ "text", "html", "lcov" ],
+ 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 d2347d41a4..2e5c2986f1 100644
--- a/apps/standalone/vite.config.mts
+++ b/apps/standalone/vite.config.mts
@@ -320,8 +320,12 @@ export default defineConfig(() => ({
// `src/test-output`. Anchor to the package dir (matches the CI upload path).
reportsDirectory: join(__dirname, "test-output/vitest/coverage"),
provider: "v8" as const,
+ // trilium-core lives outside this project's `root` (which is `src`),
+ // so its files are only collected when `allowExternal` is enabled.
+ allowExternal: true,
// Vite `root` above is `src`, so coverage include globs resolve relative to src/.
- include: ["**/*.{ts,tsx}"],
+ // `../../../` walks src -> standalone -> apps -> repo root to reach the core package.
+ include: ["**/*.{ts,tsx}", "../../../packages/trilium-core/src/**/*.{ts,tsx}"],
exclude: ["**/*.{test,spec}.{ts,mts,cts,tsx,js,jsx}", "**/*.d.ts"],
reporter: ["text", "html", "lcov"]
},
diff --git a/codecov.yml b/codecov.yml
index 1802a306b4..62cc8c793c 100644
--- a/codecov.yml
+++ b/codecov.yml
@@ -9,6 +9,15 @@ 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/"
+
flags:
client:
paths: