Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

preview-keyboard.test.mjs

46 lines1.9 KB

1import * as NodeChildProcess from "node:child_process";
2import * as NodeFS from "node:fs";
3import * as NodeOS from "node:os";
4import * as NodePath from "node:path";
5import * as NodeModule from "node:module";
6import * as NodeURL from "node:url";
7import { describe, expect, it } from "vite-plus/test";
8​
9const require = NodeModule.createRequire(import.meta.url);
10// Opt in because this regression needs a real Electron window and a desktop session.
11describe.skipIf(process.env.T3CODE_TEST_ELECTRON !== "1")("desktop preview keyboard", () => {
12 it("delivers input to visible and hidden guests while preserving the host draft", async () => {
13 const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-preview-keyboard-"));
14 const environment = { ...process.env };
15 delete environment.ELECTRON_RUN_AS_NODE;
16 try {
17 const output = await new Promise((resolve, reject) => {
18 NodeChildProcess.execFile(
19 require("electron"),
20 [
21 NodeURL.fileURLToPath(new URL("./fixtures/preview-keyboard.cjs", import.meta.url)),
22 directory,
23 ],
24 { env: environment, timeout: 30_000 },
25 (error, stdout, stderr) => {
26 if (error) reject(new Error(`${error.message}\n${stdout}\n${stderr}`));
27 else resolve(stdout);
28 },
29 );
30 });
31 const result = JSON.parse(output.trim().split("\n").at(-1));
32 expect(result.results).toEqual([
33 "hidden input and keys",
34 "visible input and keys",
35 "textarea, contenteditable, and shadow input",
36 "same-site frame",
37 "cross-site frame",
38 "editing shortcuts, canceled keys, and trusted events",
39 "undeliverable text fails and the queue recovers",
40 "Enter navigation preserves the host draft",
41 ]);
42 } finally {
43 NodeFS.rmSync(directory, { recursive: true, force: true });
44 }
45 });
46});