@mpcore/simulator 1.3.5-dev.20261117.1 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +5 -3
  2. package/dist/index.mjs +208 -112
  3. package/package.json +6 -14
package/README.md CHANGED
@@ -76,13 +76,15 @@ Node/browser 宿主提供 `BeforeAppRoute`、`BeforePageUnload`、`AppRoute`、`
76
76
 
77
77
  Node/browser 的原生 tap 到达未禁用的 `button form-type="submit"` 时,在 tap 回调之后提交最近的参与表单。提交目标、字段值与方法所有者在回调前固定;组件销毁、重渲染或同路由重建不会把提交转交给新实例。`tap()` 等待 tap 与 submit 的异步处理,继续传递结果或错误。普通插槽按声明归属参与;跨私有组件边界的按钮需要 `wx://form-field-button`,原生字段分组需要 `wx://form-field-group`。WXML 按 XML 节点结构解析,不应用 HTML 对嵌套 `form` 的隐式修复。
78
78
 
79
+ `checked` / `disabled` 在序列化前保留原始绑定值,裸属性为 true,空值或缺失绑定为 false。禁用按钮不派发 tap 或 submit。保留的 tap 句柄在激活前按节点身份重新定位到当前渲染树,节点已移除时拒绝分发,不能调用旧回调。
80
+
79
81
  后续监听器同步抛错时,测试句柄仍观察并等待此前已启动的异步处理。只有该同步错误时原样抛出;异步处理也失败时,抛出包含全部已收集失败的 `AggregateError`,并以原同步错误作为 `cause`,避免遗留未处理的 Promise 拒绝。
80
82
 
81
- `submit.detail.value` 来自参与表单的具名原生控件当前渲染绑定,包含 input/textarea、switch、slider、picker、radio-group 与 checkbox-group;picker 数组保留原始绑定类型,不从逗号字符串猜测值。此能力不补齐未绑定输入的宿主状态、`wx://form-field` 自定义值导出、reset 或真实 `formId` 上报,也不把任意页面数据当作原生字段值。
83
+ `submit.detail.value` 来自参与表单的具名原生控件当前渲染绑定,包含 input/textarea、switch、slider、picker、radio-group 与 checkbox-group;picker 数组保留原始绑定类型,不从逗号字符串猜测值。参与的 `wx://form-field` 组件按自己的当前 name/value 收集,保留对象、false、0 和 null,并在 tap 回调前克隆值。私有组件内部字段仍被隔离。此能力不补齐未绑定输入的宿主状态、reset 或真实 `formId` 上报,也不把任意页面数据当作原生字段值。
82
84
 
83
- `rich-text` 的结构化 `nodes` 与 HTML 字符串通过 `@weapp-core/shared/rich-text` 的共同安全规则生成实际渲染子树,支持更新和清空。内容不会再次解释为 WXML 表达式、事件或自定义组件;外部内容不能伪造 `data-sim-*` 元数据。通用 `text()`、快照和序列化观察同一份渲染内容,`attr('nodes')` 仍是既有字符串属性,不是结构化属性 API。富文本内部不获得 WXML 声明作用域;需要检查内部渲染节点时使用 XPath,而不是放宽声明作用域内的 CSS 查询。
85
+ `rich-text` 的结构化 `nodes` 与 HTML 字符串通过 `@weapp-core/shared/rich-text` 的 `normalizeNativeRichTextNodes` 生成实际渲染子树,支持更新和清空。仅保留微信原生支持的节点和逐标签属性,未知节点及子树被移除;文本实体仅解码一次,内容不会再次解释为 WXML 表达式、事件或自定义组件,也不能伪造 `data-sim-*` 元数据。`normalizeRichTextNodes` 保持独立的 Web 规范化策略,不携带原生策略及其额外解码代码。通用 `text()`、快照和序列化观察同一份渲染内容,`attr('nodes')` 仍是既有字符串属性,不是结构化属性 API。富文本内部不获得 WXML 声明作用域;需要检查内部渲染节点时使用 XPath,而不是放宽声明作用域内的 CSS 查询。
84
86
 
85
- 浏览器预览取消富文本链接的普通/辅助点击导航和 HTML 表单默认提交;业务 tap 与原生表单动作仍由模拟器分发,不能让浏览器额外导航或再次提交。
87
+ 浏览器预览取消富文本链接的普通/辅助点击导航和 HTML 表单默认提交;富文本链接与表单按钮的中键按下阶段也取消 Windows 自动滚动等宿主默认动作,不影响主键按下。业务 tap 与原生表单动作仍由模拟器分发,不能让浏览器额外导航或再次提交。
86
88
 
87
89
  上述能力属于模拟器模型,不代表真实微信 IDE 或设备验收。
88
90
 
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { TemplateLexicalError, compileDialect, createParser, decodeAttribute, ex
7
7
  import postcss from "postcss";
8
8
  import valueParser from "postcss-value-parser";
9
9
  import { weapp } from "@weapp-vite/wxml/presets";
10
- import { normalizeRichTextNodes } from "@weapp-core/shared/rich-text";
10
+ import { normalizeNativeRichTextNodes } from "@weapp-core/shared/rich-text";
11
11
  import { selectAll } from "css-select";
12
12
  import { AttributeAction, SelectorType, parse as parse$1 } from "css-what";
13
13
  import * as fontoxpath from "fontoxpath";
@@ -3122,6 +3122,36 @@ function resolveEventBindingPhases(attributes, eventName, includeCapture = true)
3122
3122
  }
3123
3123
  return bindings;
3124
3124
  }
3125
+ // src/view/nativeBoolean.ts
3126
+ const nativeBooleanValues = /* @__PURE__ */ new WeakMap();
3127
+ /** 保留原始布尔属性值,避免 null/undefined 在属性序列化后退化为裸属性。 */
3128
+ function setNativeBooleanValue(node, name, value, valueless = false) {
3129
+ if (name !== "checked" && name !== "disabled") return;
3130
+ let values = nativeBooleanValues.get(node);
3131
+ if (!values) {
3132
+ values = /* @__PURE__ */ new Map();
3133
+ nativeBooleanValues.set(node, values);
3134
+ }
3135
+ values.set(name, {
3136
+ value,
3137
+ valueless
3138
+ });
3139
+ }
3140
+ function getNativeBooleanValue(node, name) {
3141
+ const attributes = node.attribs;
3142
+ if (!attributes || !Object.hasOwn(attributes, name)) return false;
3143
+ const snapshot = node.nativeBooleanValues;
3144
+ const stored = nativeBooleanValues.get(node)?.get(name) ?? snapshot?.get(name);
3145
+ if (stored) {
3146
+ if (stored.valueless) return true;
3147
+ return stored.value !== void 0 && stored.value !== null && stored.value !== false && stored.value !== 0 && stored.value !== "" && stored.value !== "false" && stored.value !== "0";
3148
+ }
3149
+ const value = attributes[name];
3150
+ return value !== "false" && value !== "0";
3151
+ }
3152
+ function getNativeBooleanSnapshot(node) {
3153
+ return nativeBooleanValues.get(node);
3154
+ }
3125
3155
  // src/view/nodeDataset.ts
3126
3156
  const DATASET_NAME_RE = /-([a-z])/g;
3127
3157
  function isDatasetAttribute(attributeName) {
@@ -3182,7 +3212,8 @@ function mergeComponentEventRoot(root, host) {
3182
3212
  const entry = eventNodes.get(root);
3183
3213
  if (entry.target === root) entry.target = {
3184
3214
  attribs: root.attribs,
3185
- dataset: root.dataset
3215
+ dataset: root.dataset,
3216
+ nativeBooleanValues: getNativeBooleanSnapshot(root)
3186
3217
  };
3187
3218
  entry.hosts ??= [];
3188
3219
  entry.hosts.push(host);
@@ -4061,6 +4092,52 @@ function getNativeBindingCommit(node, previous) {
4061
4092
  }
4062
4093
  };
4063
4094
  }
4095
+ // src/testing/sessionHandle/shared.ts
4096
+ const LEADING_SLASH_RE$5 = /^\/+/;
4097
+ const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
4098
+ const DEFAULT_WAIT_INTERVAL$1 = 10;
4099
+ function normalizeRoute$1(route) {
4100
+ return route.replace(LEADING_SLASH_RE$5, "");
4101
+ }
4102
+ function resolvePageScopeId$1(scopeId) {
4103
+ const pagePathIndex = scopeId.indexOf("/page/");
4104
+ return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
4105
+ }
4106
+ function normalizeNonEmptyInput(value, label) {
4107
+ const normalizedValue = value.trim();
4108
+ if (!normalizedValue) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
4109
+ return normalizedValue;
4110
+ }
4111
+ function cloneProtocolValue(value) {
4112
+ if (!value || typeof value !== "object") return value;
4113
+ return JSON.parse(JSON.stringify(value));
4114
+ }
4115
+ async function waitForDelay(ms = 0) {
4116
+ if (ms <= 0) return;
4117
+ await new Promise((resolve) => setTimeout(resolve, ms));
4118
+ }
4119
+ async function pollUntil$2(check, errorMessage, options = {}) {
4120
+ const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT$1)) : DEFAULT_WAIT_TIMEOUT$1;
4121
+ const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL$1)) : DEFAULT_WAIT_INTERVAL$1;
4122
+ const deadline = Date.now() + timeout;
4123
+ while (true) {
4124
+ const result = await check();
4125
+ if (result != null) return result;
4126
+ if (Date.now() >= deadline) throw new Error(errorMessage);
4127
+ await waitForDelay(interval);
4128
+ }
4129
+ }
4130
+ async function runWithTimeout(operation, timeout, message) {
4131
+ if (!Number.isFinite(timeout) || (timeout ?? 0) <= 0) return await operation();
4132
+ let timer;
4133
+ try {
4134
+ return await Promise.race([Promise.resolve().then(operation), new Promise((_resolve, reject) => {
4135
+ timer = setTimeout(() => reject(new Error(message)), Math.trunc(timeout));
4136
+ })]);
4137
+ } finally {
4138
+ if (timer) clearTimeout(timer);
4139
+ }
4140
+ }
4064
4141
  // src/view/nodeEvents.ts
4065
4142
  /** 正确字段优先;复制触点,避免处理器修改调用者持有的数据。 */
4066
4143
  function readTouchEventPayload(event) {
@@ -4138,9 +4215,33 @@ function participates(scopeId, formScopes, behavior, resolveComponent) {
4138
4215
  }
4139
4216
  return true;
4140
4217
  }
4141
- function checked(attributes, name) {
4142
- const value = attributes?.[name];
4143
- return value !== void 0 && value !== "false" && value !== "0";
4218
+ function participatesFormField(scopeId, formScopes, resolveComponent) {
4219
+ const visited = /* @__PURE__ */ new Set();
4220
+ while (!formScopes.has(scopeId)) {
4221
+ if (!scopeId || visited.has(scopeId)) return false;
4222
+ visited.add(scopeId);
4223
+ const component = resolveComponent?.(scopeId);
4224
+ if (!component || !includesBehavior(component.definition, "wx://form-field") && !includesBehavior(component.definition, "wx://form-field-group")) return false;
4225
+ scopeId = component.ownerScopeId;
4226
+ }
4227
+ return true;
4228
+ }
4229
+ function resolveFormFieldComponent(scopeId, resolveComponent) {
4230
+ const visited = /* @__PURE__ */ new Set();
4231
+ let current = scopeId;
4232
+ while (current && !visited.has(current)) {
4233
+ visited.add(current);
4234
+ const component = resolveComponent?.(current);
4235
+ if (!component) return;
4236
+ if (includesBehavior(component.definition, "wx://form-field")) return {
4237
+ scopeId: current,
4238
+ component
4239
+ };
4240
+ current = component.ownerScopeId;
4241
+ }
4242
+ }
4243
+ function checked(node, name) {
4244
+ return getNativeBooleanValue(node, name);
4144
4245
  }
4145
4246
  function choiceValues(group, pageScope, resolveComponent) {
4146
4247
  const values = [];
@@ -4150,7 +4251,7 @@ function choiceValues(group, pageScope, resolveComponent) {
4150
4251
  if (node.name === "form" || node.name === "radio-group" || node.name === "checkbox-group") return;
4151
4252
  if (node.name === choice) {
4152
4253
  const owner = nativeOwner(node);
4153
- if (checked(owner.target.attribs, "checked") && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) values.push(owner.target.attribs?.value ?? "");
4254
+ if (checked(owner.target, "checked") && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) values.push(owner.target.attribs?.value ?? "");
4154
4255
  }
4155
4256
  for (const child of node.children ?? []) visit(child);
4156
4257
  };
@@ -4163,6 +4264,12 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
4163
4264
  if (node.name === "form") return;
4164
4265
  const owner = nativeOwner(node);
4165
4266
  const attributes = owner.target.attribs;
4267
+ const field = resolveFormFieldComponent(owner.scopeId, resolveComponent);
4268
+ const componentName = field?.component.name;
4269
+ if (typeof componentName === "string" && componentName && node.attribs?.["data-sim-component"] && field && participatesFormField(field.scopeId, scopes, resolveComponent)) {
4270
+ values[componentName] = cloneProtocolValue(field.component.value);
4271
+ return;
4272
+ }
4166
4273
  const name = attributes?.name;
4167
4274
  if (attributes && name && participates(owner.scopeId, scopes, "wx://form-field-group", resolveComponent)) switch (node.name) {
4168
4275
  case "input":
@@ -4170,7 +4277,7 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
4170
4277
  values[name] = attributes.value ?? "";
4171
4278
  break;
4172
4279
  case "switch":
4173
- values[name] = checked(attributes, "checked");
4280
+ values[name] = checked(owner.target, "checked");
4174
4281
  break;
4175
4282
  case "slider":
4176
4283
  values[name] = Number(attributes.value ?? 0);
@@ -4196,7 +4303,7 @@ function collectFormValues(form, scopes, pageScope, resolveComponent) {
4196
4303
  /** 先固定提交目标、字段值和方法所有者,再允许 tap 回调改变组件树。 */
4197
4304
  function prepareNativeFormSubmit(button, pageScope, event, resolveMethod, resolveComponent) {
4198
4305
  const owner = nativeOwner(button);
4199
- if (owner.target.attribs?.["form-type"] !== "submit" || checked(owner.target.attribs, "disabled")) return;
4306
+ if (owner.target.attribs?.["form-type"] !== "submit" || checked(owner.target, "disabled")) return;
4200
4307
  let form = button.parent;
4201
4308
  while (form && form.name !== "form") form = form.parent;
4202
4309
  if (!form) return;
@@ -4218,7 +4325,6 @@ function materializeNode(node) {
4218
4325
  type: "text",
4219
4326
  data: node.text
4220
4327
  };
4221
- for (const name of Object.keys(node.attrs)) if (name.startsWith("data-sim-")) delete node.attrs[name];
4222
4328
  return {
4223
4329
  type: "tag",
4224
4330
  name: node.name,
@@ -4228,7 +4334,7 @@ function materializeNode(node) {
4228
4334
  }
4229
4335
  /** 富文本直接成为已渲染节点,不能再进入 WXML 表达式或组件处理流程。 */
4230
4336
  function renderRichTextNodes(value) {
4231
- return normalizeRichTextNodes(value).map(materializeNode);
4337
+ return normalizeNativeRichTextNodes(value).map(materializeNode);
4232
4338
  }
4233
4339
  // src/view/templateIncludes.ts
4234
4340
  /** 展开 include 的可渲染内容,并保留嵌套引用的来源文件。 */
@@ -4326,7 +4432,7 @@ function parseWxsTemplateDocument(templateSource) {
4326
4432
  return parseSharedWxsDocument(templateSource);
4327
4433
  }
4328
4434
  // src/browser/render/shared.ts
4329
- const LEADING_SLASH_RE$5 = /^\/+/;
4435
+ const LEADING_SLASH_RE$4 = /^\/+/;
4330
4436
  const EVENT_BINDING_ATTRS$1 = [
4331
4437
  "bindtap",
4332
4438
  "bind:tap",
@@ -4406,7 +4512,7 @@ function serializeDomNode$2(node) {
4406
4512
  if (node.type === "root") return (node.children ?? []).map(serializeDomNode$2).join("");
4407
4513
  const tagName = node.name ?? "";
4408
4514
  if (!tagName) return (node.children ?? []).map(serializeDomNode$2).join("");
4409
- return `<${tagName}${Object.entries(node.attribs ?? {}).map(([key, value]) => ` ${key}="${escapeAttribute$2(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode$2).join("")}</${tagName}>`;
4515
+ return `<${tagName}${Object.entries(node.attribs ?? {}).filter(([key]) => key !== "disabled" && key !== "checked" || getNativeBooleanValue(node, key)).map(([key, value]) => ` ${key}="${escapeAttribute$2(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode$2).join("")}</${tagName}>`;
4410
4516
  }
4411
4517
  function isTagNode$1(node) {
4412
4518
  return node.type === "tag" && typeof node.name === "string";
@@ -4435,6 +4541,7 @@ function applyNodeBindings$1(node, scope, richText = false) {
4435
4541
  continue;
4436
4542
  }
4437
4543
  const resolvedValue = resolveNativeAttributeValue(node, key, scope, (source) => typeof value === "string" ? resolveAttributeValue$1(value, source) : value);
4544
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
4438
4545
  if (key === "value") setNativePickerValue(node, resolvedValue);
4439
4546
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
4440
4547
  node.attribs[key] = String(resolvedValue ?? "");
@@ -4483,7 +4590,7 @@ function resolveUsingComponent$1(context, ownerJsonPath, ownerFilePath, alias) {
4483
4590
  if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return;
4484
4591
  const rawPath = usingComponents[alias];
4485
4592
  if (typeof rawPath !== "string") return;
4486
- return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => readBrowserVirtualFile(context.files, candidate) !== void 0)).replace(LEADING_SLASH_RE$5, "");
4593
+ return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => readBrowserVirtualFile(context.files, candidate) !== void 0)).replace(LEADING_SLASH_RE$4, "");
4487
4594
  } catch {
4488
4595
  return;
4489
4596
  }
@@ -4502,8 +4609,8 @@ function resolveComponentGenerics$1(context, hostNode, ownerJsonPath, ownerFileP
4502
4609
  }
4503
4610
  const defaultPath = typeof definition === "object" && definition !== null ? definition.default : void 0;
4504
4611
  if (typeof defaultPath !== "string" || !defaultPath) continue;
4505
- const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$5, "") : normalize(join(dirname(componentFilePath), defaultPath));
4506
- resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$5, ""));
4612
+ const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$4, "") : normalize(join(dirname(componentFilePath), defaultPath));
4613
+ resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$4, ""));
4507
4614
  }
4508
4615
  return resolved.size > 0 ? resolved : void 0;
4509
4616
  }
@@ -4787,7 +4894,7 @@ function reconcileBrowserPageTree(context, page, bindingsOnly = false) {
4787
4894
  for (;;) {
4788
4895
  bindAttachmentBindingScope(context, page);
4789
4896
  if (page.__lastChangedKeys__) context.changedPageKeys = page.__lastChangedKeys__;
4790
- const route = page.route.replace(LEADING_SLASH_RE$5, "");
4897
+ const route = page.route.replace(LEADING_SLASH_RE$4, "");
4791
4898
  const resourcePath = context.project.routes.find((item) => item.route === route)?.resourcePath ?? route;
4792
4899
  const templatePath = join(context.project.miniprogramRootPath, `${resourcePath}.wxml`);
4793
4900
  const document = parseTemplateDocument$1(readTemplateSource$1(context.files, templatePath, context.templateSource));
@@ -5205,11 +5312,11 @@ function assignByPath(target, path, value) {
5205
5312
  const normalizedLeafSegment = isArrayIndexSegment(leafSegment) ? Number(leafSegment) : leafSegment;
5206
5313
  current[normalizedLeafSegment] = value;
5207
5314
  }
5208
- function normalizeRoute$1(route) {
5315
+ function normalizeRoute(route) {
5209
5316
  return route.replace(LEADING_ROUTE_SLASH_RE, "");
5210
5317
  }
5211
5318
  function createPageInstance(route, definition, options = {}, pageState = {}) {
5212
- const normalizedRoute = normalizeRoute$1(route);
5319
+ const normalizedRoute = normalizeRoute(route);
5213
5320
  const data = {
5214
5321
  ...resolveInitialData(definition),
5215
5322
  ...isComponentPageDefinition(definition) ? resolveInitialProperties(definition, {}) : {}
@@ -7279,7 +7386,7 @@ function createValueEventDetail(value, detail) {
7279
7386
  ...detail ?? {}
7280
7387
  };
7281
7388
  }
7282
- function resolvePageScopeId$1(scopeId) {
7389
+ function resolvePageScopeId(scopeId) {
7283
7390
  if (!scopeId) return null;
7284
7391
  const pagePathIndex = scopeId.indexOf("/page/");
7285
7392
  return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
@@ -7304,7 +7411,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
7304
7411
  if (!scope || !this.interactions) return nodes;
7305
7412
  return nodes.filter((node) => {
7306
7413
  const nodeScope = node.attribs?.["data-sim-scope"];
7307
- return nodeScope === scope || node.attribs?.["data-sim-component"] && (this.interactions.ownerScopeId(nodeScope ?? null) ?? resolvePageScopeId$1(nodeScope)) === scope;
7414
+ return nodeScope === scope || node.attribs?.["data-sim-component"] && (this.interactions.ownerScopeId(nodeScope ?? null) ?? resolvePageScopeId(nodeScope)) === scope;
7308
7415
  });
7309
7416
  }
7310
7417
  async $(selector) {
@@ -7341,7 +7448,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
7341
7448
  async pageScope() {
7342
7449
  this.assertActive();
7343
7450
  if (!this.interactions) throw new Error("Node interactions are not available for this headless testing node.");
7344
- return this.interactions.createScopeHandle(resolvePageScopeId$1(this.node.attribs?.["data-sim-scope"] ?? null));
7451
+ return this.interactions.createScopeHandle(resolvePageScopeId(this.node.attribs?.["data-sim-scope"] ?? null));
7345
7452
  }
7346
7453
  async page() {
7347
7454
  this.assertActive();
@@ -7434,7 +7541,7 @@ var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
7434
7541
  }
7435
7542
  };
7436
7543
  // src/view/render.ts
7437
- const LEADING_SLASH_RE$4 = /^\/+/;
7544
+ const LEADING_SLASH_RE$3 = /^\/+/;
7438
7545
  const TEMPLATE_INTERPOLATION_RE = /\{\{([^{}]+)\}\}/g;
7439
7546
  function resolveRawValueByPath$1(source, expression) {
7440
7547
  const normalized = expression.trim();
@@ -7473,6 +7580,7 @@ function interpolateDomTree(root, data) {
7473
7580
  let dataset;
7474
7581
  for (const [key, value] of Object.entries(node.attribs)) {
7475
7582
  const resolvedValue = isMustacheOnly$1(value) ? resolveRawValueByPath$1(data, value.trim().slice(2, -2)) : interpolateTemplate$1(value, data);
7583
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
7476
7584
  if (key === "value") setNativePickerValue(node, resolvedValue);
7477
7585
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
7478
7586
  node.attribs[key] = String(resolvedValue ?? "");
@@ -7500,7 +7608,7 @@ function serializeDomNode$1(node) {
7500
7608
  return `<${tagName}${Object.entries(node.attribs ?? {}).map(([key, value]) => ` ${key}="${escapeAttribute$1(value)}"`).join("")}>${(node.children ?? []).map(serializeDomNode$1).join("")}</${tagName}>`;
7501
7609
  }
7502
7610
  function renderPageTree(project, page) {
7503
- const route = page.route.replace(LEADING_SLASH_RE$4, "");
7611
+ const route = page.route.replace(LEADING_SLASH_RE$3, "");
7504
7612
  const templatePath = path.resolve(project.miniprogramRootPath, `${route}.wxml`);
7505
7613
  const templateSource = project.artifactSource.readText(templatePath);
7506
7614
  if (templateSource == null) throw new Error(`Missing template in headless runtime: ${templatePath}`);
@@ -7796,6 +7904,21 @@ function coordinate(value) {
7796
7904
  function nodeKey(node) {
7797
7905
  return node.attribs?.["data-sim-node"] ?? "";
7798
7906
  }
7907
+ /** 按稳定渲染键把保留的测试节点句柄映射到当前树;有键但已移除时返回 undefined。 */
7908
+ function resolveNativeNode(root, node) {
7909
+ const key = nodeKey(node);
7910
+ if (!key) return node;
7911
+ let match;
7912
+ const visit = (current) => {
7913
+ if (current.attribs?.["data-sim-node"] === key) {
7914
+ match = current;
7915
+ return;
7916
+ }
7917
+ for (const child of current.children ?? []) if (!match) visit(child);
7918
+ };
7919
+ visit(root);
7920
+ return match;
7921
+ }
7799
7922
  /** 原生滚动位置独立于绑定值;未改变的绑定不能覆盖用户滚动。 */
7800
7923
  function syncNativeScrollViews(page, root, emit) {
7801
7924
  let states = pageScrollViews.get(page);
@@ -7897,6 +8020,14 @@ function dispatchNativeNodeEvent(page, node, eventName, event, wx, resolveMethod
7897
8020
  const origin = getNativeNodeOwner(node)?.target ?? node;
7898
8021
  let handlers;
7899
8022
  let handled = false;
8023
+ let eligibility = node;
8024
+ while (eligibility) {
8025
+ if (eligibility.name === "button") {
8026
+ if (getNativeBooleanValue(getNativeNodeOwner(eligibility)?.target ?? eligibility, "disabled")) return true;
8027
+ break;
8028
+ }
8029
+ eligibility = eligibility.parent;
8030
+ }
7900
8031
  const collectHandler = (scopeId, target, binding) => {
7901
8032
  if (binding.method) {
7902
8033
  const call = resolveMethod(scopeId, binding.method);
@@ -8860,14 +8991,14 @@ function createHeadlessVideoContext(driver, videoId, scope) {
8860
8991
  };
8861
8992
  }
8862
8993
  // src/browser/session.ts
8863
- const LEADING_SLASH_RE$3 = /^\/+/;
8994
+ const LEADING_SLASH_RE$2 = /^\/+/;
8864
8995
  const PAGE_STACK_LIMIT$1 = 10;
8865
8996
  const WHITESPACE_RE$1 = /\s+/;
8866
8997
  const DATA_ATTR_SELECTOR_RE$1 = /^\[data-([^=\]]+)="([^"]*)"\]$/;
8867
8998
  const COMPOUND_SELECTOR_PART_RE$1 = /#[\w-]+|\.[\w-]+|\[data-[^=\]]+="[^"]*"\]|[A-Za-z][\w-]*/g;
8868
8999
  const DATASET_KEY_RE$1 = /-([a-z])/g;
8869
9000
  function stripLeadingSlash$1(route) {
8870
- return route.replace(LEADING_SLASH_RE$3, "");
9001
+ return route.replace(LEADING_SLASH_RE$2, "");
8871
9002
  }
8872
9003
  function normalizeQuery$1(queryString) {
8873
9004
  const query = new URLSearchParams(queryString);
@@ -8919,9 +9050,9 @@ function readJsonObject$2(files, filePath) {
8919
9050
  }
8920
9051
  function resolveNavigationPath$1(targetPath, baseRoute) {
8921
9052
  if (!targetPath) throw new Error("Navigation url must include a pathname in browser simulator runtime.");
8922
- if (targetPath.startsWith("/")) return posix.normalize(targetPath).replace(LEADING_SLASH_RE$3, "");
9053
+ if (targetPath.startsWith("/")) return posix.normalize(targetPath).replace(LEADING_SLASH_RE$2, "");
8923
9054
  if (!baseRoute) throw new Error(`Cannot resolve relative navigation url "${targetPath}" without an active page.`);
8924
- return posix.resolve(`/${posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$3, "");
9055
+ return posix.resolve(`/${posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$2, "");
8925
9056
  }
8926
9057
  var BrowserHeadlessSession = class {
8927
9058
  files;
@@ -9504,15 +9635,20 @@ var BrowserHeadlessSession = class {
9504
9635
  }
9505
9636
  dispatchNativeNodeEvent(node, eventName, event, onHandlerResult) {
9506
9637
  const current = this.requireCurrentPage("dispatchNativeNodeEvent()");
9507
- if (eventName === "tap") this.renderCurrentPage();
9508
- return dispatchNativeNodeEvent(current, node, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
9638
+ const rendered = eventName === "tap" ? this.renderCurrentPage() : void 0;
9639
+ const currentNode = rendered ? resolveNativeNode(rendered.root, node) : node;
9640
+ if (!currentNode) throw new Error("Native testing node is no longer present in the current page.");
9641
+ const handled = dispatchNativeNodeEvent(current, currentNode, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
9509
9642
  const instance = this.componentCache.get(scopeId);
9510
9643
  const scope = this.componentScopes.get(scopeId);
9511
9644
  return instance?.__definition__ && scope ? {
9512
9645
  definition: instance.__definition__,
9513
- ownerScopeId: scope.ownerScopeId ?? null
9646
+ ownerScopeId: scope.ownerScopeId ?? null,
9647
+ name: typeof instance.properties?.name === "string" ? instance.properties.name : void 0,
9648
+ value: instance.properties && Object.hasOwn(instance.properties, "value") ? instance.properties.value : void 0
9514
9649
  } : void 0;
9515
9650
  });
9651
+ return eventName === "tap" && Boolean(node.attribs?.["data-sim-node"]) ? true : handled;
9516
9652
  }
9517
9653
  requestRender(callback) {
9518
9654
  this.assertActive();
@@ -10248,7 +10384,7 @@ function getRuntimeWxsLoader(owner, artifactSource) {
10248
10384
  return loader.load;
10249
10385
  }
10250
10386
  // src/runtime/render/shared.ts
10251
- const LEADING_SLASH_RE$2 = /^\/+/;
10387
+ const LEADING_SLASH_RE$1 = /^\/+/;
10252
10388
  const EVENT_BINDING_ATTRS = [
10253
10389
  "bindtap",
10254
10390
  "bind:tap",
@@ -10357,6 +10493,7 @@ function applyNodeBindings(node, scope, richText = false) {
10357
10493
  continue;
10358
10494
  }
10359
10495
  const resolvedValue = resolveNativeAttributeValue(node, key, scope, (source) => typeof value === "string" ? resolveAttributeValue(value, source) : value);
10496
+ setNativeBooleanValue(node, key, resolvedValue, isValuelessTemplateAttribute(node, key));
10360
10497
  if (key === "value") setNativePickerValue(node, resolvedValue);
10361
10498
  if (richText && key === "nodes") node.children = renderRichTextNodes(resolvedValue);
10362
10499
  node.attribs[key] = String(resolvedValue ?? "");
@@ -10412,7 +10549,7 @@ function resolveOwnerComponent(context, ownerJsonPath, ownerFilePath, alias) {
10412
10549
  if (!usingComponents || typeof usingComponents !== "object" || Array.isArray(usingComponents)) return;
10413
10550
  const rawPath = usingComponents[alias];
10414
10551
  if (typeof rawPath !== "string") return;
10415
- return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => context.artifactSource.has(candidate))).replace(LEADING_SLASH_RE$2, "");
10552
+ return (resolvePluginRequest(context.project.plugins, rawPath, "publicComponent")?.resourcePath ?? resolveMiniProgramComponent(ownerFilePath, rawPath, context.project.miniprogramRootPath, (candidate) => context.artifactSource.has(candidate))).replace(LEADING_SLASH_RE$1, "");
10416
10553
  } catch {
10417
10554
  return;
10418
10555
  }
@@ -10460,8 +10597,8 @@ function resolveComponentGenerics(context, hostNode, ownerJsonPath, ownerFilePat
10460
10597
  }
10461
10598
  const defaultPath = typeof definition === "object" && definition !== null ? definition.default : void 0;
10462
10599
  if (typeof defaultPath !== "string" || !defaultPath) continue;
10463
- const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$2, "") : path.posix.normalize(path.posix.join(path.posix.dirname(componentFilePath), defaultPath));
10464
- resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$2, ""));
10600
+ const resolvedDefault = defaultPath.startsWith("/") ? defaultPath.replace(LEADING_SLASH_RE$1, "") : path.posix.normalize(path.posix.join(path.posix.dirname(componentFilePath), defaultPath));
10601
+ resolved.set(genericName, resolvedDefault.replace(LEADING_SLASH_RE$1, ""));
10465
10602
  }
10466
10603
  return resolved.size > 0 ? resolved : void 0;
10467
10604
  }
@@ -10748,7 +10885,7 @@ function reconcileRuntimePageTree(context, page, bindingsOnly = false) {
10748
10885
  for (;;) {
10749
10886
  bindAttachmentBindingScope(context, page);
10750
10887
  if (page.__lastChangedKeys__) context.changedPageKeys = page.__lastChangedKeys__;
10751
- const route = page.route.replace(LEADING_SLASH_RE$2, "");
10888
+ const route = page.route.replace(LEADING_SLASH_RE$1, "");
10752
10889
  const resourcePath = context.project.routes.find((item) => item.route === route)?.resourcePath ?? route;
10753
10890
  const templatePath = path.resolve(context.project.miniprogramRootPath, `${resourcePath}.wxml`);
10754
10891
  const document = parseTemplateDocument(readTemplateSource(context.artifactSource, templatePath));
@@ -10988,14 +11125,14 @@ function createModuleLoader(registries, getCurrentPages, getApp, wxDriver, optio
10988
11125
  return loader;
10989
11126
  }
10990
11127
  // src/runtime/session.ts
10991
- const LEADING_SLASH_RE$1 = /^\/+/;
11128
+ const LEADING_SLASH_RE = /^\/+/;
10992
11129
  const PAGE_STACK_LIMIT = 10;
10993
11130
  const WHITESPACE_RE = /\s+/;
10994
11131
  const DATA_ATTR_SELECTOR_RE = /^\[data-([^=\]]+)="([^"]*)"\]$/;
10995
11132
  const COMPOUND_SELECTOR_PART_RE = /#[\w-]+|\.[\w-]+|\[data-[^=\]]+="[^"]*"\]|[A-Za-z][\w-]*/g;
10996
11133
  const DATASET_KEY_RE = /-([a-z])/g;
10997
11134
  function stripLeadingSlash(route) {
10998
- return route.replace(LEADING_SLASH_RE$1, "");
11135
+ return route.replace(LEADING_SLASH_RE, "");
10999
11136
  }
11000
11137
  function normalizeQuery(queryString) {
11001
11138
  const query = new URLSearchParams(queryString);
@@ -11046,9 +11183,9 @@ function readJsonObject(project, filePath) {
11046
11183
  }
11047
11184
  function resolveNavigationPath(targetPath, baseRoute) {
11048
11185
  if (!targetPath) throw new Error("Navigation url must include a pathname in headless runtime.");
11049
- if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE$1, "");
11186
+ if (targetPath.startsWith("/")) return path.posix.normalize(targetPath).replace(LEADING_SLASH_RE, "");
11050
11187
  if (!baseRoute) throw new Error(`Cannot resolve relative navigation url "${targetPath}" without an active page.`);
11051
- return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE$1, "");
11188
+ return path.posix.resolve(`/${path.posix.dirname(baseRoute)}`, targetPath).replace(LEADING_SLASH_RE, "");
11052
11189
  }
11053
11190
  var HeadlessSession = class {
11054
11191
  project;
@@ -11389,15 +11526,20 @@ var HeadlessSession = class {
11389
11526
  }
11390
11527
  dispatchNativeNodeEvent(node, eventName, event, onHandlerResult) {
11391
11528
  const current = this.requireCurrentPage("dispatchNativeNodeEvent()");
11392
- if (eventName === "tap") this.renderCurrentPage();
11393
- return dispatchNativeNodeEvent(current, node, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
11529
+ const rendered = eventName === "tap" ? this.renderCurrentPage() : void 0;
11530
+ const currentNode = rendered ? resolveNativeNode(rendered.root, node) : node;
11531
+ if (!currentNode) throw new Error("Native testing node is no longer present in the current page.");
11532
+ const handled = dispatchNativeNodeEvent(current, currentNode, eventName, event, this.moduleLoader.wx, (scopeId, method) => this.resolveScopeMethod(current, scopeId, method), onHandlerResult, (scopeId) => {
11394
11533
  const instance = this.componentCache.get(scopeId);
11395
11534
  const scope = this.componentScopes.get(scopeId);
11396
11535
  return instance?.__definition__ && scope ? {
11397
11536
  definition: instance.__definition__,
11398
- ownerScopeId: scope.ownerScopeId ?? null
11537
+ ownerScopeId: scope.ownerScopeId ?? null,
11538
+ name: typeof instance.properties?.name === "string" ? instance.properties.name : void 0,
11539
+ value: instance.properties && Object.hasOwn(instance.properties, "value") ? instance.properties.value : void 0
11399
11540
  } : void 0;
11400
11541
  });
11542
+ return eventName === "tap" && Boolean(node.attribs?.["data-sim-node"]) ? true : handled;
11401
11543
  }
11402
11544
  requestRender(callback) {
11403
11545
  this.assertActive();
@@ -12268,16 +12410,16 @@ function resolveTestingPagePath(route) {
12268
12410
  return route.replace(PRIVATE_PLUGIN_ROUTE_RE, "__plugin__/$1/$2");
12269
12411
  }
12270
12412
  // src/testing/pageWait.ts
12271
- const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
12272
- const DEFAULT_WAIT_INTERVAL$1 = 10;
12413
+ const DEFAULT_WAIT_TIMEOUT = 1e3;
12414
+ const DEFAULT_WAIT_INTERVAL = 10;
12273
12415
  function normalizeInput(value, label) {
12274
12416
  const normalized = value.trim();
12275
12417
  if (!normalized) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
12276
12418
  return normalized;
12277
12419
  }
12278
- async function pollUntil$2(access, check, errorMessage, options) {
12279
- const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT$1)) : DEFAULT_WAIT_TIMEOUT$1;
12280
- const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL$1)) : DEFAULT_WAIT_INTERVAL$1;
12420
+ async function pollUntil$1(access, check, errorMessage, options) {
12421
+ const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT)) : DEFAULT_WAIT_TIMEOUT;
12422
+ const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL)) : DEFAULT_WAIT_INTERVAL;
12281
12423
  const deadline = Date.now() + timeout;
12282
12424
  while (true) {
12283
12425
  const result = await check();
@@ -12289,34 +12431,34 @@ async function pollUntil$2(access, check, errorMessage, options) {
12289
12431
  async function waitForPageSelector(access, selector, options = {}) {
12290
12432
  const normalizedSelector = normalizeInput(selector, "Selector");
12291
12433
  if (options.state === "detached") {
12292
- await pollUntil$2(access, async () => await access.findOne(normalizedSelector) ? null : true, `Timed out waiting for selector "${normalizedSelector}" to become detached in headless testing runtime.`, options);
12434
+ await pollUntil$1(access, async () => await access.findOne(normalizedSelector) ? null : true, `Timed out waiting for selector "${normalizedSelector}" to become detached in headless testing runtime.`, options);
12293
12435
  return null;
12294
12436
  }
12295
- return await pollUntil$2(access, async () => await access.findOne(normalizedSelector), `Timed out waiting for selector "${normalizedSelector}" to appear in headless testing runtime.`, options);
12437
+ return await pollUntil$1(access, async () => await access.findOne(normalizedSelector), `Timed out waiting for selector "${normalizedSelector}" to appear in headless testing runtime.`, options);
12296
12438
  }
12297
12439
  async function waitForPageComponent(access, selector, options = {}) {
12298
12440
  const normalizedSelector = normalizeInput(selector, "Selector");
12299
- return await pollUntil$2(access, async () => await access.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12441
+ return await pollUntil$1(access, async () => await access.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12300
12442
  }
12301
12443
  async function waitForPageComponents(access, selector, count = 1, options = {}) {
12302
12444
  const normalizedSelector = normalizeInput(selector, "Selector");
12303
12445
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
12304
- return await pollUntil$2(access, async () => {
12446
+ return await pollUntil$1(access, async () => {
12305
12447
  const components = await access.selectComponents(normalizedSelector);
12306
12448
  return components.length >= normalizedCount ? components : null;
12307
12449
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
12308
12450
  }
12309
12451
  async function waitForPageText(access, text, options = {}) {
12310
12452
  const normalizedText = normalizeInput(text, "Text");
12311
- return await pollUntil$2(access, async () => (await access.wxml()).includes(normalizedText) ? normalizedText : null, `Timed out waiting for text "${normalizedText}" in headless testing runtime.`, options);
12453
+ return await pollUntil$1(access, async () => (await access.wxml()).includes(normalizedText) ? normalizedText : null, `Timed out waiting for text "${normalizedText}" in headless testing runtime.`, options);
12312
12454
  }
12313
12455
  async function waitForPageTextGone(access, text, options = {}) {
12314
12456
  const normalizedText = normalizeInput(text, "Text");
12315
- await pollUntil$2(access, async () => (await access.wxml()).includes(normalizedText) ? null : true, `Timed out waiting for text "${normalizedText}" to disappear in headless testing runtime.`, options);
12457
+ await pollUntil$1(access, async () => (await access.wxml()).includes(normalizedText) ? null : true, `Timed out waiting for text "${normalizedText}" to disappear in headless testing runtime.`, options);
12316
12458
  }
12317
12459
  async function waitForPageData(access, path, matcher, hasMatcher, options = {}) {
12318
12460
  const normalizedPath = normalizeInput(path, "Data path");
12319
- return await pollUntil$2(access, async () => {
12461
+ return await pollUntil$1(access, async () => {
12320
12462
  const value = await access.data(normalizedPath);
12321
12463
  if (typeof matcher === "function") return matcher(value) ? value : null;
12322
12464
  if (hasMatcher) return Object.is(value, matcher) ? value : null;
@@ -12336,7 +12478,7 @@ function matchesDataset(node, expected) {
12336
12478
  const dataset = node.dataset ?? {};
12337
12479
  return Object.entries(expected).every(([key, value]) => String(dataset[key] ?? "") === String(value));
12338
12480
  }
12339
- async function pollUntil$1(access, check, errorMessage, options) {
12481
+ async function pollUntil(access, check, errorMessage, options) {
12340
12482
  const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_RENDERED_WAIT_TIMEOUT)) : DEFAULT_RENDERED_WAIT_TIMEOUT;
12341
12483
  const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_RENDERED_WAIT_INTERVAL)) : DEFAULT_RENDERED_WAIT_INTERVAL;
12342
12484
  const deadline = Date.now() + timeout;
@@ -12375,7 +12517,7 @@ async function waitForRenderedPage(access, options = {}) {
12375
12517
  access.assertActive();
12376
12518
  if (options.selector) {
12377
12519
  const selector = normalizeSelector(options.selector);
12378
- return await pollUntil$1(access, async () => {
12520
+ return await pollUntil(access, async () => {
12379
12521
  const nodes = await readRenderedNodes(access, selector, options);
12380
12522
  return nodes.some((node) => matchesDataset(node, options.dataset)) ? JSON.stringify({
12381
12523
  nodes,
@@ -12383,7 +12525,7 @@ async function waitForRenderedPage(access, options = {}) {
12383
12525
  }) : null;
12384
12526
  }, `Timed out waiting page rendered: selector=${selector} dataset=${JSON.stringify(options.dataset ?? {})}`, options);
12385
12527
  }
12386
- return await pollUntil$1(access, async () => {
12528
+ return await pollUntil(access, async () => {
12387
12529
  const wxml = await access.wxml();
12388
12530
  const normalizedWxml = wxml.trim();
12389
12531
  if (options.predicate?.(wxml)) return wxml;
@@ -12392,52 +12534,6 @@ async function waitForRenderedPage(access, options = {}) {
12392
12534
  return null;
12393
12535
  }, options.text ? `Timed out waiting page rendered: text=${options.text}` : options.predicate ? "Timed out waiting page rendered: predicate=true" : "Timed out waiting page rendered: non-empty wxml", options);
12394
12536
  }
12395
- // src/testing/sessionHandle/shared.ts
12396
- const LEADING_SLASH_RE = /^\/+/;
12397
- const DEFAULT_WAIT_TIMEOUT = 1e3;
12398
- const DEFAULT_WAIT_INTERVAL = 10;
12399
- function normalizeRoute(route) {
12400
- return route.replace(LEADING_SLASH_RE, "");
12401
- }
12402
- function resolvePageScopeId(scopeId) {
12403
- const pagePathIndex = scopeId.indexOf("/page/");
12404
- return pagePathIndex >= 0 ? scopeId.slice(0, pagePathIndex) : scopeId;
12405
- }
12406
- function normalizeNonEmptyInput(value, label) {
12407
- const normalizedValue = value.trim();
12408
- if (!normalizedValue) throw new Error(`${label} must be a non-empty string in headless testing runtime.`);
12409
- return normalizedValue;
12410
- }
12411
- function cloneProtocolValue(value) {
12412
- if (!value || typeof value !== "object") return value;
12413
- return JSON.parse(JSON.stringify(value));
12414
- }
12415
- async function waitForDelay(ms = 0) {
12416
- if (ms <= 0) return;
12417
- await new Promise((resolve) => setTimeout(resolve, ms));
12418
- }
12419
- async function pollUntil(check, errorMessage, options = {}) {
12420
- const timeout = Number.isFinite(options.timeout) ? Math.max(0, Math.trunc(options.timeout ?? DEFAULT_WAIT_TIMEOUT)) : DEFAULT_WAIT_TIMEOUT;
12421
- const interval = Number.isFinite(options.interval) ? Math.max(1, Math.trunc(options.interval ?? DEFAULT_WAIT_INTERVAL)) : DEFAULT_WAIT_INTERVAL;
12422
- const deadline = Date.now() + timeout;
12423
- while (true) {
12424
- const result = await check();
12425
- if (result != null) return result;
12426
- if (Date.now() >= deadline) throw new Error(errorMessage);
12427
- await waitForDelay(interval);
12428
- }
12429
- }
12430
- async function runWithTimeout(operation, timeout, message) {
12431
- if (!Number.isFinite(timeout) || (timeout ?? 0) <= 0) return await operation();
12432
- let timer;
12433
- try {
12434
- return await Promise.race([Promise.resolve().then(operation), new Promise((_resolve, reject) => {
12435
- timer = setTimeout(() => reject(new Error(message)), Math.trunc(timeout));
12436
- })]);
12437
- } finally {
12438
- if (timer) clearTimeout(timer);
12439
- }
12440
- }
12441
12537
  // src/testing/pageHandle.ts
12442
12538
  var HeadlessTestingPageHandle = class {
12443
12539
  project;
@@ -12775,13 +12871,13 @@ var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
12775
12871
  return currentPage ? new HeadlessTestingPageHandle(this.project, currentPage, this.session) : null;
12776
12872
  }
12777
12873
  async pageScope() {
12778
- return new HeadlessTestingScopeHandle(resolvePageScopeId(this.scopeId), this.project, this.session);
12874
+ return new HeadlessTestingScopeHandle(resolvePageScopeId$1(this.scopeId), this.project, this.session);
12779
12875
  }
12780
12876
  async ownerComponent() {
12781
12877
  return this.createScopeHandle(this.session.selectOwnerComponent(this.scopeId));
12782
12878
  }
12783
12879
  async waitForOwnerComponent(options = {}) {
12784
- return await pollUntil(async () => await this.ownerComponent(), "Timed out waiting for owner component in headless testing runtime.", options);
12880
+ return await pollUntil$2(async () => await this.ownerComponent(), "Timed out waiting for owner component in headless testing runtime.", options);
12785
12881
  }
12786
12882
  async selectComponent(selector) {
12787
12883
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
@@ -12794,12 +12890,12 @@ var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
12794
12890
  }
12795
12891
  async waitForComponent(selector, options = {}) {
12796
12892
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12797
- return await pollUntil(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12893
+ return await pollUntil$2(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12798
12894
  }
12799
12895
  async waitForComponents(selector, count = 1, options = {}) {
12800
12896
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12801
12897
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
12802
- return await pollUntil(async () => {
12898
+ return await pollUntil$2(async () => {
12803
12899
  const components = await this.selectAllComponents(normalizedSelector);
12804
12900
  return components.length >= normalizedCount ? components : null;
12805
12901
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
@@ -12902,12 +12998,12 @@ var HeadlessTestingSessionHandle = class {
12902
12998
  }
12903
12999
  async waitForComponent(selector, options = {}) {
12904
13000
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12905
- return await pollUntil(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
13001
+ return await pollUntil$2(async () => await this.selectComponent(normalizedSelector), `Timed out waiting for component "${normalizedSelector}" in headless testing runtime.`, options);
12906
13002
  }
12907
13003
  async waitForComponents(selector, count = 1, options = {}) {
12908
13004
  const normalizedSelector = normalizeNonEmptyInput(selector, "Selector");
12909
13005
  const normalizedCount = Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1;
12910
- return await pollUntil(async () => {
13006
+ return await pollUntil$2(async () => {
12911
13007
  const components = await this.selectAllComponents(normalizedSelector);
12912
13008
  return components.length >= normalizedCount ? components : null;
12913
13009
  }, `Timed out waiting for ${normalizedCount} component(s) matching "${normalizedSelector}" in headless testing runtime.`, options);
@@ -12943,14 +13039,14 @@ var HeadlessTestingSessionHandle = class {
12943
13039
  async waitForCurrentPage(route, options = {}) {
12944
13040
  const normalizedRoute = route?.trim();
12945
13041
  if (normalizedRoute != null && !normalizedRoute) throw new Error("Route must be a non-empty string in headless testing runtime.");
12946
- return await pollUntil(async () => {
13042
+ return await pollUntil$2(async () => {
12947
13043
  const currentPageInstance = this.session.getCurrentPages().at(-1);
12948
13044
  if (!currentPageInstance) return null;
12949
13045
  const current = new HeadlessTestingPageHandle(this.project, currentPageInstance, this.session);
12950
13046
  if (!normalizedRoute) return current;
12951
- if (normalizeRoute(current.path) === resolveTestingPagePath(normalizeRoute(normalizedRoute))) return current;
13047
+ if (normalizeRoute$1(current.path) === resolveTestingPagePath(normalizeRoute$1(normalizedRoute))) return current;
12952
13048
  return null;
12953
- }, 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);
13049
+ }, normalizedRoute ? `Timed out waiting for current page "${normalizeRoute$1(normalizedRoute)}" in headless testing runtime.` : "Timed out waiting for a current page in headless testing runtime.", options);
12954
13050
  }
12955
13051
  async pageScrollTo(scrollTop) {
12956
13052
  this.session.pageScrollTo({ scrollTop });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mpcore/simulator",
3
3
  "type": "module",
4
- "version": "1.3.5-dev.20261117.1",
4
+ "version": "1.3.5",
5
5
  "description": "Headless mini-program runtime and testing kernel for the weapp-vite ecosystem",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -44,9 +44,9 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/parser": "^8.1.2",
47
- "@weapp-core/constants": "0.6.1-dev.20261117.1",
48
- "@weapp-core/shared": "3.5.1-dev.20261117.1",
49
- "@weapp-vite/wxml": "0.0.3-dev.20261117.1",
47
+ "@weapp-core/constants": "0.6.1",
48
+ "@weapp-core/shared": "3.5.1",
49
+ "@weapp-vite/wxml": "0.0.3",
50
50
  "css-select": "^7.0.0",
51
51
  "css-what": "^8.0.0",
52
52
  "fontoxpath": "^3.34.0",
@@ -56,19 +56,11 @@
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public",
59
- "registry": "https://registry.npmjs.org/",
60
- "tag": "snapshot-nightly"
59
+ "registry": "https://registry.npmjs.org"
61
60
  },
62
61
  "devDependencies": {
63
62
  "htmlparser2": "^12.0.0"
64
63
  },
65
- "repoctlSnapshot": {
66
- "kind": "nightly",
67
- "commit": "1218da39b57ef783727d51ad86b2eecde20c375a",
68
- "buildId": "44017370760-1",
69
- "identityKey": "308bcda13e3bd3f6b91c0a3c717e48c6f2dcd2caee9b39cdf00c077ef771f58a",
70
- "tag": "snapshot-nightly"
71
- },
72
64
  "scripts": {
73
65
  "dev": "tsdown -w",
74
66
  "build": "tsdown",
@@ -81,4 +73,4 @@
81
73
  "test:types:check": "tsd --files \"test-d/**/*.test-d.ts\"",
82
74
  "typecheck": "tsc --noEmit"
83
75
  }
84
- }
76
+ }