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(codemirror/autocomplete): use stricter assertions
Elian Dorana721f063adbe
diff --git a/packages/codemirror/src/type_completion/index.spec.ts b/packages/codemirror/src/type_completion/index.spec.tsindex 29d6fe7274..6a5cc782e9 100644--- a/packages/codemirror/src/type_completion/index.spec.ts+++ b/packages/codemirror/src/type_completion/index.spec.ts@@ -2,55 +2,53 @@ import { describe, expect, it } from "vitest";import { getScriptDiagnosticCodes, SCRIPT_MIME_BACKEND, SCRIPT_MIME_FRONTEND } from "./index.js";-/** "Parameter 'x' implicitly has an 'any' type." */-const TS_IMPLICIT_ANY = 7006;/** "Property 'x' does not exist on type 'y'." */const TS_UNKNOWN_PROPERTY = 2339;-/** "A 'return' statement can only be used within a function body." */-const TS_RETURN_OUTSIDE_FUNCTION = 1108;// Loading TypeScript + the bundled lib.*.d.ts the first time is not instant.const TIMEOUT = 30_000;+// Valid script snippets must produce *no* diagnostics at all — asserting the+// empty set (rather than just "not code N") also catches any unrelated spurious+// diagnostic from a config/lib/api-typing regression. The test name records the+// specific false positive each snippet guards against.describe("script note diagnostics", () => {- it("does not flag untyped parameters as implicit any", async () => {- // Loose JS — untyped params are normal in script notes and must not warn.+ it("does not flag untyped parameters as implicit any (TS7006)", async () => {+ // Loose JS — untyped params are normal in script notes.const codes = await getScriptDiagnosticCodes(SCRIPT_MIME_FRONTEND,"function handleClick(event) { return event; }\nconst add = (a, b) => a + b;");- expect(codes).not.toContain(TS_IMPLICIT_ANY);+ expect(codes).toEqual([]);}, TIMEOUT);- it("does not flag untyped parameters in backend scripts either", async () => {+ it("does not flag untyped parameters in backend scripts either (TS7006)", async () => {const codes = await getScriptDiagnosticCodes(SCRIPT_MIME_BACKEND,"function process(note, depth) { return note; }");- expect(codes).not.toContain(TS_IMPLICIT_ANY);+ expect(codes).toEqual([]);}, TIMEOUT);- it("does not flag a top-level return (scripts run inside a function wrapper)", async () => {- // Trilium wraps scripts in a function before executing them, so a- // top-level `return` is valid at runtime and must not be flagged.+ it("does not flag a top-level return — scripts run inside a function wrapper (TS1108)", async () => {const codes = await getScriptDiagnosticCodes(SCRIPT_MIME_FRONTEND,"if (!api.currentNote) { return; }\nreturn api.showMessage('done');");- expect(codes).not.toContain(TS_RETURN_OUTSIDE_FUNCTION);+ expect(codes).toEqual([]);}, TIMEOUT);- it("does not flag a top-level return in backend scripts either", async () => {+ it("does not flag a top-level return in backend scripts either (TS1108)", async () => {const codes = await getScriptDiagnosticCodes(SCRIPT_MIME_BACKEND,"const note = api.getNote('root');\nif (!note) { return; }\nreturn note.title;");- expect(codes).not.toContain(TS_RETURN_OUTSIDE_FUNCTION);+ expect(codes).toEqual([]);}, TIMEOUT);it("still surfaces real errors (unknown api member)", async () => {- // Guards against "fixing" implicit-any by disabling all checking: genuine- // semantic errors must still be reported.+ // Guards against "fixing" false positives by disabling all checking:+ // genuine semantic errors must still be reported.const codes = await getScriptDiagnosticCodes(SCRIPT_MIME_FRONTEND,"api.thisMethodDoesNotExist();"