Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
build(ckeditor5): let the browser tests take a system Chrome
Elian Doran7cdc0bdf4711
diff --git a/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.md b/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.mdindex be77378b2c..205d5a3571 100644--- a/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.md+++ b/.claude/skills/ckeditor5-plugin-development/references/tooling-and-packaging.md@@ -188,6 +188,10 @@ pnpm --filter @triliumnext/ckeditor5-<feature> lint # eslint-config-ckedipnpm --filter @triliumnext/ckeditor5-<feature> stylelint # theme CSS```+Tests run in a real headless Chrome that webdriverio downloads. Where that build cannot run — NixOS+being the case in point — set `CHROME_BIN` and `CHROMEDRIVER_PATH` to a matching system pair, which+`nix develop` already exports; don't start a driver by hand.+For test setup, model/view assertions, and command/UI test patterns, use the separate**`ckeditor5-testing`** skill.diff --git a/.claude/skills/ckeditor5-testing/SKILL.md b/.claude/skills/ckeditor5-testing/SKILL.mdindex 3042f65394..99dfbc1f77 100644--- a/.claude/skills/ckeditor5-testing/SKILL.md+++ b/.claude/skills/ckeditor5-testing/SKILL.md@@ -85,6 +85,25 @@ test:sequential` runs `ckeditor5` **sequentially** (browser resourcelimits), alongside the server. `pnpm test:all` runs both. Each package exposes `"test": "vitest"` and`"test:debug": "vitest --inspect-brk --no-file-parallelism --browser.headless=false"`.+**When the downloaded browser cannot run** — on NixOS the Chrome for Testing build and chromedriver+webdriverio fetches into `/tmp` are linked against libraries no store path provides and die on a+missing `libxcb.so.1` — point the suite at a system pair instead:++```bash+CHROME_BIN=/path/to/chromium CHROMEDRIVER_PATH=/path/to/chromedriver \+ pnpm --filter @triliumnext/ckeditor5 test+```++`CHROMEDRIVER_PATH` is webdriverio's own variable and makes it spawn that driver on a free port;+`CHROME_BIN` is read by the package's `vitest.config.ts` and passed as `goog:chromeOptions.binary`,+which also stops the browser download (`setupPuppeteerBrowser` returns early for a string `binary`).+The two versions must match at least in their major. `nix develop` sets both from `pkgs.chromium`+and `pkgs.chromedriver`, so inside the dev shell the plain command works — **don't** start a driver+by hand or write a local override config.++Failed browser tests dump PNGs into a gitignored `__screenshots__` beside the spec; delete them+afterwards.+## Anatomy of a testIn the aggregate (`packages/ckeditor5`), use the shared **editor kit** —diff --git a/.claude/skills/ckeditor5-testing/references/running-and-config.md b/.claude/skills/ckeditor5-testing/references/running-and-config.mdindex b148f140eb..ddc4b4a3bb 100644--- a/.claude/skills/ckeditor5-testing/references/running-and-config.md+++ b/.claude/skills/ckeditor5-testing/references/running-and-config.md@@ -23,6 +23,30 @@ pnpm --filter @triliumnext/ckeditor5 testOr, from the package directory: `vitest run`. Add `-t "name"` to filter by test name, or afilename substring to filter by file.+### Supplying the browser and driver++webdriverio downloads a Chrome for Testing build and a matching chromedriver into `/tmp` on first+run. Where those cannot execute — NixOS, where they are linked against libraries no store path+provides and abort on a missing `libxcb.so.1` — two variables hand it a system pair instead:++| Variable | Read by | Effect |+|---|---|---|+| `CHROMEDRIVER_PATH` | webdriverio (`@wdio/utils` `startWebDriver`) | Spawns that driver on a free port instead of downloading one. |+| `CHROME_BIN` | `packages/ckeditor5/vitest.config.ts` | Passed as `goog:chromeOptions.binary`; `setupPuppeteerBrowser` returns early for a string `binary`, so no browser is downloaded either. |++```bash+CHROME_BIN=/path/to/chromium CHROMEDRIVER_PATH=/path/to/chromedriver \+ pnpm --filter @triliumnext/ckeditor5 test+```++The versions must match at least in their major. `nix develop` exports both from `pkgs.chromium`+and `pkgs.chromedriver` (same nixpkgs revision, so they agree), which is why the plain command works+inside the dev shell. Starting a chromedriver by hand and writing a local config that connects to+its port does work, but it is strictly more setup — reach for the variables.++A failing browser test writes a PNG into a gitignored `__screenshots__` directory next to the spec.+Clean those up when done.+## The config shapeBoth packages run **WebdriverIO browser mode**: real headless Chrome viadiff --git a/CLAUDE.md b/CLAUDE.mdindex 6a09554850..0449e50919 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -205,6 +205,7 @@ SQLite via `better-sqlite3`. SQL abstraction in `packages/trilium-core/src/servi- Client tests can run in parallel- E2E tests use Playwright for both server and desktop apps- Build validation tests check artifact integrity+- **Browser-mode tests** (`packages/ckeditor5`) drive a real headless Chrome via `@vitest/browser-webdriverio`, which downloads its own Chrome and chromedriver. Where those cannot run (NixOS: they die on a missing `libxcb.so.1`), set `CHROME_BIN` and `CHROMEDRIVER_PATH` to a system pair of matching versions — `nix develop` exports both. Never start a chromedriver by hand or add a local override config; see `docs/Developer Guide/Developer Guide/Testing.md`- **Write concise tests**: Group related assertions together in a single test case rather than creating many one-shot tests- **Extract and test business logic**: When adding pure business logic (e.g., data transformations, migrations, validations), extract it as a separate function and always write unit tests for itdiff --git a/docs/Developer Guide/Developer Guide/Testing.md b/docs/Developer Guide/Developer Guide/Testing.mdindex 9342613c16..0521bbd0fb 100644--- a/docs/Developer Guide/Developer Guide/Testing.md+++ b/docs/Developer Guide/Developer Guide/Testing.md@@ -68,6 +68,20 @@ npm run testNote that some integration tests rely on an in-memory database in order to function.+### Browser-mode tests for the text editor++`packages/ckeditor5` runs its tests in a real headless Chrome, through `@vitest/browser-webdriverio`, because the editor needs a real DOM and real selection handling. By default webdriverio downloads both a Chrome for Testing build and a matching chromedriver, which is what happens on a normal machine and needs no setup.++Where those downloaded binaries cannot run — NixOS being the case in point, since they are dynamically linked against libraries no store path provides and die on a missing `libxcb.so.1` — point the suite at a system browser and driver instead:++```+CHROME_BIN=/path/to/chromium CHROMEDRIVER_PATH=/path/to/chromedriver pnpm --filter @triliumnext/ckeditor5 test+```++`CHROMEDRIVER_PATH` is webdriverio's own variable; `CHROME_BIN` is read by the package's `vitest.config.ts` and passed through as a capability, which also stops webdriverio from downloading a browser at all. The two versions have to match, at least in their major.++The Nix dev shell (`nix develop`) sets both from `pkgs.chromium` and `pkgs.chromedriver`, so inside it the tests run unchanged.+### REST API testing for the serverAPI tests are handled via `vitest` and `supertest` to initialize the Express server and run assertions without having to make actual requests to the server.diff --git a/flake.nix b/flake.nixindex 1ebb1c31c4..50dcdaeeab 100644--- a/flake.nix+++ b/flake.nix@@ -387,7 +387,18 @@ nodejs.pythonpnpmelectronnodejs.python+ # For the browser-mode tests (packages/ckeditor5). The Chrome and chromedriver+ # webdriverio downloads for itself are dynamically linked against libraries no NixOS+ # system provides, so they die on a missing libxcb.so.1; these come from the same+ # nixpkgs revision, so their versions match.+ pkgs.chromium+ pkgs.chromedriver];++ # Read by packages/ckeditor5/vitest.config.ts and by webdriverio itself, respectively.+ # Without them webdriverio downloads its own pair and the suite cannot start.+ CHROME_BIN = "${pkgs.chromium}/bin/chromium";+ CHROMEDRIVER_PATH = "${pkgs.chromedriver}/bin/chromedriver";};});diff --git a/packages/ckeditor5/vitest.config.ts b/packages/ckeditor5/vitest.config.tsindex 61ea6c7441..dfe3b013d5 100644--- a/packages/ckeditor5/vitest.config.ts+++ b/packages/ckeditor5/vitest.config.ts@@ -3,11 +3,22 @@ import { resolve } from "node:path";import { webdriverio } from "@vitest/browser-webdriverio";import { defineConfig } from "vitest/config";+/**+ * The browser to drive, when the one webdriverio would fetch for itself cannot run — on NixOS the+ * downloaded Chrome for Testing dies on a missing `libxcb.so.1`, since nothing outside the store+ * provides it. Point `CHROME_BIN` at a system Chrome/Chromium and webdriverio skips the download+ * altogether; pair it with `CHROMEDRIVER_PATH` (webdriverio's own variable) for the driver, which+ * has the same problem. The Nix dev shell sets both.+ */+const systemChrome = process.env.CHROME_BIN;+export default defineConfig({test: {browser: {enabled: true,- provider: webdriverio(),+ provider: webdriverio(systemChrome+ ? { capabilities: { browserName: "chrome", "goog:chromeOptions": { binary: systemChrome } } }+ : {}),headless: true,ui: false,instances: [{ browser: "chrome" }]