@testid/antd-testid-runtime 1.0.17 → 1.0.18

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
@@ -1,3 +1,5 @@
1
+ import { App } from 'vue';
2
+
1
3
  /**
2
4
  * UI 库适配器接口 — adapters/types.ts
3
5
  *
@@ -486,4 +488,30 @@ declare class TestIdChecker {
486
488
  private static reportGroupDuplicates;
487
489
  }
488
490
 
489
- export { type ParsedBaseKey, type PopupType, TestIdChecker, type TestIdMarkConfig, TestIdObserver, type UiAdapter, antdAdapter, buildAnchorTestId, buildPopupTestId, defaultConfig, elementAdapter, getAnchorCounterMap, getConfig, getNextAnchorLocalIndex, getNextPopupId, getPopupCounterSnapshot, initConfig, mergeConfig, parseBaseKey, resetAllAnchorCounters, resetAllPopupCounters, resetPopupCounter };
491
+ /**
492
+ * Vue 3 插件桥接 — testIdVuePlugin.ts
493
+ *
494
+ * 铁三角第二层:绕过 UI 库组件 inheritAttrs: false 的限制。
495
+ *
496
+ * 问题背景:
497
+ * 编译期在 <a-menu-item data-test-base-key="..."> 上注入属性,
498
+ * 但 Ant Design Vue 等 UI 库组件通常设置 inheritAttrs: false,
499
+ * 导致非 prop 属性不会自动传递到渲染后的 DOM 元素上。
500
+ *
501
+ * 解决方案:
502
+ * 通过 app.mixin({ mounted() }) 全局混入,在每个组件挂载后,
503
+ * 从 Vue 内部的 $attrs 中读取插件关注的属性并手动写入 $el。
504
+ *
505
+ * 对于 inheritAttrs: true (默认) 的组件,Vue 已自动应用属性到 $el,
506
+ * hasAttribute 检查会跳过避免重复写入。
507
+ *
508
+ * 使用方式:
509
+ * import { TestIdVuePlugin } from '@testid/antd-testid-runtime';
510
+ * app.use(TestIdVuePlugin); // 必须在 app.mount() 之前调用
511
+ */
512
+
513
+ declare const TestIdVuePlugin: {
514
+ install(app: App): void;
515
+ };
516
+
517
+ export { type ParsedBaseKey, type PopupType, TestIdChecker, type TestIdMarkConfig, TestIdObserver, TestIdVuePlugin, type UiAdapter, antdAdapter, buildAnchorTestId, buildPopupTestId, defaultConfig, elementAdapter, getAnchorCounterMap, getConfig, getNextAnchorLocalIndex, getNextPopupId, getPopupCounterSnapshot, initConfig, mergeConfig, parseBaseKey, resetAllAnchorCounters, resetAllPopupCounters, resetPopupCounter };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { App } from 'vue';
2
+
1
3
  /**
2
4
  * UI 库适配器接口 — adapters/types.ts
3
5
  *
@@ -486,4 +488,30 @@ declare class TestIdChecker {
486
488
  private static reportGroupDuplicates;
487
489
  }
488
490
 
489
- export { type ParsedBaseKey, type PopupType, TestIdChecker, type TestIdMarkConfig, TestIdObserver, type UiAdapter, antdAdapter, buildAnchorTestId, buildPopupTestId, defaultConfig, elementAdapter, getAnchorCounterMap, getConfig, getNextAnchorLocalIndex, getNextPopupId, getPopupCounterSnapshot, initConfig, mergeConfig, parseBaseKey, resetAllAnchorCounters, resetAllPopupCounters, resetPopupCounter };
491
+ /**
492
+ * Vue 3 插件桥接 — testIdVuePlugin.ts
493
+ *
494
+ * 铁三角第二层:绕过 UI 库组件 inheritAttrs: false 的限制。
495
+ *
496
+ * 问题背景:
497
+ * 编译期在 <a-menu-item data-test-base-key="..."> 上注入属性,
498
+ * 但 Ant Design Vue 等 UI 库组件通常设置 inheritAttrs: false,
499
+ * 导致非 prop 属性不会自动传递到渲染后的 DOM 元素上。
500
+ *
501
+ * 解决方案:
502
+ * 通过 app.mixin({ mounted() }) 全局混入,在每个组件挂载后,
503
+ * 从 Vue 内部的 $attrs 中读取插件关注的属性并手动写入 $el。
504
+ *
505
+ * 对于 inheritAttrs: true (默认) 的组件,Vue 已自动应用属性到 $el,
506
+ * hasAttribute 检查会跳过避免重复写入。
507
+ *
508
+ * 使用方式:
509
+ * import { TestIdVuePlugin } from '@testid/antd-testid-runtime';
510
+ * app.use(TestIdVuePlugin); // 必须在 app.mount() 之前调用
511
+ */
512
+
513
+ declare const TestIdVuePlugin: {
514
+ install(app: App): void;
515
+ };
516
+
517
+ export { type ParsedBaseKey, type PopupType, TestIdChecker, type TestIdMarkConfig, TestIdObserver, TestIdVuePlugin, type UiAdapter, antdAdapter, buildAnchorTestId, buildPopupTestId, defaultConfig, elementAdapter, getAnchorCounterMap, getConfig, getNextAnchorLocalIndex, getNextPopupId, getPopupCounterSnapshot, initConfig, mergeConfig, parseBaseKey, resetAllAnchorCounters, resetAllPopupCounters, resetPopupCounter };
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ var index_exports = {};
39
39
  __export(index_exports, {
40
40
  TestIdChecker: () => TestIdChecker,
41
41
  TestIdObserver: () => TestIdObserver,
42
+ TestIdVuePlugin: () => TestIdVuePlugin,
42
43
  antdAdapter: () => antdAdapter,
43
44
  buildAnchorTestId: () => buildAnchorTestId,
44
45
  buildPopupTestId: () => buildPopupTestId,
@@ -882,10 +883,32 @@ var TestIdChecker = class {
882
883
  console.groupEnd();
883
884
  }
884
885
  };
886
+
887
+ // src/utils/testIdVuePlugin.ts
888
+ var WATCHED_ATTRS = ["data-testid", "data-test-base-key"];
889
+ var TestIdVuePlugin = {
890
+ install(app) {
891
+ app.mixin({
892
+ mounted() {
893
+ const el = this.$el;
894
+ if (!el) return;
895
+ const attrs = this.$attrs || {};
896
+ if (!attrs || typeof attrs !== "object") return;
897
+ for (const attr of WATCHED_ATTRS) {
898
+ const value = attrs[attr];
899
+ if (value != null && !el.hasAttribute(attr)) {
900
+ el.setAttribute(attr, String(value));
901
+ }
902
+ }
903
+ }
904
+ });
905
+ }
906
+ };
885
907
  // Annotate the CommonJS export names for ESM import in node:
886
908
  0 && (module.exports = {
887
909
  TestIdChecker,
888
910
  TestIdObserver,
911
+ TestIdVuePlugin,
889
912
  antdAdapter,
890
913
  buildAnchorTestId,
891
914
  buildPopupTestId,
package/dist/index.mjs CHANGED
@@ -842,9 +842,31 @@ var TestIdChecker = class {
842
842
  console.groupEnd();
843
843
  }
844
844
  };
845
+
846
+ // src/utils/testIdVuePlugin.ts
847
+ var WATCHED_ATTRS = ["data-testid", "data-test-base-key"];
848
+ var TestIdVuePlugin = {
849
+ install(app) {
850
+ app.mixin({
851
+ mounted() {
852
+ const el = this.$el;
853
+ if (!el) return;
854
+ const attrs = this.$attrs || {};
855
+ if (!attrs || typeof attrs !== "object") return;
856
+ for (const attr of WATCHED_ATTRS) {
857
+ const value = attrs[attr];
858
+ if (value != null && !el.hasAttribute(attr)) {
859
+ el.setAttribute(attr, String(value));
860
+ }
861
+ }
862
+ }
863
+ });
864
+ }
865
+ };
845
866
  export {
846
867
  TestIdChecker,
847
868
  TestIdObserver,
869
+ TestIdVuePlugin,
848
870
  antdAdapter,
849
871
  buildAnchorTestId,
850
872
  buildPopupTestId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testid/antd-testid-runtime",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "运行时兜底打标模块 — MutationObserver + 锚点计数器 + 浮层计数器 + ID 重复检测",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -25,8 +25,12 @@
25
25
  "dev": "tsup src/index.ts --dts --format esm,cjs --watch --target es2015"
26
26
  },
27
27
  "dependencies": {},
28
+ "peerDependencies": {
29
+ "vue": "^3.0.0"
30
+ },
28
31
  "devDependencies": {
29
32
  "tsup": "^8.0.0",
30
- "typescript": "^5.3.0"
33
+ "typescript": "^5.3.0",
34
+ "vue": "^3.4.0"
31
35
  }
32
36
  }