@testid/antd-testid-runtime 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -30,6 +30,13 @@ interface TestIdMarkConfig {
30
30
  runtimePagePrefix: string;
31
31
  /** Antd 浮层组件专属前缀映射 */
32
32
  popupPrefixMap: Record<PopupType, string>;
33
+ /**
34
+ * Ant Design Vue CSS 类名前缀 (对应 ConfigProvider 的 prefixCls)
35
+ *
36
+ * 默认: 'ant' → 匹配 .ant-modal, .ant-picker-dropdown 等
37
+ * 若项目使用 <a-config-provider prefixCls="my-ui"> 则设为 'my-ui'
38
+ */
39
+ antdClassPrefix: string;
33
40
  /** 忽略不打标的 HTML 标签名 */
34
41
  ignoreTags: string[];
35
42
  /** 包含此 class 的 DOM 跳过打标 */
@@ -169,11 +176,13 @@ declare function resetPopupCounter(type: PopupType): void;
169
176
  */
170
177
  declare function getPopupCounterSnapshot(): Record<PopupType, number>;
171
178
  /**
172
- * 生成浮层节点 testid
179
+ * 生成浮层根节点 testid
173
180
  *
174
- * 格式: ${prefix}${tag}_${counterId}
181
+ * 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counterId}
182
+ * 例: hall_dynamic_modal_div_0, hall_dynamic_select_div_2
175
183
  *
176
- * 例: modal_button_0, select_div_2
184
+ * 浮层均为运行时注入,因此统一使用 runtimePagePrefix 作为前缀,
185
+ * 与页面内动态节点保持一致。
177
186
  *
178
187
  * @param type - 浮层类型
179
188
  * @param tag - HTML 标签名 (简化后)
@@ -194,6 +203,8 @@ declare function buildPopupTestId(type: PopupType, tag: string, counterId: numbe
194
203
  */
195
204
  declare class TestIdObserver {
196
205
  private state;
206
+ /** 浮层 class 匹配映射 (根据 antdClassPrefix 动态构建) */
207
+ private popupClassMap;
197
208
  constructor();
198
209
  /**
199
210
  * 启动 MutationObserver
@@ -299,8 +310,10 @@ declare class TestIdObserver {
299
310
  /**
300
311
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
301
312
  *
302
- * ID 格式: ${popupPrefix}${popupType}_${tag}_${counter}
303
- * 例: hall_modal_button_0, hall_select_div_2
313
+ * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
314
+ * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
315
+ *
316
+ * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
304
317
  */
305
318
  private handlePopupChildNode;
306
319
  /**
package/dist/index.d.ts CHANGED
@@ -30,6 +30,13 @@ interface TestIdMarkConfig {
30
30
  runtimePagePrefix: string;
31
31
  /** Antd 浮层组件专属前缀映射 */
32
32
  popupPrefixMap: Record<PopupType, string>;
33
+ /**
34
+ * Ant Design Vue CSS 类名前缀 (对应 ConfigProvider 的 prefixCls)
35
+ *
36
+ * 默认: 'ant' → 匹配 .ant-modal, .ant-picker-dropdown 等
37
+ * 若项目使用 <a-config-provider prefixCls="my-ui"> 则设为 'my-ui'
38
+ */
39
+ antdClassPrefix: string;
33
40
  /** 忽略不打标的 HTML 标签名 */
34
41
  ignoreTags: string[];
35
42
  /** 包含此 class 的 DOM 跳过打标 */
@@ -169,11 +176,13 @@ declare function resetPopupCounter(type: PopupType): void;
169
176
  */
170
177
  declare function getPopupCounterSnapshot(): Record<PopupType, number>;
171
178
  /**
172
- * 生成浮层节点 testid
179
+ * 生成浮层根节点 testid
173
180
  *
174
- * 格式: ${prefix}${tag}_${counterId}
181
+ * 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counterId}
182
+ * 例: hall_dynamic_modal_div_0, hall_dynamic_select_div_2
175
183
  *
176
- * 例: modal_button_0, select_div_2
184
+ * 浮层均为运行时注入,因此统一使用 runtimePagePrefix 作为前缀,
185
+ * 与页面内动态节点保持一致。
177
186
  *
178
187
  * @param type - 浮层类型
179
188
  * @param tag - HTML 标签名 (简化后)
@@ -194,6 +203,8 @@ declare function buildPopupTestId(type: PopupType, tag: string, counterId: numbe
194
203
  */
195
204
  declare class TestIdObserver {
196
205
  private state;
206
+ /** 浮层 class 匹配映射 (根据 antdClassPrefix 动态构建) */
207
+ private popupClassMap;
197
208
  constructor();
198
209
  /**
199
210
  * 启动 MutationObserver
@@ -299,8 +310,10 @@ declare class TestIdObserver {
299
310
  /**
300
311
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
301
312
  *
302
- * ID 格式: ${popupPrefix}${popupType}_${tag}_${counter}
303
- * 例: hall_modal_button_0, hall_select_div_2
313
+ * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
314
+ * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
315
+ *
316
+ * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
304
317
  */
305
318
  private handlePopupChildNode;
306
319
  /**
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ var defaultConfig = {
60
60
  globalPrefix: "",
61
61
  compilePrefix: "static_",
62
62
  runtimePagePrefix: "dynamic_",
63
+ antdClassPrefix: "ant",
63
64
  popupPrefixMap: {
64
65
  modal: "modal_",
65
66
  drawer: "drawer_",
@@ -100,9 +101,10 @@ function applyGlobalPrefix(cfg) {
100
101
  ...cfg,
101
102
  compilePrefix: prepend(cfg.compilePrefix),
102
103
  runtimePagePrefix: prepend(cfg.runtimePagePrefix),
103
- popupPrefixMap: Object.fromEntries(
104
- Object.entries(cfg.popupPrefixMap).map(([k, v]) => [k, prepend(v)])
105
- )
104
+ // 注意: popupPrefixMap 不拼接 globalPrefix
105
+ // 浮层 testid 格式为 ${runtimePagePrefix}${popupPrefixMap[type]}...,
106
+ // runtimePagePrefix 已携带 globalPrefix,避免重复
107
+ popupPrefixMap: { ...cfg.popupPrefixMap }
106
108
  };
107
109
  }
108
110
  var globalConfig = { ...defaultConfig };
@@ -176,20 +178,28 @@ function getPopupCounterSnapshot() {
176
178
  }
177
179
  function buildPopupTestId(type, tag, counterId) {
178
180
  const config = getConfig();
179
- const prefix = config.popupPrefixMap[type] || `${type}_`;
180
- return `${prefix}${tag}_${counterId}`;
181
+ const popupPrefix = config.popupPrefixMap[type] || `${type}_`;
182
+ return `${config.runtimePagePrefix}${popupPrefix}${tag}_${counterId}`;
181
183
  }
182
184
 
183
185
  // src/utils/testIdObserver.ts
184
- var POPUP_CLASS_MAP = {
185
- modal: ".ant-modal",
186
- drawer: ".ant-drawer",
187
- select: ".ant-select-dropdown",
188
- datePicker: ".ant-picker-dropdown",
189
- popconfirm: ".ant-popover.ant-popconfirm",
190
- dropdown: ".ant-dropdown",
191
- tooltip: ".ant-tooltip"
186
+ var POPUP_CLASS_SUFFIX_MAP = {
187
+ modal: ".{prefix}-modal",
188
+ drawer: ".{prefix}-drawer",
189
+ select: ".{prefix}-select-dropdown",
190
+ datePicker: ".{prefix}-picker-dropdown",
191
+ popconfirm: ".{prefix}-popover.{prefix}-popconfirm",
192
+ dropdown: ".{prefix}-dropdown",
193
+ tooltip: ".{prefix}-tooltip"
192
194
  };
195
+ function buildPopupClassMap(prefix) {
196
+ const result = {};
197
+ const entries = Object.entries(POPUP_CLASS_SUFFIX_MAP);
198
+ for (const [type, template] of entries) {
199
+ result[type] = template.replace(/\{prefix\}/g, prefix);
200
+ }
201
+ return result;
202
+ }
193
203
  var TestIdObserver = class {
194
204
  constructor() {
195
205
  // ==========================================================
@@ -208,6 +218,8 @@ var TestIdObserver = class {
208
218
  });
209
219
  }
210
220
  };
221
+ const config = getConfig();
222
+ this.popupClassMap = buildPopupClassMap(config.antdClassPrefix);
211
223
  this.state = {
212
224
  observer: null,
213
225
  isRunning: false,
@@ -441,7 +453,7 @@ var TestIdObserver = class {
441
453
  matchPopupClass(node) {
442
454
  const classStr = node.className || "";
443
455
  if (typeof classStr !== "string") return null;
444
- const entries = Object.entries(POPUP_CLASS_MAP);
456
+ const entries = Object.entries(this.popupClassMap);
445
457
  for (const [type, selector] of entries) {
446
458
  const classes = selector.replace(/^\./, "").split(".");
447
459
  const allMatch = classes.every(
@@ -474,8 +486,10 @@ var TestIdObserver = class {
474
486
  /**
475
487
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
476
488
  *
477
- * ID 格式: ${popupPrefix}${popupType}_${tag}_${counter}
478
- * 例: hall_modal_button_0, hall_select_div_2
489
+ * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
490
+ * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
491
+ *
492
+ * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
479
493
  */
480
494
  handlePopupChildNode(node, popupType, config) {
481
495
  if (config.onlyInteractive && !this.isInteractive(node)) return;
@@ -483,8 +497,8 @@ var TestIdObserver = class {
483
497
  const key = `${popupType}_${tag}`;
484
498
  const current = this.state.popupChildCounter.get(key) ?? 0;
485
499
  this.state.popupChildCounter.set(key, current + 1);
486
- const prefix = config.popupPrefixMap[popupType] || `${popupType}_`;
487
- const testId = `${prefix}${tag}_${current}`;
500
+ const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
501
+ const testId = `${config.runtimePagePrefix}${popupPrefix}${tag}_${current}`;
488
502
  node.setAttribute("data-testid", testId);
489
503
  }
490
504
  // ==========================================================
package/dist/index.mjs CHANGED
@@ -18,6 +18,7 @@ var defaultConfig = {
18
18
  globalPrefix: "",
19
19
  compilePrefix: "static_",
20
20
  runtimePagePrefix: "dynamic_",
21
+ antdClassPrefix: "ant",
21
22
  popupPrefixMap: {
22
23
  modal: "modal_",
23
24
  drawer: "drawer_",
@@ -58,9 +59,10 @@ function applyGlobalPrefix(cfg) {
58
59
  ...cfg,
59
60
  compilePrefix: prepend(cfg.compilePrefix),
60
61
  runtimePagePrefix: prepend(cfg.runtimePagePrefix),
61
- popupPrefixMap: Object.fromEntries(
62
- Object.entries(cfg.popupPrefixMap).map(([k, v]) => [k, prepend(v)])
63
- )
62
+ // 注意: popupPrefixMap 不拼接 globalPrefix
63
+ // 浮层 testid 格式为 ${runtimePagePrefix}${popupPrefixMap[type]}...,
64
+ // runtimePagePrefix 已携带 globalPrefix,避免重复
65
+ popupPrefixMap: { ...cfg.popupPrefixMap }
64
66
  };
65
67
  }
66
68
  var globalConfig = { ...defaultConfig };
@@ -134,20 +136,28 @@ function getPopupCounterSnapshot() {
134
136
  }
135
137
  function buildPopupTestId(type, tag, counterId) {
136
138
  const config = getConfig();
137
- const prefix = config.popupPrefixMap[type] || `${type}_`;
138
- return `${prefix}${tag}_${counterId}`;
139
+ const popupPrefix = config.popupPrefixMap[type] || `${type}_`;
140
+ return `${config.runtimePagePrefix}${popupPrefix}${tag}_${counterId}`;
139
141
  }
140
142
 
141
143
  // src/utils/testIdObserver.ts
142
- var POPUP_CLASS_MAP = {
143
- modal: ".ant-modal",
144
- drawer: ".ant-drawer",
145
- select: ".ant-select-dropdown",
146
- datePicker: ".ant-picker-dropdown",
147
- popconfirm: ".ant-popover.ant-popconfirm",
148
- dropdown: ".ant-dropdown",
149
- tooltip: ".ant-tooltip"
144
+ var POPUP_CLASS_SUFFIX_MAP = {
145
+ modal: ".{prefix}-modal",
146
+ drawer: ".{prefix}-drawer",
147
+ select: ".{prefix}-select-dropdown",
148
+ datePicker: ".{prefix}-picker-dropdown",
149
+ popconfirm: ".{prefix}-popover.{prefix}-popconfirm",
150
+ dropdown: ".{prefix}-dropdown",
151
+ tooltip: ".{prefix}-tooltip"
150
152
  };
153
+ function buildPopupClassMap(prefix) {
154
+ const result = {};
155
+ const entries = Object.entries(POPUP_CLASS_SUFFIX_MAP);
156
+ for (const [type, template] of entries) {
157
+ result[type] = template.replace(/\{prefix\}/g, prefix);
158
+ }
159
+ return result;
160
+ }
151
161
  var TestIdObserver = class {
152
162
  constructor() {
153
163
  // ==========================================================
@@ -166,6 +176,8 @@ var TestIdObserver = class {
166
176
  });
167
177
  }
168
178
  };
179
+ const config = getConfig();
180
+ this.popupClassMap = buildPopupClassMap(config.antdClassPrefix);
169
181
  this.state = {
170
182
  observer: null,
171
183
  isRunning: false,
@@ -399,7 +411,7 @@ var TestIdObserver = class {
399
411
  matchPopupClass(node) {
400
412
  const classStr = node.className || "";
401
413
  if (typeof classStr !== "string") return null;
402
- const entries = Object.entries(POPUP_CLASS_MAP);
414
+ const entries = Object.entries(this.popupClassMap);
403
415
  for (const [type, selector] of entries) {
404
416
  const classes = selector.replace(/^\./, "").split(".");
405
417
  const allMatch = classes.every(
@@ -432,8 +444,10 @@ var TestIdObserver = class {
432
444
  /**
433
445
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
434
446
  *
435
- * ID 格式: ${popupPrefix}${popupType}_${tag}_${counter}
436
- * 例: hall_modal_button_0, hall_select_div_2
447
+ * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
448
+ * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
449
+ *
450
+ * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
437
451
  */
438
452
  handlePopupChildNode(node, popupType, config) {
439
453
  if (config.onlyInteractive && !this.isInteractive(node)) return;
@@ -441,8 +455,8 @@ var TestIdObserver = class {
441
455
  const key = `${popupType}_${tag}`;
442
456
  const current = this.state.popupChildCounter.get(key) ?? 0;
443
457
  this.state.popupChildCounter.set(key, current + 1);
444
- const prefix = config.popupPrefixMap[popupType] || `${popupType}_`;
445
- const testId = `${prefix}${tag}_${current}`;
458
+ const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
459
+ const testId = `${config.runtimePagePrefix}${popupPrefix}${tag}_${current}`;
446
460
  node.setAttribute("data-testid", testId);
447
461
  }
448
462
  // ==========================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testid/antd-testid-runtime",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "运行时兜底打标模块 — MutationObserver + 锚点计数器 + 浮层计数器 + ID 重复检测",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",