tauri-test-cli 0.7.0 → 0.7.1

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.
Files changed (2) hide show
  1. package/dist/cli.js +153 -14
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -120707,7 +120707,9 @@ async function connect(options) {
120707
120707
  }
120708
120708
  async function disconnect() {
120709
120709
  if (browser) {
120710
- await browser.deleteSession();
120710
+ try {
120711
+ await browser.deleteSession();
120712
+ } catch {}
120711
120713
  browser = null;
120712
120714
  }
120713
120715
  stopDriver();
@@ -120905,6 +120907,12 @@ async function waitForInteractive(selector, timeout = 5000) {
120905
120907
  await element.waitForClickable({ timeout });
120906
120908
  }
120907
120909
 
120910
+ // src/commands/utils.ts
120911
+ var xvfbDisplay = null;
120912
+ function getXvfbDisplay() {
120913
+ return xvfbDisplay;
120914
+ }
120915
+
120908
120916
  // src/commands/screenshot.ts
120909
120917
  var HTML2CANVAS_CDN = "https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js";
120910
120918
  async function screenshot(options = {}) {
@@ -120921,12 +120929,21 @@ async function screenshot(options = {}) {
120921
120929
  data2 = await withTimeout(captureWithHtml2Canvas(browser3), timeout, "html2canvas timed out");
120922
120930
  method = "html2canvas";
120923
120931
  } catch (err) {
120924
- console.error(`html2canvas failed: ${err}, trying native...`);
120932
+ console.error(`html2canvas failed: ${err}, trying canvas fallback...`);
120925
120933
  try {
120926
- data2 = await withTimeout(browser3.takeScreenshot(), timeout, `Native screenshot timed out after ${timeout}ms`);
120927
- method = "native";
120928
- } catch (nativeErr) {
120929
- throw new Error(`All screenshot methods failed: ${err}, ${nativeErr}`);
120934
+ data2 = await withTimeout(captureWithCanvas(browser3), timeout, "Canvas screenshot timed out");
120935
+ method = "canvas";
120936
+ } catch (canvasErr) {
120937
+ if (getXvfbDisplay() !== null) {
120938
+ throw new Error(`All screenshot methods failed in Xvfb: html2canvas: ${err}, canvas: ${canvasErr}`);
120939
+ }
120940
+ console.error(`Canvas failed: ${canvasErr}, trying native...`);
120941
+ try {
120942
+ data2 = await withTimeout(browser3.takeScreenshot(), timeout, `Native screenshot timed out after ${timeout}ms`);
120943
+ method = "native";
120944
+ } catch (nativeErr) {
120945
+ throw new Error(`All screenshot methods failed: html2canvas: ${err}, canvas: ${canvasErr}, native: ${nativeErr}`);
120946
+ }
120930
120947
  }
120931
120948
  }
120932
120949
  if (options.output) {
@@ -120993,6 +121010,61 @@ async function captureWithHtml2Canvas(browser3) {
120993
121010
  }
120994
121011
  return base64;
120995
121012
  }
121013
+ async function captureWithCanvas(browser3) {
121014
+ const base64 = await browser3.executeAsync((done) => {
121015
+ try {
121016
+ const w2 = window.innerWidth || 800;
121017
+ const h = window.innerHeight || 600;
121018
+ const canvas = document.createElement("canvas");
121019
+ canvas.width = w2;
121020
+ canvas.height = h;
121021
+ const ctx = canvas.getContext("2d");
121022
+ ctx.fillStyle = "#ffffff";
121023
+ ctx.fillRect(0, 0, w2, h);
121024
+ const serializer = new XMLSerializer;
121025
+ const cloned = document.documentElement.cloneNode(true);
121026
+ const html3 = serializer.serializeToString(cloned);
121027
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${w2}" height="${h}">
121028
+ <foreignObject width="100%" height="100%">
121029
+ ${html3}
121030
+ </foreignObject>
121031
+ </svg>`;
121032
+ const blob = new Blob([svg], { type: "image/svg+xml;charset=utf-8" });
121033
+ const url2 = URL.createObjectURL(blob);
121034
+ const img = new Image;
121035
+ img.onload = () => {
121036
+ ctx.drawImage(img, 0, 0);
121037
+ URL.revokeObjectURL(url2);
121038
+ const dataUrl = canvas.toDataURL("image/png");
121039
+ done(dataUrl.replace(/^data:image\/png;base64,/, ""));
121040
+ };
121041
+ img.onerror = () => {
121042
+ URL.revokeObjectURL(url2);
121043
+ ctx.fillStyle = "#000000";
121044
+ ctx.font = "16px monospace";
121045
+ const text3 = document.body.innerText || "";
121046
+ const lines = text3.split(`
121047
+ `);
121048
+ for (let i = 0;i < lines.length && i < 40; i++) {
121049
+ ctx.fillText(lines[i], 10, 20 + i * 20);
121050
+ }
121051
+ const dataUrl = canvas.toDataURL("image/png");
121052
+ done(dataUrl.replace(/^data:image\/png;base64,/, ""));
121053
+ };
121054
+ img.src = url2;
121055
+ setTimeout(() => {
121056
+ const dataUrl = canvas.toDataURL("image/png");
121057
+ done(dataUrl.replace(/^data:image\/png;base64,/, ""));
121058
+ }, 4000);
121059
+ } catch (e) {
121060
+ done("");
121061
+ }
121062
+ });
121063
+ if (!base64) {
121064
+ throw new Error("Canvas screenshot capture returned empty");
121065
+ }
121066
+ return base64;
121067
+ }
120996
121068
 
120997
121069
  // src/commands/snapshot.ts
120998
121070
  import { writeFile as writeFile2 } from "fs/promises";
@@ -121285,12 +121357,21 @@ async function screenshot2(options = {}) {
121285
121357
  data2 = await withTimeout2(captureWithHtml2Canvas2(browser3), timeout, "html2canvas timed out");
121286
121358
  method = "html2canvas";
121287
121359
  } catch (err) {
121288
- console.error(`html2canvas failed: ${err}, trying native...`);
121360
+ console.error(`html2canvas failed: ${err}, trying canvas fallback...`);
121289
121361
  try {
121290
- data2 = await withTimeout2(browser3.takeScreenshot(), timeout, `Native screenshot timed out after ${timeout}ms`);
121291
- method = "native";
121292
- } catch (nativeErr) {
121293
- throw new Error(`All screenshot methods failed: ${err}, ${nativeErr}`);
121362
+ data2 = await withTimeout2(captureWithCanvas2(browser3), timeout, "Canvas screenshot timed out");
121363
+ method = "canvas";
121364
+ } catch (canvasErr) {
121365
+ if (getXvfbDisplay() !== null) {
121366
+ throw new Error(`All screenshot methods failed in Xvfb: html2canvas: ${err}, canvas: ${canvasErr}`);
121367
+ }
121368
+ console.error(`Canvas failed: ${canvasErr}, trying native...`);
121369
+ try {
121370
+ data2 = await withTimeout2(browser3.takeScreenshot(), timeout, `Native screenshot timed out after ${timeout}ms`);
121371
+ method = "native";
121372
+ } catch (nativeErr) {
121373
+ throw new Error(`All screenshot methods failed: html2canvas: ${err}, canvas: ${canvasErr}, native: ${nativeErr}`);
121374
+ }
121294
121375
  }
121295
121376
  }
121296
121377
  if (options.output) {
@@ -121357,6 +121438,61 @@ async function captureWithHtml2Canvas2(browser3) {
121357
121438
  }
121358
121439
  return base64;
121359
121440
  }
121441
+ async function captureWithCanvas2(browser3) {
121442
+ const base64 = await browser3.executeAsync((done) => {
121443
+ try {
121444
+ const w2 = window.innerWidth || 800;
121445
+ const h = window.innerHeight || 600;
121446
+ const canvas = document.createElement("canvas");
121447
+ canvas.width = w2;
121448
+ canvas.height = h;
121449
+ const ctx = canvas.getContext("2d");
121450
+ ctx.fillStyle = "#ffffff";
121451
+ ctx.fillRect(0, 0, w2, h);
121452
+ const serializer = new XMLSerializer;
121453
+ const cloned = document.documentElement.cloneNode(true);
121454
+ const html3 = serializer.serializeToString(cloned);
121455
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${w2}" height="${h}">
121456
+ <foreignObject width="100%" height="100%">
121457
+ ${html3}
121458
+ </foreignObject>
121459
+ </svg>`;
121460
+ const blob = new Blob([svg], { type: "image/svg+xml;charset=utf-8" });
121461
+ const url2 = URL.createObjectURL(blob);
121462
+ const img = new Image;
121463
+ img.onload = () => {
121464
+ ctx.drawImage(img, 0, 0);
121465
+ URL.revokeObjectURL(url2);
121466
+ const dataUrl = canvas.toDataURL("image/png");
121467
+ done(dataUrl.replace(/^data:image\/png;base64,/, ""));
121468
+ };
121469
+ img.onerror = () => {
121470
+ URL.revokeObjectURL(url2);
121471
+ ctx.fillStyle = "#000000";
121472
+ ctx.font = "16px monospace";
121473
+ const text3 = document.body.innerText || "";
121474
+ const lines = text3.split(`
121475
+ `);
121476
+ for (let i = 0;i < lines.length && i < 40; i++) {
121477
+ ctx.fillText(lines[i], 10, 20 + i * 20);
121478
+ }
121479
+ const dataUrl = canvas.toDataURL("image/png");
121480
+ done(dataUrl.replace(/^data:image\/png;base64,/, ""));
121481
+ };
121482
+ img.src = url2;
121483
+ setTimeout(() => {
121484
+ const dataUrl = canvas.toDataURL("image/png");
121485
+ done(dataUrl.replace(/^data:image\/png;base64,/, ""));
121486
+ }, 4000);
121487
+ } catch (e) {
121488
+ done("");
121489
+ }
121490
+ });
121491
+ if (!base64) {
121492
+ throw new Error("Canvas screenshot capture returned empty");
121493
+ }
121494
+ return base64;
121495
+ }
121360
121496
 
121361
121497
  // src/commands/snapshot.ts
121362
121498
  import { writeFile as writeFile4 } from "fs/promises";
@@ -121649,6 +121785,9 @@ async function executeCommand(cmd, globalAutoWait) {
121649
121785
  console.error(`[${new Date().toISOString()}] activateWindow took ${Date.now() - activateStart}ms`);
121650
121786
  const cmdStart = Date.now();
121651
121787
  let result;
121788
+ if (cmd.cmd === "screenshot" || cmd.cmd === "snapshot") {
121789
+ await injectKeepAlive();
121790
+ }
121652
121791
  switch (cmd.cmd) {
121653
121792
  case "screenshot":
121654
121793
  result = await screenshot2({
@@ -122124,7 +122263,7 @@ async function waitForDisplay(display, timeoutMs = 1e4) {
122124
122263
  return false;
122125
122264
  }
122126
122265
  var xvfbProcess = null;
122127
- var xvfbDisplay = null;
122266
+ var xvfbDisplay2 = null;
122128
122267
  async function startXvfb() {
122129
122268
  const display = findAvailableDisplay();
122130
122269
  const displayStr = `:${display}`;
@@ -122154,7 +122293,7 @@ async function startXvfb() {
122154
122293
  throw new Error(`Xvfb display ${displayStr} failed to start within timeout`);
122155
122294
  }
122156
122295
  console.error(`Xvfb ready on display ${displayStr}`);
122157
- xvfbDisplay = display;
122296
+ xvfbDisplay2 = display;
122158
122297
  process.env.DISPLAY = displayStr;
122159
122298
  delete process.env.WAYLAND_DISPLAY;
122160
122299
  process.env.GDK_BACKEND = "x11";
@@ -122165,7 +122304,7 @@ function stopXvfb() {
122165
122304
  console.error("Stopping Xvfb...");
122166
122305
  xvfbProcess.kill("SIGTERM");
122167
122306
  xvfbProcess = null;
122168
- xvfbDisplay = null;
122307
+ xvfbDisplay2 = null;
122169
122308
  }
122170
122309
  }
122171
122310
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-test-cli",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "CLI for testing Tauri applications with screenshot capture, DOM inspection, and user interaction simulation",
5
5
  "type": "module",
6
6
  "bin": {