@weapp-vite/miniprogram-automator 1.2.0 → 1.2.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.
package/dist/index.d.mts CHANGED
@@ -277,6 +277,10 @@ declare class MiniProgram extends EventEmitter {
277
277
  on(event: string | symbol, listener: (...args: any[]) => void): this;
278
278
  exposeFunction(name: string, bindingFunction: AutomatorCallable): Promise<void>;
279
279
  checkVersion(): Promise<void>;
280
+ /**
281
+ * @description 等待小程序 App 域协议可用,避免返回半就绪自动化会话。
282
+ */
283
+ waitForAppReady(timeout?: number): Promise<void>;
280
284
  screenshot(options?: IScreenshotOptions): Promise<any>;
281
285
  testAccounts(): Promise<any>;
282
286
  /**
package/dist/index.mjs CHANGED
@@ -683,7 +683,7 @@ async function acquireAutomatorPortLease(preferredPort) {
683
683
  }
684
684
  //#endregion
685
685
  //#region package.json
686
- var version = "1.2.0";
686
+ var version = "1.2.1";
687
687
  //#endregion
688
688
  //#region src/Native.ts
689
689
  /** Native 的实现。 */
@@ -880,6 +880,9 @@ const CHANGE_ROUTE_CONTEXT_TIMEOUT = 12e3;
880
880
  const CHANGE_ROUTE_CALL_TIMEOUT = 12e3;
881
881
  const CHANGE_ROUTE_READY_TIMEOUT = 15e3;
882
882
  const CHANGE_ROUTE_POLL_DELAY = 500;
883
+ const APP_READY_TIMEOUT = 2e4;
884
+ const APP_READY_PROBE_TIMEOUT = 3e3;
885
+ const APP_READY_POLL_DELAY = 500;
883
886
  const CHANGE_ROUTE_DEBUG_ENABLED = process.env.WEAPP_VITE_E2E_CHANGE_ROUTE_DEBUG === "1";
884
887
  function sleep(ms) {
885
888
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -1107,6 +1110,21 @@ var MiniProgram = class extends EventEmitter {
1107
1110
  const sdkVersion = (await this.send("Tool.getInfo")).SDKVersion;
1108
1111
  if (sdkVersion !== "dev" && cmpVersion(sdkVersion, "2.7.3") < 0) throw new Error(`SDKVersion is currently ${sdkVersion}, while automator(${version}) requires at least version 2.7.3`);
1109
1112
  }
1113
+ /**
1114
+ * @description 等待小程序 App 域协议可用,避免返回半就绪自动化会话。
1115
+ */
1116
+ async waitForAppReady(timeout = APP_READY_TIMEOUT) {
1117
+ const startedAt = Date.now();
1118
+ let lastError;
1119
+ while (Date.now() - startedAt <= timeout) try {
1120
+ await this.send("App.captureScreenshot", {}, { timeout: APP_READY_PROBE_TIMEOUT });
1121
+ return;
1122
+ } catch (error) {
1123
+ lastError = error;
1124
+ await sleep(APP_READY_POLL_DELAY);
1125
+ }
1126
+ throw lastError instanceof Error ? lastError : /* @__PURE__ */ new Error(`Timed out waiting App domain readiness after ${timeout}ms`);
1127
+ }
1110
1128
  async screenshot(options = {}) {
1111
1129
  const { data } = await this.send("App.captureScreenshot");
1112
1130
  if (!options.path) return data;
@@ -1815,6 +1833,7 @@ var Launcher = class {
1815
1833
  const candidate = await this.connectTool({ wsEndpoint: `ws://127.0.0.1:${port}` });
1816
1834
  try {
1817
1835
  await candidate.checkVersion();
1836
+ if (typeof candidate.waitForAppReady === "function") await candidate.waitForAppReady(timeout);
1818
1837
  } catch (error) {
1819
1838
  candidate.disconnect();
1820
1839
  lastConnectError = error;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-vite/miniprogram-automator",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "description": "完全兼容微信 miniprogram-automator 的现代化替代实现",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",