@gtkx/vitest 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default } from "./plugin.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { default } from "./plugin.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/dist/plugin.d.ts CHANGED
@@ -19,3 +19,4 @@ import type { Plugin } from "vitest/config";
19
19
  */
20
20
  declare const gtkx: () => Plugin;
21
21
  export default gtkx;
22
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,IAAI,QAAO,MAgBhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/dist/plugin.js CHANGED
@@ -33,3 +33,4 @@ const gtkx = () => {
33
33
  };
34
34
  };
35
35
  export default gtkx;
36
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,IAAI,GAAG,GAAW,EAAE;IACtB,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAE9D,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,MAAM,CAAC,MAAM;YACT,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC;YAEjD,OAAO;gBACH,IAAI,EAAE;oBACF,UAAU,EAAE,CAAC,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;oBACzF,IAAI,EAAE,OAAO;iBAChB;aACJ,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/dist/setup.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":""}
package/dist/setup.js CHANGED
@@ -41,3 +41,4 @@ const waitForDisplay = async (timeout = 5000) => {
41
41
  beforeAll(async () => {
42
42
  await waitForDisplay();
43
43
  });
44
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;AAC3C,MAAM,UAAU,GAAG,mBAAmB,OAAO,EAAE,CAAC;AAEhD,MAAM,IAAI,GAAG,KAAK,CA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,UAAU,CAAC,EAAE,CAAC;YACzB,OAAO;QACX,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,OAAO,oCAAoC,OAAO,IAAI,CAAC,CAAC;AAC7F,CAAC,CAAC;AAEF,SAAS,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,cAAc,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/vitest",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Vitest plugin for GTKX applications with Xvfb display isolation",
5
5
  "keywords": [
6
6
  "gtkx",
@@ -32,8 +32,10 @@
32
32
  "default": "./dist/index.js"
33
33
  }
34
34
  },
35
+ "sideEffects": false,
35
36
  "files": [
36
- "dist"
37
+ "dist",
38
+ "src"
37
39
  ],
38
40
  "devDependencies": {
39
41
  "vitest": "^4.0.18"
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from "./plugin.js";
package/src/plugin.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { join } from "node:path";
2
+
3
+ import type { Plugin } from "vitest/config";
4
+
5
+ /**
6
+ * Creates the GTKX Vitest plugin for running GTK tests.
7
+ *
8
+ * Each worker spawns its own Xvfb instance on a PID-based display number.
9
+ *
10
+ * @returns Vitest plugin configuration
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // vitest.config.ts
15
+ * import { defineConfig } from "vitest/config";
16
+ * import gtkx from "@gtkx/vitest";
17
+ *
18
+ * export default defineConfig({
19
+ * plugins: [gtkx()],
20
+ * });
21
+ * ```
22
+ */
23
+ const gtkx = (): Plugin => {
24
+ const workerSetupPath = join(import.meta.dirname, "setup.js");
25
+
26
+ return {
27
+ name: "gtkx",
28
+ config(config) {
29
+ const setupFiles = config.test?.setupFiles ?? [];
30
+
31
+ return {
32
+ test: {
33
+ setupFiles: [workerSetupPath, ...(Array.isArray(setupFiles) ? setupFiles : [setupFiles])],
34
+ pool: "forks",
35
+ },
36
+ };
37
+ },
38
+ };
39
+ };
40
+
41
+ export default gtkx;
package/src/setup.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { beforeAll } from "vitest";
4
+
5
+ const display = 100 + (process.pid % 5000);
6
+ const socketPath = `/tmp/.X11-unix/X${display}`;
7
+
8
+ const xvfb = spawn("Xvfb", [`:${display}`, "-screen", "0", "1024x768x24"], {
9
+ stdio: "ignore",
10
+ });
11
+
12
+ xvfb.unref();
13
+
14
+ process.env.GDK_BACKEND = "x11";
15
+ process.env.GSK_RENDERER = "cairo";
16
+ process.env.LIBGL_ALWAYS_SOFTWARE = "1";
17
+ process.env.DISPLAY = `:${display}`;
18
+
19
+ const killXvfb = (): void => {
20
+ if (xvfb.pid !== undefined) {
21
+ try {
22
+ process.kill(xvfb.pid, "SIGTERM");
23
+ } catch {}
24
+ }
25
+ };
26
+
27
+ process.on("exit", killXvfb);
28
+
29
+ process.on("SIGTERM", () => {
30
+ killXvfb();
31
+ process.exit(143);
32
+ });
33
+
34
+ process.on("SIGINT", () => {
35
+ killXvfb();
36
+ process.exit(130);
37
+ });
38
+
39
+ const waitForDisplay = async (timeout = 5000): Promise<void> => {
40
+ const start = Date.now();
41
+ while (Date.now() - start < timeout) {
42
+ if (existsSync(socketPath)) {
43
+ return;
44
+ }
45
+ await new Promise((resolve) => setTimeout(resolve, 50));
46
+ }
47
+ throw new Error(`Xvfb display :${display} did not become available within ${timeout}ms`);
48
+ };
49
+
50
+ beforeAll(async () => {
51
+ await waitForDisplay();
52
+ });