H2: warm up first editor and modals outside the test budget

The first CodeMirror view and the first render of the editor area,
the palette and the settings dialog in a jsdom worker cost 0.3-0.6 s
once. The first test of EditorArea, language and modals paid it inside
its own 5 s budget and timed out under load. A beforeAll warm-up now
pays it once; no timeout changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-25 13:30:57 +01:00
parent e969f6497c
commit 9407d5d6c2
3 changed files with 88 additions and 16 deletions

View file

@ -7,7 +7,7 @@
import { forceParsing, syntaxTree } from "@codemirror/language";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { editorExtensions, lutraEditorTheme } from "../../src/components/editor/extensions";
import { languageOf, SYNTAX_TOKENS } from "../../src/components/editor/language";
@ -57,17 +57,36 @@ function highlighted(view: EditorView): Record<string, string[]> {
return out;
}
beforeEach(() => {
stubRangeGeometry();
});
afterEach(() => {
/** Destroys every view a test showed. */
function destroyViews(): void {
for (const view of views) {
view.destroy();
}
views = [];
}
/**
* Pays the one-time cost of the first highlighted PHP view outside any
* test. The first view in a jsdom worker injects CodeMirror's base theme
* and builds the PHP, HTML, CSS and JavaScript parsers cold (about 0.5 s
* on an idle machine, against 5-30 ms for later views). Without this, the
* first highlighting test paid that cost inside its own 5 s budget and
* timed out under load.
*/
function warmUpHighlighting(): void {
stubRangeGeometry();
show("a.php", '<div class="a"><?php\nfunction f(int $a): float { return $a * 1.5; }\n?></div>\n<script>let x = 1;</script>\n');
destroyViews();
}
beforeAll(warmUpHighlighting);
beforeEach(() => {
stubRangeGeometry();
});
afterEach(destroyViews);
describe("languageOf", () => {
it.each([
["src/Controller/Home.php", "php"],