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
test(standalone): run core's specs in a worker-shaped environment
Elian Doran13c7374db051
diff --git a/.claude/skills/adding-llm-mcp-tools/references/spec-harness.md b/.claude/skills/adding-llm-mcp-tools/references/spec-harness.mdindex 9a1a21f22d..25653cd0a0 100644--- a/.claude/skills/adding-llm-mcp-tools/references/spec-harness.md+++ b/.claude/skills/adding-llm-mcp-tools/references/spec-harness.md@@ -1,6 +1,6 @@# Spec harness for LLM/MCP tools-Tools are tested in-source: `packages/trilium-core/src/services/llm/tools/<name>_tools.spec.ts`. Because they live in `trilium-core`, which has no runner of its own, **both** app suites pick these specs up and run them against different platform providers — node + better-sqlite3, and happy-dom + sqlite-wasm. Green under one is not proof:+Tools are tested in-source: `packages/trilium-core/src/services/llm/tools/<name>_tools.spec.ts`. Because they live in `trilium-core`, which has no runner of its own, **both** app suites pick these specs up and run them against different platform providers — node + better-sqlite3, and sqlite-wasm in a scope shaped like standalone's Web Worker. Green under one is not proof:```bashpnpm --filter server test src/services/llm/tools/note_tools.spec.tsdiff --git a/.claude/skills/developing-standalone/SKILL.md b/.claude/skills/developing-standalone/SKILL.mdindex d0c8333939..6d30745262 100644--- a/.claude/skills/developing-standalone/SKILL.md+++ b/.claude/skills/developing-standalone/SKILL.md@@ -22,7 +22,8 @@ apps/standalone/src/lightweight/ # browser implementations of every core provider + standalone-only routessrc/services/ # image provider, Capacitor HTTP handlersrc/stubs/ # officeparser entry + Buffer polyfill, empty stubs for pdfjs/tesseract/puppeteer- src/test_setup.ts # boots core with the real lightweight providers under vitest/happy-dom+ src/test_setup.ts # boots core with the real lightweight providers, for both test projects+ src/test_environment_worker.ts # the Vitest environment core's specs run in: a worker's scope, no DOMpublic/_headers, manifest.webmanifest, favicon.icoe2e/multi_tab.spec.ts, extra_window.spec.tsvite.config.mts # root is src/; aliases, stubs, asset copies, worker + SW build, vitest config@@ -93,4 +94,4 @@ pnpm --filter standalone e2e # Playwright: multi-tab lea## Testing-`pnpm --filter standalone test <pattern>` — Vitest, happy-dom, **real sqlite-wasm**. `test_setup.ts` shims wasm loading (happy-dom's `fetch` refuses `file://` and its `Response` breaks `instantiateStreaming`) and boots core with the real lightweight providers, so a spec exercises the same code path as the browser. `local-server-worker.ts` is excluded from coverage on purpose (it boots a second core). This suite is also the **second runtime for every `packages/trilium-core` spec** — green under `pnpm --filter server test` is not proof; the cross-runtime traps (capability gaps, provider differences, `serialize()`, backup) are in the `writing-unit-tests` skill.+`pnpm --filter standalone test <pattern>` — Vitest, **real sqlite-wasm**, in two projects: `standalone` runs `src/**` under happy-dom, and `core` runs every `packages/trilium-core` spec in `test_environment_worker.ts`, a scope with no `window`, `document` or `DOMParser`, resolving dependencies with the `browser` condition as the worker bundle does. A dependency whose browser build needs a page fails there as it does in production; fix it with a `resolve.alias` in `vite.config.mts` (see `turnish`), never by giving the project a DOM. `test_setup.ts` shims wasm loading (happy-dom's `fetch` refuses `file://` and its `Response` breaks `instantiateStreaming`) and boots core with the real lightweight providers, so a spec exercises the same code path as the browser. `local-server-worker.ts` is excluded from coverage on purpose (it boots a second core). This suite is also the **second runtime for every `packages/trilium-core` spec** — green under `pnpm --filter server test` is not proof; the cross-runtime traps (capability gaps, provider differences, `serialize()`, backup) are in the `writing-unit-tests` skill.diff --git a/.claude/skills/writing-unit-tests/server-and-core.md b/.claude/skills/writing-unit-tests/server-and-core.mdindex 7f5aed2d56..ad2872ed7d 100644--- a/.claude/skills/writing-unit-tests/server-and-core.md+++ b/.claude/skills/writing-unit-tests/server-and-core.md@@ -5,10 +5,11 @@`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.### ⚠️ A core spec runs under BOTH runtimes — verify both before calling it done-The same `packages/trilium-core/src/**` spec executes under the **server** suite (vitest env `node`, better-sqlite3 + `NodejsCryptoProvider`) **and** the **standalone** suite (env `happy-dom`, sqlite-wasm + `Browser*Provider`). Passing `pnpm --filter server exec vitest run <spec>` is **not enough** — also run `pnpm --filter standalone exec vitest run <spec>`. A spec green on server can fail on standalone because the providers differ. Known cross-runtime traps:+The same `packages/trilium-core/src/**` spec executes under the **server** suite (vitest env `node`, better-sqlite3 + `NodejsCryptoProvider`) **and** the **standalone** suite (the `core` project: a Web Worker's scope with no DOM, dependencies resolved through their `browser` builds, sqlite-wasm + `Browser*Provider`). Passing `pnpm --filter server exec vitest run <spec>` is **not enough** — also run `pnpm --filter standalone exec vitest run <spec>`. A spec green on server can fail on standalone because the providers differ. Known cross-runtime traps:- **`BNote.getContent()` of a non-string note** is a `Buffer` on Node (`.toString()` → UTF-8) but a `Uint8Array` on WASM (`.toString()` → `"40,40,..."`). Decode portably: `unwrapStringOrBuffer(note.getContent())` (import from a **relative** path like `./utils/binary.js`, never `@triliumnext/core` — self-import fails inside core).+- **A dependency's browser build** is what standalone runs, and the `core` project loads it too: one that needs a page's DOM (Turnish) fails there as in production, so fix the build with a `resolve.alias` in `apps/standalone/vite.config.mts`. A test-only tool whose browser entry is a stub (Jimp) gets a `test.alias` in that project instead.- **Provider implementation details differ** and are NOT cross-runtime contracts: e.g. better-sqlite3 caches raw vs non-raw statements as distinct objects (sqlite-wasm may not); `crypto.hmac` of `Uint8Array` vs `string` inputs differs on Node but not in the browser provider. Don't assert these — assert the portable contract.-- **Capability gaps**: `getSql().serialize()` throws on better-sqlite3 (Node) but works on sqlite-wasm; `BrowserZipProvider.createFileStream()` throws (no file streams in the browser) and its streaming/finalize model differs (Node-style `pipe`→`end` never fires). For genuinely runtime-specific behavior, gate with `const isBrowserRuntime = typeof window !== "undefined";` + `it.skipIf(isBrowserRuntime)` / `describe.skipIf(...)` and a one-line reason — but prefer a portable assertion or capability-aware branch over skipping when the behavior is actually the same.+- **Capability gaps**: `getSql().serialize()` throws on better-sqlite3 (Node) but works on sqlite-wasm; `BrowserZipProvider.createFileStream()` throws (no file streams in the browser) and its streaming/finalize model differs (Node-style `pipe`→`end` never fires). For genuinely runtime-specific behavior, gate with `const isBrowserRuntime = typeof self !== "undefined";` (a worker has `self` but no `window`) + `it.skipIf(isBrowserRuntime)` / `describe.skipIf(...)` and a one-line reason — but prefer a portable assertion or capability-aware branch over skipping when the behavior is actually the same.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`.@@ -51,10 +52,10 @@ Both test setups (`apps/server/spec/setup.ts`, `apps/standalone/src/test_setup.t### When a core route still needs a *targeted* mock (the genuine exceptions)Only where the platform op can't run against the ephemeral test env — keep it minimal and documented, and prefer `vi.spyOn(importedServiceObject, "method")` over `vi.mock`:-- **backup**: better-sqlite3 `.backup()` rejects `SQLITE_NOTADB` against the in-memory fixture (node) and there's no OPFS in happy-dom (standalone) → spy `backupNow`/`getBackupContent`; keep `getExistingBackups` + 400/404 real.+- **backup**: better-sqlite3 `.backup()` rejects `SQLITE_NOTADB` against the in-memory fixture (node) and there's no OPFS (standalone) → spy `backupNow`/`getBackupContent`; keep `getExistingBackups` + 400/404 real.- **sync** `testSync`/`syncNow`/`forceFullSync`: real network → spy `syncService.login`/`sync`. `getChanged`/`update`/`checkSync` run real.- **setup** `createInitialDatabase`/`createDatabaseForSync`: they wipe/replace the DB → spy them.-- A genuinely runtime-specific path (e.g. backup download needs the file on disk, node-only): gate with `it.skipIf(typeof window !== "undefined")` + a one-line reason; the line still counts via the node suite.+- A genuinely runtime-specific path (e.g. backup download needs the file on disk, node-only): gate with `it.skipIf(typeof self !== "undefined")` + a one-line reason; the line still counts via the node suite.## Pattern 1 — Express transport / middleware via supertest agentdiff --git a/.github/workflows/dev.yml b/.github/workflows/dev.ymlindex 103ff8f189..f2e8a768db 100644--- a/.github/workflows/dev.yml+++ b/.github/workflows/dev.yml@@ -420,8 +420,8 @@ jobs:id: test-standaloneif: env.AFFECTED == 'true'# Runs the same trilium-core spec set as the server suite, but in- # happy-dom + sql.js WASM via BrowserSqlProvider (see- # apps/standalone/src/test_setup.ts). Catches differences+ # a Web Worker-shaped environment + sql.js WASM via BrowserSqlProvider+ # (see apps/standalone/src/test_setup.ts). Catches differences# between the Node-side and browser-side runtimes.run: pnpm run --filter=standalone test --coveragediff --git a/CLAUDE.md b/CLAUDE.mdindex ff1f18dc36..fc7040171c 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -222,7 +222,7 @@ Use `note.getOwnedAttribute()` for direct, `note.getAttribute()` for inherited.- **Server tests** (`apps/server/spec/`): Vitest, must run sequentially (shared DB), forks pool, max 6 workers- **Client tests** (`apps/client/src/`): Vitest with happy-dom environment, can run in parallel-- **Core tests** (`packages/trilium-core/src/**/*.spec.ts`): `trilium-core` has no runner of its own — the **server and standalone suites both include** its specs (`apps/server/vite.config.mts`, `apps/standalone/vite.config.mts`) and run them against different platform providers (node + better-sqlite3 vs. happy-dom + sqlite-wasm). Green under `pnpm --filter server test` is **not** proof; run `pnpm --filter standalone test` as well. See the `writing-unit-tests` skill for the cross-runtime traps+- **Core tests** (`packages/trilium-core/src/**/*.spec.ts`): `trilium-core` has no runner of its own — the **server and standalone suites both include** its specs (`apps/server/vite.config.mts`, `apps/standalone/vite.config.mts`) and run them against different platform providers (node + better-sqlite3 vs. sqlite-wasm in a scope shaped like standalone's Web Worker: no DOM, and dependencies resolved through their `browser` builds). Green under `pnpm --filter server test` is **not** proof; run `pnpm --filter standalone test` as well. See the `writing-unit-tests` skill for the cross-runtime traps- **E2E tests** (`packages/trilium-e2e/`): Shared Playwright tests, run via `pnpm --filter server e2e` or `pnpm --filter standalone e2e`- **ETAPI tests** (`apps/server/spec/etapi/`): External API contract tests- **Browser-mode tests** (`packages/ckeditor5`) drive a real headless Chromium via `@vitest/browser-playwright` (`pnpm exec playwright install chromium` once); where that browser cannot run (NixOS), point `CHROME_BIN` at a system one — never add a local override config. See the `ckeditor5-testing` skilldiff --git a/apps/standalone/src/test_environment_worker.ts b/apps/standalone/src/test_environment_worker.tsnew file mode 100644index 0000000000..88e2282d25--- /dev/null+++ b/apps/standalone/src/test_environment_worker.ts@@ -0,0 +1,21 @@+import type { Environment } from "vitest/environments";++/**+ * A Vitest environment shaped like the dedicated Web Worker core runs in under standalone:+ * modules resolve with the `browser` export condition, as Vite bundles the worker, and the global+ * scope is Node's, which lacks `window`, `document` and `DOMParser` as a worker does. A dependency+ * whose browser build needs a page's DOM fails here as it fails in production, where happy-dom+ * would hide it.+ */+export default {+ name: "web-worker",+ viteEnvironment: "client",+ setup(global) {+ global.self = global;+ return {+ teardown() {+ delete global.self;+ }+ };+ }+} satisfies Environment;diff --git a/apps/standalone/src/test_setup.ts b/apps/standalone/src/test_setup.tsindex 777ebbe569..d5d84c5f40 100644--- a/apps/standalone/src/test_setup.ts+++ b/apps/standalone/src/test_setup.ts@@ -66,25 +66,6 @@ WebAssembly.instantiateStreaming = (async (source, importObject) => {return WebAssembly.instantiate(bytes, importObject);}) as typeof WebAssembly.instantiateStreaming;-// =============================================================================-// happy-dom HTMLParser spec compliance patch-// =============================================================================-// Per HTML5 parsing spec, a single U+000A LINE FEED immediately after a <pre>,-// <listing>, or <textarea> start tag must be ignored ("newlines at the start-// of pre blocks are ignored as an authoring convenience"). Real browsers and-// domino (which turnish uses in Node) both implement this; happy-dom does not.-// Patch at the DOMParser boundary since turnish prefers DOMParser when it's-// available — patching via module-level HTMLParser import hits a different-// happy-dom copy than the vitest env loaded.-const LEADING_LF_IN_PRE_RE = /(<(?:pre|listing|textarea)\b[^>]*>)(\r\n|\r|\n)/gi;-const originalParseFromString = DOMParser.prototype.parseFromString;-DOMParser.prototype.parseFromString = function (source: string, type: DOMParserSupportedType) {- const patched = typeof source === "string"- ? source.replace(LEADING_LF_IN_PRE_RE, "$1")- : source;- return originalParseFromString.call(this, patched, type);-};-// =============================================================================// Core initialization for standalone-flavored tests// =============================================================================diff --git a/apps/standalone/vite.config.mts b/apps/standalone/vite.config.mtsindex 09d46619d1..18fbf8977f 100644--- a/apps/standalone/vite.config.mts+++ b/apps/standalone/vite.config.mts@@ -3,7 +3,7 @@ import { join, resolve, sep } from "path";import { codecovVitePlugin } from "@codecov/vite-plugin";import prefresh from "@prefresh/vite";-import { defineConfig, type Plugin } from "vite";+import { defaultClientConditions, defineConfig, type Plugin } from "vite";import { viteStaticCopy } from "vite-plugin-static-copy";import { shareTheme, stripUniverEmojiData, stripUniverHyphenation } from "../client/vite-plugins.mjs";@@ -483,9 +483,31 @@ export default defineConfig(() => ({// package dir to match the other apps and the CI upload path.["junit", { outputFile: join(__dirname, "test-output/vitest/junit.xml"), addFileAttribute: true }]],- include: [- "src/**/*.{test,spec}.{ts,tsx}",- "../../packages/trilium-core/src/**/*.{test,spec}.{ts,tsx}"+ projects: [+ {+ extends: true,+ test: {+ name: "standalone",+ include: ["src/**/*.{test,spec}.{ts,tsx}"]+ }+ },+ // Core runs in a dedicated Web Worker, so its specs run in a scope shaped like one, with+ // dependencies resolved as the worker bundle resolves them. `ssr.resolve.conditions`+ // reaches the packages Node loads itself, through `--conditions`.+ {+ extends: true,+ resolve: { conditions: defaultClientConditions },+ ssr: { resolve: { conditions: ["browser", "development|production"] } },+ test: {+ name: "core",+ include: ["../../packages/trilium-core/src/**/*.{test,spec}.{ts,tsx}"],+ environment: join(__dirname, "src/test_environment_worker.ts"),+ alias: {+ // The specs make their test images with Jimp, whose `browser` entry is an empty stub.+ jimp: join(__dirname, "../../node_modules/jimp/dist/esm/index.js")+ }+ }+ }],coverage: {// Absolute path for the same reason as the junit reporter above: thediff --git a/packages/trilium-core/src/routes/api/backup.spec.ts b/packages/trilium-core/src/routes/api/backup.spec.tsindex e0230cb24e..af026f2059 100644--- a/packages/trilium-core/src/routes/api/backup.spec.ts+++ b/packages/trilium-core/src/routes/api/backup.spec.ts@@ -11,8 +11,8 @@ import { CoreApiTester } from "../../test/api_tester";* backup service on both runtimes. The two filesystem-touching service calls* are stubbed because the underlying platform I/O cannot run against the* ephemeral in-memory fixture: on node, better-sqlite3's `.backup()` rejects- * with `SQLITE_NOTADB` against the in-memory DB; on standalone (happy-dom)- * there is no OPFS. So `backupNow` and `getBackupContent` are isolated — the+ * with `SQLITE_NOTADB` against the in-memory DB; on standalone there is no+ * OPFS. So `backupNow` and `getBackupContent` are isolated — the* route's own logic (mapping, filename extraction, headers) is what we assert.*/let api: CoreApiTester;diff --git a/packages/trilium-core/src/routes/api/login.spec.ts b/packages/trilium-core/src/routes/api/login.spec.tsindex 6ede8c3ec2..76c6b7ed23 100644--- a/packages/trilium-core/src/routes/api/login.spec.ts+++ b/packages/trilium-core/src/routes/api/login.spec.ts@@ -8,9 +8,9 @@ import { CoreApiTester } from "../../test/api_tester";// The protected-session login does real scrypt (N=16384) password verification// and data-key derivation. Under the browser provider that runs in pure JS// (scrypt-js), ~10x slower with V8 coverage instrumentation than Node's native-// scryptSync — enough to blow the 5s default. Give the standalone (happy-dom)+// scryptSync — enough to blow the 5s default. Give the standalone// suite a larger timeout; the server suite keeps the strict default.-const isBrowserRuntime = typeof window !== "undefined";+const isBrowserRuntime = typeof self !== "undefined";if (isBrowserRuntime) {vi.setConfig({ testTimeout: 60000, hookTimeout: 60000 });}diff --git a/packages/trilium-core/src/routes/api/password.spec.ts b/packages/trilium-core/src/routes/api/password.spec.tsindex 3fbf7e24ed..cd66d8e4f4 100644--- a/packages/trilium-core/src/routes/api/password.spec.ts+++ b/packages/trilium-core/src/routes/api/password.spec.ts@@ -7,9 +7,9 @@ import { CoreApiTester } from "../../test/api_tester";// Changing/setting a password does real scrypt (N=16384) hashing + data-key// re-derivation. Under the browser provider that runs in pure JS (scrypt-js),// ~10x slower with V8 coverage instrumentation than Node's native scryptSync —-// enough to blow the 5s default. Give the standalone (happy-dom) suite a larger+// enough to blow the 5s default. Give the standalone suite a larger// timeout; the server suite keeps the strict default.-const isBrowserRuntime = typeof window !== "undefined";+const isBrowserRuntime = typeof self !== "undefined";if (isBrowserRuntime) {vi.setConfig({ testTimeout: 60000, hookTimeout: 60000 });}diff --git a/packages/trilium-core/src/services/encryption/crypto.spec.ts b/packages/trilium-core/src/services/encryption/crypto.spec.tsindex cdf7edd914..05dfddb010 100644--- a/packages/trilium-core/src/services/encryption/crypto.spec.ts+++ b/packages/trilium-core/src/services/encryption/crypto.spec.ts@@ -15,9 +15,9 @@ import { type CryptoProvider, getCrypto, initCrypto } from "./crypto.js";// scrypt (N=16384) runs in pure JS (scrypt-js) under the browser provider, which is// ~10x slower under V8 coverage instrumentation than Node's native scryptSync. Give the-// standalone (happy-dom) suite a larger timeout; the server suite keeps the strict+// standalone suite a larger timeout; the server suite keeps the strict// default. The derived bytes are identical across runtimes — only the speed differs.-const isBrowserRuntime = typeof window !== "undefined";+const isBrowserRuntime = typeof self !== "undefined";if (isBrowserRuntime) {vi.setConfig({ testTimeout: 60000, hookTimeout: 60000 });}diff --git a/packages/trilium-core/src/services/encryption/password.spec.ts b/packages/trilium-core/src/services/encryption/password.spec.tsindex 60cf9de625..595f96388a 100644--- a/packages/trilium-core/src/services/encryption/password.spec.ts+++ b/packages/trilium-core/src/services/encryption/password.spec.ts@@ -15,9 +15,9 @@ const FIXTURE_PASSWORD = "demo1234";// scrypt (N=16384) runs in pure JS (scrypt-js) under the browser provider, which is// ~10x slower under V8 coverage instrumentation than Node's native scryptSync. Give the-// standalone (happy-dom) suite a larger timeout; the server suite keeps the strict+// standalone suite a larger timeout; the server suite keeps the strict// default. The derived bytes are identical across runtimes — only the speed differs.-const isBrowserRuntime = typeof window !== "undefined";+const isBrowserRuntime = typeof self !== "undefined";if (isBrowserRuntime) {vi.setConfig({ testTimeout: 60000, hookTimeout: 60000 });}diff --git a/packages/trilium-core/src/services/encryption/password_encryption.spec.ts b/packages/trilium-core/src/services/encryption/password_encryption.spec.tsindex d41fe1e8f1..f349d33efc 100644--- a/packages/trilium-core/src/services/encryption/password_encryption.spec.ts+++ b/packages/trilium-core/src/services/encryption/password_encryption.spec.ts@@ -15,9 +15,9 @@ const FIXTURE_PASSWORD = "demo1234";// scrypt (N=16384) runs in pure JS (scrypt-js) under the browser provider, which is// ~10x slower under V8 coverage instrumentation than Node's native scryptSync. Give the-// standalone (happy-dom) suite a larger timeout; the server suite keeps the strict+// standalone suite a larger timeout; the server suite keeps the strict// default. The derived bytes are identical across runtimes — only the speed differs.-const isBrowserRuntime = typeof window !== "undefined";+const isBrowserRuntime = typeof self !== "undefined";if (isBrowserRuntime) {vi.setConfig({ testTimeout: 60000, hookTimeout: 60000 });}diff --git a/packages/trilium-core/src/services/encryption/scrypt.spec.ts b/packages/trilium-core/src/services/encryption/scrypt.spec.tsindex b7434cec0a..6c1177defd 100644--- a/packages/trilium-core/src/services/encryption/scrypt.spec.ts+++ b/packages/trilium-core/src/services/encryption/scrypt.spec.ts@@ -18,9 +18,9 @@ const FIXTURE_PASSWORD = "demo1234";// scrypt (N=16384) runs in pure JS (scrypt-js) under the browser provider, which is// ~10x slower under V8 coverage instrumentation than Node's native scryptSync. Give the-// standalone (happy-dom) suite a larger timeout; the server suite keeps the strict+// standalone suite a larger timeout; the server suite keeps the strict// default. The derived bytes are identical across runtimes — only the speed differs.-const isBrowserRuntime = typeof window !== "undefined";+const isBrowserRuntime = typeof self !== "undefined";if (isBrowserRuntime) {vi.setConfig({ testTimeout: 60000, hookTimeout: 60000 });}diff --git a/packages/trilium-core/src/services/export/markdown.spec.ts b/packages/trilium-core/src/services/export/markdown.spec.tsindex 55803dc349..9f949f197b 100644--- a/packages/trilium-core/src/services/export/markdown.spec.ts+++ b/packages/trilium-core/src/services/export/markdown.spec.ts@@ -131,9 +131,8 @@ describe("Markdown export", () => {expect(exported).toContain('<a href="https://e.com/?a=1&b=2">A & B <x></a>');// The section wrapper and its data attributes survive so the preview re-imports losslessly.- // The escaping of `<`/`>` inside data-title is left to turndown's serializer, which differs by- // environment (server/node uses domino and escapes them; standalone/happy-dom uses the browser- // serializer and leaves them raw). It is not asserted because both forms decode to the same value.+ // The escaping of `<`/`>` inside data-title is left to Turnish's serializer and is not asserted,+ // since the escaped and raw forms decode to the same value.expect(exported).toContain('<section class="link-embed" data-url="https://e.com/?a=1&b=2" data-embed-type="opengraph"');});diff --git a/packages/trilium-core/src/services/export/zip.spec.ts b/packages/trilium-core/src/services/export/zip.spec.tsindex 00490e51fc..49d36c68e9 100644--- a/packages/trilium-core/src/services/export/zip.spec.ts+++ b/packages/trilium-core/src/services/export/zip.spec.ts@@ -26,8 +26,8 @@ import {type ZipExportProviderFactory} from "./zip_export_provider_factory.js";-// happy-dom (standalone/WASM) exposes `window`; the Node server suite does not.-const isBrowserRuntime = typeof window !== "undefined";+// Standalone runs core in a Web Worker, whose scope has `self`; the Node server suite has none.+const isBrowserRuntime = typeof self !== "undefined";let counter = 0;diff --git a/packages/trilium-core/src/services/sql/sql.spec.ts b/packages/trilium-core/src/services/sql/sql.spec.tsindex b60de25e18..92f35d0a10 100644--- a/packages/trilium-core/src/services/sql/sql.spec.ts+++ b/packages/trilium-core/src/services/sql/sql.spec.ts@@ -5,8 +5,8 @@ import { getLog } from "../log.js";import { getSql } from "./index.js";import { SqlService, type SqlServiceParams } from "./sql.js";-// happy-dom (standalone/WASM) exposes `window`; the Node server suite does not.-const isBrowserRuntime = typeof window !== "undefined";+// Standalone runs core in a Web Worker, whose scope has `self`; the Node server suite has none.+const isBrowserRuntime = typeof self !== "undefined";let tableCounter = 0;