diff --git a/ui/tests/editor/language.test.ts b/ui/tests/editor/language.test.ts index 72f7a4e..5c8aedb 100644 --- a/ui/tests/editor/language.test.ts +++ b/ui/tests/editor/language.test.ts @@ -4,7 +4,7 @@ * the spans CodeMirror draws for PHP, embedded HTML and the other * languages, each coloured by its `--lt-syntax-*` token. */ -import { ensureSyntaxTree } from "@codemirror/language"; +import { forceParsing, syntaxTree } from "@codemirror/language"; import { EditorState } from "@codemirror/state"; import { EditorView } from "@codemirror/view"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; @@ -23,16 +23,21 @@ function stubRangeGeometry(): void { /** * Shows a document in a view with the extensions of a file path, parsed - * completely. + * completely before it returns. The parse is forced on the view itself: + * left alone, the view parses in time-budgeted slices, so under load the + * nested HTML layer of a PHP file could still be missing when a test reads + * the spans. Plain text has nothing to parse. * * @param path - the file path that picks the language. * @param doc - the text. + * @throws Error if the parse does not finish within a minute. */ function show(path: string, doc: string): EditorView { - const state = EditorState.create({ doc, extensions: editorExtensions(path) }); - ensureSyntaxTree(state, state.doc.length, 5000); - const view = new EditorView({ state, parent: document.body }); + const view = new EditorView({ state: EditorState.create({ doc, extensions: editorExtensions(path) }), parent: document.body }); views.push(view); + if (languageOf(path) !== null && (!forceParsing(view, doc.length, 60_000) || syntaxTree(view.state).length < doc.length)) { + throw new Error(`parse of ${path} did not finish`); + } return view; }