@testid/antd-testid-runtime 1.0.12 → 1.0.14

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.js CHANGED
@@ -1,8 +1,25 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
6
23
  var __export = (target, all) => {
7
24
  for (var name in all)
8
25
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -73,7 +90,14 @@ var antdAdapter = {
73
90
  "a-textarea",
74
91
  "a-checkbox",
75
92
  "a-radio",
76
- "a-switch"
93
+ "a-switch",
94
+ "a-menu-item",
95
+ "a-dropdown-button",
96
+ "a-tabs-tab-pane",
97
+ "a-table",
98
+ "a-tag",
99
+ "a-card",
100
+ "a-collapse-panel"
77
101
  ],
78
102
  tagPrefixPattern: /^a-/
79
103
  };
@@ -103,18 +127,13 @@ var defaultConfig = {
103
127
  };
104
128
  function mergeConfig(userConfig) {
105
129
  if (!userConfig) {
106
- const cfg = { ...defaultConfig };
130
+ const cfg = __spreadValues({}, defaultConfig);
107
131
  return applyGlobalPrefix(cfg);
108
132
  }
109
- const merged = {
110
- ...defaultConfig,
111
- ...userConfig,
133
+ const merged = __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), userConfig), {
112
134
  // popupPrefixMap 需要深度合并: 允许用户只覆盖部分浮层前缀
113
- popupPrefixMap: {
114
- ...defaultConfig.popupPrefixMap,
115
- ...userConfig.popupPrefixMap || {}
116
- }
117
- };
135
+ popupPrefixMap: __spreadValues(__spreadValues({}, defaultConfig.popupPrefixMap), userConfig.popupPrefixMap || {})
136
+ });
118
137
  return applyGlobalPrefix(merged);
119
138
  }
120
139
  function applyGlobalPrefix(cfg) {
@@ -122,17 +141,16 @@ function applyGlobalPrefix(cfg) {
122
141
  if (!g) return cfg;
123
142
  const prefix = `${g}_`;
124
143
  const prepend = (val) => val.startsWith(prefix) ? val : `${prefix}${val}`;
125
- return {
126
- ...cfg,
144
+ return __spreadProps(__spreadValues({}, cfg), {
127
145
  compilePrefix: prepend(cfg.compilePrefix),
128
146
  runtimePagePrefix: prepend(cfg.runtimePagePrefix),
129
147
  // 注意: popupPrefixMap 不拼接 globalPrefix
130
148
  // 浮层 testid 格式为 ${runtimePagePrefix}${popupPrefixMap[type]}...,
131
149
  // runtimePagePrefix 已携带 globalPrefix,避免重复
132
- popupPrefixMap: { ...cfg.popupPrefixMap }
133
- };
150
+ popupPrefixMap: __spreadValues({}, cfg.popupPrefixMap)
151
+ });
134
152
  }
135
- var globalConfig = { ...defaultConfig };
153
+ var globalConfig = __spreadValues({}, defaultConfig);
136
154
  function initConfig(custom) {
137
155
  globalConfig = mergeConfig(custom);
138
156
  }
@@ -200,8 +218,9 @@ function buildAnchorKey(anchorTestId, componentName, tagName) {
200
218
  return `${anchorTestId}__${componentName}__${tagName}`;
201
219
  }
202
220
  function getNextAnchorLocalIndex(anchorTestId, componentName, tagName) {
221
+ var _a;
203
222
  const key = buildAnchorKey(anchorTestId, componentName, tagName);
204
- const current = anchorCounterMap.get(key) ?? 0;
223
+ const current = (_a = anchorCounterMap.get(key)) != null ? _a : 0;
205
224
  anchorCounterMap.set(key, current + 1);
206
225
  return current;
207
226
  }
@@ -213,9 +232,16 @@ function getAnchorCounterMap() {
213
232
  }
214
233
  function parseBaseKey(baseKey) {
215
234
  const match = baseKey.match(
216
- /^common_comp_(.+?)_tag_(.+?)_(\d+)$/
235
+ /^common_comp_(.+?)_tag_(.+)_(\d+)$/
217
236
  );
218
- if (!match) return null;
237
+ if (!match) {
238
+ console.warn(
239
+ "[antd-testid-runtime] parseBaseKey \u5931\u8D25\uFF0CbaseKey \u683C\u5F0F\u4E0D\u5339\u914D:",
240
+ baseKey,
241
+ "\u671F\u671B\u683C\u5F0F: common_comp_{componentName}_tag_{tagName}_{index}"
242
+ );
243
+ return null;
244
+ }
219
245
  return {
220
246
  componentName: match[1],
221
247
  tagName: match[2],
@@ -254,7 +280,7 @@ function resetPopupCounter(type) {
254
280
  }
255
281
  }
256
282
  function getPopupCounterSnapshot() {
257
- return { ...popupCounters };
283
+ return __spreadValues({}, popupCounters);
258
284
  }
259
285
  function buildPopupTestId(type, tag, counterId) {
260
286
  const config = getConfig();
@@ -359,7 +385,8 @@ var TestIdObserver = class {
359
385
  * 停止 Observer
360
386
  */
361
387
  stop() {
362
- this.state.observer?.disconnect();
388
+ var _a;
389
+ (_a = this.state.observer) == null ? void 0 : _a.disconnect();
363
390
  this.state.observer = null;
364
391
  this.state.isRunning = false;
365
392
  }
@@ -583,11 +610,12 @@ var TestIdObserver = class {
583
610
  * ID 格式: ${runtimePagePrefix}${route}_${tag}_${counter}
584
611
  */
585
612
  handleDynamicNode(node, config) {
613
+ var _a;
586
614
  if (config.onlyInteractive && !this.isInteractive(node)) return;
587
615
  const tag = this.getSimpleTag(node);
588
616
  const route = this.state.currentRoute || "unknown";
589
617
  const key = `${route}_${tag}`;
590
- const current = this.state.dynamicCounter.get(key) ?? 0;
618
+ const current = (_a = this.state.dynamicCounter.get(key)) != null ? _a : 0;
591
619
  this.state.dynamicCounter.set(key, current + 1);
592
620
  const testId = `${config.runtimePagePrefix}${route}_${tag}_${current}`;
593
621
  node.setAttribute("data-testid", testId);
@@ -604,10 +632,11 @@ var TestIdObserver = class {
604
632
  * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
605
633
  */
606
634
  handlePopupChildNode(node, popupType, config) {
635
+ var _a;
607
636
  if (config.onlyInteractive && !this.isInteractive(node)) return;
608
637
  const tag = this.getSimpleTag(node);
609
638
  const key = `${popupType}_${tag}`;
610
- const current = this.state.popupChildCounter.get(key) ?? 0;
639
+ const current = (_a = this.state.popupChildCounter.get(key)) != null ? _a : 0;
611
640
  this.state.popupChildCounter.set(key, current + 1);
612
641
  const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
613
642
  const testId = `${config.runtimePagePrefix}${popupPrefix}${tag}_${current}`;
package/dist/index.mjs CHANGED
@@ -1,3 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
1
21
  // src/adapters/antd.ts
2
22
  var popupClassSuffixMap = {
3
23
  modal: [["-modal"]],
@@ -30,7 +50,14 @@ var antdAdapter = {
30
50
  "a-textarea",
31
51
  "a-checkbox",
32
52
  "a-radio",
33
- "a-switch"
53
+ "a-switch",
54
+ "a-menu-item",
55
+ "a-dropdown-button",
56
+ "a-tabs-tab-pane",
57
+ "a-table",
58
+ "a-tag",
59
+ "a-card",
60
+ "a-collapse-panel"
34
61
  ],
35
62
  tagPrefixPattern: /^a-/
36
63
  };
@@ -60,18 +87,13 @@ var defaultConfig = {
60
87
  };
61
88
  function mergeConfig(userConfig) {
62
89
  if (!userConfig) {
63
- const cfg = { ...defaultConfig };
90
+ const cfg = __spreadValues({}, defaultConfig);
64
91
  return applyGlobalPrefix(cfg);
65
92
  }
66
- const merged = {
67
- ...defaultConfig,
68
- ...userConfig,
93
+ const merged = __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), userConfig), {
69
94
  // popupPrefixMap 需要深度合并: 允许用户只覆盖部分浮层前缀
70
- popupPrefixMap: {
71
- ...defaultConfig.popupPrefixMap,
72
- ...userConfig.popupPrefixMap || {}
73
- }
74
- };
95
+ popupPrefixMap: __spreadValues(__spreadValues({}, defaultConfig.popupPrefixMap), userConfig.popupPrefixMap || {})
96
+ });
75
97
  return applyGlobalPrefix(merged);
76
98
  }
77
99
  function applyGlobalPrefix(cfg) {
@@ -79,17 +101,16 @@ function applyGlobalPrefix(cfg) {
79
101
  if (!g) return cfg;
80
102
  const prefix = `${g}_`;
81
103
  const prepend = (val) => val.startsWith(prefix) ? val : `${prefix}${val}`;
82
- return {
83
- ...cfg,
104
+ return __spreadProps(__spreadValues({}, cfg), {
84
105
  compilePrefix: prepend(cfg.compilePrefix),
85
106
  runtimePagePrefix: prepend(cfg.runtimePagePrefix),
86
107
  // 注意: popupPrefixMap 不拼接 globalPrefix
87
108
  // 浮层 testid 格式为 ${runtimePagePrefix}${popupPrefixMap[type]}...,
88
109
  // runtimePagePrefix 已携带 globalPrefix,避免重复
89
- popupPrefixMap: { ...cfg.popupPrefixMap }
90
- };
110
+ popupPrefixMap: __spreadValues({}, cfg.popupPrefixMap)
111
+ });
91
112
  }
92
- var globalConfig = { ...defaultConfig };
113
+ var globalConfig = __spreadValues({}, defaultConfig);
93
114
  function initConfig(custom) {
94
115
  globalConfig = mergeConfig(custom);
95
116
  }
@@ -157,8 +178,9 @@ function buildAnchorKey(anchorTestId, componentName, tagName) {
157
178
  return `${anchorTestId}__${componentName}__${tagName}`;
158
179
  }
159
180
  function getNextAnchorLocalIndex(anchorTestId, componentName, tagName) {
181
+ var _a;
160
182
  const key = buildAnchorKey(anchorTestId, componentName, tagName);
161
- const current = anchorCounterMap.get(key) ?? 0;
183
+ const current = (_a = anchorCounterMap.get(key)) != null ? _a : 0;
162
184
  anchorCounterMap.set(key, current + 1);
163
185
  return current;
164
186
  }
@@ -170,9 +192,16 @@ function getAnchorCounterMap() {
170
192
  }
171
193
  function parseBaseKey(baseKey) {
172
194
  const match = baseKey.match(
173
- /^common_comp_(.+?)_tag_(.+?)_(\d+)$/
195
+ /^common_comp_(.+?)_tag_(.+)_(\d+)$/
174
196
  );
175
- if (!match) return null;
197
+ if (!match) {
198
+ console.warn(
199
+ "[antd-testid-runtime] parseBaseKey \u5931\u8D25\uFF0CbaseKey \u683C\u5F0F\u4E0D\u5339\u914D:",
200
+ baseKey,
201
+ "\u671F\u671B\u683C\u5F0F: common_comp_{componentName}_tag_{tagName}_{index}"
202
+ );
203
+ return null;
204
+ }
176
205
  return {
177
206
  componentName: match[1],
178
207
  tagName: match[2],
@@ -211,7 +240,7 @@ function resetPopupCounter(type) {
211
240
  }
212
241
  }
213
242
  function getPopupCounterSnapshot() {
214
- return { ...popupCounters };
243
+ return __spreadValues({}, popupCounters);
215
244
  }
216
245
  function buildPopupTestId(type, tag, counterId) {
217
246
  const config = getConfig();
@@ -316,7 +345,8 @@ var TestIdObserver = class {
316
345
  * 停止 Observer
317
346
  */
318
347
  stop() {
319
- this.state.observer?.disconnect();
348
+ var _a;
349
+ (_a = this.state.observer) == null ? void 0 : _a.disconnect();
320
350
  this.state.observer = null;
321
351
  this.state.isRunning = false;
322
352
  }
@@ -540,11 +570,12 @@ var TestIdObserver = class {
540
570
  * ID 格式: ${runtimePagePrefix}${route}_${tag}_${counter}
541
571
  */
542
572
  handleDynamicNode(node, config) {
573
+ var _a;
543
574
  if (config.onlyInteractive && !this.isInteractive(node)) return;
544
575
  const tag = this.getSimpleTag(node);
545
576
  const route = this.state.currentRoute || "unknown";
546
577
  const key = `${route}_${tag}`;
547
- const current = this.state.dynamicCounter.get(key) ?? 0;
578
+ const current = (_a = this.state.dynamicCounter.get(key)) != null ? _a : 0;
548
579
  this.state.dynamicCounter.set(key, current + 1);
549
580
  const testId = `${config.runtimePagePrefix}${route}_${tag}_${current}`;
550
581
  node.setAttribute("data-testid", testId);
@@ -561,10 +592,11 @@ var TestIdObserver = class {
561
592
  * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
562
593
  */
563
594
  handlePopupChildNode(node, popupType, config) {
595
+ var _a;
564
596
  if (config.onlyInteractive && !this.isInteractive(node)) return;
565
597
  const tag = this.getSimpleTag(node);
566
598
  const key = `${popupType}_${tag}`;
567
- const current = this.state.popupChildCounter.get(key) ?? 0;
599
+ const current = (_a = this.state.popupChildCounter.get(key)) != null ? _a : 0;
568
600
  this.state.popupChildCounter.set(key, current + 1);
569
601
  const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
570
602
  const testId = `${config.runtimePagePrefix}${popupPrefix}${tag}_${current}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testid/antd-testid-runtime",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "运行时兜底打标模块 — MutationObserver + 锚点计数器 + 浮层计数器 + ID 重复检测",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -21,8 +21,8 @@
21
21
  "directory": "packages/antd-testid-runtime"
22
22
  },
23
23
  "scripts": {
24
- "build": "tsup src/index.ts --dts --format esm,cjs --clean",
25
- "dev": "tsup src/index.ts --dts --format esm,cjs --watch"
24
+ "build": "tsup src/index.ts --dts --format esm,cjs --clean --target es2015",
25
+ "dev": "tsup src/index.ts --dts --format esm,cjs --watch --target es2015"
26
26
  },
27
27
  "dependencies": {},
28
28
  "devDependencies": {