@mpcore/simulator 0.0.1 → 0.0.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/README.md +3 -0
- package/dist/index.d.mts +824 -26
- package/dist/index.mjs +1336 -66
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dirname, join, normalize, posix } from "pathe";
|
|
2
2
|
import { parseDocument } from "htmlparser2";
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import process from "node:process";
|
|
@@ -48,25 +49,234 @@ function invokeWxApi(operation, option) {
|
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
function resolveCapabilityValue(source, schema) {
|
|
53
|
+
const segments = schema.split(".").map((segment) => segment.trim()).filter(Boolean);
|
|
54
|
+
let current = source;
|
|
55
|
+
for (const segment of segments) {
|
|
56
|
+
if (current == null || !(segment in current)) return;
|
|
57
|
+
current = current[segment];
|
|
58
|
+
}
|
|
59
|
+
return current;
|
|
60
|
+
}
|
|
51
61
|
function createHeadlessWx(driver) {
|
|
62
|
+
const capabilityTree = {
|
|
63
|
+
canIUse: true,
|
|
64
|
+
clearStorage: true,
|
|
65
|
+
clearStorageSync: true,
|
|
66
|
+
getAppBaseInfo: { return: {
|
|
67
|
+
SDKVersion: true,
|
|
68
|
+
enableDebug: true,
|
|
69
|
+
host: { env: true },
|
|
70
|
+
language: true,
|
|
71
|
+
platform: true,
|
|
72
|
+
version: true
|
|
73
|
+
} },
|
|
74
|
+
getAppBaseInfoSync: { return: {
|
|
75
|
+
SDKVersion: true,
|
|
76
|
+
enableDebug: true,
|
|
77
|
+
host: { env: true },
|
|
78
|
+
language: true,
|
|
79
|
+
platform: true,
|
|
80
|
+
version: true
|
|
81
|
+
} },
|
|
82
|
+
getEnterOptionsSync: { return: {
|
|
83
|
+
path: true,
|
|
84
|
+
query: true,
|
|
85
|
+
referrerInfo: {
|
|
86
|
+
appId: true,
|
|
87
|
+
extraData: true
|
|
88
|
+
},
|
|
89
|
+
scene: true
|
|
90
|
+
} },
|
|
91
|
+
getLaunchOptionsSync: { return: {
|
|
92
|
+
path: true,
|
|
93
|
+
query: true,
|
|
94
|
+
referrerInfo: {
|
|
95
|
+
appId: true,
|
|
96
|
+
extraData: true
|
|
97
|
+
},
|
|
98
|
+
scene: true
|
|
99
|
+
} },
|
|
100
|
+
getMenuButtonBoundingClientRect: { return: {
|
|
101
|
+
bottom: true,
|
|
102
|
+
height: true,
|
|
103
|
+
left: true,
|
|
104
|
+
right: true,
|
|
105
|
+
top: true,
|
|
106
|
+
width: true
|
|
107
|
+
} },
|
|
108
|
+
getNetworkType: { return: { networkType: true } },
|
|
109
|
+
getStorage: true,
|
|
110
|
+
getStorageInfo: { return: {
|
|
111
|
+
currentSize: true,
|
|
112
|
+
keys: true,
|
|
113
|
+
limitSize: true
|
|
114
|
+
} },
|
|
115
|
+
getStorageInfoSync: { return: {
|
|
116
|
+
currentSize: true,
|
|
117
|
+
keys: true,
|
|
118
|
+
limitSize: true
|
|
119
|
+
} },
|
|
120
|
+
getStorageSync: true,
|
|
121
|
+
getSystemInfo: { return: {
|
|
122
|
+
SDKVersion: true,
|
|
123
|
+
brand: true,
|
|
124
|
+
language: true,
|
|
125
|
+
model: true,
|
|
126
|
+
pixelRatio: true,
|
|
127
|
+
platform: true,
|
|
128
|
+
screenHeight: true,
|
|
129
|
+
screenWidth: true,
|
|
130
|
+
system: true,
|
|
131
|
+
version: true,
|
|
132
|
+
windowHeight: true,
|
|
133
|
+
windowWidth: true
|
|
134
|
+
} },
|
|
135
|
+
getSystemInfoSync: { return: {
|
|
136
|
+
SDKVersion: true,
|
|
137
|
+
brand: true,
|
|
138
|
+
language: true,
|
|
139
|
+
model: true,
|
|
140
|
+
pixelRatio: true,
|
|
141
|
+
platform: true,
|
|
142
|
+
screenHeight: true,
|
|
143
|
+
screenWidth: true,
|
|
144
|
+
system: true,
|
|
145
|
+
version: true,
|
|
146
|
+
windowHeight: true,
|
|
147
|
+
windowWidth: true
|
|
148
|
+
} },
|
|
149
|
+
getWindowInfo: { return: {
|
|
150
|
+
pixelRatio: true,
|
|
151
|
+
screenHeight: true,
|
|
152
|
+
screenWidth: true,
|
|
153
|
+
statusBarHeight: true,
|
|
154
|
+
windowHeight: true,
|
|
155
|
+
windowWidth: true
|
|
156
|
+
} },
|
|
157
|
+
getWindowInfoSync: { return: {
|
|
158
|
+
pixelRatio: true,
|
|
159
|
+
screenHeight: true,
|
|
160
|
+
screenWidth: true,
|
|
161
|
+
statusBarHeight: true,
|
|
162
|
+
windowHeight: true,
|
|
163
|
+
windowWidth: true
|
|
164
|
+
} },
|
|
165
|
+
hideLoading: true,
|
|
166
|
+
hideToast: true,
|
|
167
|
+
navigateBack: true,
|
|
168
|
+
navigateTo: true,
|
|
169
|
+
nextTick: true,
|
|
170
|
+
offNetworkStatusChange: true,
|
|
171
|
+
onNetworkStatusChange: true,
|
|
172
|
+
pageScrollTo: true,
|
|
173
|
+
reLaunch: true,
|
|
174
|
+
redirectTo: true,
|
|
175
|
+
removeStorage: true,
|
|
176
|
+
removeStorageSync: true,
|
|
177
|
+
request: true,
|
|
178
|
+
setBackgroundColor: true,
|
|
179
|
+
setBackgroundTextStyle: true,
|
|
180
|
+
setStorage: true,
|
|
181
|
+
setStorageSync: true,
|
|
182
|
+
setNavigationBarColor: true,
|
|
183
|
+
setNavigationBarTitle: true,
|
|
184
|
+
hideShareMenu: true,
|
|
185
|
+
hideNavigationBarLoading: true,
|
|
186
|
+
hideTabBar: true,
|
|
187
|
+
hideTabBarRedDot: true,
|
|
188
|
+
showShareMenu: true,
|
|
189
|
+
showNavigationBarLoading: true,
|
|
190
|
+
showTabBar: true,
|
|
191
|
+
showTabBarRedDot: true,
|
|
192
|
+
showActionSheet: true,
|
|
193
|
+
showLoading: true,
|
|
194
|
+
showModal: true,
|
|
195
|
+
showToast: true,
|
|
196
|
+
stopPullDownRefresh: true,
|
|
197
|
+
switchTab: true,
|
|
198
|
+
removeTabBarBadge: true,
|
|
199
|
+
setTabBarBadge: true,
|
|
200
|
+
updateShareMenu: true
|
|
201
|
+
};
|
|
52
202
|
return {
|
|
203
|
+
canIUse: (schema) => typeof schema === "string" && schema.trim() !== "" && resolveCapabilityValue(capabilityTree, schema.trim()) != null,
|
|
204
|
+
clearStorage: (option) => invokeWxApi(() => {
|
|
205
|
+
driver.clearStorageSync();
|
|
206
|
+
return { errMsg: "clearStorage:ok" };
|
|
207
|
+
}, option),
|
|
53
208
|
clearStorageSync: () => driver.clearStorageSync(),
|
|
209
|
+
getEnterOptionsSync: () => driver.getEnterOptionsSync(),
|
|
210
|
+
getAppBaseInfo: (option) => invokeWxApi(() => driver.getAppBaseInfoSync(), option),
|
|
211
|
+
getAppBaseInfoSync: () => driver.getAppBaseInfoSync(),
|
|
212
|
+
getLaunchOptionsSync: () => driver.getLaunchOptionsSync(),
|
|
213
|
+
getMenuButtonBoundingClientRect: () => driver.getMenuButtonBoundingClientRect(),
|
|
214
|
+
getNetworkType: (option) => invokeWxApi(() => driver.getNetworkType(), option),
|
|
215
|
+
getStorageInfo: (option) => invokeWxApi(() => driver.getStorageInfoSync(), option),
|
|
216
|
+
getStorageInfoSync: () => driver.getStorageInfoSync(),
|
|
217
|
+
getStorage: (option) => invokeWxApi(() => ({
|
|
218
|
+
data: driver.getStorageSync(option.key),
|
|
219
|
+
errMsg: "getStorage:ok"
|
|
220
|
+
}), option),
|
|
54
221
|
getStorageSync: (key) => driver.getStorageSync(key),
|
|
222
|
+
getSystemInfo: (option) => invokeWxApi(() => driver.getSystemInfoSync(), option),
|
|
223
|
+
getSystemInfoSync: () => driver.getSystemInfoSync(),
|
|
224
|
+
getWindowInfo: (option) => invokeWxApi(() => driver.getWindowInfoSync(), option),
|
|
225
|
+
getWindowInfoSync: () => driver.getWindowInfoSync(),
|
|
226
|
+
hideLoading: (option) => invokeWxApi(() => driver.hideLoading(), option),
|
|
55
227
|
hideToast: () => driver.hideToast(),
|
|
56
|
-
navigateBack: (option) => invokeWxApi(() =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
228
|
+
navigateBack: (option) => invokeWxApi(() => {
|
|
229
|
+
driver.navigateBack(option);
|
|
230
|
+
}, option),
|
|
231
|
+
navigateTo: (option) => invokeWxApi(() => {
|
|
232
|
+
driver.navigateTo(option);
|
|
233
|
+
}, option),
|
|
234
|
+
nextTick: (callback) => driver.nextTick(callback),
|
|
235
|
+
offNetworkStatusChange: (callback) => driver.offNetworkStatusChange(callback),
|
|
236
|
+
onNetworkStatusChange: (callback) => driver.onNetworkStatusChange(callback),
|
|
237
|
+
pageScrollTo: (option) => invokeWxApi(() => {
|
|
238
|
+
driver.pageScrollTo(option);
|
|
239
|
+
}, option),
|
|
240
|
+
reLaunch: (option) => invokeWxApi(() => {
|
|
241
|
+
driver.reLaunch(option);
|
|
242
|
+
}, option),
|
|
243
|
+
redirectTo: (option) => invokeWxApi(() => {
|
|
244
|
+
driver.redirectTo(option);
|
|
245
|
+
}, option),
|
|
246
|
+
removeStorage: (option) => invokeWxApi(() => {
|
|
247
|
+
driver.removeStorageSync(option.key);
|
|
248
|
+
return { errMsg: "removeStorage:ok" };
|
|
249
|
+
}, option),
|
|
61
250
|
removeStorageSync: (key) => driver.removeStorageSync(key),
|
|
62
|
-
request: (option) =>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
251
|
+
request: (option) => driver.request(option),
|
|
252
|
+
setBackgroundColor: (option) => invokeWxApi(() => driver.setBackgroundColor(option), option),
|
|
253
|
+
setBackgroundTextStyle: (option) => invokeWxApi(() => driver.setBackgroundTextStyle(option), option),
|
|
254
|
+
setStorage: (option) => invokeWxApi(() => {
|
|
255
|
+
driver.setStorageSync(option.key, option.data);
|
|
256
|
+
return { errMsg: "setStorage:ok" };
|
|
257
|
+
}, option),
|
|
66
258
|
setStorageSync: (key, value) => driver.setStorageSync(key, value),
|
|
259
|
+
setNavigationBarColor: (option) => invokeWxApi(() => driver.setNavigationBarColor(option), option),
|
|
260
|
+
setNavigationBarTitle: (option) => invokeWxApi(() => driver.setNavigationBarTitle(option), option),
|
|
261
|
+
hideShareMenu: (option) => invokeWxApi(() => driver.hideShareMenu(), option),
|
|
262
|
+
hideNavigationBarLoading: (option) => invokeWxApi(() => driver.hideNavigationBarLoading(), option),
|
|
263
|
+
hideTabBar: (option) => invokeWxApi(() => driver.hideTabBar(), option),
|
|
264
|
+
hideTabBarRedDot: (option) => invokeWxApi(() => driver.hideTabBarRedDot(option), option),
|
|
265
|
+
showShareMenu: (option) => invokeWxApi(() => driver.showShareMenu(option ?? {}), option),
|
|
266
|
+
showNavigationBarLoading: (option) => invokeWxApi(() => driver.showNavigationBarLoading(), option),
|
|
267
|
+
showTabBar: (option) => invokeWxApi(() => driver.showTabBar(), option),
|
|
268
|
+
showTabBarRedDot: (option) => invokeWxApi(() => driver.showTabBarRedDot(option), option),
|
|
269
|
+
showActionSheet: (option) => invokeWxApi(() => driver.showActionSheet(option), option),
|
|
270
|
+
showLoading: (option) => invokeWxApi(() => driver.showLoading(option), option),
|
|
271
|
+
showModal: (option) => invokeWxApi(() => driver.showModal(option), option),
|
|
67
272
|
showToast: (option) => invokeWxApi(() => driver.showToast(option), option),
|
|
68
273
|
stopPullDownRefresh: () => driver.stopPullDownRefresh(),
|
|
69
|
-
switchTab: (option) => invokeWxApi(() =>
|
|
274
|
+
switchTab: (option) => invokeWxApi(() => {
|
|
275
|
+
driver.switchTab(option);
|
|
276
|
+
}, option),
|
|
277
|
+
removeTabBarBadge: (option) => invokeWxApi(() => driver.removeTabBarBadge(option), option),
|
|
278
|
+
setTabBarBadge: (option) => invokeWxApi(() => driver.setTabBarBadge(option), option),
|
|
279
|
+
updateShareMenu: (option) => invokeWxApi(() => driver.updateShareMenu(option ?? {}), option)
|
|
70
280
|
};
|
|
71
281
|
}
|
|
72
282
|
//#endregion
|
|
@@ -197,11 +407,11 @@ function createBrowserModuleLoader(files, registries, getCurrentPages, getApp, w
|
|
|
197
407
|
}
|
|
198
408
|
//#endregion
|
|
199
409
|
//#region src/project/resolveRoutes.ts
|
|
200
|
-
const LEADING_SLASH_RE$
|
|
410
|
+
const LEADING_SLASH_RE$5 = /^\/+/;
|
|
201
411
|
const TRAILING_SLASH_RE = /\/+$/;
|
|
202
412
|
const DUPLICATE_SLASH_RE = /\/{2,}/g;
|
|
203
413
|
function normalizeSegment(value) {
|
|
204
|
-
return value.replace(LEADING_SLASH_RE$
|
|
414
|
+
return value.replace(LEADING_SLASH_RE$5, "").replace(TRAILING_SLASH_RE, "");
|
|
205
415
|
}
|
|
206
416
|
function pushRoute(records, seen, record) {
|
|
207
417
|
if (!record.route || seen.has(record.route)) return;
|
|
@@ -255,7 +465,7 @@ function createProjectDescriptor(options) {
|
|
|
255
465
|
}
|
|
256
466
|
//#endregion
|
|
257
467
|
//#region src/browser/project.ts
|
|
258
|
-
function readJsonObject$
|
|
468
|
+
function readJsonObject$3(files, filePath) {
|
|
259
469
|
const content = readBrowserVirtualFile(files, filePath);
|
|
260
470
|
if (!content) return;
|
|
261
471
|
try {
|
|
@@ -268,7 +478,7 @@ function readJsonObject$1(files, filePath) {
|
|
|
268
478
|
function createBrowserProject(files, options = {}) {
|
|
269
479
|
const appConfigPath = options.appConfigPath ?? "app.json";
|
|
270
480
|
if (!hasBrowserVirtualFile(files, appConfigPath)) throw new Error(`Missing built app.json for browser simulator project: ${appConfigPath}`);
|
|
271
|
-
const appConfig = readJsonObject$
|
|
481
|
+
const appConfig = readJsonObject$3(files, appConfigPath);
|
|
272
482
|
if (!appConfig) throw new Error(`Failed to read built app.json for browser simulator project: ${appConfigPath}`);
|
|
273
483
|
return createProjectDescriptor({
|
|
274
484
|
appConfig,
|
|
@@ -547,7 +757,7 @@ function runComponentPageLifetime(instance, lifetimeName, payload) {
|
|
|
547
757
|
}
|
|
548
758
|
//#endregion
|
|
549
759
|
//#region src/browser/render.ts
|
|
550
|
-
const LEADING_SLASH_RE$
|
|
760
|
+
const LEADING_SLASH_RE$4 = /^\/+/;
|
|
551
761
|
const TEMPLATE_INTERPOLATION_RE$1 = /\{\{([^{}]+)\}\}/g;
|
|
552
762
|
const EVENT_BINDING_ATTRS = [
|
|
553
763
|
"bindtap",
|
|
@@ -571,7 +781,7 @@ const STRUCTURAL_ATTRS = [
|
|
|
571
781
|
"wx:key"
|
|
572
782
|
];
|
|
573
783
|
const WX_ELSE_ATTRS = new Set(["wx:elif", "wx:else"]);
|
|
574
|
-
const DATASET_NAME_RE = /-([a-z])/g;
|
|
784
|
+
const DATASET_NAME_RE$1 = /-([a-z])/g;
|
|
575
785
|
const BRACKET_INDEX_RE = /\[(\d+)\]/g;
|
|
576
786
|
const CLASS_SPLIT_RE = /\s+/;
|
|
577
787
|
const JS_FILE_RE = /\.js$/;
|
|
@@ -579,14 +789,14 @@ function isMustacheOnly(value) {
|
|
|
579
789
|
const trimmed = value.trim();
|
|
580
790
|
return trimmed.startsWith("{{") && trimmed.endsWith("}}") && !trimmed.includes("{{", 2);
|
|
581
791
|
}
|
|
582
|
-
function toDatasetKey(attributeName) {
|
|
583
|
-
return attributeName.slice(5).replace(DATASET_NAME_RE, (_match, char) => char.toUpperCase());
|
|
792
|
+
function toDatasetKey$1(attributeName) {
|
|
793
|
+
return attributeName.slice(5).replace(DATASET_NAME_RE$1, (_match, char) => char.toUpperCase());
|
|
584
794
|
}
|
|
585
|
-
function collectDataset(node) {
|
|
795
|
+
function collectDataset$1(node) {
|
|
586
796
|
const dataset = {};
|
|
587
797
|
for (const [key, value] of Object.entries(node.attribs ?? {})) {
|
|
588
798
|
if (!key.startsWith("data-") || key === "data-sim-scope" || key === "data-sim-tap" || key === "data-sim-component") continue;
|
|
589
|
-
dataset[toDatasetKey(key)] = String(value);
|
|
799
|
+
dataset[toDatasetKey$1(key)] = String(value);
|
|
590
800
|
}
|
|
591
801
|
return dataset;
|
|
592
802
|
}
|
|
@@ -691,8 +901,8 @@ function resolveUsingComponents(files, ownerJsonPath, ownerFilePath) {
|
|
|
691
901
|
const resolved = /* @__PURE__ */ new Map();
|
|
692
902
|
for (const [alias, rawPath] of Object.entries(usingComponents)) {
|
|
693
903
|
if (typeof rawPath !== "string") continue;
|
|
694
|
-
const basePath = rawPath.startsWith("/") ? rawPath.replace(LEADING_SLASH_RE$
|
|
695
|
-
resolved.set(alias, basePath.replace(LEADING_SLASH_RE$
|
|
904
|
+
const basePath = rawPath.startsWith("/") ? rawPath.replace(LEADING_SLASH_RE$4, "") : normalize(join(dirname(ownerFilePath), rawPath));
|
|
905
|
+
resolved.set(alias, basePath.replace(LEADING_SLASH_RE$4, ""));
|
|
696
906
|
}
|
|
697
907
|
return resolved;
|
|
698
908
|
} catch {
|
|
@@ -725,7 +935,7 @@ function collectComponentEventBindings(hostNode) {
|
|
|
725
935
|
return eventBindings;
|
|
726
936
|
}
|
|
727
937
|
function buildComponentTrigger(componentScopeId, context, hostNode) {
|
|
728
|
-
const hostDataset = collectDataset(hostNode);
|
|
938
|
+
const hostDataset = collectDataset$1(hostNode);
|
|
729
939
|
const hostId = hostNode.attribs?.id ?? "";
|
|
730
940
|
return (instance, eventName, detail, triggerOptions) => {
|
|
731
941
|
const interactionTarget = instance.__lastInteractionEvent__?.target;
|
|
@@ -920,7 +1130,7 @@ function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, inst
|
|
|
920
1130
|
alias: clonedNode.name,
|
|
921
1131
|
classList: String(clonedNode.attribs?.class ?? "").split(CLASS_SPLIT_RE).map((item) => item.trim()).filter(Boolean),
|
|
922
1132
|
data: createMergedScopeData(scope.data, componentInstance.properties, componentInstance.data),
|
|
923
|
-
dataset: collectDataset(clonedNode),
|
|
1133
|
+
dataset: collectDataset$1(clonedNode),
|
|
924
1134
|
eventBindings: collectComponentEventBindings(clonedNode),
|
|
925
1135
|
getMethod: (methodName) => {
|
|
926
1136
|
const method = componentInstance?.[methodName];
|
|
@@ -947,7 +1157,7 @@ function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, inst
|
|
|
947
1157
|
return clonedNode;
|
|
948
1158
|
}
|
|
949
1159
|
function renderBrowserPageTree(context, page) {
|
|
950
|
-
const route = page.route.replace(LEADING_SLASH_RE$
|
|
1160
|
+
const route = page.route.replace(LEADING_SLASH_RE$4, "");
|
|
951
1161
|
const templatePath = join(context.project.miniprogramRootPath, `${route}.wxml`);
|
|
952
1162
|
const document = parseTemplateDocument(readTemplateSource(context.files, templatePath));
|
|
953
1163
|
const pageScopeId = `page:${route}`;
|
|
@@ -975,6 +1185,69 @@ function renderBrowserPageTree(context, page) {
|
|
|
975
1185
|
};
|
|
976
1186
|
}
|
|
977
1187
|
//#endregion
|
|
1188
|
+
//#region src/project/pageConfig.ts
|
|
1189
|
+
const DEFAULT_NAVIGATION_BAR_BACKGROUND_COLOR = "#ffffff";
|
|
1190
|
+
const DEFAULT_NAVIGATION_BAR_FRONT_COLOR = "#000000";
|
|
1191
|
+
const DEFAULT_NAVIGATION_BAR_FRONT_COLOR_WHITE = "#ffffff";
|
|
1192
|
+
const DEFAULT_BACKGROUND_TEXT_STYLE = "dark";
|
|
1193
|
+
const DEFAULT_BACKGROUND_COLOR = "#ffffff";
|
|
1194
|
+
function resolveNavigationBarTitle(appConfig, pageConfig) {
|
|
1195
|
+
if (typeof pageConfig?.navigationBarTitleText === "string") return pageConfig.navigationBarTitleText;
|
|
1196
|
+
if (typeof appConfig.window?.navigationBarTitleText === "string") return appConfig.window.navigationBarTitleText;
|
|
1197
|
+
return "";
|
|
1198
|
+
}
|
|
1199
|
+
function resolveNavigationBarBackgroundColor(appConfig, pageConfig) {
|
|
1200
|
+
if (typeof pageConfig?.navigationBarBackgroundColor === "string") return pageConfig.navigationBarBackgroundColor;
|
|
1201
|
+
if (typeof appConfig.window?.navigationBarBackgroundColor === "string") return appConfig.window.navigationBarBackgroundColor;
|
|
1202
|
+
return DEFAULT_NAVIGATION_BAR_BACKGROUND_COLOR;
|
|
1203
|
+
}
|
|
1204
|
+
function resolveNavigationBarFrontColor(appConfig, pageConfig) {
|
|
1205
|
+
if ((typeof pageConfig?.navigationBarTextStyle === "string" ? pageConfig.navigationBarTextStyle : typeof appConfig.window?.navigationBarTextStyle === "string" ? appConfig.window.navigationBarTextStyle : void 0) === "white") return DEFAULT_NAVIGATION_BAR_FRONT_COLOR_WHITE;
|
|
1206
|
+
return DEFAULT_NAVIGATION_BAR_FRONT_COLOR;
|
|
1207
|
+
}
|
|
1208
|
+
function cloneNavigationBarSnapshot(snapshot) {
|
|
1209
|
+
return {
|
|
1210
|
+
animation: snapshot.animation ? { ...snapshot.animation } : null,
|
|
1211
|
+
backgroundColor: snapshot.backgroundColor,
|
|
1212
|
+
frontColor: snapshot.frontColor,
|
|
1213
|
+
loading: snapshot.loading,
|
|
1214
|
+
title: snapshot.title
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
function resolveNavigationBarSnapshot(appConfig, pageConfig) {
|
|
1218
|
+
return {
|
|
1219
|
+
animation: null,
|
|
1220
|
+
backgroundColor: resolveNavigationBarBackgroundColor(appConfig, pageConfig),
|
|
1221
|
+
frontColor: resolveNavigationBarFrontColor(appConfig, pageConfig),
|
|
1222
|
+
loading: false,
|
|
1223
|
+
title: resolveNavigationBarTitle(appConfig, pageConfig)
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
function resolveBackgroundTextStyle(appConfig, pageConfig) {
|
|
1227
|
+
return (typeof pageConfig?.backgroundTextStyle === "string" ? pageConfig.backgroundTextStyle : typeof appConfig.window?.backgroundTextStyle === "string" ? appConfig.window.backgroundTextStyle : void 0) === "light" ? "light" : DEFAULT_BACKGROUND_TEXT_STYLE;
|
|
1228
|
+
}
|
|
1229
|
+
function resolveBackgroundColorValue(appConfig, pageConfig, key) {
|
|
1230
|
+
if (typeof pageConfig?.[key] === "string") return pageConfig[key];
|
|
1231
|
+
if (typeof appConfig.window?.[key] === "string") return appConfig.window[key];
|
|
1232
|
+
return DEFAULT_BACKGROUND_COLOR;
|
|
1233
|
+
}
|
|
1234
|
+
function cloneBackgroundSnapshot(snapshot) {
|
|
1235
|
+
return {
|
|
1236
|
+
backgroundColor: snapshot.backgroundColor,
|
|
1237
|
+
backgroundColorBottom: snapshot.backgroundColorBottom,
|
|
1238
|
+
backgroundColorTop: snapshot.backgroundColorTop,
|
|
1239
|
+
textStyle: snapshot.textStyle
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
function resolveBackgroundSnapshot(appConfig, pageConfig) {
|
|
1243
|
+
return {
|
|
1244
|
+
backgroundColor: resolveBackgroundColorValue(appConfig, pageConfig, "backgroundColor"),
|
|
1245
|
+
backgroundColorBottom: resolveBackgroundColorValue(appConfig, pageConfig, "backgroundColorBottom"),
|
|
1246
|
+
backgroundColorTop: resolveBackgroundColorValue(appConfig, pageConfig, "backgroundColorTop"),
|
|
1247
|
+
textStyle: resolveBackgroundTextStyle(appConfig, pageConfig)
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
//#endregion
|
|
978
1251
|
//#region src/runtime/appInstance.ts
|
|
979
1252
|
function bindFunction$1(target, key, value) {
|
|
980
1253
|
if (typeof value !== "function") {
|
|
@@ -1001,6 +1274,9 @@ function createAppInstance(definition) {
|
|
|
1001
1274
|
}
|
|
1002
1275
|
//#endregion
|
|
1003
1276
|
//#region src/runtime/pageInstance.ts
|
|
1277
|
+
const ARRAY_INDEX_PATH_RE = /\[(\d+)\]/g;
|
|
1278
|
+
const ARRAY_INDEX_SEGMENT_RE = /^\d+$/;
|
|
1279
|
+
const LEADING_ROUTE_SLASH_RE = /^\/+/;
|
|
1004
1280
|
function bindFunction(target, key, value) {
|
|
1005
1281
|
if (typeof value !== "function") {
|
|
1006
1282
|
target[key] = value;
|
|
@@ -1020,10 +1296,10 @@ function resolveInitialData(definition) {
|
|
|
1020
1296
|
return rawData && typeof rawData === "object" && !Array.isArray(rawData) ? cloneObject(rawData) : {};
|
|
1021
1297
|
}
|
|
1022
1298
|
function parseDataPath(path) {
|
|
1023
|
-
return path.replace(
|
|
1299
|
+
return path.replace(ARRAY_INDEX_PATH_RE, ".$1").split(".").map((segment) => segment.trim()).filter(Boolean);
|
|
1024
1300
|
}
|
|
1025
1301
|
function isArrayIndexSegment(segment) {
|
|
1026
|
-
return
|
|
1302
|
+
return ARRAY_INDEX_SEGMENT_RE.test(segment);
|
|
1027
1303
|
}
|
|
1028
1304
|
function createContainerByNextSegment(nextSegment) {
|
|
1029
1305
|
return isArrayIndexSegment(nextSegment ?? "") ? [] : {};
|
|
@@ -1040,17 +1316,21 @@ function assignByPath(target, path, value) {
|
|
|
1040
1316
|
if (!next || typeof next !== "object") current[normalizedSegment] = createContainerByNextSegment(nextSegment);
|
|
1041
1317
|
current = current[normalizedSegment];
|
|
1042
1318
|
}
|
|
1043
|
-
const leafSegment = segments
|
|
1319
|
+
const leafSegment = segments.at(-1);
|
|
1044
1320
|
const normalizedLeafSegment = isArrayIndexSegment(leafSegment) ? Number(leafSegment) : leafSegment;
|
|
1045
1321
|
current[normalizedLeafSegment] = value;
|
|
1046
1322
|
}
|
|
1047
|
-
function normalizeRoute(route) {
|
|
1048
|
-
return route.replace(
|
|
1323
|
+
function normalizeRoute$1(route) {
|
|
1324
|
+
return route.replace(LEADING_ROUTE_SLASH_RE, "");
|
|
1049
1325
|
}
|
|
1050
|
-
function createPageInstance(route, definition, options = {}) {
|
|
1051
|
-
const normalizedRoute = normalizeRoute(route);
|
|
1326
|
+
function createPageInstance(route, definition, options = {}, pageState = {}) {
|
|
1327
|
+
const normalizedRoute = normalizeRoute$1(route);
|
|
1052
1328
|
const instance = {
|
|
1329
|
+
__background__: pageState.background ? cloneBackgroundSnapshot(pageState.background) : void 0,
|
|
1330
|
+
__backgroundTextStyle__: pageState.background?.textStyle ?? pageState.backgroundTextStyle,
|
|
1053
1331
|
__route__: normalizedRoute,
|
|
1332
|
+
__navigationBar__: pageState.navigationBar ? cloneNavigationBarSnapshot(pageState.navigationBar) : void 0,
|
|
1333
|
+
__navigationBarTitle__: pageState.navigationBar?.title,
|
|
1054
1334
|
data: resolveInitialData(definition),
|
|
1055
1335
|
options: { ...options },
|
|
1056
1336
|
route: normalizedRoute,
|
|
@@ -1067,7 +1347,93 @@ function createPageInstance(route, definition, options = {}) {
|
|
|
1067
1347
|
return instance;
|
|
1068
1348
|
}
|
|
1069
1349
|
//#endregion
|
|
1350
|
+
//#region src/runtime/systemInfo.ts
|
|
1351
|
+
function createDefaultSystemInfo() {
|
|
1352
|
+
return {
|
|
1353
|
+
SDKVersion: "0.0.0",
|
|
1354
|
+
brand: "devtools",
|
|
1355
|
+
language: "zh_CN",
|
|
1356
|
+
model: "headless-simulator",
|
|
1357
|
+
pixelRatio: 2,
|
|
1358
|
+
platform: "devtools",
|
|
1359
|
+
screenHeight: 667,
|
|
1360
|
+
screenWidth: 375,
|
|
1361
|
+
system: "iOS 0.0.0",
|
|
1362
|
+
version: "0.0.0",
|
|
1363
|
+
windowHeight: 667,
|
|
1364
|
+
windowWidth: 375
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
function applyResizeToSystemInfo(systemInfo, options) {
|
|
1368
|
+
const size = options?.size;
|
|
1369
|
+
const nextWindowWidth = Number(size?.windowWidth);
|
|
1370
|
+
const nextWindowHeight = Number(size?.windowHeight);
|
|
1371
|
+
if (Number.isFinite(nextWindowWidth) && nextWindowWidth > 0) {
|
|
1372
|
+
systemInfo.windowWidth = nextWindowWidth;
|
|
1373
|
+
systemInfo.screenWidth = nextWindowWidth;
|
|
1374
|
+
}
|
|
1375
|
+
if (Number.isFinite(nextWindowHeight) && nextWindowHeight > 0) {
|
|
1376
|
+
systemInfo.windowHeight = nextWindowHeight;
|
|
1377
|
+
systemInfo.screenHeight = nextWindowHeight;
|
|
1378
|
+
}
|
|
1379
|
+
return systemInfo;
|
|
1380
|
+
}
|
|
1381
|
+
function deriveWindowInfo(systemInfo) {
|
|
1382
|
+
return {
|
|
1383
|
+
pixelRatio: systemInfo.pixelRatio,
|
|
1384
|
+
screenHeight: systemInfo.screenHeight,
|
|
1385
|
+
screenWidth: systemInfo.screenWidth,
|
|
1386
|
+
statusBarHeight: 20,
|
|
1387
|
+
windowHeight: systemInfo.windowHeight,
|
|
1388
|
+
windowWidth: systemInfo.windowWidth
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
function deriveAppBaseInfo(systemInfo) {
|
|
1392
|
+
return {
|
|
1393
|
+
SDKVersion: systemInfo.SDKVersion,
|
|
1394
|
+
enableDebug: false,
|
|
1395
|
+
host: { env: systemInfo.platform },
|
|
1396
|
+
language: systemInfo.language,
|
|
1397
|
+
platform: systemInfo.platform,
|
|
1398
|
+
version: systemInfo.version
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
function deriveMenuButtonBoundingClientRect(systemInfo) {
|
|
1402
|
+
const width = 87;
|
|
1403
|
+
const height = 32;
|
|
1404
|
+
const top = 32;
|
|
1405
|
+
const right = Math.max(systemInfo.windowWidth - 12, width);
|
|
1406
|
+
const left = Math.max(0, right - width);
|
|
1407
|
+
return {
|
|
1408
|
+
bottom: top + height,
|
|
1409
|
+
height,
|
|
1410
|
+
left,
|
|
1411
|
+
right,
|
|
1412
|
+
top,
|
|
1413
|
+
width
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
//#endregion
|
|
1070
1417
|
//#region src/runtime/wxState.ts
|
|
1418
|
+
const STORAGE_LIMIT_SIZE = 10 * 1024;
|
|
1419
|
+
const DEFAULT_MODAL_CANCEL_COLOR = "#000000";
|
|
1420
|
+
const DEFAULT_MODAL_CANCEL_TEXT = "取消";
|
|
1421
|
+
const DEFAULT_MODAL_CONFIRM_COLOR = "#576B95";
|
|
1422
|
+
const DEFAULT_MODAL_CONFIRM_TEXT = "确定";
|
|
1423
|
+
function cloneShareMenuSnapshot(snapshot) {
|
|
1424
|
+
return {
|
|
1425
|
+
isUpdatableMessage: snapshot.isUpdatableMessage,
|
|
1426
|
+
menus: [...snapshot.menus],
|
|
1427
|
+
visible: snapshot.visible,
|
|
1428
|
+
withShareTicket: snapshot.withShareTicket
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
function createNetworkSnapshot(networkType) {
|
|
1432
|
+
return {
|
|
1433
|
+
isConnected: networkType !== "none",
|
|
1434
|
+
networkType
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1071
1437
|
function cloneValue$1(value) {
|
|
1072
1438
|
if (value == null || typeof value !== "object") return value;
|
|
1073
1439
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -1104,14 +1470,46 @@ function resolveRequestResponse(mock, option) {
|
|
|
1104
1470
|
};
|
|
1105
1471
|
}
|
|
1106
1472
|
function createHeadlessWxState() {
|
|
1473
|
+
const actionSheetLogs = [];
|
|
1474
|
+
const actionSheetMocks = [];
|
|
1475
|
+
const modalLogs = [];
|
|
1476
|
+
const networkStatusChangeCallbacks = /* @__PURE__ */ new Set();
|
|
1477
|
+
const modalMocks = [];
|
|
1107
1478
|
const requestLogs = [];
|
|
1108
1479
|
const requestMocks = [];
|
|
1109
1480
|
const storage = /* @__PURE__ */ new Map();
|
|
1481
|
+
let loading = null;
|
|
1482
|
+
let networkType = "wifi";
|
|
1483
|
+
let shareMenu = {
|
|
1484
|
+
isUpdatableMessage: false,
|
|
1485
|
+
menus: [],
|
|
1486
|
+
visible: false,
|
|
1487
|
+
withShareTicket: false
|
|
1488
|
+
};
|
|
1110
1489
|
let toast = null;
|
|
1111
1490
|
return {
|
|
1112
1491
|
clearStorageSync() {
|
|
1113
1492
|
storage.clear();
|
|
1114
1493
|
},
|
|
1494
|
+
getActionSheetLogs() {
|
|
1495
|
+
return actionSheetLogs.map((entry) => ({
|
|
1496
|
+
...entry,
|
|
1497
|
+
itemList: [...entry.itemList],
|
|
1498
|
+
result: entry.result ? { ...entry.result } : void 0
|
|
1499
|
+
}));
|
|
1500
|
+
},
|
|
1501
|
+
getNetworkType() {
|
|
1502
|
+
return {
|
|
1503
|
+
errMsg: "getNetworkType:ok",
|
|
1504
|
+
networkType
|
|
1505
|
+
};
|
|
1506
|
+
},
|
|
1507
|
+
getModalLogs() {
|
|
1508
|
+
return modalLogs.map((entry) => ({
|
|
1509
|
+
...entry,
|
|
1510
|
+
result: { ...entry.result }
|
|
1511
|
+
}));
|
|
1512
|
+
},
|
|
1115
1513
|
getRequestLogs() {
|
|
1116
1514
|
return requestLogs.map((entry) => ({
|
|
1117
1515
|
...entry,
|
|
@@ -1125,25 +1523,77 @@ function createHeadlessWxState() {
|
|
|
1125
1523
|
} : void 0
|
|
1126
1524
|
}));
|
|
1127
1525
|
},
|
|
1526
|
+
getStorageInfoSync() {
|
|
1527
|
+
const keys = Array.from(storage.keys()).sort((a, b) => a.localeCompare(b));
|
|
1528
|
+
const totalBytes = Array.from(storage.entries()).reduce((sum, [key, value]) => {
|
|
1529
|
+
return sum + Buffer.byteLength(JSON.stringify([key, value]));
|
|
1530
|
+
}, 0);
|
|
1531
|
+
return {
|
|
1532
|
+
currentSize: Math.ceil(totalBytes / 1024),
|
|
1533
|
+
errMsg: "getStorageInfo:ok",
|
|
1534
|
+
keys,
|
|
1535
|
+
limitSize: STORAGE_LIMIT_SIZE
|
|
1536
|
+
};
|
|
1537
|
+
},
|
|
1128
1538
|
getStorageSnapshot() {
|
|
1129
1539
|
return Object.fromEntries(Array.from(storage.entries(), ([key, value]) => [key, cloneValue$1(value)]));
|
|
1130
1540
|
},
|
|
1131
1541
|
getStorageSync(key) {
|
|
1132
1542
|
return cloneValue$1(storage.get(key));
|
|
1133
1543
|
},
|
|
1544
|
+
getShareMenu() {
|
|
1545
|
+
return cloneShareMenuSnapshot(shareMenu);
|
|
1546
|
+
},
|
|
1547
|
+
getLoading() {
|
|
1548
|
+
return loading ? { ...loading } : null;
|
|
1549
|
+
},
|
|
1550
|
+
hideShareMenu() {
|
|
1551
|
+
shareMenu = {
|
|
1552
|
+
...shareMenu,
|
|
1553
|
+
visible: false
|
|
1554
|
+
};
|
|
1555
|
+
return { errMsg: "hideShareMenu:ok" };
|
|
1556
|
+
},
|
|
1134
1557
|
getToast() {
|
|
1135
1558
|
return toast ? { ...toast } : null;
|
|
1136
1559
|
},
|
|
1560
|
+
hideLoading() {
|
|
1561
|
+
loading = null;
|
|
1562
|
+
return { errMsg: "hideLoading:ok" };
|
|
1563
|
+
},
|
|
1137
1564
|
hideToast() {
|
|
1138
1565
|
toast = null;
|
|
1139
1566
|
return { errMsg: "hideToast:ok" };
|
|
1140
1567
|
},
|
|
1568
|
+
offNetworkStatusChange(callback) {
|
|
1569
|
+
if (!callback) {
|
|
1570
|
+
networkStatusChangeCallbacks.clear();
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
networkStatusChangeCallbacks.delete(callback);
|
|
1574
|
+
},
|
|
1141
1575
|
mockRequest(definition) {
|
|
1142
1576
|
requestMocks.push({
|
|
1143
1577
|
...definition,
|
|
1578
|
+
delay: definition.delay,
|
|
1144
1579
|
header: definition.header ? { ...definition.header } : void 0
|
|
1145
1580
|
});
|
|
1146
1581
|
},
|
|
1582
|
+
mockModal(definition = {}) {
|
|
1583
|
+
modalMocks.push({
|
|
1584
|
+
cancel: definition.cancel,
|
|
1585
|
+
confirm: definition.confirm
|
|
1586
|
+
});
|
|
1587
|
+
},
|
|
1588
|
+
mockActionSheet(definition = {}) {
|
|
1589
|
+
actionSheetMocks.push({
|
|
1590
|
+
cancel: definition.cancel,
|
|
1591
|
+
tapIndex: definition.tapIndex
|
|
1592
|
+
});
|
|
1593
|
+
},
|
|
1594
|
+
onNetworkStatusChange(callback) {
|
|
1595
|
+
networkStatusChangeCallbacks.add(callback);
|
|
1596
|
+
},
|
|
1147
1597
|
removeStorageSync(key) {
|
|
1148
1598
|
storage.delete(key);
|
|
1149
1599
|
},
|
|
@@ -1158,22 +1608,119 @@ function createHeadlessWxState() {
|
|
|
1158
1608
|
url: option.url
|
|
1159
1609
|
};
|
|
1160
1610
|
requestLogs.push(logEntry);
|
|
1161
|
-
|
|
1611
|
+
const error = /* @__PURE__ */ new Error(`No request mock matched in headless runtime: ${normalizeMethod(option.method)} ${option.url}`);
|
|
1612
|
+
option.fail?.(error);
|
|
1613
|
+
option.complete?.();
|
|
1614
|
+
return { abort() {} };
|
|
1162
1615
|
}
|
|
1163
1616
|
const response = resolveRequestResponse(matchedMock, option);
|
|
1164
|
-
|
|
1617
|
+
const requestLogEntry = {
|
|
1165
1618
|
data: cloneValue$1(option.data),
|
|
1166
1619
|
header: { ...option.header ?? {} },
|
|
1167
1620
|
matched: true,
|
|
1168
1621
|
method: normalizeMethod(option.method),
|
|
1169
1622
|
response,
|
|
1170
1623
|
url: option.url
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1624
|
+
};
|
|
1625
|
+
const delay = Number.isFinite(matchedMock.delay) ? Math.max(0, Math.trunc(matchedMock.delay ?? 0)) : 0;
|
|
1626
|
+
if (delay <= 0) {
|
|
1627
|
+
requestLogs.push(requestLogEntry);
|
|
1628
|
+
option.success?.(response);
|
|
1629
|
+
option.complete?.(response);
|
|
1630
|
+
return { abort() {} };
|
|
1631
|
+
}
|
|
1632
|
+
let completed = false;
|
|
1633
|
+
const timer = setTimeout(() => {
|
|
1634
|
+
if (completed) return;
|
|
1635
|
+
completed = true;
|
|
1636
|
+
requestLogs.push(requestLogEntry);
|
|
1637
|
+
option.success?.(response);
|
|
1638
|
+
option.complete?.(response);
|
|
1639
|
+
}, delay);
|
|
1640
|
+
return { abort() {
|
|
1641
|
+
if (completed) return;
|
|
1642
|
+
completed = true;
|
|
1643
|
+
clearTimeout(timer);
|
|
1644
|
+
const error = /* @__PURE__ */ new Error("request:fail abort");
|
|
1645
|
+
option.fail?.(error);
|
|
1646
|
+
option.complete?.();
|
|
1647
|
+
} };
|
|
1173
1648
|
},
|
|
1174
1649
|
setStorageSync(key, value) {
|
|
1175
1650
|
storage.set(key, cloneValue$1(value));
|
|
1176
1651
|
},
|
|
1652
|
+
setNetworkType(nextNetworkType) {
|
|
1653
|
+
networkType = nextNetworkType;
|
|
1654
|
+
const snapshot = createNetworkSnapshot(networkType);
|
|
1655
|
+
networkStatusChangeCallbacks.forEach((callback) => callback({ ...snapshot }));
|
|
1656
|
+
return {
|
|
1657
|
+
errMsg: "getNetworkType:ok",
|
|
1658
|
+
networkType
|
|
1659
|
+
};
|
|
1660
|
+
},
|
|
1661
|
+
showActionSheet(option) {
|
|
1662
|
+
const itemList = Array.isArray(option.itemList) ? option.itemList.filter((item) => typeof item === "string") : [];
|
|
1663
|
+
if (itemList.length === 0) throw new Error("showActionSheet:fail invalid itemList");
|
|
1664
|
+
const nextMock = actionSheetMocks.shift();
|
|
1665
|
+
if (nextMock?.cancel) {
|
|
1666
|
+
actionSheetLogs.push({ itemList: [...itemList] });
|
|
1667
|
+
throw new Error("showActionSheet:fail cancel");
|
|
1668
|
+
}
|
|
1669
|
+
const tapIndex = Number.isInteger(nextMock?.tapIndex) ? Number(nextMock?.tapIndex) : 0;
|
|
1670
|
+
if (tapIndex < 0 || tapIndex >= itemList.length) throw new Error("showActionSheet:fail invalid tapIndex");
|
|
1671
|
+
const result = {
|
|
1672
|
+
errMsg: "showActionSheet:ok",
|
|
1673
|
+
tapIndex
|
|
1674
|
+
};
|
|
1675
|
+
actionSheetLogs.push({
|
|
1676
|
+
itemList: [...itemList],
|
|
1677
|
+
result: { ...result }
|
|
1678
|
+
});
|
|
1679
|
+
return result;
|
|
1680
|
+
},
|
|
1681
|
+
showShareMenu(option = {}) {
|
|
1682
|
+
shareMenu = {
|
|
1683
|
+
isUpdatableMessage: Boolean(option.isUpdatableMessage),
|
|
1684
|
+
menus: Array.isArray(option.menus) ? option.menus.filter((item) => typeof item === "string") : shareMenu.menus,
|
|
1685
|
+
visible: true,
|
|
1686
|
+
withShareTicket: Boolean(option.withShareTicket)
|
|
1687
|
+
};
|
|
1688
|
+
return { errMsg: "showShareMenu:ok" };
|
|
1689
|
+
},
|
|
1690
|
+
showLoading(option) {
|
|
1691
|
+
loading = {
|
|
1692
|
+
mask: Boolean(option.mask),
|
|
1693
|
+
title: option.title
|
|
1694
|
+
};
|
|
1695
|
+
return { errMsg: "showLoading:ok" };
|
|
1696
|
+
},
|
|
1697
|
+
showModal(option) {
|
|
1698
|
+
const showCancel = option.showCancel !== false;
|
|
1699
|
+
const nextMock = modalMocks.shift();
|
|
1700
|
+
let confirm = nextMock?.confirm ?? true;
|
|
1701
|
+
let cancel = nextMock?.cancel ?? !confirm;
|
|
1702
|
+
if (!showCancel) {
|
|
1703
|
+
confirm = true;
|
|
1704
|
+
cancel = false;
|
|
1705
|
+
} else if (confirm) cancel = false;
|
|
1706
|
+
else cancel = true;
|
|
1707
|
+
const result = {
|
|
1708
|
+
cancel,
|
|
1709
|
+
confirm,
|
|
1710
|
+
errMsg: "showModal:ok"
|
|
1711
|
+
};
|
|
1712
|
+
modalLogs.push({
|
|
1713
|
+
cancelColor: option.cancelColor ?? DEFAULT_MODAL_CANCEL_COLOR,
|
|
1714
|
+
cancelText: option.cancelText ?? DEFAULT_MODAL_CANCEL_TEXT,
|
|
1715
|
+
confirmColor: option.confirmColor ?? DEFAULT_MODAL_CONFIRM_COLOR,
|
|
1716
|
+
confirmText: option.confirmText ?? DEFAULT_MODAL_CONFIRM_TEXT,
|
|
1717
|
+
content: option.content,
|
|
1718
|
+
result: { ...result },
|
|
1719
|
+
showCancel,
|
|
1720
|
+
title: option.title ?? ""
|
|
1721
|
+
});
|
|
1722
|
+
return result;
|
|
1723
|
+
},
|
|
1177
1724
|
showToast(option) {
|
|
1178
1725
|
toast = {
|
|
1179
1726
|
duration: Number(option.duration ?? 1500),
|
|
@@ -1182,17 +1729,26 @@ function createHeadlessWxState() {
|
|
|
1182
1729
|
title: option.title
|
|
1183
1730
|
};
|
|
1184
1731
|
return { errMsg: "showToast:ok" };
|
|
1732
|
+
},
|
|
1733
|
+
updateShareMenu(option = {}) {
|
|
1734
|
+
shareMenu = {
|
|
1735
|
+
isUpdatableMessage: option.isUpdatableMessage == null ? shareMenu.isUpdatableMessage : Boolean(option.isUpdatableMessage),
|
|
1736
|
+
menus: Array.isArray(option.menus) ? option.menus.filter((item) => typeof item === "string") : shareMenu.menus,
|
|
1737
|
+
visible: true,
|
|
1738
|
+
withShareTicket: option.withShareTicket == null ? shareMenu.withShareTicket : Boolean(option.withShareTicket)
|
|
1739
|
+
};
|
|
1740
|
+
return { errMsg: "updateShareMenu:ok" };
|
|
1185
1741
|
}
|
|
1186
1742
|
};
|
|
1187
1743
|
}
|
|
1188
1744
|
//#endregion
|
|
1189
1745
|
//#region src/browser/session.ts
|
|
1190
|
-
const LEADING_SLASH_RE$
|
|
1746
|
+
const LEADING_SLASH_RE$3 = /^\/+/;
|
|
1191
1747
|
const PAGE_STACK_LIMIT$1 = 10;
|
|
1192
1748
|
const DATA_ATTR_SELECTOR_RE$1 = /^\[data-([^=\]]+)="([^"]*)"\]$/;
|
|
1193
1749
|
const DATASET_KEY_RE = /-([a-z])/g;
|
|
1194
1750
|
function stripLeadingSlash$1(route) {
|
|
1195
|
-
return route.replace(LEADING_SLASH_RE$
|
|
1751
|
+
return route.replace(LEADING_SLASH_RE$3, "");
|
|
1196
1752
|
}
|
|
1197
1753
|
function normalizeQuery$1(queryString) {
|
|
1198
1754
|
const query = new URLSearchParams(queryString);
|
|
@@ -1221,11 +1777,21 @@ function createAppLaunchOptions$1(pathname, query) {
|
|
|
1221
1777
|
scene: 1001
|
|
1222
1778
|
};
|
|
1223
1779
|
}
|
|
1780
|
+
function readJsonObject$2(files, filePath) {
|
|
1781
|
+
const content = readBrowserVirtualFile(files, filePath);
|
|
1782
|
+
if (!content) return;
|
|
1783
|
+
try {
|
|
1784
|
+
const value = JSON.parse(content);
|
|
1785
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
1786
|
+
} catch {
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1224
1790
|
function resolveNavigationPath$1(targetPath, baseRoute) {
|
|
1225
1791
|
if (!targetPath) throw new Error("Navigation url must include a pathname in browser simulator runtime.");
|
|
1226
|
-
if (targetPath.startsWith("/")) return posix.normalize(targetPath).replace(LEADING_SLASH_RE$
|
|
1792
|
+
if (targetPath.startsWith("/")) return posix.normalize(targetPath).replace(LEADING_SLASH_RE$3, "");
|
|
1227
1793
|
if (!baseRoute) throw new Error(`Cannot resolve relative navigation url "${targetPath}" without an active page.`);
|
|
1228
|
-
return posix.resolve(`/${posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$
|
|
1794
|
+
return posix.resolve(`/${posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$3, "");
|
|
1229
1795
|
}
|
|
1230
1796
|
var BrowserHeadlessSession = class {
|
|
1231
1797
|
files;
|
|
@@ -1241,6 +1807,11 @@ var BrowserHeadlessSession = class {
|
|
|
1241
1807
|
tabBarRoutes;
|
|
1242
1808
|
tabPages = /* @__PURE__ */ new Map();
|
|
1243
1809
|
tabBarItems = /* @__PURE__ */ new Map();
|
|
1810
|
+
tabBarState = /* @__PURE__ */ new Map();
|
|
1811
|
+
tabBarVisible = false;
|
|
1812
|
+
systemInfo = createDefaultSystemInfo();
|
|
1813
|
+
enterOptions = createAppLaunchOptions$1("", {});
|
|
1814
|
+
launchOptions = createAppLaunchOptions$1("", {});
|
|
1244
1815
|
wxState = createHeadlessWxState();
|
|
1245
1816
|
constructor(options) {
|
|
1246
1817
|
this.files = options.files;
|
|
@@ -1258,22 +1829,74 @@ var BrowserHeadlessSession = class {
|
|
|
1258
1829
|
pagePath,
|
|
1259
1830
|
text: typeof item.text === "string" ? item.text : void 0
|
|
1260
1831
|
});
|
|
1832
|
+
this.tabBarState.set(index, {
|
|
1833
|
+
badge: null,
|
|
1834
|
+
index,
|
|
1835
|
+
pagePath,
|
|
1836
|
+
redDot: false,
|
|
1837
|
+
text: typeof item.text === "string" ? item.text : void 0
|
|
1838
|
+
});
|
|
1261
1839
|
});
|
|
1840
|
+
this.tabBarVisible = this.tabBarRoutes.size > 0;
|
|
1262
1841
|
this.moduleLoader = createBrowserModuleLoader(this.files, this.registries, () => this.pages.slice(), () => this.getApp(), {
|
|
1842
|
+
getEnterOptionsSync: () => ({
|
|
1843
|
+
...this.enterOptions,
|
|
1844
|
+
query: { ...this.enterOptions.query },
|
|
1845
|
+
referrerInfo: {
|
|
1846
|
+
...this.enterOptions.referrerInfo,
|
|
1847
|
+
extraData: { ...this.enterOptions.referrerInfo.extraData }
|
|
1848
|
+
}
|
|
1849
|
+
}),
|
|
1850
|
+
getAppBaseInfoSync: () => deriveAppBaseInfo(this.systemInfo),
|
|
1851
|
+
getLaunchOptionsSync: () => ({
|
|
1852
|
+
...this.launchOptions,
|
|
1853
|
+
query: { ...this.launchOptions.query },
|
|
1854
|
+
referrerInfo: {
|
|
1855
|
+
...this.launchOptions.referrerInfo,
|
|
1856
|
+
extraData: { ...this.launchOptions.referrerInfo.extraData }
|
|
1857
|
+
}
|
|
1858
|
+
}),
|
|
1859
|
+
getMenuButtonBoundingClientRect: () => deriveMenuButtonBoundingClientRect(this.systemInfo),
|
|
1860
|
+
getNetworkType: () => this.wxState.getNetworkType(),
|
|
1263
1861
|
navigateBack: (option) => this.navigateBack(option?.delta),
|
|
1264
1862
|
navigateTo: (option) => this.navigateTo(option.url),
|
|
1265
1863
|
pageScrollTo: (option) => this.pageScrollTo(option),
|
|
1266
1864
|
clearStorageSync: () => this.wxState.clearStorageSync(),
|
|
1865
|
+
getStorageInfoSync: () => this.wxState.getStorageInfoSync(),
|
|
1267
1866
|
getStorageSync: (key) => this.wxState.getStorageSync(key),
|
|
1867
|
+
getSystemInfoSync: () => ({ ...this.systemInfo }),
|
|
1868
|
+
getWindowInfoSync: () => deriveWindowInfo(this.systemInfo),
|
|
1869
|
+
hideLoading: () => this.wxState.hideLoading(),
|
|
1268
1870
|
hideToast: () => this.wxState.hideToast(),
|
|
1269
1871
|
reLaunch: (option) => this.reLaunch(option.url),
|
|
1270
1872
|
redirectTo: (option) => this.redirectTo(option.url),
|
|
1873
|
+
nextTick: (callback) => queueMicrotask(() => callback?.()),
|
|
1874
|
+
offNetworkStatusChange: (callback) => this.wxState.offNetworkStatusChange(callback),
|
|
1875
|
+
onNetworkStatusChange: (callback) => this.wxState.onNetworkStatusChange(callback),
|
|
1271
1876
|
removeStorageSync: (key) => this.wxState.removeStorageSync(key),
|
|
1272
1877
|
request: (option) => this.wxState.request(option),
|
|
1878
|
+
setBackgroundColor: (option) => this.setBackgroundColor(option),
|
|
1879
|
+
setBackgroundTextStyle: (option) => this.setBackgroundTextStyle(option.textStyle),
|
|
1273
1880
|
setStorageSync: (key, value) => this.wxState.setStorageSync(key, value),
|
|
1881
|
+
setNavigationBarColor: (option) => this.setNavigationBarColor(option),
|
|
1882
|
+
setNavigationBarTitle: (option) => this.setNavigationBarTitle(option.title),
|
|
1883
|
+
hideShareMenu: () => this.wxState.hideShareMenu(),
|
|
1884
|
+
hideNavigationBarLoading: () => this.hideNavigationBarLoading(),
|
|
1885
|
+
hideTabBar: () => this.hideTabBar(),
|
|
1886
|
+
hideTabBarRedDot: (option) => this.hideTabBarRedDot(option.index),
|
|
1887
|
+
showShareMenu: (option) => this.wxState.showShareMenu(option),
|
|
1888
|
+
showNavigationBarLoading: () => this.showNavigationBarLoading(),
|
|
1889
|
+
showTabBar: () => this.showTabBar(),
|
|
1890
|
+
showTabBarRedDot: (option) => this.showTabBarRedDot(option.index),
|
|
1891
|
+
showActionSheet: (option) => this.wxState.showActionSheet(option),
|
|
1892
|
+
showLoading: (option) => this.wxState.showLoading(option),
|
|
1893
|
+
showModal: (option) => this.wxState.showModal(option),
|
|
1274
1894
|
showToast: (option) => this.wxState.showToast(option),
|
|
1275
1895
|
stopPullDownRefresh: () => this.stopPullDownRefresh(),
|
|
1276
|
-
switchTab: (option) => this.switchTab(option.url)
|
|
1896
|
+
switchTab: (option) => this.switchTab(option.url),
|
|
1897
|
+
removeTabBarBadge: (option) => this.removeTabBarBadge(option.index),
|
|
1898
|
+
setTabBarBadge: (option) => this.setTabBarBadge(option.index, option.text),
|
|
1899
|
+
updateShareMenu: (option) => this.wxState.updateShareMenu(option)
|
|
1277
1900
|
});
|
|
1278
1901
|
}
|
|
1279
1902
|
getApp() {
|
|
@@ -1282,18 +1905,213 @@ var BrowserHeadlessSession = class {
|
|
|
1282
1905
|
getCurrentPages() {
|
|
1283
1906
|
return this.pages.slice();
|
|
1284
1907
|
}
|
|
1908
|
+
getCurrentPageNavigationBarTitle() {
|
|
1909
|
+
return this.currentPageInstance?.__navigationBarTitle__ ?? null;
|
|
1910
|
+
}
|
|
1911
|
+
getCurrentPageNavigationBar() {
|
|
1912
|
+
const snapshot = this.currentPageInstance?.__navigationBar__;
|
|
1913
|
+
return snapshot ? cloneNavigationBarSnapshot(snapshot) : null;
|
|
1914
|
+
}
|
|
1915
|
+
getCurrentPageBackground() {
|
|
1916
|
+
const snapshot = this.currentPageInstance?.__background__;
|
|
1917
|
+
return snapshot ? cloneBackgroundSnapshot(snapshot) : null;
|
|
1918
|
+
}
|
|
1919
|
+
getActionSheetLogs() {
|
|
1920
|
+
return this.wxState.getActionSheetLogs();
|
|
1921
|
+
}
|
|
1285
1922
|
getRequestLogs() {
|
|
1286
1923
|
return this.wxState.getRequestLogs();
|
|
1287
1924
|
}
|
|
1288
1925
|
getStorageSnapshot() {
|
|
1289
1926
|
return this.wxState.getStorageSnapshot();
|
|
1290
1927
|
}
|
|
1928
|
+
getShareMenu() {
|
|
1929
|
+
return this.wxState.getShareMenu();
|
|
1930
|
+
}
|
|
1931
|
+
getTabBar() {
|
|
1932
|
+
return { visible: this.tabBarVisible };
|
|
1933
|
+
}
|
|
1934
|
+
getTabBarSnapshot() {
|
|
1935
|
+
return {
|
|
1936
|
+
items: Array.from(this.tabBarState.values(), (item) => ({
|
|
1937
|
+
badge: item.badge,
|
|
1938
|
+
index: item.index,
|
|
1939
|
+
pagePath: item.pagePath,
|
|
1940
|
+
redDot: item.redDot,
|
|
1941
|
+
text: item.text
|
|
1942
|
+
})),
|
|
1943
|
+
visible: this.tabBarVisible
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
getStorageInfo() {
|
|
1947
|
+
return this.wxState.getStorageInfoSync();
|
|
1948
|
+
}
|
|
1949
|
+
getSystemInfo() {
|
|
1950
|
+
return { ...this.systemInfo };
|
|
1951
|
+
}
|
|
1952
|
+
getWindowInfo() {
|
|
1953
|
+
return deriveWindowInfo(this.systemInfo);
|
|
1954
|
+
}
|
|
1955
|
+
getAppBaseInfo() {
|
|
1956
|
+
return deriveAppBaseInfo(this.systemInfo);
|
|
1957
|
+
}
|
|
1958
|
+
getLaunchOptions() {
|
|
1959
|
+
return {
|
|
1960
|
+
...this.launchOptions,
|
|
1961
|
+
query: { ...this.launchOptions.query },
|
|
1962
|
+
referrerInfo: {
|
|
1963
|
+
...this.launchOptions.referrerInfo,
|
|
1964
|
+
extraData: { ...this.launchOptions.referrerInfo.extraData }
|
|
1965
|
+
}
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
getEnterOptions() {
|
|
1969
|
+
return {
|
|
1970
|
+
...this.enterOptions,
|
|
1971
|
+
query: { ...this.enterOptions.query },
|
|
1972
|
+
referrerInfo: {
|
|
1973
|
+
...this.enterOptions.referrerInfo,
|
|
1974
|
+
extraData: { ...this.enterOptions.referrerInfo.extraData }
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
getMenuButtonBoundingClientRect() {
|
|
1979
|
+
return deriveMenuButtonBoundingClientRect(this.systemInfo);
|
|
1980
|
+
}
|
|
1981
|
+
getNetworkType() {
|
|
1982
|
+
return this.wxState.getNetworkType();
|
|
1983
|
+
}
|
|
1984
|
+
getLoading() {
|
|
1985
|
+
return this.wxState.getLoading();
|
|
1986
|
+
}
|
|
1987
|
+
getModalLogs() {
|
|
1988
|
+
return this.wxState.getModalLogs();
|
|
1989
|
+
}
|
|
1291
1990
|
getToast() {
|
|
1292
1991
|
return this.wxState.getToast();
|
|
1293
1992
|
}
|
|
1993
|
+
mockModal(definition = {}) {
|
|
1994
|
+
this.wxState.mockModal(definition);
|
|
1995
|
+
}
|
|
1996
|
+
mockActionSheet(definition = {}) {
|
|
1997
|
+
this.wxState.mockActionSheet(definition);
|
|
1998
|
+
}
|
|
1294
1999
|
mockRequest(definition) {
|
|
1295
2000
|
this.wxState.mockRequest(definition);
|
|
1296
2001
|
}
|
|
2002
|
+
setNetworkType(networkType) {
|
|
2003
|
+
return this.wxState.setNetworkType(networkType);
|
|
2004
|
+
}
|
|
2005
|
+
setBackgroundTextStyle(textStyle) {
|
|
2006
|
+
if (textStyle !== "dark" && textStyle !== "light") throw new Error("setBackgroundTextStyle:fail invalid textStyle");
|
|
2007
|
+
const current = this.requireCurrentPage("wx.setBackgroundTextStyle()");
|
|
2008
|
+
current.__background__ ??= {
|
|
2009
|
+
backgroundColor: "#ffffff",
|
|
2010
|
+
backgroundColorBottom: "#ffffff",
|
|
2011
|
+
backgroundColorTop: "#ffffff",
|
|
2012
|
+
textStyle: "dark"
|
|
2013
|
+
};
|
|
2014
|
+
current.__background__.textStyle = textStyle;
|
|
2015
|
+
current.__backgroundTextStyle__ = textStyle;
|
|
2016
|
+
return { errMsg: "setBackgroundTextStyle:ok" };
|
|
2017
|
+
}
|
|
2018
|
+
setBackgroundColor(option) {
|
|
2019
|
+
const current = this.requireCurrentPage("wx.setBackgroundColor()");
|
|
2020
|
+
current.__background__ ??= {
|
|
2021
|
+
backgroundColor: "#ffffff",
|
|
2022
|
+
backgroundColorBottom: "#ffffff",
|
|
2023
|
+
backgroundColorTop: "#ffffff",
|
|
2024
|
+
textStyle: current.__backgroundTextStyle__ ?? "dark"
|
|
2025
|
+
};
|
|
2026
|
+
if (typeof option.backgroundColor === "string") current.__background__.backgroundColor = option.backgroundColor;
|
|
2027
|
+
if (typeof option.backgroundColorTop === "string") current.__background__.backgroundColorTop = option.backgroundColorTop;
|
|
2028
|
+
if (typeof option.backgroundColorBottom === "string") current.__background__.backgroundColorBottom = option.backgroundColorBottom;
|
|
2029
|
+
return { errMsg: "setBackgroundColor:ok" };
|
|
2030
|
+
}
|
|
2031
|
+
setNavigationBarTitle(title) {
|
|
2032
|
+
const current = this.requireCurrentPage("wx.setNavigationBarTitle()");
|
|
2033
|
+
current.__navigationBar__ ??= {
|
|
2034
|
+
animation: null,
|
|
2035
|
+
backgroundColor: "#ffffff",
|
|
2036
|
+
frontColor: "#000000",
|
|
2037
|
+
loading: false,
|
|
2038
|
+
title: ""
|
|
2039
|
+
};
|
|
2040
|
+
current.__navigationBar__.title = title;
|
|
2041
|
+
current.__navigationBarTitle__ = title;
|
|
2042
|
+
return { errMsg: "setNavigationBarTitle:ok" };
|
|
2043
|
+
}
|
|
2044
|
+
setNavigationBarColor(option) {
|
|
2045
|
+
const current = this.requireCurrentPage("wx.setNavigationBarColor()");
|
|
2046
|
+
current.__navigationBar__ ??= {
|
|
2047
|
+
animation: null,
|
|
2048
|
+
backgroundColor: "#ffffff",
|
|
2049
|
+
frontColor: "#000000",
|
|
2050
|
+
loading: false,
|
|
2051
|
+
title: current.__navigationBarTitle__ ?? ""
|
|
2052
|
+
};
|
|
2053
|
+
if (typeof option.backgroundColor === "string") current.__navigationBar__.backgroundColor = option.backgroundColor;
|
|
2054
|
+
if (typeof option.frontColor === "string") current.__navigationBar__.frontColor = option.frontColor;
|
|
2055
|
+
current.__navigationBar__.animation = option.animation ? {
|
|
2056
|
+
duration: option.animation.duration,
|
|
2057
|
+
timingFunction: option.animation.timingFunction
|
|
2058
|
+
} : null;
|
|
2059
|
+
return { errMsg: "setNavigationBarColor:ok" };
|
|
2060
|
+
}
|
|
2061
|
+
showNavigationBarLoading() {
|
|
2062
|
+
const current = this.requireCurrentPage("wx.showNavigationBarLoading()");
|
|
2063
|
+
current.__navigationBar__ ??= {
|
|
2064
|
+
animation: null,
|
|
2065
|
+
backgroundColor: "#ffffff",
|
|
2066
|
+
frontColor: "#000000",
|
|
2067
|
+
loading: false,
|
|
2068
|
+
title: current.__navigationBarTitle__ ?? ""
|
|
2069
|
+
};
|
|
2070
|
+
current.__navigationBar__.loading = true;
|
|
2071
|
+
return { errMsg: "showNavigationBarLoading:ok" };
|
|
2072
|
+
}
|
|
2073
|
+
hideNavigationBarLoading() {
|
|
2074
|
+
const current = this.requireCurrentPage("wx.hideNavigationBarLoading()");
|
|
2075
|
+
current.__navigationBar__ ??= {
|
|
2076
|
+
animation: null,
|
|
2077
|
+
backgroundColor: "#ffffff",
|
|
2078
|
+
frontColor: "#000000",
|
|
2079
|
+
loading: false,
|
|
2080
|
+
title: current.__navigationBarTitle__ ?? ""
|
|
2081
|
+
};
|
|
2082
|
+
current.__navigationBar__.loading = false;
|
|
2083
|
+
return { errMsg: "hideNavigationBarLoading:ok" };
|
|
2084
|
+
}
|
|
2085
|
+
hideTabBar() {
|
|
2086
|
+
this.tabBarVisible = false;
|
|
2087
|
+
return { errMsg: "hideTabBar:ok" };
|
|
2088
|
+
}
|
|
2089
|
+
hideTabBarRedDot(index) {
|
|
2090
|
+
const item = this.requireTabBarItem(index, "wx.hideTabBarRedDot()");
|
|
2091
|
+
item.redDot = false;
|
|
2092
|
+
return { errMsg: "hideTabBarRedDot:ok" };
|
|
2093
|
+
}
|
|
2094
|
+
showTabBar() {
|
|
2095
|
+
this.tabBarVisible = this.tabBarRoutes.size > 0;
|
|
2096
|
+
return { errMsg: "showTabBar:ok" };
|
|
2097
|
+
}
|
|
2098
|
+
showTabBarRedDot(index) {
|
|
2099
|
+
const item = this.requireTabBarItem(index, "wx.showTabBarRedDot()");
|
|
2100
|
+
item.badge = null;
|
|
2101
|
+
item.redDot = true;
|
|
2102
|
+
return { errMsg: "showTabBarRedDot:ok" };
|
|
2103
|
+
}
|
|
2104
|
+
removeTabBarBadge(index) {
|
|
2105
|
+
const item = this.requireTabBarItem(index, "wx.removeTabBarBadge()");
|
|
2106
|
+
item.badge = null;
|
|
2107
|
+
return { errMsg: "removeTabBarBadge:ok" };
|
|
2108
|
+
}
|
|
2109
|
+
setTabBarBadge(index, text) {
|
|
2110
|
+
const item = this.requireTabBarItem(index, "wx.setTabBarBadge()");
|
|
2111
|
+
item.badge = text;
|
|
2112
|
+
item.redDot = false;
|
|
2113
|
+
return { errMsg: "setTabBarBadge:ok" };
|
|
2114
|
+
}
|
|
1297
2115
|
getScopeSnapshot(scopeId) {
|
|
1298
2116
|
const scope = this.componentScopes.get(scopeId);
|
|
1299
2117
|
if (!scope) return null;
|
|
@@ -1416,6 +2234,8 @@ var BrowserHeadlessSession = class {
|
|
|
1416
2234
|
}
|
|
1417
2235
|
bootstrap(launchOptions = createAppLaunchOptions$1("", {})) {
|
|
1418
2236
|
if (this.appInstance) return this.appInstance;
|
|
2237
|
+
this.launchOptions = createAppLaunchOptions$1(launchOptions.path, launchOptions.query);
|
|
2238
|
+
this.enterOptions = createAppLaunchOptions$1(launchOptions.path, launchOptions.query);
|
|
1419
2239
|
const appModulePath = join(this.project.miniprogramRootPath, "app.js");
|
|
1420
2240
|
this.appDefinition = this.moduleLoader.executeAppModule(appModulePath);
|
|
1421
2241
|
this.appInstance = createAppInstance(this.appDefinition);
|
|
@@ -1520,6 +2340,7 @@ var BrowserHeadlessSession = class {
|
|
|
1520
2340
|
}
|
|
1521
2341
|
triggerResize(options) {
|
|
1522
2342
|
const current = this.requireCurrentPage("triggerResize()");
|
|
2343
|
+
applyResizeToSystemInfo(this.systemInfo, options);
|
|
1523
2344
|
current.onResize?.(options);
|
|
1524
2345
|
this.runPageComponentLifetime(current.route, "resize", options);
|
|
1525
2346
|
return current;
|
|
@@ -1532,8 +2353,13 @@ var BrowserHeadlessSession = class {
|
|
|
1532
2353
|
stopPullDownRefresh() {}
|
|
1533
2354
|
createFreshPage(target) {
|
|
1534
2355
|
const pageModulePath = join(this.project.miniprogramRootPath, `${target.routeRecord.route}.js`);
|
|
2356
|
+
const pageConfigPath = join(this.project.miniprogramRootPath, `${target.routeRecord.route}.json`);
|
|
1535
2357
|
const pageDefinition = this.moduleLoader.executePageModule(pageModulePath, target.routeRecord.route);
|
|
1536
|
-
const
|
|
2358
|
+
const pageConfig = readJsonObject$2(this.files, pageConfigPath);
|
|
2359
|
+
const pageInstance = createPageInstance(target.routeRecord.route, pageDefinition, target.query, {
|
|
2360
|
+
background: resolveBackgroundSnapshot(this.project.appConfig, pageConfig),
|
|
2361
|
+
navigationBar: resolveNavigationBarSnapshot(this.project.appConfig, pageConfig)
|
|
2362
|
+
});
|
|
1537
2363
|
pageInstance.selectComponent = (selector) => this.selectComponent(selector);
|
|
1538
2364
|
pageInstance.selectAllComponents = (selector) => this.selectAllComponents(selector);
|
|
1539
2365
|
pageInstance.onLoad?.(target.query);
|
|
@@ -1570,6 +2396,12 @@ var BrowserHeadlessSession = class {
|
|
|
1570
2396
|
if (!item) throw new Error(`Missing tabBar metadata for route "${route}" in browser simulator runtime.`);
|
|
1571
2397
|
return { ...item };
|
|
1572
2398
|
}
|
|
2399
|
+
requireTabBarItem(index, action) {
|
|
2400
|
+
const normalizedIndex = Number.isFinite(index) ? Math.trunc(index) : NaN;
|
|
2401
|
+
const item = this.tabBarState.get(normalizedIndex);
|
|
2402
|
+
if (!item) throw new Error(`Cannot call ${action} with unknown tabBar index ${index} in browser simulator runtime.`);
|
|
2403
|
+
return item;
|
|
2404
|
+
}
|
|
1573
2405
|
unloadAllPages() {
|
|
1574
2406
|
const pagesToUnload = new Set([...this.pages, ...this.tabPages.values()]);
|
|
1575
2407
|
for (const page of [...pagesToUnload].reverse()) this.unloadPage(page);
|
|
@@ -1612,7 +2444,7 @@ function createBrowserHeadlessSession(options) {
|
|
|
1612
2444
|
}
|
|
1613
2445
|
//#endregion
|
|
1614
2446
|
//#region src/project/loadProject.ts
|
|
1615
|
-
function readJsonObject(filePath) {
|
|
2447
|
+
function readJsonObject$1(filePath) {
|
|
1616
2448
|
try {
|
|
1617
2449
|
const content = fs.readFileSync(filePath, "utf8");
|
|
1618
2450
|
const value = JSON.parse(content);
|
|
@@ -1625,7 +2457,7 @@ function resolveProjectConfigFiles(projectPath) {
|
|
|
1625
2457
|
const entries = [];
|
|
1626
2458
|
for (const fileName of ["project.config.json", "project.private.config.json"]) {
|
|
1627
2459
|
const filePath = path.resolve(projectPath, fileName);
|
|
1628
|
-
const value = readJsonObject(filePath);
|
|
2460
|
+
const value = readJsonObject$1(filePath);
|
|
1629
2461
|
if (!value) continue;
|
|
1630
2462
|
entries.push({
|
|
1631
2463
|
filePath,
|
|
@@ -1647,7 +2479,7 @@ function ensureFileExists(filePath, label) {
|
|
|
1647
2479
|
throw new Error(`Missing ${label} for headless runtime project: ${normalize(filePath)}`);
|
|
1648
2480
|
}
|
|
1649
2481
|
function loadAppConfig(appConfigPath) {
|
|
1650
|
-
const appConfig = readJsonObject(appConfigPath);
|
|
2482
|
+
const appConfig = readJsonObject$1(appConfigPath);
|
|
1651
2483
|
if (!appConfig) throw new Error(`Failed to read built app.json for headless runtime project: ${normalize(appConfigPath)}`);
|
|
1652
2484
|
return appConfig;
|
|
1653
2485
|
}
|
|
@@ -1763,10 +2595,10 @@ function createModuleLoader(registries, getCurrentPages, getApp, wxDriver) {
|
|
|
1763
2595
|
}
|
|
1764
2596
|
//#endregion
|
|
1765
2597
|
//#region src/runtime/session.ts
|
|
1766
|
-
const LEADING_SLASH_RE$
|
|
2598
|
+
const LEADING_SLASH_RE$2 = /^\/+/;
|
|
1767
2599
|
const PAGE_STACK_LIMIT = 10;
|
|
1768
2600
|
function stripLeadingSlash(route) {
|
|
1769
|
-
return route.replace(LEADING_SLASH_RE$
|
|
2601
|
+
return route.replace(LEADING_SLASH_RE$2, "");
|
|
1770
2602
|
}
|
|
1771
2603
|
function normalizeQuery(queryString) {
|
|
1772
2604
|
const query = new URLSearchParams(queryString);
|
|
@@ -1795,11 +2627,19 @@ function createAppLaunchOptions(pathname, query) {
|
|
|
1795
2627
|
scene: 1001
|
|
1796
2628
|
};
|
|
1797
2629
|
}
|
|
2630
|
+
function readJsonObject(filePath) {
|
|
2631
|
+
try {
|
|
2632
|
+
const value = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
2633
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
2634
|
+
} catch {
|
|
2635
|
+
return;
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
1798
2638
|
function resolveNavigationPath(targetPath, baseRoute) {
|
|
1799
2639
|
if (!targetPath) throw new Error("Navigation url must include a pathname in headless runtime.");
|
|
1800
|
-
if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE$
|
|
2640
|
+
if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE$2, "");
|
|
1801
2641
|
if (!baseRoute) throw new Error(`Cannot resolve relative navigation url "${targetPath}" without an active page.`);
|
|
1802
|
-
return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$
|
|
2642
|
+
return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$2, "");
|
|
1803
2643
|
}
|
|
1804
2644
|
var HeadlessSession = class {
|
|
1805
2645
|
project;
|
|
@@ -1812,6 +2652,11 @@ var HeadlessSession = class {
|
|
|
1812
2652
|
tabBarRoutes;
|
|
1813
2653
|
tabPages = /* @__PURE__ */ new Map();
|
|
1814
2654
|
tabBarItems = /* @__PURE__ */ new Map();
|
|
2655
|
+
tabBarState = /* @__PURE__ */ new Map();
|
|
2656
|
+
tabBarVisible = false;
|
|
2657
|
+
systemInfo = createDefaultSystemInfo();
|
|
2658
|
+
enterOptions = createAppLaunchOptions("", {});
|
|
2659
|
+
launchOptions = createAppLaunchOptions("", {});
|
|
1815
2660
|
wxState = createHeadlessWxState();
|
|
1816
2661
|
constructor(options) {
|
|
1817
2662
|
this.project = loadProject(options.projectPath);
|
|
@@ -1828,22 +2673,74 @@ var HeadlessSession = class {
|
|
|
1828
2673
|
pagePath,
|
|
1829
2674
|
text: typeof item.text === "string" ? item.text : void 0
|
|
1830
2675
|
});
|
|
2676
|
+
this.tabBarState.set(index, {
|
|
2677
|
+
badge: null,
|
|
2678
|
+
index,
|
|
2679
|
+
pagePath,
|
|
2680
|
+
redDot: false,
|
|
2681
|
+
text: typeof item.text === "string" ? item.text : void 0
|
|
2682
|
+
});
|
|
1831
2683
|
});
|
|
2684
|
+
this.tabBarVisible = this.tabBarRoutes.size > 0;
|
|
1832
2685
|
this.moduleLoader = createModuleLoader(this.registries, () => this.pages.slice(), () => this.getApp(), {
|
|
2686
|
+
getEnterOptionsSync: () => ({
|
|
2687
|
+
...this.enterOptions,
|
|
2688
|
+
query: { ...this.enterOptions.query },
|
|
2689
|
+
referrerInfo: {
|
|
2690
|
+
...this.enterOptions.referrerInfo,
|
|
2691
|
+
extraData: { ...this.enterOptions.referrerInfo.extraData }
|
|
2692
|
+
}
|
|
2693
|
+
}),
|
|
2694
|
+
getAppBaseInfoSync: () => deriveAppBaseInfo(this.systemInfo),
|
|
2695
|
+
getLaunchOptionsSync: () => ({
|
|
2696
|
+
...this.launchOptions,
|
|
2697
|
+
query: { ...this.launchOptions.query },
|
|
2698
|
+
referrerInfo: {
|
|
2699
|
+
...this.launchOptions.referrerInfo,
|
|
2700
|
+
extraData: { ...this.launchOptions.referrerInfo.extraData }
|
|
2701
|
+
}
|
|
2702
|
+
}),
|
|
2703
|
+
getMenuButtonBoundingClientRect: () => deriveMenuButtonBoundingClientRect(this.systemInfo),
|
|
2704
|
+
getNetworkType: () => this.wxState.getNetworkType(),
|
|
1833
2705
|
navigateBack: (option) => this.navigateBack(option?.delta),
|
|
1834
2706
|
navigateTo: (option) => this.navigateTo(option.url),
|
|
1835
2707
|
pageScrollTo: (option) => this.pageScrollTo(option),
|
|
1836
2708
|
clearStorageSync: () => this.wxState.clearStorageSync(),
|
|
2709
|
+
getStorageInfoSync: () => this.wxState.getStorageInfoSync(),
|
|
1837
2710
|
getStorageSync: (key) => this.wxState.getStorageSync(key),
|
|
2711
|
+
getSystemInfoSync: () => ({ ...this.systemInfo }),
|
|
2712
|
+
getWindowInfoSync: () => deriveWindowInfo(this.systemInfo),
|
|
2713
|
+
hideLoading: () => this.wxState.hideLoading(),
|
|
1838
2714
|
hideToast: () => this.wxState.hideToast(),
|
|
1839
2715
|
reLaunch: (option) => this.reLaunch(option.url),
|
|
1840
2716
|
redirectTo: (option) => this.redirectTo(option.url),
|
|
2717
|
+
nextTick: (callback) => queueMicrotask(() => callback?.()),
|
|
2718
|
+
offNetworkStatusChange: (callback) => this.wxState.offNetworkStatusChange(callback),
|
|
2719
|
+
onNetworkStatusChange: (callback) => this.wxState.onNetworkStatusChange(callback),
|
|
1841
2720
|
removeStorageSync: (key) => this.wxState.removeStorageSync(key),
|
|
1842
2721
|
request: (option) => this.wxState.request(option),
|
|
2722
|
+
setBackgroundColor: (option) => this.setBackgroundColor(option),
|
|
2723
|
+
setBackgroundTextStyle: (option) => this.setBackgroundTextStyle(option.textStyle),
|
|
1843
2724
|
setStorageSync: (key, value) => this.wxState.setStorageSync(key, value),
|
|
2725
|
+
setNavigationBarColor: (option) => this.setNavigationBarColor(option),
|
|
2726
|
+
setNavigationBarTitle: (option) => this.setNavigationBarTitle(option.title),
|
|
2727
|
+
hideShareMenu: () => this.wxState.hideShareMenu(),
|
|
2728
|
+
hideNavigationBarLoading: () => this.hideNavigationBarLoading(),
|
|
2729
|
+
hideTabBar: () => this.hideTabBar(),
|
|
2730
|
+
hideTabBarRedDot: (option) => this.hideTabBarRedDot(option.index),
|
|
2731
|
+
showShareMenu: (option) => this.wxState.showShareMenu(option),
|
|
2732
|
+
showNavigationBarLoading: () => this.showNavigationBarLoading(),
|
|
2733
|
+
showTabBar: () => this.showTabBar(),
|
|
2734
|
+
showTabBarRedDot: (option) => this.showTabBarRedDot(option.index),
|
|
2735
|
+
showActionSheet: (option) => this.wxState.showActionSheet(option),
|
|
2736
|
+
showLoading: (option) => this.wxState.showLoading(option),
|
|
2737
|
+
showModal: (option) => this.wxState.showModal(option),
|
|
1844
2738
|
showToast: (option) => this.wxState.showToast(option),
|
|
1845
2739
|
stopPullDownRefresh: () => this.stopPullDownRefresh(),
|
|
1846
|
-
switchTab: (option) => this.switchTab(option.url)
|
|
2740
|
+
switchTab: (option) => this.switchTab(option.url),
|
|
2741
|
+
removeTabBarBadge: (option) => this.removeTabBarBadge(option.index),
|
|
2742
|
+
setTabBarBadge: (option) => this.setTabBarBadge(option.index, option.text),
|
|
2743
|
+
updateShareMenu: (option) => this.wxState.updateShareMenu(option)
|
|
1847
2744
|
});
|
|
1848
2745
|
}
|
|
1849
2746
|
getApp() {
|
|
@@ -1852,20 +2749,217 @@ var HeadlessSession = class {
|
|
|
1852
2749
|
getCurrentPages() {
|
|
1853
2750
|
return this.pages.slice();
|
|
1854
2751
|
}
|
|
2752
|
+
getCurrentPageNavigationBarTitle() {
|
|
2753
|
+
return this.currentPageInstance?.__navigationBarTitle__ ?? null;
|
|
2754
|
+
}
|
|
2755
|
+
getCurrentPageNavigationBar() {
|
|
2756
|
+
const snapshot = this.currentPageInstance?.__navigationBar__;
|
|
2757
|
+
return snapshot ? cloneNavigationBarSnapshot(snapshot) : null;
|
|
2758
|
+
}
|
|
2759
|
+
getCurrentPageBackground() {
|
|
2760
|
+
const snapshot = this.currentPageInstance?.__background__;
|
|
2761
|
+
return snapshot ? cloneBackgroundSnapshot(snapshot) : null;
|
|
2762
|
+
}
|
|
2763
|
+
getActionSheetLogs() {
|
|
2764
|
+
return this.wxState.getActionSheetLogs();
|
|
2765
|
+
}
|
|
1855
2766
|
getRequestLogs() {
|
|
1856
2767
|
return this.wxState.getRequestLogs();
|
|
1857
2768
|
}
|
|
1858
2769
|
getStorageSnapshot() {
|
|
1859
2770
|
return this.wxState.getStorageSnapshot();
|
|
1860
2771
|
}
|
|
2772
|
+
getShareMenu() {
|
|
2773
|
+
return this.wxState.getShareMenu();
|
|
2774
|
+
}
|
|
2775
|
+
getTabBar() {
|
|
2776
|
+
return { visible: this.tabBarVisible };
|
|
2777
|
+
}
|
|
2778
|
+
getTabBarSnapshot() {
|
|
2779
|
+
return {
|
|
2780
|
+
items: Array.from(this.tabBarState.values(), (item) => ({
|
|
2781
|
+
badge: item.badge,
|
|
2782
|
+
index: item.index,
|
|
2783
|
+
pagePath: item.pagePath,
|
|
2784
|
+
redDot: item.redDot,
|
|
2785
|
+
text: item.text
|
|
2786
|
+
})),
|
|
2787
|
+
visible: this.tabBarVisible
|
|
2788
|
+
};
|
|
2789
|
+
}
|
|
2790
|
+
getStorageInfo() {
|
|
2791
|
+
return this.wxState.getStorageInfoSync();
|
|
2792
|
+
}
|
|
2793
|
+
getSystemInfo() {
|
|
2794
|
+
return { ...this.systemInfo };
|
|
2795
|
+
}
|
|
2796
|
+
getWindowInfo() {
|
|
2797
|
+
return deriveWindowInfo(this.systemInfo);
|
|
2798
|
+
}
|
|
2799
|
+
getAppBaseInfo() {
|
|
2800
|
+
return deriveAppBaseInfo(this.systemInfo);
|
|
2801
|
+
}
|
|
2802
|
+
getLaunchOptions() {
|
|
2803
|
+
return {
|
|
2804
|
+
...this.launchOptions,
|
|
2805
|
+
query: { ...this.launchOptions.query },
|
|
2806
|
+
referrerInfo: {
|
|
2807
|
+
...this.launchOptions.referrerInfo,
|
|
2808
|
+
extraData: { ...this.launchOptions.referrerInfo.extraData }
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
getEnterOptions() {
|
|
2813
|
+
return {
|
|
2814
|
+
...this.enterOptions,
|
|
2815
|
+
query: { ...this.enterOptions.query },
|
|
2816
|
+
referrerInfo: {
|
|
2817
|
+
...this.enterOptions.referrerInfo,
|
|
2818
|
+
extraData: { ...this.enterOptions.referrerInfo.extraData }
|
|
2819
|
+
}
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
getMenuButtonBoundingClientRect() {
|
|
2823
|
+
return deriveMenuButtonBoundingClientRect(this.systemInfo);
|
|
2824
|
+
}
|
|
2825
|
+
getNetworkType() {
|
|
2826
|
+
return this.wxState.getNetworkType();
|
|
2827
|
+
}
|
|
2828
|
+
getLoading() {
|
|
2829
|
+
return this.wxState.getLoading();
|
|
2830
|
+
}
|
|
2831
|
+
getModalLogs() {
|
|
2832
|
+
return this.wxState.getModalLogs();
|
|
2833
|
+
}
|
|
1861
2834
|
getToast() {
|
|
1862
2835
|
return this.wxState.getToast();
|
|
1863
2836
|
}
|
|
2837
|
+
mockModal(definition = {}) {
|
|
2838
|
+
this.wxState.mockModal(definition);
|
|
2839
|
+
}
|
|
2840
|
+
mockActionSheet(definition = {}) {
|
|
2841
|
+
this.wxState.mockActionSheet(definition);
|
|
2842
|
+
}
|
|
1864
2843
|
mockRequest(definition) {
|
|
1865
2844
|
this.wxState.mockRequest(definition);
|
|
1866
2845
|
}
|
|
2846
|
+
setNetworkType(networkType) {
|
|
2847
|
+
return this.wxState.setNetworkType(networkType);
|
|
2848
|
+
}
|
|
2849
|
+
setBackgroundTextStyle(textStyle) {
|
|
2850
|
+
if (textStyle !== "dark" && textStyle !== "light") throw new Error("setBackgroundTextStyle:fail invalid textStyle");
|
|
2851
|
+
const current = this.requireCurrentPage("wx.setBackgroundTextStyle()");
|
|
2852
|
+
current.__background__ ??= {
|
|
2853
|
+
backgroundColor: "#ffffff",
|
|
2854
|
+
backgroundColorBottom: "#ffffff",
|
|
2855
|
+
backgroundColorTop: "#ffffff",
|
|
2856
|
+
textStyle: "dark"
|
|
2857
|
+
};
|
|
2858
|
+
current.__background__.textStyle = textStyle;
|
|
2859
|
+
current.__backgroundTextStyle__ = textStyle;
|
|
2860
|
+
return { errMsg: "setBackgroundTextStyle:ok" };
|
|
2861
|
+
}
|
|
2862
|
+
setBackgroundColor(option) {
|
|
2863
|
+
const current = this.requireCurrentPage("wx.setBackgroundColor()");
|
|
2864
|
+
current.__background__ ??= {
|
|
2865
|
+
backgroundColor: "#ffffff",
|
|
2866
|
+
backgroundColorBottom: "#ffffff",
|
|
2867
|
+
backgroundColorTop: "#ffffff",
|
|
2868
|
+
textStyle: current.__backgroundTextStyle__ ?? "dark"
|
|
2869
|
+
};
|
|
2870
|
+
if (typeof option.backgroundColor === "string") current.__background__.backgroundColor = option.backgroundColor;
|
|
2871
|
+
if (typeof option.backgroundColorTop === "string") current.__background__.backgroundColorTop = option.backgroundColorTop;
|
|
2872
|
+
if (typeof option.backgroundColorBottom === "string") current.__background__.backgroundColorBottom = option.backgroundColorBottom;
|
|
2873
|
+
return { errMsg: "setBackgroundColor:ok" };
|
|
2874
|
+
}
|
|
2875
|
+
setNavigationBarTitle(title) {
|
|
2876
|
+
const current = this.requireCurrentPage("wx.setNavigationBarTitle()");
|
|
2877
|
+
current.__navigationBar__ ??= {
|
|
2878
|
+
animation: null,
|
|
2879
|
+
backgroundColor: "#ffffff",
|
|
2880
|
+
frontColor: "#000000",
|
|
2881
|
+
loading: false,
|
|
2882
|
+
title: ""
|
|
2883
|
+
};
|
|
2884
|
+
current.__navigationBar__.title = title;
|
|
2885
|
+
current.__navigationBarTitle__ = title;
|
|
2886
|
+
return { errMsg: "setNavigationBarTitle:ok" };
|
|
2887
|
+
}
|
|
2888
|
+
setNavigationBarColor(option) {
|
|
2889
|
+
const current = this.requireCurrentPage("wx.setNavigationBarColor()");
|
|
2890
|
+
current.__navigationBar__ ??= {
|
|
2891
|
+
animation: null,
|
|
2892
|
+
backgroundColor: "#ffffff",
|
|
2893
|
+
frontColor: "#000000",
|
|
2894
|
+
loading: false,
|
|
2895
|
+
title: current.__navigationBarTitle__ ?? ""
|
|
2896
|
+
};
|
|
2897
|
+
if (typeof option.backgroundColor === "string") current.__navigationBar__.backgroundColor = option.backgroundColor;
|
|
2898
|
+
if (typeof option.frontColor === "string") current.__navigationBar__.frontColor = option.frontColor;
|
|
2899
|
+
current.__navigationBar__.animation = option.animation ? {
|
|
2900
|
+
duration: option.animation.duration,
|
|
2901
|
+
timingFunction: option.animation.timingFunction
|
|
2902
|
+
} : null;
|
|
2903
|
+
return { errMsg: "setNavigationBarColor:ok" };
|
|
2904
|
+
}
|
|
2905
|
+
showNavigationBarLoading() {
|
|
2906
|
+
const current = this.requireCurrentPage("wx.showNavigationBarLoading()");
|
|
2907
|
+
current.__navigationBar__ ??= {
|
|
2908
|
+
animation: null,
|
|
2909
|
+
backgroundColor: "#ffffff",
|
|
2910
|
+
frontColor: "#000000",
|
|
2911
|
+
loading: false,
|
|
2912
|
+
title: current.__navigationBarTitle__ ?? ""
|
|
2913
|
+
};
|
|
2914
|
+
current.__navigationBar__.loading = true;
|
|
2915
|
+
return { errMsg: "showNavigationBarLoading:ok" };
|
|
2916
|
+
}
|
|
2917
|
+
hideNavigationBarLoading() {
|
|
2918
|
+
const current = this.requireCurrentPage("wx.hideNavigationBarLoading()");
|
|
2919
|
+
current.__navigationBar__ ??= {
|
|
2920
|
+
animation: null,
|
|
2921
|
+
backgroundColor: "#ffffff",
|
|
2922
|
+
frontColor: "#000000",
|
|
2923
|
+
loading: false,
|
|
2924
|
+
title: current.__navigationBarTitle__ ?? ""
|
|
2925
|
+
};
|
|
2926
|
+
current.__navigationBar__.loading = false;
|
|
2927
|
+
return { errMsg: "hideNavigationBarLoading:ok" };
|
|
2928
|
+
}
|
|
2929
|
+
hideTabBar() {
|
|
2930
|
+
this.tabBarVisible = false;
|
|
2931
|
+
return { errMsg: "hideTabBar:ok" };
|
|
2932
|
+
}
|
|
2933
|
+
hideTabBarRedDot(index) {
|
|
2934
|
+
const item = this.requireTabBarItem(index, "wx.hideTabBarRedDot()");
|
|
2935
|
+
item.redDot = false;
|
|
2936
|
+
return { errMsg: "hideTabBarRedDot:ok" };
|
|
2937
|
+
}
|
|
2938
|
+
showTabBar() {
|
|
2939
|
+
this.tabBarVisible = this.tabBarRoutes.size > 0;
|
|
2940
|
+
return { errMsg: "showTabBar:ok" };
|
|
2941
|
+
}
|
|
2942
|
+
showTabBarRedDot(index) {
|
|
2943
|
+
const item = this.requireTabBarItem(index, "wx.showTabBarRedDot()");
|
|
2944
|
+
item.badge = null;
|
|
2945
|
+
item.redDot = true;
|
|
2946
|
+
return { errMsg: "showTabBarRedDot:ok" };
|
|
2947
|
+
}
|
|
2948
|
+
removeTabBarBadge(index) {
|
|
2949
|
+
const item = this.requireTabBarItem(index, "wx.removeTabBarBadge()");
|
|
2950
|
+
item.badge = null;
|
|
2951
|
+
return { errMsg: "removeTabBarBadge:ok" };
|
|
2952
|
+
}
|
|
2953
|
+
setTabBarBadge(index, text) {
|
|
2954
|
+
const item = this.requireTabBarItem(index, "wx.setTabBarBadge()");
|
|
2955
|
+
item.badge = text;
|
|
2956
|
+
item.redDot = false;
|
|
2957
|
+
return { errMsg: "setTabBarBadge:ok" };
|
|
2958
|
+
}
|
|
1867
2959
|
bootstrap(launchOptions = createAppLaunchOptions("", {})) {
|
|
1868
2960
|
if (this.appInstance) return this.appInstance;
|
|
2961
|
+
this.launchOptions = createAppLaunchOptions(launchOptions.path, launchOptions.query);
|
|
2962
|
+
this.enterOptions = createAppLaunchOptions(launchOptions.path, launchOptions.query);
|
|
1869
2963
|
const appModulePath = path.resolve(this.project.miniprogramRootPath, "app.js");
|
|
1870
2964
|
this.appDefinition = this.moduleLoader.executeAppModule(appModulePath);
|
|
1871
2965
|
this.appInstance = createAppInstance(this.appDefinition);
|
|
@@ -1962,6 +3056,7 @@ var HeadlessSession = class {
|
|
|
1962
3056
|
}
|
|
1963
3057
|
triggerResize(options) {
|
|
1964
3058
|
const current = this.requireCurrentPage("triggerResize()");
|
|
3059
|
+
applyResizeToSystemInfo(this.systemInfo, options);
|
|
1965
3060
|
current.onResize?.(options);
|
|
1966
3061
|
return current;
|
|
1967
3062
|
}
|
|
@@ -1973,8 +3068,13 @@ var HeadlessSession = class {
|
|
|
1973
3068
|
stopPullDownRefresh() {}
|
|
1974
3069
|
createFreshPage(target) {
|
|
1975
3070
|
const pageModulePath = path.resolve(this.project.miniprogramRootPath, `${target.routeRecord.route}.js`);
|
|
3071
|
+
const pageConfigPath = path.resolve(this.project.miniprogramRootPath, `${target.routeRecord.route}.json`);
|
|
1976
3072
|
const pageDefinition = this.moduleLoader.executePageModule(pageModulePath, target.routeRecord.route);
|
|
1977
|
-
const
|
|
3073
|
+
const pageConfig = readJsonObject(pageConfigPath);
|
|
3074
|
+
const pageInstance = createPageInstance(`/${target.routeRecord.route}`, pageDefinition, target.query, {
|
|
3075
|
+
background: resolveBackgroundSnapshot(this.project.appConfig, pageConfig),
|
|
3076
|
+
navigationBar: resolveNavigationBarSnapshot(this.project.appConfig, pageConfig)
|
|
3077
|
+
});
|
|
1978
3078
|
pageInstance.onLoad?.(target.query);
|
|
1979
3079
|
pageInstance.onShow?.();
|
|
1980
3080
|
pageInstance.onReady?.();
|
|
@@ -1990,6 +3090,12 @@ var HeadlessSession = class {
|
|
|
1990
3090
|
if (!item) throw new Error(`Missing tabBar metadata for route "${route}" in headless runtime.`);
|
|
1991
3091
|
return { ...item };
|
|
1992
3092
|
}
|
|
3093
|
+
requireTabBarItem(index, action) {
|
|
3094
|
+
const normalizedIndex = Number.isFinite(index) ? Math.trunc(index) : NaN;
|
|
3095
|
+
const item = this.tabBarState.get(normalizedIndex);
|
|
3096
|
+
if (!item) throw new Error(`Cannot call ${action} with unknown tabBar index ${index} in headless runtime.`);
|
|
3097
|
+
return item;
|
|
3098
|
+
}
|
|
1993
3099
|
removePageInstance(page) {
|
|
1994
3100
|
const index = this.pages.indexOf(page);
|
|
1995
3101
|
if (index >= 0) this.pages.splice(index, 1);
|
|
@@ -2073,9 +3179,62 @@ function querySelectorAll(root, selector) {
|
|
|
2073
3179
|
}
|
|
2074
3180
|
//#endregion
|
|
2075
3181
|
//#region src/view/nodeHandle.ts
|
|
3182
|
+
const DATASET_NAME_RE = /-([a-z])/g;
|
|
2076
3183
|
function escapeText$1(text) {
|
|
2077
3184
|
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
2078
3185
|
}
|
|
3186
|
+
function toDatasetKey(attributeName) {
|
|
3187
|
+
return attributeName.slice(5).replace(DATASET_NAME_RE, (_match, char) => char.toUpperCase());
|
|
3188
|
+
}
|
|
3189
|
+
function collectDataset(node) {
|
|
3190
|
+
const dataset = {};
|
|
3191
|
+
for (const [key, value] of Object.entries(node.attribs ?? {})) {
|
|
3192
|
+
if (!key.startsWith("data-")) continue;
|
|
3193
|
+
dataset[toDatasetKey(key)] = value;
|
|
3194
|
+
}
|
|
3195
|
+
return dataset;
|
|
3196
|
+
}
|
|
3197
|
+
function resolveEventBinding(node, eventName) {
|
|
3198
|
+
const normalizedEventName = eventName.trim();
|
|
3199
|
+
if (!normalizedEventName) return null;
|
|
3200
|
+
const bindingAttrs = [
|
|
3201
|
+
`bind${normalizedEventName}`,
|
|
3202
|
+
`bind:${normalizedEventName}`,
|
|
3203
|
+
`catch${normalizedEventName}`,
|
|
3204
|
+
`catch:${normalizedEventName}`
|
|
3205
|
+
];
|
|
3206
|
+
for (const attributeName of bindingAttrs) {
|
|
3207
|
+
const methodName = node.attribs?.[attributeName]?.trim();
|
|
3208
|
+
if (methodName) return methodName;
|
|
3209
|
+
}
|
|
3210
|
+
return null;
|
|
3211
|
+
}
|
|
3212
|
+
function createEventPayload(node, eventName, event) {
|
|
3213
|
+
const dataset = collectDataset(node);
|
|
3214
|
+
const nodeId = node.attribs?.id ?? "";
|
|
3215
|
+
return {
|
|
3216
|
+
bubbles: false,
|
|
3217
|
+
capturePhase: false,
|
|
3218
|
+
composed: false,
|
|
3219
|
+
currentTarget: {
|
|
3220
|
+
dataset: event.currentTarget?.dataset ?? event.dataset ?? dataset,
|
|
3221
|
+
id: event.currentTarget?.id ?? event.id ?? nodeId
|
|
3222
|
+
},
|
|
3223
|
+
detail: event.detail,
|
|
3224
|
+
mark: event.mark,
|
|
3225
|
+
target: {
|
|
3226
|
+
dataset: event.target?.dataset ?? event.dataset ?? dataset,
|
|
3227
|
+
id: event.target?.id ?? event.id ?? nodeId
|
|
3228
|
+
},
|
|
3229
|
+
type: eventName
|
|
3230
|
+
};
|
|
3231
|
+
}
|
|
3232
|
+
function createValueEventDetail(value, detail) {
|
|
3233
|
+
return {
|
|
3234
|
+
value,
|
|
3235
|
+
...detail ?? {}
|
|
3236
|
+
};
|
|
3237
|
+
}
|
|
2079
3238
|
function escapeAttribute$1(value) {
|
|
2080
3239
|
return escapeText$1(value).replaceAll("\"", """);
|
|
2081
3240
|
}
|
|
@@ -2092,34 +3251,62 @@ function collectText(node) {
|
|
|
2092
3251
|
return (node.children ?? []).map(collectText).join("");
|
|
2093
3252
|
}
|
|
2094
3253
|
var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
|
|
2095
|
-
constructor(node) {
|
|
3254
|
+
constructor(node, interactions) {
|
|
2096
3255
|
this.node = node;
|
|
3256
|
+
this.interactions = interactions;
|
|
2097
3257
|
}
|
|
2098
3258
|
async $(selector) {
|
|
2099
3259
|
const match = querySelectorAll(this.node, selector)[0];
|
|
2100
|
-
return match ? new HeadlessTestingNodeHandle(match) : null;
|
|
3260
|
+
return match ? new HeadlessTestingNodeHandle(match, this.interactions) : null;
|
|
2101
3261
|
}
|
|
2102
3262
|
async $$(selector) {
|
|
2103
|
-
return querySelectorAll(this.node, selector).map((node) => new HeadlessTestingNodeHandle(node));
|
|
3263
|
+
return querySelectorAll(this.node, selector).map((node) => new HeadlessTestingNodeHandle(node, this.interactions));
|
|
2104
3264
|
}
|
|
2105
3265
|
async attr(name) {
|
|
2106
3266
|
return this.node.attribs?.[name];
|
|
2107
3267
|
}
|
|
2108
3268
|
async dataset() {
|
|
2109
|
-
|
|
2110
|
-
for (const [key, value] of Object.entries(this.node.attribs ?? {})) if (key.startsWith("data-")) dataset[key.slice(5)] = value;
|
|
2111
|
-
return dataset;
|
|
3269
|
+
return collectDataset(this.node);
|
|
2112
3270
|
}
|
|
2113
3271
|
async text() {
|
|
2114
3272
|
return collectText(this.node);
|
|
2115
3273
|
}
|
|
3274
|
+
async trigger(eventName, event = {}) {
|
|
3275
|
+
if (!this.interactions) throw new Error("Node interactions are not available for this headless testing node.");
|
|
3276
|
+
const normalizedEventName = eventName.trim();
|
|
3277
|
+
if (!normalizedEventName) throw new Error("Event name must be a non-empty string in headless testing runtime.");
|
|
3278
|
+
const methodName = resolveEventBinding(this.node, normalizedEventName);
|
|
3279
|
+
if (!methodName) throw new Error(`No ${normalizedEventName} binding was found on <${this.node.name ?? "unknown"}> in headless testing runtime.`);
|
|
3280
|
+
return await this.interactions.callMethod(methodName, createEventPayload(this.node, normalizedEventName, event));
|
|
3281
|
+
}
|
|
3282
|
+
async tap(event = {}) {
|
|
3283
|
+
return await this.trigger("tap", event);
|
|
3284
|
+
}
|
|
3285
|
+
async input(value, event = {}) {
|
|
3286
|
+
return await this.trigger("input", {
|
|
3287
|
+
...event,
|
|
3288
|
+
detail: createValueEventDetail(value, event.detail)
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
async change(value, event = {}) {
|
|
3292
|
+
return await this.trigger("change", {
|
|
3293
|
+
...event,
|
|
3294
|
+
detail: createValueEventDetail(value, event.detail)
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
async blur(value, event = {}) {
|
|
3298
|
+
return await this.trigger("blur", {
|
|
3299
|
+
...event,
|
|
3300
|
+
detail: value == null ? event.detail : createValueEventDetail(value, event.detail)
|
|
3301
|
+
});
|
|
3302
|
+
}
|
|
2116
3303
|
async wxml() {
|
|
2117
3304
|
return serializeNode(this.node);
|
|
2118
3305
|
}
|
|
2119
3306
|
};
|
|
2120
3307
|
//#endregion
|
|
2121
3308
|
//#region src/view/render.ts
|
|
2122
|
-
const LEADING_SLASH_RE = /^\/+/;
|
|
3309
|
+
const LEADING_SLASH_RE$1 = /^\/+/;
|
|
2123
3310
|
const TEMPLATE_INTERPOLATION_RE = /\{\{([^{}]+)\}\}/g;
|
|
2124
3311
|
function resolveValueByPath(source, expression) {
|
|
2125
3312
|
const normalized = expression.trim();
|
|
@@ -2159,7 +3346,7 @@ function serializeDomNode(node) {
|
|
|
2159
3346
|
return `<${tagName}${Object.entries(node.attribs ?? {}).map(([key, value]) => ` ${key}="${escapeAttribute(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode).join("")}</${tagName}>`;
|
|
2160
3347
|
}
|
|
2161
3348
|
function renderPageTree(project, page) {
|
|
2162
|
-
const route = page.route.replace(LEADING_SLASH_RE, "");
|
|
3349
|
+
const route = page.route.replace(LEADING_SLASH_RE$1, "");
|
|
2163
3350
|
const templatePath = path.resolve(project.miniprogramRootPath, `${route}.wxml`);
|
|
2164
3351
|
const document = parseDocument(`<page>${fs.readFileSync(templatePath, "utf8")}</page>`, {
|
|
2165
3352
|
xmlMode: false,
|
|
@@ -2174,30 +3361,46 @@ function renderPageTree(project, page) {
|
|
|
2174
3361
|
}
|
|
2175
3362
|
//#endregion
|
|
2176
3363
|
//#region src/testing/pageHandle.ts
|
|
3364
|
+
const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
|
|
3365
|
+
const DEFAULT_WAIT_INTERVAL$1 = 10;
|
|
2177
3366
|
var HeadlessTestingPageHandle = class {
|
|
2178
3367
|
constructor(project, page) {
|
|
2179
3368
|
this.project = project;
|
|
2180
3369
|
this.page = page;
|
|
2181
3370
|
}
|
|
2182
|
-
|
|
2183
|
-
const method = this.page[methodName];
|
|
2184
|
-
if (typeof method !== "function") throw new Error(`Method "${methodName}" does not exist on headless page ${this.page.route}.`);
|
|
2185
|
-
return await method.apply(this.page, args);
|
|
2186
|
-
}
|
|
2187
|
-
async data(path) {
|
|
3371
|
+
resolveDataByPath(path) {
|
|
2188
3372
|
if (!path) return this.page.data;
|
|
2189
3373
|
const segments = path.split(".").filter(Boolean);
|
|
2190
3374
|
let current = this.page.data;
|
|
2191
3375
|
for (const segment of segments) current = current?.[segment];
|
|
2192
3376
|
return current;
|
|
2193
3377
|
}
|
|
3378
|
+
async pollUntil(check, errorMessage, options = {}) {
|
|
3379
|
+
const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT$1)) : DEFAULT_WAIT_TIMEOUT$1;
|
|
3380
|
+
const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL$1)) : DEFAULT_WAIT_INTERVAL$1;
|
|
3381
|
+
const deadline = Date.now() + timeout;
|
|
3382
|
+
while (true) {
|
|
3383
|
+
const result = await check();
|
|
3384
|
+
if (result != null) return result;
|
|
3385
|
+
if (Date.now() >= deadline) throw new Error(errorMessage);
|
|
3386
|
+
await this.waitFor(interval);
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
async callMethod(methodName, ...args) {
|
|
3390
|
+
const method = this.page[methodName];
|
|
3391
|
+
if (typeof method !== "function") throw new TypeError(`Method "${methodName}" does not exist on headless page ${this.page.route}.`);
|
|
3392
|
+
return await method.apply(this.page, args);
|
|
3393
|
+
}
|
|
3394
|
+
async data(path) {
|
|
3395
|
+
return this.resolveDataByPath(path);
|
|
3396
|
+
}
|
|
2194
3397
|
async waitFor(ms = 0) {
|
|
2195
3398
|
if (ms <= 0) return;
|
|
2196
3399
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
2197
3400
|
}
|
|
2198
3401
|
async $(selector) {
|
|
2199
3402
|
const tree = renderPageTree(this.project, this.page);
|
|
2200
|
-
const root = new HeadlessTestingNodeHandle(tree.root.children?.[0] ?? tree.root);
|
|
3403
|
+
const root = new HeadlessTestingNodeHandle(tree.root.children?.[0] ?? tree.root, { callMethod: (methodName, event) => this.callMethod(methodName, event) });
|
|
2201
3404
|
if (selector === "page") return root;
|
|
2202
3405
|
return await root.$(selector);
|
|
2203
3406
|
}
|
|
@@ -2207,17 +3410,72 @@ var HeadlessTestingPageHandle = class {
|
|
|
2207
3410
|
if (selector === "page") return [root];
|
|
2208
3411
|
return await root.$$(selector);
|
|
2209
3412
|
}
|
|
3413
|
+
async waitForSelector(selector, options = {}) {
|
|
3414
|
+
const normalizedSelector = selector.trim();
|
|
3415
|
+
if (!normalizedSelector) throw new Error("Selector must be a non-empty string in headless testing runtime.");
|
|
3416
|
+
if ((options.state ?? "attached") === "detached") {
|
|
3417
|
+
await this.pollUntil(async () => await this.$(normalizedSelector) ? null : true, `Timed out waiting for selector "${normalizedSelector}" to become detached in headless testing runtime.`, options);
|
|
3418
|
+
return null;
|
|
3419
|
+
}
|
|
3420
|
+
return await this.pollUntil(async () => await this.$(normalizedSelector), `Timed out waiting for selector "${normalizedSelector}" to appear in headless testing runtime.`, options);
|
|
3421
|
+
}
|
|
3422
|
+
async waitForText(text, options = {}) {
|
|
3423
|
+
const normalizedText = text.trim();
|
|
3424
|
+
if (!normalizedText) throw new Error("Text must be a non-empty string in headless testing runtime.");
|
|
3425
|
+
return await this.pollUntil(async () => {
|
|
3426
|
+
return (await this.wxml()).includes(normalizedText) ? normalizedText : null;
|
|
3427
|
+
}, `Timed out waiting for text "${normalizedText}" in headless testing runtime.`, options);
|
|
3428
|
+
}
|
|
3429
|
+
async waitForTextGone(text, options = {}) {
|
|
3430
|
+
const normalizedText = text.trim();
|
|
3431
|
+
if (!normalizedText) throw new Error("Text must be a non-empty string in headless testing runtime.");
|
|
3432
|
+
await this.pollUntil(async () => {
|
|
3433
|
+
return (await this.wxml()).includes(normalizedText) ? null : true;
|
|
3434
|
+
}, `Timed out waiting for text "${normalizedText}" to disappear in headless testing runtime.`, options);
|
|
3435
|
+
}
|
|
3436
|
+
async waitForData(path, matcher, options = {}) {
|
|
3437
|
+
const normalizedPath = path.trim();
|
|
3438
|
+
if (!normalizedPath) throw new Error("Data path must be a non-empty string in headless testing runtime.");
|
|
3439
|
+
const hasMatcher = arguments.length >= 2;
|
|
3440
|
+
return await this.pollUntil(async () => {
|
|
3441
|
+
const value = this.resolveDataByPath(normalizedPath);
|
|
3442
|
+
if (typeof matcher === "function") return matcher(value) ? value : null;
|
|
3443
|
+
if (hasMatcher) return Object.is(value, matcher) ? value : null;
|
|
3444
|
+
return value === void 0 ? null : value;
|
|
3445
|
+
}, `Timed out waiting for data "${normalizedPath}" in headless testing runtime.`, options);
|
|
3446
|
+
}
|
|
2210
3447
|
async wxml() {
|
|
2211
3448
|
return renderPageTree(this.project, this.page).wxml;
|
|
2212
3449
|
}
|
|
2213
3450
|
};
|
|
2214
3451
|
//#endregion
|
|
2215
3452
|
//#region src/testing/sessionHandle.ts
|
|
3453
|
+
const LEADING_SLASH_RE = /^\/+/;
|
|
3454
|
+
const DEFAULT_WAIT_TIMEOUT = 1e3;
|
|
3455
|
+
const DEFAULT_WAIT_INTERVAL = 10;
|
|
3456
|
+
function normalizeRoute(route) {
|
|
3457
|
+
return route.replace(LEADING_SLASH_RE, "");
|
|
3458
|
+
}
|
|
2216
3459
|
var HeadlessTestingSessionHandle = class {
|
|
2217
3460
|
constructor(project, session) {
|
|
2218
3461
|
this.project = project;
|
|
2219
3462
|
this.session = session;
|
|
2220
3463
|
}
|
|
3464
|
+
async waitFor(ms = 0) {
|
|
3465
|
+
if (ms <= 0) return;
|
|
3466
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
3467
|
+
}
|
|
3468
|
+
async pollUntil(check, errorMessage, options = {}) {
|
|
3469
|
+
const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT)) : DEFAULT_WAIT_TIMEOUT;
|
|
3470
|
+
const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL)) : DEFAULT_WAIT_INTERVAL;
|
|
3471
|
+
const deadline = Date.now() + timeout;
|
|
3472
|
+
while (true) {
|
|
3473
|
+
const result = await check();
|
|
3474
|
+
if (result != null) return result;
|
|
3475
|
+
if (Date.now() >= deadline) throw new Error(errorMessage);
|
|
3476
|
+
await this.waitFor(interval);
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
2221
3479
|
async close() {}
|
|
2222
3480
|
async currentPage() {
|
|
2223
3481
|
const current = this.session.getCurrentPages().at(-1);
|
|
@@ -2230,6 +3488,18 @@ var HeadlessTestingSessionHandle = class {
|
|
|
2230
3488
|
const page = this.session.reLaunch(route);
|
|
2231
3489
|
return new HeadlessTestingPageHandle(this.project, page);
|
|
2232
3490
|
}
|
|
3491
|
+
async waitForCurrentPage(route, options = {}) {
|
|
3492
|
+
const normalizedRoute = route?.trim();
|
|
3493
|
+
if (normalizedRoute != null && !normalizedRoute) throw new Error("Route must be a non-empty string in headless testing runtime.");
|
|
3494
|
+
return await this.pollUntil(async () => {
|
|
3495
|
+
const currentPageInstance = this.session.getCurrentPages().at(-1);
|
|
3496
|
+
if (!currentPageInstance) return null;
|
|
3497
|
+
const current = new HeadlessTestingPageHandle(this.project, currentPageInstance);
|
|
3498
|
+
if (!normalizedRoute) return current;
|
|
3499
|
+
if (normalizeRoute(currentPageInstance.route) === normalizeRoute(normalizedRoute)) return current;
|
|
3500
|
+
return null;
|
|
3501
|
+
}, normalizedRoute ? `Timed out waiting for current page "${normalizeRoute(normalizedRoute)}" in headless testing runtime.` : "Timed out waiting for a current page in headless testing runtime.", options);
|
|
3502
|
+
}
|
|
2233
3503
|
async pageScrollTo(scrollTop) {
|
|
2234
3504
|
this.session.pageScrollTo({ scrollTop });
|
|
2235
3505
|
}
|