M2.2: deterministic highlighting tests
Force the parse on the view itself instead of a throwaway state, so the nested HTML layer of PHP files is parsed before the spans are read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
62f9ab1564
commit
645fa6a10f
1 changed files with 10 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue