@weapp-vite/miniprogram-automator 1.0.3 → 1.0.4
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 +27 -5
- package/dist/index.mjs +75 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -202,6 +202,12 @@ interface IScreenshotOptions {
|
|
|
202
202
|
interface IAuditsOptions {
|
|
203
203
|
path?: string;
|
|
204
204
|
}
|
|
205
|
+
interface IToolCompileOptions {
|
|
206
|
+
force?: boolean;
|
|
207
|
+
}
|
|
208
|
+
interface IToolClearCacheOptions {
|
|
209
|
+
clean: 'all' | 'auth' | 'compile' | 'file' | 'network' | 'session' | 'storage';
|
|
210
|
+
}
|
|
205
211
|
type AutomatorCallable = (...args: any[]) => any;
|
|
206
212
|
/** MiniProgram 的实现。 */
|
|
207
213
|
declare class MiniProgram extends EventEmitter {
|
|
@@ -211,11 +217,11 @@ declare class MiniProgram extends EventEmitter {
|
|
|
211
217
|
private nativeIns?;
|
|
212
218
|
constructor(connection: Connection);
|
|
213
219
|
pageStack(): Promise<any>;
|
|
214
|
-
navigateTo(url: string): Promise<
|
|
215
|
-
redirectTo(url: string): Promise<
|
|
216
|
-
navigateBack(): Promise<
|
|
217
|
-
reLaunch(url: string): Promise<
|
|
218
|
-
switchTab(url: string): Promise<
|
|
220
|
+
navigateTo(url: string): Promise<any>;
|
|
221
|
+
redirectTo(url: string): Promise<any>;
|
|
222
|
+
navigateBack(): Promise<any>;
|
|
223
|
+
reLaunch(url: string): Promise<any>;
|
|
224
|
+
switchTab(url: string): Promise<any>;
|
|
219
225
|
currentPage(): Promise<Page>;
|
|
220
226
|
systemInfo(): Promise<any>;
|
|
221
227
|
callWxMethod(method: string, ...args: any[]): Promise<any>;
|
|
@@ -234,6 +240,22 @@ declare class MiniProgram extends EventEmitter {
|
|
|
234
240
|
checkVersion(): Promise<void>;
|
|
235
241
|
screenshot(options?: IScreenshotOptions): Promise<any>;
|
|
236
242
|
testAccounts(): Promise<any>;
|
|
243
|
+
/**
|
|
244
|
+
* @description 获取开发者工具 Tool 域基础信息。
|
|
245
|
+
*/
|
|
246
|
+
toolInfo(): Promise<any>;
|
|
247
|
+
/**
|
|
248
|
+
* @description 触发开发者工具执行一次项目编译。
|
|
249
|
+
*/
|
|
250
|
+
compile(options?: IToolCompileOptions): Promise<any>;
|
|
251
|
+
/**
|
|
252
|
+
* @description 清理开发者工具缓存。
|
|
253
|
+
*/
|
|
254
|
+
clearCache(options: IToolClearCacheOptions): Promise<any>;
|
|
255
|
+
/**
|
|
256
|
+
* @description 调用开发者工具 Tool 域协议方法。
|
|
257
|
+
*/
|
|
258
|
+
tool(method: string, params?: Record<string, any>): Promise<any>;
|
|
237
259
|
stopAudits(options?: IAuditsOptions): Promise<any>;
|
|
238
260
|
getTicket(): Promise<any>;
|
|
239
261
|
setTicket(ticket: string): Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -581,7 +581,7 @@ async function launchHeadlessAutomator(options) {
|
|
|
581
581
|
}
|
|
582
582
|
//#endregion
|
|
583
583
|
//#region package.json
|
|
584
|
-
var version = "1.0.
|
|
584
|
+
var version = "1.0.4";
|
|
585
585
|
//#endregion
|
|
586
586
|
//#region src/Native.ts
|
|
587
587
|
/** Native 的实现。 */
|
|
@@ -772,6 +772,9 @@ function extractPluginId(p) {
|
|
|
772
772
|
const CLOSE_STEP_TIMEOUT = 2e3;
|
|
773
773
|
const CURRENT_PAGE_RETRIES = 3;
|
|
774
774
|
const CURRENT_PAGE_RETRY_DELAY = 400;
|
|
775
|
+
const CHANGE_ROUTE_READY_TIMEOUT = 15e3;
|
|
776
|
+
const CHANGE_ROUTE_POLL_DELAY = 500;
|
|
777
|
+
const CHANGE_ROUTE_DEBUG_ENABLED = process.env.WEAPP_VITE_E2E_CHANGE_ROUTE_DEBUG === "1";
|
|
775
778
|
function sleep(ms) {
|
|
776
779
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
777
780
|
}
|
|
@@ -797,6 +800,13 @@ function isFnStr(value) {
|
|
|
797
800
|
function isCurrentPageProtocolTimeout(error) {
|
|
798
801
|
return error instanceof Error && "code" in error && error.code === "DEVTOOLS_PROTOCOL_TIMEOUT" && "method" in error && error.method === "App.getCurrentPage";
|
|
799
802
|
}
|
|
803
|
+
function normalizeRoutePath(value) {
|
|
804
|
+
return String(value ?? "").split("?", 1)[0].replace(/^\/+/, "").replace(/\/+$/, "");
|
|
805
|
+
}
|
|
806
|
+
function logChangeRouteDebug(message) {
|
|
807
|
+
if (!CHANGE_ROUTE_DEBUG_ENABLED) return;
|
|
808
|
+
process.stdout.write(`[automator:changeRoute] ${message}\n`);
|
|
809
|
+
}
|
|
800
810
|
/** MiniProgram 的实现。 */
|
|
801
811
|
var MiniProgram = class extends EventEmitter {
|
|
802
812
|
appBindings = /* @__PURE__ */ new Map();
|
|
@@ -964,6 +974,30 @@ var MiniProgram = class extends EventEmitter {
|
|
|
964
974
|
async testAccounts() {
|
|
965
975
|
return (await this.send("Tool.getTestAccounts")).accounts;
|
|
966
976
|
}
|
|
977
|
+
/**
|
|
978
|
+
* @description 获取开发者工具 Tool 域基础信息。
|
|
979
|
+
*/
|
|
980
|
+
async toolInfo() {
|
|
981
|
+
return await this.send("Tool.getInfo");
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* @description 触发开发者工具执行一次项目编译。
|
|
985
|
+
*/
|
|
986
|
+
async compile(options = {}) {
|
|
987
|
+
return await this.send("Tool.compile", options);
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* @description 清理开发者工具缓存。
|
|
991
|
+
*/
|
|
992
|
+
async clearCache(options) {
|
|
993
|
+
return await this.send("Tool.clearCache", options);
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* @description 调用开发者工具 Tool 域协议方法。
|
|
997
|
+
*/
|
|
998
|
+
async tool(method, params = {}) {
|
|
999
|
+
return await this.send(`Tool.${method}`, params);
|
|
1000
|
+
}
|
|
967
1001
|
async stopAudits(options = {}) {
|
|
968
1002
|
const result = await this.send("Tool.stopAudits");
|
|
969
1003
|
if (options.path) await fs.writeFile(options.path, result.report, "utf8");
|
|
@@ -984,12 +1018,50 @@ var MiniProgram = class extends EventEmitter {
|
|
|
984
1018
|
}
|
|
985
1019
|
async changeRoute(method, url) {
|
|
986
1020
|
const currentPage = await this.currentPage();
|
|
1021
|
+
logChangeRouteDebug(`start method=${method} url=${url ?? "<none>"} current=${currentPage?.path ?? "<none>"}`);
|
|
987
1022
|
if (currentPage && isPluginPath(currentPage.path)) {
|
|
988
1023
|
const pluginId = extractPluginId(currentPage.path);
|
|
989
1024
|
await this.callPluginWxMethod(pluginId, method, { url });
|
|
990
1025
|
} else await this.callWxMethod(method, { url });
|
|
991
|
-
|
|
992
|
-
|
|
1026
|
+
const expectedRoute = normalizeRoutePath(url);
|
|
1027
|
+
const startedAt = Date.now();
|
|
1028
|
+
let lastPage;
|
|
1029
|
+
let lastError;
|
|
1030
|
+
while (Date.now() - startedAt <= CHANGE_ROUTE_READY_TIMEOUT) {
|
|
1031
|
+
try {
|
|
1032
|
+
const page = await this.currentPage();
|
|
1033
|
+
lastPage = page;
|
|
1034
|
+
logChangeRouteDebug(`poll method=${method} url=${url ?? "<none>"} current=${page?.path ?? "<none>"}`);
|
|
1035
|
+
if (!expectedRoute || normalizeRoutePath(page?.path) === expectedRoute) {
|
|
1036
|
+
logChangeRouteDebug(`ready method=${method} url=${url ?? "<none>"} current=${page?.path ?? "<none>"}`);
|
|
1037
|
+
return page;
|
|
1038
|
+
}
|
|
1039
|
+
} catch (error) {
|
|
1040
|
+
lastError = error;
|
|
1041
|
+
logChangeRouteDebug(`poll-error method=${method} url=${url ?? "<none>"} error=${error instanceof Error ? error.message : String(error)}`);
|
|
1042
|
+
}
|
|
1043
|
+
try {
|
|
1044
|
+
const stackTop = (await this.pageStack()).at(-1);
|
|
1045
|
+
if (stackTop) {
|
|
1046
|
+
lastPage = stackTop;
|
|
1047
|
+
logChangeRouteDebug(`stack method=${method} url=${url ?? "<none>"} current=${stackTop.path}`);
|
|
1048
|
+
if (!expectedRoute || normalizeRoutePath(stackTop.path) === expectedRoute) {
|
|
1049
|
+
logChangeRouteDebug(`stack-ready method=${method} url=${url ?? "<none>"} current=${stackTop.path}`);
|
|
1050
|
+
return stackTop;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
lastError = error;
|
|
1055
|
+
logChangeRouteDebug(`stack-error method=${method} url=${url ?? "<none>"} error=${error instanceof Error ? error.message : String(error)}`);
|
|
1056
|
+
}
|
|
1057
|
+
await sleep(CHANGE_ROUTE_POLL_DELAY);
|
|
1058
|
+
}
|
|
1059
|
+
if (lastPage) {
|
|
1060
|
+
logChangeRouteDebug(`timeout method=${method} url=${url ?? "<none>"} current=${lastPage.path}`);
|
|
1061
|
+
throw new Error(`Timed out waiting route ${expectedRoute || "<current>"} after ${method}; current page: ${lastPage.path}`);
|
|
1062
|
+
}
|
|
1063
|
+
logChangeRouteDebug(`timeout method=${method} url=${url ?? "<none>"} current=<none> error=${lastError instanceof Error ? lastError.message : String(lastError)}`);
|
|
1064
|
+
throw lastError instanceof Error ? lastError : /* @__PURE__ */ new Error(`Timed out waiting route ${expectedRoute || "<current>"} after ${method}`);
|
|
993
1065
|
}
|
|
994
1066
|
async send(method, params = {}) {
|
|
995
1067
|
return await this.connection.send(method, params);
|
package/package.json
CHANGED