@immense/vue-pom-generator 1.0.96 → 1.0.97

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.
@@ -0,0 +1,112 @@
1
+ import { DOMWrapper, type VueWrapper } from "@vue/test-utils";
2
+
3
+ export type VueTestUtilsPomRoot = DOMWrapper<Element> | VueWrapper;
4
+
5
+ export interface VueTestUtilsPomOptions {
6
+ testIdAttribute?: string;
7
+ }
8
+
9
+ /**
10
+ * Behavior-oriented runtime for generated Vue Test Utils component objects.
11
+ *
12
+ * Generated objects scope every lookup to `wrapper`; consumers can use that wrapper
13
+ * directly for assertions that do not warrant a generated behavior method.
14
+ */
15
+ export class VueTestUtilsPom {
16
+ public readonly wrapper: VueTestUtilsPomRoot;
17
+ private readonly testIdAttribute: string;
18
+
19
+ public constructor(wrapper: VueTestUtilsPomRoot, options: VueTestUtilsPomOptions = {}) {
20
+ this.wrapper = wrapper;
21
+ this.testIdAttribute = (options.testIdAttribute ?? "data-testid").trim() || "data-testid";
22
+ }
23
+
24
+ protected getByTestId(testId: string): DOMWrapper<Element> {
25
+ return this.getInScope(this.wrapper, this.selectorFor(this.testIdAttribute, testId));
26
+ }
27
+
28
+ protected getByAnyTestId(testIds: readonly string[]): DOMWrapper<Element> {
29
+ for (const testId of testIds) {
30
+ const candidate = this.findInScope(this.wrapper, this.selectorFor(this.testIdAttribute, testId));
31
+ if (candidate) {
32
+ return candidate;
33
+ }
34
+ }
35
+
36
+ throw new Error(`[vue-pom-generator] None of the generated test ids were found: ${testIds.join(", ")}`);
37
+ }
38
+
39
+ protected getComponentInstance(instanceId: string, within?: VueTestUtilsPomRoot): DOMWrapper<Element> {
40
+ return this.getInScope(
41
+ within ?? this.wrapper,
42
+ this.selectorFor("data-pom-instance", instanceId),
43
+ );
44
+ }
45
+
46
+ protected async clickByTestId(testId: string): Promise<void> {
47
+ await this.getByTestId(testId).trigger("click");
48
+ }
49
+
50
+ protected async selectVSelectByTestId(testId: string, value: string): Promise<void> {
51
+ await this.selectVSelect(this.getByTestId(testId), value);
52
+ }
53
+
54
+ protected async selectVSelectByAnyTestId(testIds: readonly string[], value: string): Promise<void> {
55
+ await this.selectVSelect(this.getByAnyTestId(testIds), value);
56
+ }
57
+
58
+ private async selectVSelect(root: DOMWrapper<Element>, value: string): Promise<void> {
59
+ const input = root.get<HTMLInputElement>("input");
60
+ await input.trigger("click");
61
+ await input.setValue(value);
62
+ await root.get("ul.vs__dropdown-menu li[role='option']").trigger("click");
63
+ }
64
+
65
+ protected async clickWithinTestIdByLabel(
66
+ rootTestId: string,
67
+ labelText: string,
68
+ exact: boolean = false,
69
+ ): Promise<void> {
70
+ const labels = this.getByTestId(rootTestId).findAll("label");
71
+ const matchingLabels = labels.filter((label) => {
72
+ const text = label.text().trim();
73
+ return exact ? text === labelText : text.includes(labelText);
74
+ });
75
+ if (matchingLabels.length !== 1) {
76
+ throw new Error(
77
+ `[vue-pom-generator] Expected one label ${JSON.stringify(labelText)} within ${JSON.stringify(rootTestId)}, found ${matchingLabels.length}.`,
78
+ );
79
+ }
80
+
81
+ const input = matchingLabels[0]!.find<HTMLInputElement>("input");
82
+ if (input.exists()) {
83
+ await input.setValue();
84
+ return;
85
+ }
86
+
87
+ await matchingLabels[0]!.trigger("click");
88
+ }
89
+
90
+ private getInScope(root: VueTestUtilsPomRoot, selector: string): DOMWrapper<Element> {
91
+ const candidate = this.findInScope(root, selector);
92
+ if (candidate) {
93
+ return candidate;
94
+ }
95
+
96
+ // Delegate the missing-element error to VTU so callers receive its DOM snapshot.
97
+ return root.get<Element>(selector) as DOMWrapper<Element>;
98
+ }
99
+
100
+ private findInScope(root: VueTestUtilsPomRoot, selector: string): DOMWrapper<Element> | null {
101
+ if (root.element instanceof Element && root.element.matches(selector)) {
102
+ return new DOMWrapper(root.element);
103
+ }
104
+
105
+ const candidate = root.find<Element>(selector);
106
+ return candidate.exists() ? candidate : null;
107
+ }
108
+
109
+ private selectorFor(attribute: string, value: string): string {
110
+ return `[${attribute}=${JSON.stringify(value)}]`;
111
+ }
112
+ }
@@ -53,6 +53,8 @@ export interface GenerateFilesOptions {
53
53
  generateFixtures?: boolean | string | {
54
54
  outDir?: string;
55
55
  };
56
+ /** Generate Vue Test Utils component objects in this directory when set. */
57
+ vueTestUtilsOutDir?: string;
56
58
  /**
57
59
  * Project root used for resolving conventional paths (e.g. src/views, tests/playwright/pom/custom).
58
60
  * Defaults to process.cwd() for backwards compatibility.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../class-generation/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkC,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAE5G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA2C7D,OAAO,EACL,sBAAsB,EAQvB,MAAM,UAAU,CAAC;AAuBlB,OAAO,EAAE,oCAAoC,EAAE,CAAC;AA2ChD,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,UAAU;IAClB,+FAA+F;IAC/F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,SAAS;IACjB,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,mFAAmF;IACnF,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAID,UAAU,mBAAmB;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,oBAAoB,CAAC;IAClE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AASD,MAAM,MAAM,yBAAyB,GAA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C;IACzB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEjD,mFAAmF;IACnF,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAC7D;AAsCD,wBAAsB,aAAa,CACjC,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,EAC1D,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,iBAAiB,EAAE,MAAM,EACzB,OAAO,GAAE,oBAAyB,iBAuHnC"}
@@ -0,0 +1,28 @@
1
+ import { DOMWrapper, type VueWrapper } from "@vue/test-utils";
2
+ export type VueTestUtilsPomRoot = DOMWrapper<Element> | VueWrapper;
3
+ export interface VueTestUtilsPomOptions {
4
+ testIdAttribute?: string;
5
+ }
6
+ /**
7
+ * Behavior-oriented runtime for generated Vue Test Utils component objects.
8
+ *
9
+ * Generated objects scope every lookup to `wrapper`; consumers can use that wrapper
10
+ * directly for assertions that do not warrant a generated behavior method.
11
+ */
12
+ export declare class VueTestUtilsPom {
13
+ readonly wrapper: VueTestUtilsPomRoot;
14
+ private readonly testIdAttribute;
15
+ constructor(wrapper: VueTestUtilsPomRoot, options?: VueTestUtilsPomOptions);
16
+ protected getByTestId(testId: string): DOMWrapper<Element>;
17
+ protected getByAnyTestId(testIds: readonly string[]): DOMWrapper<Element>;
18
+ protected getComponentInstance(instanceId: string, within?: VueTestUtilsPomRoot): DOMWrapper<Element>;
19
+ protected clickByTestId(testId: string): Promise<void>;
20
+ protected selectVSelectByTestId(testId: string, value: string): Promise<void>;
21
+ protected selectVSelectByAnyTestId(testIds: readonly string[], value: string): Promise<void>;
22
+ private selectVSelect;
23
+ protected clickWithinTestIdByLabel(rootTestId: string, labelText: string, exact?: boolean): Promise<void>;
24
+ private getInScope;
25
+ private findInScope;
26
+ private selectorFor;
27
+ }
28
+ //# sourceMappingURL=vue-test-utils-pom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue-test-utils-pom.d.ts","sourceRoot":"","sources":["../../class-generation/vue-test-utils-pom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;AAEnE,MAAM,WAAW,sBAAsB;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,SAAgB,OAAO,EAAE,mBAAmB,CAAC;IAC7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAEtB,OAAO,EAAE,mBAAmB,EAAE,OAAO,GAAE,sBAA2B;IAKrF,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC;IAI1D,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC;IAWzE,SAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,mBAAmB,GAAG,UAAU,CAAC,OAAO,CAAC;cAOrF,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;cAI5C,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;cAInE,wBAAwB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIpF,aAAa;cAOX,wBAAwB,CACtC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,KAAK,GAAE,OAAe,GACrB,OAAO,CAAC,IAAI,CAAC;IAqBhB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,WAAW;CAGpB"}
package/dist/index.cjs CHANGED
@@ -254,6 +254,7 @@ function resolveGenerationSupportOptions(options) {
254
254
  typescriptOutputStructure: options.typescriptOutputStructure ?? "aggregated",
255
255
  csharp: options.csharp,
256
256
  generateFixtures: options.generateFixtures,
257
+ vueTestUtilsOutDir: options.vueTestUtilsOutDir?.trim() || void 0,
257
258
  customPomAttachments: options.customPomAttachments ?? [],
258
259
  customPomDir: options.customPomDir ?? "tests/playwright/pom/custom",
259
260
  requireCustomPomDir: options.requireCustomPomDir ?? false,
@@ -5566,11 +5567,11 @@ function generateMethodMembersFromPom(componentName, primary, targetPageObjectMo
5566
5567
  primary.parameters
5567
5568
  );
5568
5569
  }
5569
- function generateMethodsContentForDependencies(componentName, dependencies) {
5570
+ function getUniquePrimaryPomSpecs(dependencies) {
5570
5571
  const entries = Array.from(dependencies.dataTestIdSet ?? []);
5571
5572
  const primarySpecsAll = entries.map((e) => ({ pom: e.pom, target: e.targetPageObjectModelClass })).filter((x) => !!x.pom).sort((a, b) => a.pom.methodName.localeCompare(b.pom.methodName));
5572
5573
  const seenPrimaryKeys = /* @__PURE__ */ new Set();
5573
- const primarySpecs = primarySpecsAll.filter(({ pom, target }) => {
5574
+ return primarySpecsAll.filter(({ pom, target }) => {
5574
5575
  const alternates = (pom.alternateSelectors ?? []).slice().sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
5575
5576
  const key = JSON.stringify({
5576
5577
  role: pom.nativeRole,
@@ -5588,6 +5589,9 @@ function generateMethodsContentForDependencies(componentName, dependencies) {
5588
5589
  seenPrimaryKeys.add(key);
5589
5590
  return true;
5590
5591
  });
5592
+ }
5593
+ function generateMethodsContentForDependencies(componentName, dependencies) {
5594
+ const primarySpecs = getUniquePrimaryPomSpecs(dependencies);
5591
5595
  const extras = (dependencies.pomExtraMethods ?? []).slice().sort((a, b) => a.name.localeCompare(b.name));
5592
5596
  const members = [];
5593
5597
  for (const { pom, target } of primarySpecs) {
@@ -5602,6 +5606,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5602
5606
  const {
5603
5607
  outDir: outDirOverride,
5604
5608
  generateFixtures,
5609
+ vueTestUtilsOutDir,
5605
5610
  customPomAttachments = [],
5606
5611
  projectRoot,
5607
5612
  customPomDir,
@@ -5623,6 +5628,9 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5623
5628
  } = options;
5624
5629
  const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
5625
5630
  const outDir = outDirOverride ?? "./pom";
5631
+ if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
5632
+ throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
5633
+ }
5626
5634
  const routeMetaByComponent = routeMetaByComponentOverride ?? (vueRouterFluentChaining ? await getRouteMetaByComponent(projectRoot, routerEntry, routerType, {
5627
5635
  pageDirs,
5628
5636
  componentDirs,
@@ -5681,11 +5689,247 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5681
5689
  writeGeneratedFile(file);
5682
5690
  }
5683
5691
  }
5692
+ if (vueTestUtilsOutDir) {
5693
+ const vueTestUtilsFiles = generateVueTestUtilsFiles(
5694
+ emittableComponentHierarchyMap,
5695
+ vueTestUtilsOutDir,
5696
+ { testIdAttribute }
5697
+ );
5698
+ for (const file of vueTestUtilsFiles) {
5699
+ writeGeneratedFile(file);
5700
+ }
5701
+ }
5684
5702
  const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFilePaths);
5685
5703
  for (const file of gitattributesFiles) {
5686
5704
  createFile(file.filePath, file.content);
5687
5705
  }
5688
5706
  }
5707
+ const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
5708
+ function getVueTestUtilsParameters(parameters, patterns, options = {}) {
5709
+ return orderPomPatternParameters(parameters, patterns, options).filter((parameter) => !VUE_TEST_UTILS_OMITTED_PARAMETERS.has(parameter.name));
5710
+ }
5711
+ function getVueTestUtilsPrimaryMembers(primary) {
5712
+ if (primary.emitPrimary === false) {
5713
+ return [];
5714
+ }
5715
+ const selectors = uniquePomStringPatterns(primary.selector, primary.alternateSelectors);
5716
+ const parameters = getVueTestUtilsParameters(primary.parameters, selectors);
5717
+ const actionName = buildPomGeneratedActionName(primary);
5718
+ const selectorExpressions = selectors.map((selector) => toTypeScriptPomPatternExpression(selector));
5719
+ const targetExpression = selectorExpressions.length === 1 ? `this.getByTestId(${selectorExpressions[0]})` : `this.getByAnyTestId([${selectorExpressions.join(", ")}])`;
5720
+ let actionStatement;
5721
+ switch (primary.nativeRole) {
5722
+ case "input":
5723
+ actionStatement = `await ${targetExpression}.setValue(text);`;
5724
+ break;
5725
+ case "select":
5726
+ actionStatement = `await ${targetExpression}.setValue(value);`;
5727
+ break;
5728
+ case "vselect":
5729
+ actionStatement = selectors.length === 1 ? `await this.selectVSelectByTestId(${selectorExpressions[0]}, value);` : `await this.selectVSelectByAnyTestId([${selectorExpressions.join(", ")}], value);`;
5730
+ break;
5731
+ case "radio":
5732
+ actionStatement = `await ${targetExpression}.setValue();`;
5733
+ break;
5734
+ default:
5735
+ actionStatement = `await ${targetExpression}.trigger("click");`;
5736
+ break;
5737
+ }
5738
+ return [createClassMethod({
5739
+ name: actionName,
5740
+ isAsync: true,
5741
+ parameters: toTypeScriptPomParameterStructures(parameters),
5742
+ statements: [actionStatement]
5743
+ })];
5744
+ }
5745
+ function getVueTestUtilsExtraMembers(extra) {
5746
+ if (extra.kind !== "click") {
5747
+ return [];
5748
+ }
5749
+ const patterns = extra.selector.kind === "testId" ? [extra.selector.testId] : [extra.selector.rootTestId, extra.selector.label];
5750
+ const parameters = getVueTestUtilsParameters(extra.parameters, patterns, {
5751
+ omit: extra.keyLiteral === void 0 ? [] : ["key"]
5752
+ });
5753
+ return [createClassMethod({
5754
+ name: extra.name,
5755
+ isAsync: true,
5756
+ parameters: toTypeScriptPomParameterStructures(parameters),
5757
+ statements: (writer) => {
5758
+ if (extra.keyLiteral !== void 0) {
5759
+ writer.writeLine(`const key = ${JSON.stringify(extra.keyLiteral)};`);
5760
+ }
5761
+ if (extra.selector.kind === "testId") {
5762
+ writer.writeLine(`await this.clickByTestId(${toTypeScriptPomPatternExpression(extra.selector.testId)});`);
5763
+ return;
5764
+ }
5765
+ writer.writeLine(
5766
+ `await this.clickWithinTestIdByLabel(${toTypeScriptPomPatternExpression(extra.selector.rootTestId)}, ${toTypeScriptPomPatternExpression(extra.selector.label)}, ${extra.selector.exact ?? false});`
5767
+ );
5768
+ }
5769
+ })];
5770
+ }
5771
+ function getVueTestUtilsComponentMembers(componentInstances, projectedComponentInstances, testIdAttribute) {
5772
+ const members = [];
5773
+ for (const instance of componentInstances) {
5774
+ if (instance.parameters.length === 0) {
5775
+ members.push(createClassGetter({
5776
+ name: instance.instanceName,
5777
+ returnType: instance.className,
5778
+ statements: [
5779
+ `return new ${instance.className}(this.getComponentInstance(${toTypeScriptPomPatternExpression(instance.selector)}));`
5780
+ ]
5781
+ }));
5782
+ continue;
5783
+ }
5784
+ members.push(createClassMethod({
5785
+ name: instance.instanceName,
5786
+ parameters: toTypeScriptPomParameterStructures(instance.parameters),
5787
+ returnType: instance.className,
5788
+ statements: [
5789
+ `return new ${instance.className}(this.getComponentInstance(${toTypeScriptPomPatternExpression(instance.selector)}));`
5790
+ ]
5791
+ }));
5792
+ }
5793
+ for (const projection of projectedComponentInstances) {
5794
+ const projectedPropertiesType = projection.contents.length > 0 ? ` & { ${projection.contents.map((content) => `readonly ${content.instanceName}: ${content.className}`).join("; ")} }` : "";
5795
+ const statements = (writer) => {
5796
+ writer.writeLine(`const ownerRoot = this.getComponentInstance(${toTypeScriptPomPatternExpression(projection.owner.selector)});`);
5797
+ writer.writeLine(`const root = this.getComponentInstance(${toTypeScriptPomPatternExpression(projection.target.selector)}, ownerRoot);`);
5798
+ writer.writeLine(`const instance = new ${projection.target.className}(root);`);
5799
+ if (projection.contents.length === 0) {
5800
+ writer.writeLine("return instance;");
5801
+ return;
5802
+ }
5803
+ writer.writeLine("return Object.assign(instance, {");
5804
+ writer.indent(() => {
5805
+ for (const content of projection.contents) {
5806
+ writer.writeLine(
5807
+ `${content.instanceName}: new ${content.className}(this.getComponentInstance(${toTypeScriptPomPatternExpression(content.selector)}, root)),`
5808
+ );
5809
+ }
5810
+ });
5811
+ writer.writeLine("});");
5812
+ };
5813
+ const returnType = `${projection.target.className}${projectedPropertiesType}`;
5814
+ members.push(projection.target.parameters.length > 0 ? createClassMethod({
5815
+ name: projection.target.instanceName,
5816
+ parameters: toTypeScriptPomParameterStructures(projection.target.parameters),
5817
+ returnType,
5818
+ statements
5819
+ }) : createClassGetter({
5820
+ name: projection.target.instanceName,
5821
+ returnType,
5822
+ statements
5823
+ }));
5824
+ }
5825
+ members.push(createClassConstructor({
5826
+ parameters: [{ name: "wrapper", type: "VueTestUtilsPomRoot" }],
5827
+ statements: (writer) => {
5828
+ writer.writeLine(`super(wrapper, { testIdAttribute: ${JSON.stringify(testIdAttribute)} });`);
5829
+ }
5830
+ }));
5831
+ return members;
5832
+ }
5833
+ function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute) {
5834
+ const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
5835
+ testIdAttribute
5836
+ });
5837
+ const runtimeImport = stripExtension(toPosixRelativePath(outputDir, runtimePath));
5838
+ const sourceRel = toPosixRelativePath(outputDir, dependencies.filePath);
5839
+ const componentImports = Array.from(prepared.componentRefsForInstances).map((componentRef) => {
5840
+ const className = componentRef.endsWith(".vue") ? componentRef.slice(0, -4) : componentRef;
5841
+ const filePath = generatedFilePathByComponent.get(className);
5842
+ return filePath ? { className, moduleSpecifier: stripExtension(toPosixRelativePath(outputDir, filePath)) } : null;
5843
+ }).filter((value) => !!value).sort((left, right) => left.className.localeCompare(right.className));
5844
+ const members = [
5845
+ ...getVueTestUtilsComponentMembers(
5846
+ prepared.directComponentInstances,
5847
+ prepared.projectedComponentInstances,
5848
+ testIdAttribute
5849
+ ),
5850
+ ...getUniquePrimaryPomSpecs(dependencies).flatMap(({ pom }) => getVueTestUtilsPrimaryMembers(pom)),
5851
+ ...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers)
5852
+ ];
5853
+ return renderSourceFile(`${componentName}.vtu.g.ts`, (sourceFile) => {
5854
+ addNamedImport(sourceFile, {
5855
+ moduleSpecifier: runtimeImport,
5856
+ namedImports: ["VueTestUtilsPom"]
5857
+ });
5858
+ addNamedImport(sourceFile, {
5859
+ moduleSpecifier: runtimeImport,
5860
+ namedImports: ["VueTestUtilsPomRoot"],
5861
+ isTypeOnly: true
5862
+ });
5863
+ for (const componentImport of componentImports) {
5864
+ addNamedImport(sourceFile, {
5865
+ moduleSpecifier: componentImport.moduleSpecifier,
5866
+ namedImports: [componentImport.className]
5867
+ });
5868
+ }
5869
+ const declaration = sourceFile.addClass({
5870
+ name: prepared.className,
5871
+ isExported: true,
5872
+ extends: "VueTestUtilsPom",
5873
+ docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`]
5874
+ });
5875
+ for (const member of members) {
5876
+ addClassMember(declaration, member);
5877
+ }
5878
+ }, {
5879
+ prefixText: buildFilePrefix({ eslintDisableSortImports: true })
5880
+ });
5881
+ }
5882
+ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {}) {
5883
+ const base = ensureDir(outDir);
5884
+ const testIdAttribute = options.testIdAttribute?.trim() || "data-testid";
5885
+ const entries = Array.from(componentHierarchyMap.entries()).sort((left, right) => left[0].localeCompare(right[0]));
5886
+ const generatedFilePathByComponent = new Map(
5887
+ entries.map(([componentName]) => [componentName, path.join(base, `${componentName}.vtu.g.ts`)])
5888
+ );
5889
+ const runtimePath = path.join(base, "_pom-runtime", "vue-test-utils-pom.ts");
5890
+ const files = entries.map(([componentName, dependencies]) => {
5891
+ const filePath = generatedFilePathByComponent.get(componentName);
5892
+ return {
5893
+ filePath,
5894
+ content: generateVueTestUtilsContent(
5895
+ componentName,
5896
+ dependencies,
5897
+ componentHierarchyMap,
5898
+ path.dirname(filePath),
5899
+ runtimePath,
5900
+ generatedFilePathByComponent,
5901
+ testIdAttribute
5902
+ )
5903
+ };
5904
+ });
5905
+ const [runtimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
5906
+ absolutePath: resolvePluginAsset("../class-generation/vue-test-utils-pom.ts"),
5907
+ description: "vue-test-utils-pom.ts",
5908
+ outputPath: runtimePath
5909
+ }]);
5910
+ if (!runtimeFile) {
5911
+ throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
5912
+ }
5913
+ const indexContent = renderSourceFile("index.ts", (sourceFile) => {
5914
+ addExportAll(sourceFile, stripExtension(toPosixRelativePath(base, runtimePath)));
5915
+ for (const [, filePath] of generatedFilePathByComponent) {
5916
+ addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
5917
+ }
5918
+ }, {
5919
+ prefixText: buildFilePrefix({
5920
+ eslintDisableSortImports: true,
5921
+ commentLines: [
5922
+ "Vue Test Utils POM exports",
5923
+ "DO NOT MODIFY BY HAND"
5924
+ ]
5925
+ })
5926
+ });
5927
+ return [
5928
+ ...files,
5929
+ { filePath: path.join(base, "index.ts"), content: indexContent },
5930
+ runtimeFile
5931
+ ];
5932
+ }
5689
5933
  async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, options = {}) {
5690
5934
  const projectRoot = options.projectRoot ?? process.cwd();
5691
5935
  const entries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
@@ -7122,7 +7366,7 @@ function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
7122
7366
  const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
7123
7367
  const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
7124
7368
  const runtimeClassGenSourceDir = resolvePluginAsset("../class-generation");
7125
- const runtimeClassGenFiles = fs.readdirSync(runtimeClassGenSourceDir).filter((file) => file.endsWith(".ts")).filter((file) => file !== "base-page.ts" && file !== "diagnostics.ts" && file !== "index.ts").sort((left, right) => left.localeCompare(right));
7369
+ const runtimeClassGenFiles = fs.readdirSync(runtimeClassGenSourceDir).filter((file) => file.endsWith(".ts")).filter((file) => !["base-page.ts", "diagnostics.ts", "index.ts", "vue-test-utils-pom.ts"].includes(file)).sort((left, right) => left.localeCompare(right));
7126
7370
  return [
7127
7371
  {
7128
7372
  absolutePath: resolvePluginAsset("../click-instrumentation.ts"),
@@ -9916,6 +10160,7 @@ function createBuildProcessorPlugin(options) {
9916
10160
  typescriptOutputStructure,
9917
10161
  csharp,
9918
10162
  generateFixtures,
10163
+ vueTestUtilsOutDir,
9919
10164
  customPomAttachments,
9920
10165
  customPomDir,
9921
10166
  requireCustomPomDir,
@@ -10132,6 +10377,7 @@ function createBuildProcessorPlugin(options) {
10132
10377
  typescriptOutputStructure,
10133
10378
  csharp,
10134
10379
  generateFixtures,
10380
+ vueTestUtilsOutDir,
10135
10381
  customPomAttachments,
10136
10382
  projectRoot: projectRootRef.current,
10137
10383
  customPomDir,
@@ -10180,6 +10426,7 @@ function createDevProcessorPlugin(options) {
10180
10426
  typescriptOutputStructure,
10181
10427
  csharp,
10182
10428
  generateFixtures,
10429
+ vueTestUtilsOutDir,
10183
10430
  customPomAttachments,
10184
10431
  customPomDir,
10185
10432
  requireCustomPomDir,
@@ -10438,6 +10685,7 @@ function createDevProcessorPlugin(options) {
10438
10685
  typescriptOutputStructure,
10439
10686
  csharp,
10440
10687
  generateFixtures,
10688
+ vueTestUtilsOutDir,
10441
10689
  customPomAttachments,
10442
10690
  projectRoot: projectRootRef.current,
10443
10691
  customPomDir,
@@ -11074,6 +11322,7 @@ function createVuePomGeneratorPlugins(options = {}) {
11074
11322
  typescriptOutputStructure: generationOptions?.playwright?.outputStructure,
11075
11323
  csharp: generationOptions?.csharp,
11076
11324
  generateFixtures,
11325
+ vueTestUtilsOutDir: generationOptions?.vueTestUtils ? generationOptions.vueTestUtils.outDir ?? "tests/unit/__generated__" : void 0,
11077
11326
  customPomAttachments: resolvedCustomPomAttachments,
11078
11327
  customPomDir: customPoms?.dir,
11079
11328
  requireCustomPomDir,
@@ -11108,6 +11357,7 @@ function createVuePomGeneratorPlugins(options = {}) {
11108
11357
  layoutDirs: isNuxt ? null : getLayoutDirs(),
11109
11358
  wrapperSearchRoots: isNuxt ? null : getWrapperSearchRoots(),
11110
11359
  outDir: resolvedGenerationOptions.outDir,
11360
+ vueTestUtilsOutDir: resolvedGenerationOptions.vueTestUtilsOutDir,
11111
11361
  testIdAttribute,
11112
11362
  routerType: resolvedGenerationOptions.routerType,
11113
11363
  vuePluginOwnership
@@ -11146,6 +11396,12 @@ function createVuePomGeneratorPlugins(options = {}) {
11146
11396
  }
11147
11397
  if (generationEnabled) {
11148
11398
  assertNonEmptyString(resolvedGenerationOptions.outDir, "[vue-pom-generator] generation.outDir");
11399
+ if (generationOptions?.vueTestUtils) {
11400
+ assertNonEmptyString(resolvedGenerationOptions.vueTestUtilsOutDir, "[vue-pom-generator] generation.vueTestUtils.outDir");
11401
+ if (path.resolve(projectRootRef.current, resolvedGenerationOptions.vueTestUtilsOutDir) === path.resolve(projectRootRef.current, resolvedGenerationOptions.outDir)) {
11402
+ throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
11403
+ }
11404
+ }
11149
11405
  assertOneOf(resolvedGenerationOptions.typescriptOutputStructure, ["aggregated", "split"], "[vue-pom-generator] generation.playwright.outputStructure");
11150
11406
  assertRouterModuleShims(resolvedGenerationOptions.routerModuleShims, "[vue-pom-generator] generation.router.moduleShims");
11151
11407
  if (!isNuxt && vueGenerationOptions?.router && resolvedGenerationOptions.routerType === "vue-router") {