@testid/antd-testid-runtime 1.0.11 → 1.0.13
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -25
- package/dist/index.mjs +42 -25
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -400,8 +400,8 @@ declare class TestIdObserver {
|
|
|
400
400
|
/**
|
|
401
401
|
* 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
|
|
402
402
|
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
403
|
+
* 同类型浮层的子节点共享全局计数器 (key: popupType_tag),
|
|
404
|
+
* 确保页面上多个同类下拉选择框的下拉选项 testid 全局唯一。
|
|
405
405
|
*
|
|
406
406
|
* ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
|
|
407
407
|
* 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
|
package/dist/index.d.ts
CHANGED
|
@@ -400,8 +400,8 @@ declare class TestIdObserver {
|
|
|
400
400
|
/**
|
|
401
401
|
* 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
|
|
402
402
|
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
403
|
+
* 同类型浮层的子节点共享全局计数器 (key: popupType_tag),
|
|
404
|
+
* 确保页面上多个同类下拉选择框的下拉选项 testid 全局唯一。
|
|
405
405
|
*
|
|
406
406
|
* ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
|
|
407
407
|
* 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
|
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 });
|
|
@@ -103,18 +120,13 @@ var defaultConfig = {
|
|
|
103
120
|
};
|
|
104
121
|
function mergeConfig(userConfig) {
|
|
105
122
|
if (!userConfig) {
|
|
106
|
-
const cfg = {
|
|
123
|
+
const cfg = __spreadValues({}, defaultConfig);
|
|
107
124
|
return applyGlobalPrefix(cfg);
|
|
108
125
|
}
|
|
109
|
-
const merged = {
|
|
110
|
-
...defaultConfig,
|
|
111
|
-
...userConfig,
|
|
126
|
+
const merged = __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), userConfig), {
|
|
112
127
|
// popupPrefixMap 需要深度合并: 允许用户只覆盖部分浮层前缀
|
|
113
|
-
popupPrefixMap: {
|
|
114
|
-
|
|
115
|
-
...userConfig.popupPrefixMap || {}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
128
|
+
popupPrefixMap: __spreadValues(__spreadValues({}, defaultConfig.popupPrefixMap), userConfig.popupPrefixMap || {})
|
|
129
|
+
});
|
|
118
130
|
return applyGlobalPrefix(merged);
|
|
119
131
|
}
|
|
120
132
|
function applyGlobalPrefix(cfg) {
|
|
@@ -122,17 +134,16 @@ function applyGlobalPrefix(cfg) {
|
|
|
122
134
|
if (!g) return cfg;
|
|
123
135
|
const prefix = `${g}_`;
|
|
124
136
|
const prepend = (val) => val.startsWith(prefix) ? val : `${prefix}${val}`;
|
|
125
|
-
return {
|
|
126
|
-
...cfg,
|
|
137
|
+
return __spreadProps(__spreadValues({}, cfg), {
|
|
127
138
|
compilePrefix: prepend(cfg.compilePrefix),
|
|
128
139
|
runtimePagePrefix: prepend(cfg.runtimePagePrefix),
|
|
129
140
|
// 注意: popupPrefixMap 不拼接 globalPrefix
|
|
130
141
|
// 浮层 testid 格式为 ${runtimePagePrefix}${popupPrefixMap[type]}...,
|
|
131
142
|
// runtimePagePrefix 已携带 globalPrefix,避免重复
|
|
132
|
-
popupPrefixMap: {
|
|
133
|
-
};
|
|
143
|
+
popupPrefixMap: __spreadValues({}, cfg.popupPrefixMap)
|
|
144
|
+
});
|
|
134
145
|
}
|
|
135
|
-
var globalConfig = {
|
|
146
|
+
var globalConfig = __spreadValues({}, defaultConfig);
|
|
136
147
|
function initConfig(custom) {
|
|
137
148
|
globalConfig = mergeConfig(custom);
|
|
138
149
|
}
|
|
@@ -200,8 +211,9 @@ function buildAnchorKey(anchorTestId, componentName, tagName) {
|
|
|
200
211
|
return `${anchorTestId}__${componentName}__${tagName}`;
|
|
201
212
|
}
|
|
202
213
|
function getNextAnchorLocalIndex(anchorTestId, componentName, tagName) {
|
|
214
|
+
var _a;
|
|
203
215
|
const key = buildAnchorKey(anchorTestId, componentName, tagName);
|
|
204
|
-
const current = anchorCounterMap.get(key)
|
|
216
|
+
const current = (_a = anchorCounterMap.get(key)) != null ? _a : 0;
|
|
205
217
|
anchorCounterMap.set(key, current + 1);
|
|
206
218
|
return current;
|
|
207
219
|
}
|
|
@@ -254,7 +266,7 @@ function resetPopupCounter(type) {
|
|
|
254
266
|
}
|
|
255
267
|
}
|
|
256
268
|
function getPopupCounterSnapshot() {
|
|
257
|
-
return {
|
|
269
|
+
return __spreadValues({}, popupCounters);
|
|
258
270
|
}
|
|
259
271
|
function buildPopupTestId(type, tag, counterId) {
|
|
260
272
|
const config = getConfig();
|
|
@@ -359,7 +371,8 @@ var TestIdObserver = class {
|
|
|
359
371
|
* 停止 Observer
|
|
360
372
|
*/
|
|
361
373
|
stop() {
|
|
362
|
-
|
|
374
|
+
var _a;
|
|
375
|
+
(_a = this.state.observer) == null ? void 0 : _a.disconnect();
|
|
363
376
|
this.state.observer = null;
|
|
364
377
|
this.state.isRunning = false;
|
|
365
378
|
}
|
|
@@ -428,7 +441,7 @@ var TestIdObserver = class {
|
|
|
428
441
|
}
|
|
429
442
|
const popupAncestor = this.detectPopupAncestor(node);
|
|
430
443
|
if (popupAncestor) {
|
|
431
|
-
this.handlePopupChildNode(node, popupAncestor.type,
|
|
444
|
+
this.handlePopupChildNode(node, popupAncestor.type, config);
|
|
432
445
|
return;
|
|
433
446
|
}
|
|
434
447
|
const popupType = this.detectPopupType(node);
|
|
@@ -583,11 +596,12 @@ var TestIdObserver = class {
|
|
|
583
596
|
* ID 格式: ${runtimePagePrefix}${route}_${tag}_${counter}
|
|
584
597
|
*/
|
|
585
598
|
handleDynamicNode(node, config) {
|
|
599
|
+
var _a;
|
|
586
600
|
if (config.onlyInteractive && !this.isInteractive(node)) return;
|
|
587
601
|
const tag = this.getSimpleTag(node);
|
|
588
602
|
const route = this.state.currentRoute || "unknown";
|
|
589
603
|
const key = `${route}_${tag}`;
|
|
590
|
-
const current = this.state.dynamicCounter.get(key)
|
|
604
|
+
const current = (_a = this.state.dynamicCounter.get(key)) != null ? _a : 0;
|
|
591
605
|
this.state.dynamicCounter.set(key, current + 1);
|
|
592
606
|
const testId = `${config.runtimePagePrefix}${route}_${tag}_${current}`;
|
|
593
607
|
node.setAttribute("data-testid", testId);
|
|
@@ -595,20 +609,20 @@ var TestIdObserver = class {
|
|
|
595
609
|
/**
|
|
596
610
|
* 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
|
|
597
611
|
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
612
|
+
* 同类型浮层的子节点共享全局计数器 (key: popupType_tag),
|
|
613
|
+
* 确保页面上多个同类下拉选择框的下拉选项 testid 全局唯一。
|
|
600
614
|
*
|
|
601
615
|
* ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
|
|
602
616
|
* 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
|
|
603
617
|
*
|
|
604
618
|
* 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
|
|
605
619
|
*/
|
|
606
|
-
handlePopupChildNode(node, popupType,
|
|
620
|
+
handlePopupChildNode(node, popupType, config) {
|
|
621
|
+
var _a;
|
|
607
622
|
if (config.onlyInteractive && !this.isInteractive(node)) return;
|
|
608
623
|
const tag = this.getSimpleTag(node);
|
|
609
|
-
const
|
|
610
|
-
const
|
|
611
|
-
const current = this.state.popupChildCounter.get(key) ?? 0;
|
|
624
|
+
const key = `${popupType}_${tag}`;
|
|
625
|
+
const current = (_a = this.state.popupChildCounter.get(key)) != null ? _a : 0;
|
|
612
626
|
this.state.popupChildCounter.set(key, current + 1);
|
|
613
627
|
const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
|
|
614
628
|
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"]],
|
|
@@ -60,18 +80,13 @@ var defaultConfig = {
|
|
|
60
80
|
};
|
|
61
81
|
function mergeConfig(userConfig) {
|
|
62
82
|
if (!userConfig) {
|
|
63
|
-
const cfg = {
|
|
83
|
+
const cfg = __spreadValues({}, defaultConfig);
|
|
64
84
|
return applyGlobalPrefix(cfg);
|
|
65
85
|
}
|
|
66
|
-
const merged = {
|
|
67
|
-
...defaultConfig,
|
|
68
|
-
...userConfig,
|
|
86
|
+
const merged = __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), userConfig), {
|
|
69
87
|
// popupPrefixMap 需要深度合并: 允许用户只覆盖部分浮层前缀
|
|
70
|
-
popupPrefixMap: {
|
|
71
|
-
|
|
72
|
-
...userConfig.popupPrefixMap || {}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
88
|
+
popupPrefixMap: __spreadValues(__spreadValues({}, defaultConfig.popupPrefixMap), userConfig.popupPrefixMap || {})
|
|
89
|
+
});
|
|
75
90
|
return applyGlobalPrefix(merged);
|
|
76
91
|
}
|
|
77
92
|
function applyGlobalPrefix(cfg) {
|
|
@@ -79,17 +94,16 @@ function applyGlobalPrefix(cfg) {
|
|
|
79
94
|
if (!g) return cfg;
|
|
80
95
|
const prefix = `${g}_`;
|
|
81
96
|
const prepend = (val) => val.startsWith(prefix) ? val : `${prefix}${val}`;
|
|
82
|
-
return {
|
|
83
|
-
...cfg,
|
|
97
|
+
return __spreadProps(__spreadValues({}, cfg), {
|
|
84
98
|
compilePrefix: prepend(cfg.compilePrefix),
|
|
85
99
|
runtimePagePrefix: prepend(cfg.runtimePagePrefix),
|
|
86
100
|
// 注意: popupPrefixMap 不拼接 globalPrefix
|
|
87
101
|
// 浮层 testid 格式为 ${runtimePagePrefix}${popupPrefixMap[type]}...,
|
|
88
102
|
// runtimePagePrefix 已携带 globalPrefix,避免重复
|
|
89
|
-
popupPrefixMap: {
|
|
90
|
-
};
|
|
103
|
+
popupPrefixMap: __spreadValues({}, cfg.popupPrefixMap)
|
|
104
|
+
});
|
|
91
105
|
}
|
|
92
|
-
var globalConfig = {
|
|
106
|
+
var globalConfig = __spreadValues({}, defaultConfig);
|
|
93
107
|
function initConfig(custom) {
|
|
94
108
|
globalConfig = mergeConfig(custom);
|
|
95
109
|
}
|
|
@@ -157,8 +171,9 @@ function buildAnchorKey(anchorTestId, componentName, tagName) {
|
|
|
157
171
|
return `${anchorTestId}__${componentName}__${tagName}`;
|
|
158
172
|
}
|
|
159
173
|
function getNextAnchorLocalIndex(anchorTestId, componentName, tagName) {
|
|
174
|
+
var _a;
|
|
160
175
|
const key = buildAnchorKey(anchorTestId, componentName, tagName);
|
|
161
|
-
const current = anchorCounterMap.get(key)
|
|
176
|
+
const current = (_a = anchorCounterMap.get(key)) != null ? _a : 0;
|
|
162
177
|
anchorCounterMap.set(key, current + 1);
|
|
163
178
|
return current;
|
|
164
179
|
}
|
|
@@ -211,7 +226,7 @@ function resetPopupCounter(type) {
|
|
|
211
226
|
}
|
|
212
227
|
}
|
|
213
228
|
function getPopupCounterSnapshot() {
|
|
214
|
-
return {
|
|
229
|
+
return __spreadValues({}, popupCounters);
|
|
215
230
|
}
|
|
216
231
|
function buildPopupTestId(type, tag, counterId) {
|
|
217
232
|
const config = getConfig();
|
|
@@ -316,7 +331,8 @@ var TestIdObserver = class {
|
|
|
316
331
|
* 停止 Observer
|
|
317
332
|
*/
|
|
318
333
|
stop() {
|
|
319
|
-
|
|
334
|
+
var _a;
|
|
335
|
+
(_a = this.state.observer) == null ? void 0 : _a.disconnect();
|
|
320
336
|
this.state.observer = null;
|
|
321
337
|
this.state.isRunning = false;
|
|
322
338
|
}
|
|
@@ -385,7 +401,7 @@ var TestIdObserver = class {
|
|
|
385
401
|
}
|
|
386
402
|
const popupAncestor = this.detectPopupAncestor(node);
|
|
387
403
|
if (popupAncestor) {
|
|
388
|
-
this.handlePopupChildNode(node, popupAncestor.type,
|
|
404
|
+
this.handlePopupChildNode(node, popupAncestor.type, config);
|
|
389
405
|
return;
|
|
390
406
|
}
|
|
391
407
|
const popupType = this.detectPopupType(node);
|
|
@@ -540,11 +556,12 @@ var TestIdObserver = class {
|
|
|
540
556
|
* ID 格式: ${runtimePagePrefix}${route}_${tag}_${counter}
|
|
541
557
|
*/
|
|
542
558
|
handleDynamicNode(node, config) {
|
|
559
|
+
var _a;
|
|
543
560
|
if (config.onlyInteractive && !this.isInteractive(node)) return;
|
|
544
561
|
const tag = this.getSimpleTag(node);
|
|
545
562
|
const route = this.state.currentRoute || "unknown";
|
|
546
563
|
const key = `${route}_${tag}`;
|
|
547
|
-
const current = this.state.dynamicCounter.get(key)
|
|
564
|
+
const current = (_a = this.state.dynamicCounter.get(key)) != null ? _a : 0;
|
|
548
565
|
this.state.dynamicCounter.set(key, current + 1);
|
|
549
566
|
const testId = `${config.runtimePagePrefix}${route}_${tag}_${current}`;
|
|
550
567
|
node.setAttribute("data-testid", testId);
|
|
@@ -552,20 +569,20 @@ var TestIdObserver = class {
|
|
|
552
569
|
/**
|
|
553
570
|
* 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
|
|
554
571
|
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
572
|
+
* 同类型浮层的子节点共享全局计数器 (key: popupType_tag),
|
|
573
|
+
* 确保页面上多个同类下拉选择框的下拉选项 testid 全局唯一。
|
|
557
574
|
*
|
|
558
575
|
* ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
|
|
559
576
|
* 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
|
|
560
577
|
*
|
|
561
578
|
* 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
|
|
562
579
|
*/
|
|
563
|
-
handlePopupChildNode(node, popupType,
|
|
580
|
+
handlePopupChildNode(node, popupType, config) {
|
|
581
|
+
var _a;
|
|
564
582
|
if (config.onlyInteractive && !this.isInteractive(node)) return;
|
|
565
583
|
const tag = this.getSimpleTag(node);
|
|
566
|
-
const
|
|
567
|
-
const
|
|
568
|
-
const current = this.state.popupChildCounter.get(key) ?? 0;
|
|
584
|
+
const key = `${popupType}_${tag}`;
|
|
585
|
+
const current = (_a = this.state.popupChildCounter.get(key)) != null ? _a : 0;
|
|
569
586
|
this.state.popupChildCounter.set(key, current + 1);
|
|
570
587
|
const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
|
|
571
588
|
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.
|
|
3
|
+
"version": "1.0.13",
|
|
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": {
|