Compare commits
No commits in common. "e73bdbbbbc8e57c229043e448b7dec8ae7876a82" and "e969f6497c8bbd1fe16ede134ebea7592d8c0e05" have entirely different histories.
e73bdbbbbc
...
e969f6497c
3 changed files with 17 additions and 89 deletions
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||||
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { defineComponent, h } from "vue";
|
import { defineComponent, h } from "vue";
|
||||||
|
|
||||||
const invoke = vi.hoisted(() => vi.fn());
|
const invoke = vi.hoisted(() => vi.fn());
|
||||||
|
|
@ -84,8 +84,7 @@ function recoveryShown(): boolean {
|
||||||
return document.querySelector("[data-test=recovery-dialog]") !== null;
|
return document.querySelector("[data-test=recovery-dialog]") !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fresh Pinia and a fake engine without commands or settings. */
|
beforeEach(() => {
|
||||||
function resetFakeEngine(): void {
|
|
||||||
pinia = createPinia();
|
pinia = createPinia();
|
||||||
setActivePinia(pinia);
|
setActivePinia(pinia);
|
||||||
listeners = [];
|
listeners = [];
|
||||||
|
|
@ -110,37 +109,14 @@ function resetFakeEngine(): void {
|
||||||
}
|
}
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/** Stops the commands and unmounts every mounted component. */
|
afterEach(() => {
|
||||||
function unmountAll(): void {
|
|
||||||
useCommandsStore(pinia).stop();
|
useCommandsStore(pinia).stop();
|
||||||
for (const wrapper of mounted) {
|
for (const wrapper of mounted) {
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Pays the one-time cost of the first modals outside any test: mounts the
|
|
||||||
* app's modals, opens the palette and then the settings dialog, and
|
|
||||||
* unmounts again. The first render of the palette and the settings dialog
|
|
||||||
* in a jsdom worker runs cold (about 0.3 s on an idle machine, against
|
|
||||||
* 50-100 ms later). Without this, the first test paid that cost inside its
|
|
||||||
* own 5 s budget and timed out under load.
|
|
||||||
*/
|
|
||||||
async function warmUpModals(): Promise<void> {
|
|
||||||
resetFakeEngine();
|
|
||||||
await mountApp();
|
|
||||||
await uiCommand("palette.open");
|
|
||||||
await uiCommand("settings.open");
|
|
||||||
unmountAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeAll(warmUpModals);
|
|
||||||
|
|
||||||
beforeEach(resetFakeEngine);
|
|
||||||
|
|
||||||
afterEach(unmountAll);
|
|
||||||
|
|
||||||
describe("one modal at a time", () => {
|
describe("one modal at a time", () => {
|
||||||
it("settings.open from the control channel closes the open palette", async () => {
|
it("settings.open from the control channel closes the open palette", async () => {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||||
import { EditorView } from "@codemirror/view";
|
import { EditorView } from "@codemirror/view";
|
||||||
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
const invoke = vi.hoisted(() => vi.fn());
|
const invoke = vi.hoisted(() => vi.fn());
|
||||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||||
|
|
@ -221,8 +221,7 @@ function stubRangeGeometry(): void {
|
||||||
Range.prototype.getBoundingClientRect = () => new DOMRect(0, 0, 0, 0);
|
Range.prototype.getBoundingClientRect = () => new DOMRect(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fresh Pinia and a fake engine with two files on its disk. */
|
beforeEach(() => {
|
||||||
function resetFakeEngine(): void {
|
|
||||||
stubRangeGeometry();
|
stubRangeGeometry();
|
||||||
pinia = createPinia();
|
pinia = createPinia();
|
||||||
setActivePinia(pinia);
|
setActivePinia(pinia);
|
||||||
|
|
@ -245,44 +244,16 @@ function resetFakeEngine(): void {
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error(`unexpected ${cmd}`));
|
return Promise.reject(new Error(`unexpected ${cmd}`));
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/** Stops the global keymap and unmounts every mounted component. */
|
afterEach(async () => {
|
||||||
async function unmountAll(): Promise<void> {
|
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
useCommandsStore(pinia).stop();
|
useCommandsStore(pinia).stop();
|
||||||
for (const wrapper of mounted) {
|
for (const wrapper of mounted) {
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
}
|
}
|
||||||
mounted = [];
|
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", () => {
|
describe("EditorArea", () => {
|
||||||
it("shows the slot without tabs and opens a file from the project tree", async () => {
|
it("shows the slot without tabs and opens a file from the project tree", async () => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
import { forceParsing, syntaxTree } from "@codemirror/language";
|
import { forceParsing, syntaxTree } from "@codemirror/language";
|
||||||
import { EditorState } from "@codemirror/state";
|
import { EditorState } from "@codemirror/state";
|
||||||
import { EditorView } from "@codemirror/view";
|
import { EditorView } from "@codemirror/view";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||||
import { editorExtensions, lutraEditorTheme } from "../../src/components/editor/extensions";
|
import { editorExtensions, lutraEditorTheme } from "../../src/components/editor/extensions";
|
||||||
import { languageOf, SYNTAX_TOKENS } from "../../src/components/editor/language";
|
import { languageOf, SYNTAX_TOKENS } from "../../src/components/editor/language";
|
||||||
|
|
||||||
|
|
@ -57,35 +57,16 @@ function highlighted(view: EditorView): Record<string, string[]> {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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(() => {
|
beforeEach(() => {
|
||||||
stubRangeGeometry();
|
stubRangeGeometry();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(destroyViews);
|
afterEach(() => {
|
||||||
|
for (const view of views) {
|
||||||
|
view.destroy();
|
||||||
|
}
|
||||||
|
views = [];
|
||||||
|
});
|
||||||
|
|
||||||
describe("languageOf", () => {
|
describe("languageOf", () => {
|
||||||
it.each([
|
it.each([
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue