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:
parent
e969f6497c
commit
9407d5d6c2
3 changed files with 88 additions and 16 deletions
|
|
@ -11,7 +11,7 @@
|
|||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const invoke = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||
|
|
@ -221,7 +221,8 @@ function stubRangeGeometry(): void {
|
|||
Range.prototype.getBoundingClientRect = () => new DOMRect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
/** Fresh Pinia and a fake engine with two files on its disk. */
|
||||
function resetFakeEngine(): void {
|
||||
stubRangeGeometry();
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
|
|
@ -244,16 +245,44 @@ beforeEach(() => {
|
|||
}
|
||||
return Promise.reject(new Error(`unexpected ${cmd}`));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
/** Stops the global keymap and unmounts every mounted component. */
|
||||
async function unmountAll(): Promise<void> {
|
||||
await flushPromises();
|
||||
useCommandsStore(pinia).stop();
|
||||
for (const wrapper of mounted) {
|
||||
wrapper.unmount();
|
||||
}
|
||||
mounted = [];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Pays the one-time cost of the first editor outside any test: mounts the
|
||||
* editor area and the project tree, opens a file from the tree and
|
||||
* unmounts again. The first CodeMirror view in a jsdom worker injects the
|
||||
* base theme and runs every extension cold, and the first render of the
|
||||
* Vue components is slower too (about 0.5 s together on an idle machine,
|
||||
* several seconds under load). Without this, the first test that opened a
|
||||
* file paid that cost inside its own 5 s budget and timed out under load.
|
||||
*/
|
||||
async function warmUpEditor(): Promise<void> {
|
||||
resetFakeEngine();
|
||||
await mountArea();
|
||||
const tree = mount(ProjectToolWindow, { attachTo: document.body, global: { plugins: [pinia] } });
|
||||
mounted.push(tree);
|
||||
emitEngineEvent({ kind: "projectOpened", root: "/tmp/demo", name: "demo" });
|
||||
await flushPromises();
|
||||
await tree.find("[data-path='a.php']").trigger("dblclick");
|
||||
await flushPromises();
|
||||
await unmountAll();
|
||||
}
|
||||
|
||||
beforeAll(warmUpEditor);
|
||||
|
||||
beforeEach(resetFakeEngine);
|
||||
|
||||
afterEach(unmountAll);
|
||||
|
||||
describe("EditorArea", () => {
|
||||
it("shows the slot without tabs and opens a file from the project tree", async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue