@immense/vue-pom-generator 1.0.95 → 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.
Files changed (38) hide show
  1. package/README.md +124 -0
  2. package/RELEASE_NOTES.md +68 -18
  3. package/class-generation/base-page.ts +18 -2
  4. package/class-generation/index.ts +564 -48
  5. package/class-generation/vue-test-utils-pom.ts +112 -0
  6. package/dist/class-generation/base-page.d.ts +6 -0
  7. package/dist/class-generation/base-page.d.ts.map +1 -1
  8. package/dist/class-generation/index.d.ts +2 -0
  9. package/dist/class-generation/index.d.ts.map +1 -1
  10. package/dist/class-generation/vue-test-utils-pom.d.ts +28 -0
  11. package/dist/class-generation/vue-test-utils-pom.d.ts.map +1 -0
  12. package/dist/index.cjs +625 -48
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.mjs +626 -49
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/playwright/runtime.cjs +12 -2
  17. package/dist/playwright/runtime.cjs.map +1 -1
  18. package/dist/playwright/runtime.mjs +12 -2
  19. package/dist/playwright/runtime.mjs.map +1 -1
  20. package/dist/plugin/create-vue-pom-generator-plugins.d.ts.map +1 -1
  21. package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
  22. package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
  23. package/dist/plugin/resolved-generation-options.d.ts +1 -0
  24. package/dist/plugin/resolved-generation-options.d.ts.map +1 -1
  25. package/dist/plugin/types.d.ts +9 -0
  26. package/dist/plugin/types.d.ts.map +1 -1
  27. package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts +2 -0
  28. package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts.map +1 -1
  29. package/dist/tests/fixtures/generated-tsc/base-page.minimal.d.ts +2 -0
  30. package/dist/tests/fixtures/generated-tsc/base-page.minimal.d.ts.map +1 -1
  31. package/dist/tests/semantic-component-instances.test.d.ts +2 -0
  32. package/dist/tests/semantic-component-instances.test.d.ts.map +1 -0
  33. package/dist/tests/vue-test-utils-pom.test.d.ts +2 -0
  34. package/dist/tests/vue-test-utils-pom.test.d.ts.map +1 -0
  35. package/dist/transform.d.ts.map +1 -1
  36. package/dist/utils.d.ts +40 -12
  37. package/dist/utils.d.ts.map +1 -1
  38. package/package.json +4 -1
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,
@@ -2942,18 +2943,18 @@ function safeMethodNameFromParts(parts) {
2942
2943
  }
2943
2944
  return name;
2944
2945
  }
2945
- function toPomKeyPattern(templateValue) {
2946
+ function toPomKeyPattern(templateValue, parameterName = "key") {
2946
2947
  const { templateLiteral } = templateValue.parsedTemplate;
2947
2948
  let out = "";
2948
2949
  let hasExpression = false;
2949
2950
  for (let i = 0; i < templateLiteral.quasis.length; i += 1) {
2950
2951
  out += templateLiteral.quasis[i]?.value.raw ?? "";
2951
2952
  if (templateLiteral.expressions[i]) {
2952
- out += "${key}";
2953
+ out += `\${${parameterName}}`;
2953
2954
  hasExpression = true;
2954
2955
  }
2955
2956
  }
2956
- return { formatted: out, templateVariables: hasExpression ? ["key"] : [] };
2957
+ return { formatted: out, templateVariables: hasExpression ? [parameterName] : [] };
2957
2958
  }
2958
2959
  function applyResolvedDataTestId(args) {
2959
2960
  const addHtmlAttribute = args.addHtmlAttribute ?? true;
@@ -3078,7 +3079,8 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3078
3079
  };
3079
3080
  const normalizedRole = normalizeNativeRole(args.nativeRole) ?? "button";
3080
3081
  const targetPageObjectModelClass = entryOverrides.targetPageObjectModelClass;
3081
- const pomKeyPattern = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId) : null;
3082
+ const selectorParameterName = args.selectorParameterName?.trim() || "key";
3083
+ const pomKeyPattern = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId, selectorParameterName) : null;
3082
3084
  const formattedDataTestIdForPom = dataTestId.kind === "template" ? pomKeyPattern.formatted : dataTestId.value;
3083
3085
  const selectorPatternKind = dataTestId.kind === "template" ? "parameterized" : "static";
3084
3086
  const selectorTemplateVariables = dataTestId.kind === "template" ? pomKeyPattern.templateVariables : [];
@@ -3224,8 +3226,11 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3224
3226
  existingPom.alternateSelectors.push(selectorPattern);
3225
3227
  }
3226
3228
  }
3227
- if (selectorIsParameterized && !existingPom.parameters.some((param) => param.name === "key")) {
3228
- existingPom.parameters = [createPomParameterSpec("key", keyTypeFromValues), ...existingPom.parameters];
3229
+ if (selectorIsParameterized && !existingPom.parameters.some((param) => param.name === selectorParameterName)) {
3230
+ existingPom.parameters = [
3231
+ createPomParameterSpec(selectorParameterName, keyTypeFromValues),
3232
+ ...existingPom.parameters
3233
+ ];
3229
3234
  }
3230
3235
  return true;
3231
3236
  };
@@ -3239,7 +3244,8 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3239
3244
  let suffix = 1;
3240
3245
  while (true) {
3241
3246
  const baseWithSuffix = suffix === 1 ? base : `${base}${suffix}`;
3242
- const candidate = selectorIsParameterized ? `${baseWithSuffix}ByKey` : baseWithSuffix;
3247
+ const parameterizedSuffix = `By${upperFirst(selectorParameterName)}`;
3248
+ const candidate = selectorIsParameterized ? normalizedRole === "radio" && selectorParameterName !== "key" ? parameterizedSuffix : `${baseWithSuffix}${parameterizedSuffix}` : baseWithSuffix;
3243
3249
  const actionName = getPrimaryActionMethodName(candidate);
3244
3250
  const getterCandidates = getPrimaryGetterNameCandidates(candidate);
3245
3251
  let chosenGetterName = getterCandidates.primary;
@@ -3265,7 +3271,7 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3265
3271
  const baseNameUpper = upperFirst(baseWithSuffix);
3266
3272
  if (!hasRoleSuffix(baseNameUpper, roleSuffix)) {
3267
3273
  const baseWithRoleSuffix = `${baseWithSuffix}${roleSuffix}`;
3268
- const candidateWithRoleSuffix = selectorIsParameterized ? `${baseWithRoleSuffix}ByKey` : baseWithRoleSuffix;
3274
+ const candidateWithRoleSuffix = selectorIsParameterized ? `${baseWithRoleSuffix}By${upperFirst(selectorParameterName)}` : baseWithRoleSuffix;
3269
3275
  const actionNameWithRoleSuffix = getPrimaryActionMethodName(candidateWithRoleSuffix);
3270
3276
  const getterCandidatesWithRoleSuffix = getPrimaryGetterNameCandidates(candidateWithRoleSuffix);
3271
3277
  let chosenGetterNameWithRoleSuffix = getterCandidatesWithRoleSuffix.primary;
@@ -3333,7 +3339,7 @@ Conflicts: getter=${last.getterName}, method=${last.actionName}
3333
3339
  Fix: make the element identifiable (e.g. add id/name/inner text or use a more specific click handler name), or switch generation.nameCollisionBehavior to "warn"/"suffix".`
3334
3340
  );
3335
3341
  }
3336
- let parameters = selectorIsParameterized ? [createPomParameterSpec("key", keyTypeFromValues)] : [];
3342
+ let parameters = selectorIsParameterized ? [createPomParameterSpec(selectorParameterName, keyTypeFromValues)] : [];
3337
3343
  switch (normalizedRole) {
3338
3344
  case "input":
3339
3345
  parameters = setPomParameter(parameters, "text", "string");
@@ -3352,7 +3358,7 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3352
3358
  parameters = setPomParameter(parameters, "annotationText", 'string = ""');
3353
3359
  break;
3354
3360
  }
3355
- const normalizedParameters = selectorIsParameterized ? setPomParameter(parameters, "key", keyTypeFromValues) : removePomParameter(parameters, "key");
3361
+ const normalizedParameters = selectorIsParameterized ? setPomParameter(parameters, selectorParameterName, keyTypeFromValues) : removePomParameter(parameters, selectorParameterName);
3356
3362
  if (addHtmlAttribute && !fromExisting) {
3357
3363
  upsertAttribute(args.element, testIdAttribute, dataTestId);
3358
3364
  }
@@ -5561,11 +5567,11 @@ function generateMethodMembersFromPom(componentName, primary, targetPageObjectMo
5561
5567
  primary.parameters
5562
5568
  );
5563
5569
  }
5564
- function generateMethodsContentForDependencies(componentName, dependencies) {
5570
+ function getUniquePrimaryPomSpecs(dependencies) {
5565
5571
  const entries = Array.from(dependencies.dataTestIdSet ?? []);
5566
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));
5567
5573
  const seenPrimaryKeys = /* @__PURE__ */ new Set();
5568
- const primarySpecs = primarySpecsAll.filter(({ pom, target }) => {
5574
+ return primarySpecsAll.filter(({ pom, target }) => {
5569
5575
  const alternates = (pom.alternateSelectors ?? []).slice().sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
5570
5576
  const key = JSON.stringify({
5571
5577
  role: pom.nativeRole,
@@ -5583,6 +5589,9 @@ function generateMethodsContentForDependencies(componentName, dependencies) {
5583
5589
  seenPrimaryKeys.add(key);
5584
5590
  return true;
5585
5591
  });
5592
+ }
5593
+ function generateMethodsContentForDependencies(componentName, dependencies) {
5594
+ const primarySpecs = getUniquePrimaryPomSpecs(dependencies);
5586
5595
  const extras = (dependencies.pomExtraMethods ?? []).slice().sort((a, b) => a.name.localeCompare(b.name));
5587
5596
  const members = [];
5588
5597
  for (const { pom, target } of primarySpecs) {
@@ -5597,6 +5606,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5597
5606
  const {
5598
5607
  outDir: outDirOverride,
5599
5608
  generateFixtures,
5609
+ vueTestUtilsOutDir,
5600
5610
  customPomAttachments = [],
5601
5611
  projectRoot,
5602
5612
  customPomDir,
@@ -5618,6 +5628,9 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5618
5628
  } = options;
5619
5629
  const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
5620
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
+ }
5621
5634
  const routeMetaByComponent = routeMetaByComponentOverride ?? (vueRouterFluentChaining ? await getRouteMetaByComponent(projectRoot, routerEntry, routerType, {
5622
5635
  pageDirs,
5623
5636
  componentDirs,
@@ -5676,11 +5689,247 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5676
5689
  writeGeneratedFile(file);
5677
5690
  }
5678
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
+ }
5679
5702
  const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFilePaths);
5680
5703
  for (const file of gitattributesFiles) {
5681
5704
  createFile(file.filePath, file.content);
5682
5705
  }
5683
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
+ }
5684
5933
  async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, options = {}) {
5685
5934
  const projectRoot = options.projectRoot ?? process.cwd();
5686
5935
  const entries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
@@ -6509,21 +6758,116 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6509
6758
  const nestedRefs = resolvedDependencies.usedComponentSet?.size ? resolvedDependencies.usedComponentSet : resolvedDependencies.childrenComponentSet;
6510
6759
  return Array.from(nestedRefs).some((child) => hasGeneratedPomSurface(child, nextSeen));
6511
6760
  };
6512
- const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
6513
6761
  const ownClassName = toPascalCaseLocal(componentName);
6514
6762
  const isSelfReference = (ref) => {
6515
6763
  return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
6516
6764
  };
6517
- const componentRefsForInstances = /* @__PURE__ */ new Set();
6518
- for (const ref of rawComponentRefsForInstances) {
6519
- const resolvedRef = resolveTrackedComponentRef(ref) ?? normalizeTrackedComponentRef(ref);
6520
- if (isSelfReference(resolvedRef)) {
6521
- continue;
6765
+ const resolveComponentInstance = (spec) => {
6766
+ const componentRef = resolveTrackedComponentRef(spec.componentName);
6767
+ if (!componentRef || isSelfReference(componentRef) || !hasGeneratedPomSurface(componentRef, /* @__PURE__ */ new Set([componentName]))) {
6768
+ return null;
6769
+ }
6770
+ return {
6771
+ ...spec,
6772
+ componentRef,
6773
+ className: normalizeTrackedComponentRef(componentRef)
6774
+ };
6775
+ };
6776
+ const uniqueInstances = (instances, ownerName) => {
6777
+ const byPublicName = /* @__PURE__ */ new Map();
6778
+ for (const instance of instances) {
6779
+ const existing = byPublicName.get(instance.instanceName);
6780
+ if (!existing) {
6781
+ byPublicName.set(instance.instanceName, instance);
6782
+ continue;
6783
+ }
6784
+ const sameInvocationShape = existing.componentRef === instance.componentRef && JSON.stringify(existing.selector) === JSON.stringify(instance.selector) && JSON.stringify(existing.parameters) === JSON.stringify(instance.parameters);
6785
+ if (sameInvocationShape) {
6786
+ continue;
6787
+ }
6788
+ throw new VuePomGeneratorError(
6789
+ `Semantic component instance name ${JSON.stringify(instance.instanceName)} is ambiguous in ${ownerName}.
6790
+ It refers to both <${existing.componentName}> and <${instance.componentName}>.
6791
+
6792
+ Fix: give the invocations distinct accessible names or distinct semantic model/options bindings.`
6793
+ );
6522
6794
  }
6523
- if (!hasGeneratedPomSurface(resolvedRef, /* @__PURE__ */ new Set([componentName]))) {
6795
+ return Array.from(byPublicName.values());
6796
+ };
6797
+ const allInvocationSpecs = dependencies.componentInstances ?? [];
6798
+ const directComponentInstances = uniqueInstances(
6799
+ allInvocationSpecs.filter((spec) => !spec.suppliedSlot).map(resolveComponentInstance).filter((instance) => !!instance),
6800
+ componentName
6801
+ );
6802
+ const projectedComponentInstances = [];
6803
+ for (const owner of directComponentInstances) {
6804
+ const ownerDependencies = componentHierarchyMap.get(owner.componentRef);
6805
+ if (!ownerDependencies?.slotOutlets?.length) {
6524
6806
  continue;
6525
6807
  }
6526
- componentRefsForInstances.add(resolvedRef);
6808
+ const suppliedBySlot = /* @__PURE__ */ new Map();
6809
+ for (const suppliedSpec of allInvocationSpecs) {
6810
+ if (suppliedSpec.suppliedSlot?.ownerSourceId !== owner.sourceId) {
6811
+ continue;
6812
+ }
6813
+ const supplied = resolveComponentInstance(suppliedSpec);
6814
+ if (!supplied) {
6815
+ continue;
6816
+ }
6817
+ const values = suppliedBySlot.get(suppliedSpec.suppliedSlot.name) ?? [];
6818
+ values.push(supplied);
6819
+ suppliedBySlot.set(suppliedSpec.suppliedSlot.name, values);
6820
+ }
6821
+ for (const [slotName, rawContents] of suppliedBySlot) {
6822
+ const outletTargetIds = new Set(
6823
+ ownerDependencies.slotOutlets.filter((outlet) => outlet.name === slotName).map((outlet) => outlet.targetSourceId)
6824
+ );
6825
+ const targetInstances = uniqueInstances(
6826
+ (ownerDependencies.componentInstances ?? []).filter((spec) => outletTargetIds.has(spec.sourceId)).map(resolveComponentInstance).filter((instance) => !!instance),
6827
+ `${owner.className} slot ${JSON.stringify(slotName)}`
6828
+ );
6829
+ const contents = uniqueInstances(rawContents, `${componentName} slot ${JSON.stringify(slotName)}`);
6830
+ for (const target of targetInstances) {
6831
+ if (owner.parameters.length > 0) {
6832
+ throw new VuePomGeneratorError(
6833
+ `Cannot project slot ${JSON.stringify(slotName)} through keyed component instance ${owner.instanceName} in ${componentName}.
6834
+ The owner and projected target require distinct key scopes, which cannot be represented by one unambiguous generated accessor.`
6835
+ );
6836
+ }
6837
+ const keyedContent = contents.find((content) => content.parameters.length > 0);
6838
+ if (keyedContent) {
6839
+ throw new VuePomGeneratorError(
6840
+ `Cannot attach keyed slot content ${keyedContent.instanceName} as a property of ${target.instanceName} in ${componentName}.
6841
+ Move the repetition to the receiving component boundary so the generator can expose it as a keyed accessor.`
6842
+ );
6843
+ }
6844
+ const existingProjection = projectedComponentInstances.find((projection) => {
6845
+ return projection.owner.sourceId === owner.sourceId && projection.target.instanceName === target.instanceName && projection.target.componentRef === target.componentRef && JSON.stringify(projection.target.selector) === JSON.stringify(target.selector);
6846
+ });
6847
+ if (existingProjection) {
6848
+ existingProjection.contents = uniqueInstances(
6849
+ [...existingProjection.contents, ...contents],
6850
+ `${componentName} projected ${target.instanceName}`
6851
+ );
6852
+ continue;
6853
+ }
6854
+ projectedComponentInstances.push({ owner, target, contents });
6855
+ }
6856
+ }
6857
+ }
6858
+ const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
6859
+ const componentRefsForInstances = /* @__PURE__ */ new Set();
6860
+ for (const instance of directComponentInstances) {
6861
+ if (!isSelfReference(instance.componentRef)) {
6862
+ componentRefsForInstances.add(instance.componentRef);
6863
+ }
6864
+ }
6865
+ for (const projection of projectedComponentInstances) {
6866
+ for (const instance of [projection.owner, projection.target, ...projection.contents]) {
6867
+ if (!isSelfReference(instance.componentRef)) {
6868
+ componentRefsForInstances.add(instance.componentRef);
6869
+ }
6870
+ }
6527
6871
  }
6528
6872
  const hasChildComponent = (needle) => {
6529
6873
  const normalizedNeedle = normalizeTrackedComponentRef(needle);
@@ -6564,7 +6908,19 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6564
6908
  }));
6565
6909
  const widgetInstances = isView ? getWidgetInstancesForView(componentName, dependencies.dataTestIdSet, customPomAvailableClassIdentifiers) : [];
6566
6910
  const className = toPascalCaseLocal(componentName);
6567
- const childInstancePropertyNames = Array.from(componentRefsForInstances).map((child) => child.split(".vue")[0]);
6911
+ const childInstancePropertyNames = [
6912
+ ...directComponentInstances.map((instance) => instance.instanceName),
6913
+ ...projectedComponentInstances.map((projection) => projection.target.instanceName)
6914
+ ];
6915
+ const duplicateChildInstanceName = childInstancePropertyNames.find((name, index) => {
6916
+ return childInstancePropertyNames.indexOf(name) !== index;
6917
+ });
6918
+ if (duplicateChildInstanceName) {
6919
+ throw new VuePomGeneratorError(
6920
+ `Semantic component instance ${JSON.stringify(duplicateChildInstanceName)} would be emitted more than once in ${componentName}.
6921
+ Fix: give direct and slot-projected instances distinct accessible names or semantic bindings.`
6922
+ );
6923
+ }
6568
6924
  const blockedViewPassthroughMethodNames = new Set(
6569
6925
  attachmentsForThisClass.filter((a) => a.flatten).flatMap((a) => Array.from(a.methodSignatures.keys()))
6570
6926
  );
@@ -6575,22 +6931,22 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6575
6931
  ]);
6576
6932
  const members = [];
6577
6933
  if (isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0 || widgetInstances.length > 0)) {
6578
- members.push(...getComponentInstances(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass, widgetInstances));
6579
- members.push(getConstructor(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass, widgetInstances, { testIdAttribute }));
6934
+ members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass, widgetInstances));
6935
+ members.push(getConstructor(directComponentInstances, attachmentsForThisClass, widgetInstances, { testIdAttribute }));
6580
6936
  }
6581
6937
  if (!isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0)) {
6582
- members.push(...getComponentInstances(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass));
6583
- members.push(getConstructor(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass, [], { testIdAttribute }));
6938
+ members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass));
6939
+ members.push(getConstructor(directComponentInstances, attachmentsForThisClass, [], { testIdAttribute }));
6584
6940
  }
6585
6941
  members.push(
6586
6942
  ...getAttachmentPassthroughMethods(componentName, dependencies, attachmentsForThisClass, reservedAttachmentPassthroughNames)
6587
6943
  );
6588
- if (isView && componentRefsForInstances.size === 1) {
6944
+ if (isView && directComponentInstances.length === 1) {
6589
6945
  members.push(
6590
6946
  ...getViewPassthroughMethods(
6591
6947
  componentName,
6592
6948
  dependencies,
6593
- componentRefsForInstances,
6949
+ directComponentInstances,
6594
6950
  componentHierarchyMap,
6595
6951
  blockedViewPassthroughMethodNames
6596
6952
  )
@@ -6605,6 +6961,8 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6605
6961
  return {
6606
6962
  className,
6607
6963
  componentRefsForInstances,
6964
+ directComponentInstances,
6965
+ projectedComponentInstances,
6608
6966
  attachmentsForThisClass,
6609
6967
  widgetInstances,
6610
6968
  isView,
@@ -6680,7 +7038,10 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
6680
7038
  addNamedImport(sourceFile, {
6681
7039
  moduleSpecifier: "@playwright/test",
6682
7040
  isTypeOnly: true,
6683
- namedImports: [{ name: "Page", alias: "PwPage" }]
7041
+ namedImports: [
7042
+ { name: "Locator", alias: "PwLocator" },
7043
+ { name: "Page", alias: "PwPage" }
7044
+ ]
6684
7045
  });
6685
7046
  }
6686
7047
  addNamedImport(sourceFile, {
@@ -6709,17 +7070,17 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
6709
7070
  }
6710
7071
  }, { prefixText });
6711
7072
  }
6712
- function getViewPassthroughMethods(viewName, viewDependencies, childrenComponentSet, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
7073
+ function getViewPassthroughMethods(viewName, viewDependencies, componentInstances, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
6713
7074
  const existingOnView = viewDependencies.generatedMethods ?? /* @__PURE__ */ new Map();
6714
7075
  const methodToChildren = /* @__PURE__ */ new Map();
6715
- for (const child of childrenComponentSet) {
6716
- const childDeps = componentHierarchyMap.get(child);
7076
+ for (const instance of componentInstances) {
7077
+ const childDeps = componentHierarchyMap.get(instance.componentRef);
6717
7078
  if (!childDeps || !childDeps.dataTestIdSet?.size)
6718
7079
  continue;
6719
7080
  const methods = childDeps.generatedMethods;
6720
7081
  if (!methods)
6721
7082
  continue;
6722
- const childProp = child.endsWith(".vue") ? child.slice(0, -4) : child;
7083
+ const childProp = instance.instanceName;
6723
7084
  for (const [name, sig] of methods.entries()) {
6724
7085
  if (!sig)
6725
7086
  continue;
@@ -7005,7 +7366,7 @@ function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
7005
7366
  const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
7006
7367
  const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
7007
7368
  const runtimeClassGenSourceDir = resolvePluginAsset("../class-generation");
7008
- 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));
7009
7370
  return [
7010
7371
  {
7011
7372
  absolutePath: resolvePluginAsset("../click-instrumentation.ts"),
@@ -7409,7 +7770,7 @@ function getWidgetInstancesForView(componentName, dataTestIdSet, availableClassI
7409
7770
  }
7410
7771
  return out;
7411
7772
  }
7412
- function getComponentInstances(childrenComponent, componentHierarchyMap, attachmentsForThisView = [], widgetInstances = []) {
7773
+ function getComponentInstances(componentInstances, projectedComponentInstances, attachmentsForThisView = [], widgetInstances = []) {
7413
7774
  const declarations = [];
7414
7775
  for (const a of attachmentsForThisView) {
7415
7776
  declarations.push(createClassProperty({
@@ -7423,35 +7784,80 @@ function getComponentInstances(childrenComponent, componentHierarchyMap, attachm
7423
7784
  type: w.className
7424
7785
  }));
7425
7786
  }
7426
- childrenComponent.forEach((child) => {
7427
- if (componentHierarchyMap.has(child)) {
7428
- const childName = child.split(".vue")[0];
7787
+ for (const instance of componentInstances) {
7788
+ if (instance.parameters.length === 0) {
7429
7789
  declarations.push(createClassProperty({
7430
- name: childName,
7431
- type: childName
7790
+ name: instance.instanceName,
7791
+ type: instance.className
7432
7792
  }));
7793
+ continue;
7433
7794
  }
7434
- });
7795
+ declarations.push(createClassMethod({
7796
+ name: instance.instanceName,
7797
+ parameters: toTypeScriptPomParameterStructures(instance.parameters),
7798
+ returnType: instance.className,
7799
+ statements: (writer) => {
7800
+ writer.writeLine(`const root = this.componentInstanceLocator(${toTypeScriptPomPatternExpression(instance.selector)});`);
7801
+ writer.writeLine(`return new ${instance.className}(this.page, root);`);
7802
+ }
7803
+ }));
7804
+ }
7805
+ for (const projection of projectedComponentInstances) {
7806
+ const projectedPropertiesType = projection.contents.length > 0 ? ` & { ${projection.contents.map((content) => `readonly ${content.instanceName}: ${content.className}`).join("; ")} }` : "";
7807
+ const statements = (writer) => {
7808
+ const ownerSelector = toTypeScriptPomPatternExpression(projection.owner.selector);
7809
+ const targetSelector = toTypeScriptPomPatternExpression(projection.target.selector);
7810
+ writer.writeLine(`const ownerRoot = this.componentInstanceLocator(${ownerSelector});`);
7811
+ writer.writeLine(`const root = this.componentInstanceLocator(${targetSelector}, ownerRoot);`);
7812
+ writer.writeLine(`const instance = new ${projection.target.className}(this.page, root);`);
7813
+ if (projection.contents.length === 0) {
7814
+ writer.writeLine("return instance;");
7815
+ return;
7816
+ }
7817
+ writer.writeLine("return Object.assign(instance, {");
7818
+ writer.indent(() => {
7819
+ for (const content of projection.contents) {
7820
+ const contentSelector = toTypeScriptPomPatternExpression(content.selector);
7821
+ writer.writeLine(`${content.instanceName}: new ${content.className}(this.page, this.componentInstanceLocator(${contentSelector}, root)),`);
7822
+ }
7823
+ });
7824
+ writer.writeLine("});");
7825
+ };
7826
+ const returnType = `${projection.target.className}${projectedPropertiesType}`;
7827
+ declarations.push(projection.target.parameters.length > 0 ? createClassMethod({
7828
+ name: projection.target.instanceName,
7829
+ parameters: toTypeScriptPomParameterStructures(projection.target.parameters),
7830
+ returnType,
7831
+ statements
7832
+ }) : createClassGetter({
7833
+ name: projection.target.instanceName,
7834
+ returnType,
7835
+ statements
7836
+ }));
7837
+ }
7435
7838
  return declarations;
7436
7839
  }
7437
- function getConstructor(childrenComponent, componentHierarchyMap, attachmentsForThisView = [], widgetInstances = [], options) {
7840
+ function getConstructor(componentInstances, attachmentsForThisView = [], widgetInstances = [], options) {
7438
7841
  const attr = (options?.testIdAttribute ?? "data-testid").trim() || "data-testid";
7439
7842
  return createClassConstructor({
7440
- parameters: [{ name: "page", type: "PwPage" }],
7843
+ parameters: [
7844
+ { name: "page", type: "PwPage" },
7845
+ { name: "root", type: "PwLocator", hasQuestionToken: true }
7846
+ ],
7441
7847
  statements: (writer) => {
7442
- writer.writeLine(`super(page, { testIdAttribute: ${JSON.stringify(attr)} });`);
7848
+ writer.writeLine(`super(page, { root, testIdAttribute: ${JSON.stringify(attr)} });`);
7443
7849
  for (const a of attachmentsForThisView) {
7444
7850
  writer.writeLine(`this.${a.propertyName} = new ${a.className}(this.page, this);`);
7445
7851
  }
7446
7852
  for (const w of widgetInstances) {
7447
7853
  writer.writeLine(`this.${w.propertyName} = new ${w.className}(this.page, ${JSON.stringify(w.testId)});`);
7448
7854
  }
7449
- childrenComponent.forEach((child) => {
7450
- if (componentHierarchyMap.has(child)) {
7451
- const childName = child.split(".vue")[0];
7452
- writer.writeLine(`this.${childName} = new ${childName}(page);`);
7855
+ for (const instance of componentInstances) {
7856
+ if (instance.parameters.length === 0) {
7857
+ const selector = toTypeScriptPomPatternExpression(instance.selector);
7858
+ writer.writeLine(`this.${instance.instanceName} = new ${instance.className}(page, this.componentInstanceLocator(${selector}));`);
7453
7859
  }
7454
- });
7860
+ }
7455
7861
  }
7456
7862
  });
7457
7863
  }
@@ -8227,6 +8633,92 @@ function resolveWrapperContractForTag(options) {
8227
8633
  return resolveTag(options.tag);
8228
8634
  }
8229
8635
  const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
8636
+ const POM_INSTANCE_ATTRIBUTE = "data-pom-instance";
8637
+ function getLastSemanticIdentifier(node) {
8638
+ if (!node) {
8639
+ return null;
8640
+ }
8641
+ if (node.type === "Identifier") {
8642
+ return node.name?.trim() || null;
8643
+ }
8644
+ if (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") {
8645
+ if (!node.computed && node.property?.type === "Identifier") {
8646
+ return node.property.name?.trim() || null;
8647
+ }
8648
+ if (node.computed && node.property?.type === "StringLiteral") {
8649
+ return node.property.value?.trim() || null;
8650
+ }
8651
+ return getLastSemanticIdentifier(node.object);
8652
+ }
8653
+ if (node.type === "CallExpression" || node.type === "OptionalCallExpression") {
8654
+ return getLastSemanticIdentifier(node.callee);
8655
+ }
8656
+ if (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "ChainExpression") {
8657
+ return getLastSemanticIdentifier(node.expression);
8658
+ }
8659
+ return null;
8660
+ }
8661
+ function getBoundSemanticName(element, attributeName) {
8662
+ const directive = element.props.find((prop) => {
8663
+ return prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === attributeName && !!prop.exp;
8664
+ });
8665
+ if (!directive?.exp) {
8666
+ return null;
8667
+ }
8668
+ const source = getVueExpressionSource(
8669
+ directive.exp,
8670
+ "loc",
8671
+ "content",
8672
+ "compiled"
8673
+ );
8674
+ if (!source) {
8675
+ return null;
8676
+ }
8677
+ try {
8678
+ const identifier = getLastSemanticIdentifier(parser.parseExpression(source, { plugins: ["typescript"] }));
8679
+ return identifier ? toPascalCase(identifier) : null;
8680
+ } catch {
8681
+ return null;
8682
+ }
8683
+ }
8684
+ function getComponentInstanceNameCandidates(element) {
8685
+ const explicitAccessibleNames = ["aria-label", "label", "title", "name"].map((attributeName) => getStaticAttributeContent(element, attributeName)).filter((value) => !!value).map(toPascalCase);
8686
+ const optionsName = getBoundSemanticName(element, "options");
8687
+ const { vModel, modelValue } = getModelBindingValues(element);
8688
+ const modelName = modelValue || vModel;
8689
+ const candidates = [
8690
+ ...explicitAccessibleNames,
8691
+ optionsName && optionsName !== "Options" ? optionsName : null,
8692
+ modelName && !(/* @__PURE__ */ new Set(["Data", "Item", "ModelValue", "Value"])).has(modelName) ? toPascalCase(modelName) : null,
8693
+ toPascalCase(element.tag)
8694
+ ].filter((value) => !!value);
8695
+ return Array.from(new Set(candidates));
8696
+ }
8697
+ function getElementSourceId(element) {
8698
+ return `${element.tag}:${element.loc.start.offset}:${element.loc.end.offset}`;
8699
+ }
8700
+ function getNearestComponentAncestor(element, hierarchyMap2, isComponentLikeTag2) {
8701
+ let parent = hierarchyMap2.get(element) ?? null;
8702
+ while (parent) {
8703
+ if (isComponentLikeTag2(parent.tag)) {
8704
+ return parent;
8705
+ }
8706
+ parent = hierarchyMap2.get(parent) ?? null;
8707
+ }
8708
+ return null;
8709
+ }
8710
+ function getSlotNameFromTemplate(element) {
8711
+ const directive = element.props.find((prop) => {
8712
+ return prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "slot";
8713
+ });
8714
+ if (!directive) {
8715
+ return null;
8716
+ }
8717
+ if (!directive.arg) {
8718
+ return "default";
8719
+ }
8720
+ return directive.arg.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION ? directive.arg.content.trim() || "default" : null;
8721
+ }
8230
8722
  function getStaticAttributeContent(element, name) {
8231
8723
  const attr = element.props.find((prop) => {
8232
8724
  return prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === name;
@@ -8565,6 +9057,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8565
9057
  Object.entries(nativeWrappers).map(([tag, config]) => [tag, { ...config }])
8566
9058
  );
8567
9059
  const wrapperContractByTag = /* @__PURE__ */ new Map();
9060
+ const instanceWrapperContractByTag = /* @__PURE__ */ new Map();
8568
9061
  const getWrapperContract = (tag) => {
8569
9062
  if (!wrapperContractByTag.has(tag)) {
8570
9063
  wrapperContractByTag.set(tag, resolveWrapperContractForTag({
@@ -8576,6 +9069,17 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8576
9069
  }
8577
9070
  return wrapperContractByTag.get(tag) ?? null;
8578
9071
  };
9072
+ const getInstanceWrapperContract = (tag) => {
9073
+ if (!instanceWrapperContractByTag.has(tag)) {
9074
+ instanceWrapperContractByTag.set(tag, resolveWrapperContractForTag({
9075
+ tag,
9076
+ vueFilesPathMap,
9077
+ wrapperSearchRoots,
9078
+ testIdAttribute: POM_INSTANCE_ATTRIBUTE
9079
+ }));
9080
+ }
9081
+ return instanceWrapperContractByTag.get(tag) ?? null;
9082
+ };
8579
9083
  const safeRealpath2 = (p) => {
8580
9084
  try {
8581
9085
  return fs.existsSync(p) ? fs.realpathSync(p) : p;
@@ -8592,6 +9096,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8592
9096
  const conditionalMergeGroupByElement = /* @__PURE__ */ new WeakMap();
8593
9097
  const conditionalMergeGroupByElementLoc = /* @__PURE__ */ new Map();
8594
9098
  const conditionalMergeGroupByIfBranch = /* @__PURE__ */ new WeakMap();
9099
+ const componentInstanceNameOwnerByName = /* @__PURE__ */ new Map();
8595
9100
  let conditionalMergeGroupCounter = 0;
8596
9101
  const getElementLocationKey = (element) => {
8597
9102
  const startOffset = element.loc?.start.offset;
@@ -8685,6 +9190,8 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8685
9190
  childrenComponentSet: /* @__PURE__ */ new Set(),
8686
9191
  usedComponentSet: /* @__PURE__ */ new Set(),
8687
9192
  dataTestIdSet: /* @__PURE__ */ new Set(),
9193
+ componentInstances: [],
9194
+ slotOutlets: [],
8688
9195
  isView,
8689
9196
  methodsContent: ""
8690
9197
  };
@@ -8698,6 +9205,17 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8698
9205
  const isUpper = isAsciiUppercaseLetterCode$1(first);
8699
9206
  return isUpper || tag.includes("-");
8700
9207
  };
9208
+ if (element.tag === "slot") {
9209
+ const slotName = getStaticAttributeContent(element, "name") ?? "default";
9210
+ const target = getNearestComponentAncestor(element, hierarchyMap, isComponentLikeTag2);
9211
+ if (target) {
9212
+ dependencies.slotOutlets ??= [];
9213
+ const outlet = { name: slotName, targetSourceId: getElementSourceId(target) };
9214
+ if (!dependencies.slotOutlets.some((existing) => existing.name === outlet.name && existing.targetSourceId === outlet.targetSourceId)) {
9215
+ dependencies.slotOutlets.push(outlet);
9216
+ }
9217
+ }
9218
+ }
8701
9219
  if (isComponentLikeTag2(element.tag)) {
8702
9220
  dependencies.usedComponentSet.add(element.tag);
8703
9221
  if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
@@ -8760,6 +9278,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8760
9278
  role: contract.role
8761
9279
  };
8762
9280
  }
9281
+ let selectorParameterName = "key";
8763
9282
  const getBestAvailableKeyInfo = () => {
8764
9283
  const parentNode = context.parent && typeof context.parent === "object" ? context.parent : null;
8765
9284
  const isDirectVForChild = parentNode?.type === compilerCore.NodeTypes.FOR;
@@ -8767,6 +9286,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8767
9286
  if (configuredAttrName && configuredAttrName !== "key") {
8768
9287
  const bindingKeyInfo = getBindingKeyInfo(element, configuredAttrName);
8769
9288
  if (bindingKeyInfo) {
9289
+ selectorParameterName = configuredAttrName === "value" ? "value" : "key";
8770
9290
  return bindingKeyInfo;
8771
9291
  }
8772
9292
  }
@@ -8793,6 +9313,50 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8793
9313
  const bestKeyInfo = getBestAvailableKeyInfo();
8794
9314
  const bestKeyPlaceholder = bestKeyInfo?.selectorFragment ?? null;
8795
9315
  const bestRuntimeKeyPlaceholder = bestKeyInfo?.runtimeFragment ?? null;
9316
+ if (isComponentLikeTag2(element.tag)) {
9317
+ const componentInstanceKeyInfo = getKeyDirectiveInfo(element) || getContainedInVForDirectiveKeyInfo(context, element, hierarchyMap);
9318
+ const instanceContract = getInstanceWrapperContract(element.tag);
9319
+ if ((instanceContract?.forwardedTestIdTargetOffsets.size ?? 0) > 0) {
9320
+ if (tryGetExistingElementDataTestId(element, POM_INSTANCE_ATTRIBUTE)) {
9321
+ const loc = element.loc.start;
9322
+ throw new Error(
9323
+ `[vue-pom-generator] ${POM_INSTANCE_ATTRIBUTE} is generator-owned and cannot be authored manually.
9324
+ Component: ${componentName}
9325
+ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9326
+ );
9327
+ }
9328
+ const sourceId = getElementSourceId(element);
9329
+ const semanticNameCandidates = getComponentInstanceNameCandidates(element);
9330
+ const componentTypeName = toPascalCase(element.tag);
9331
+ const instanceNameCandidates = componentInstanceKeyInfo ? [componentTypeName, ...semanticNameCandidates.filter((candidate) => candidate !== componentTypeName)] : semanticNameCandidates;
9332
+ const instanceName = instanceNameCandidates.find((candidate) => {
9333
+ const owner = componentInstanceNameOwnerByName.get(candidate);
9334
+ return !owner || !!componentInstanceKeyInfo && owner.keyed && owner.componentName === element.tag;
9335
+ });
9336
+ if (instanceName) {
9337
+ componentInstanceNameOwnerByName.set(instanceName, {
9338
+ componentName: element.tag,
9339
+ keyed: !!componentInstanceKeyInfo,
9340
+ sourceId
9341
+ });
9342
+ const runtimeMarker = componentInstanceKeyInfo ? templateAttributeValue(`${componentName}-${componentInstanceKeyInfo.runtimeFragment}-${instanceName}-component`) : staticAttributeValue(`${componentName}-${instanceName}-component`);
9343
+ const selector = componentInstanceKeyInfo ? createPomStringPattern(`${componentName}-\${key}-${instanceName}-component`, "parameterized", ["key"]) : createPomStringPattern(`${componentName}-${instanceName}-component`, "static", []);
9344
+ upsertAttribute(element, POM_INSTANCE_ATTRIBUTE, runtimeMarker);
9345
+ const slotTemplate = getContainedInSlotTemplateNode(element, hierarchyMap);
9346
+ const slotName = slotTemplate ? getSlotNameFromTemplate(slotTemplate) : null;
9347
+ const slotOwner = slotTemplate ? getNearestComponentAncestor(slotTemplate, hierarchyMap, isComponentLikeTag2) : null;
9348
+ dependencies.componentInstances ??= [];
9349
+ dependencies.componentInstances.push({
9350
+ sourceId,
9351
+ componentName: element.tag,
9352
+ instanceName,
9353
+ selector,
9354
+ parameters: componentInstanceKeyInfo ? [createPomParameterSpec("key", "string")] : [],
9355
+ suppliedSlot: slotName && slotOwner ? { ownerSourceId: getElementSourceId(slotOwner), name: slotName } : void 0
9356
+ });
9357
+ }
9358
+ }
9359
+ }
8796
9360
  const keyValuesOverride = tryGetContainedInStaticVForSourceLiteralValues(context);
8797
9361
  const parentKey = context?.parent ? context.parent : null;
8798
9362
  const conditional = getConditionalDirectiveInfo(element);
@@ -8901,6 +9465,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8901
9465
  preferredGeneratedValue: args.preferredGeneratedValue,
8902
9466
  preferredRuntimeValue: args.preferredRuntimeValue,
8903
9467
  keyInfo: bestKeyInfo,
9468
+ selectorParameterName,
8904
9469
  keyValuesOverride,
8905
9470
  entryOverrides: args.entryOverrides,
8906
9471
  semanticNameHint: args.semanticNameHint,
@@ -9595,6 +10160,7 @@ function createBuildProcessorPlugin(options) {
9595
10160
  typescriptOutputStructure,
9596
10161
  csharp,
9597
10162
  generateFixtures,
10163
+ vueTestUtilsOutDir,
9598
10164
  customPomAttachments,
9599
10165
  customPomDir,
9600
10166
  requireCustomPomDir,
@@ -9811,6 +10377,7 @@ function createBuildProcessorPlugin(options) {
9811
10377
  typescriptOutputStructure,
9812
10378
  csharp,
9813
10379
  generateFixtures,
10380
+ vueTestUtilsOutDir,
9814
10381
  customPomAttachments,
9815
10382
  projectRoot: projectRootRef.current,
9816
10383
  customPomDir,
@@ -9859,6 +10426,7 @@ function createDevProcessorPlugin(options) {
9859
10426
  typescriptOutputStructure,
9860
10427
  csharp,
9861
10428
  generateFixtures,
10429
+ vueTestUtilsOutDir,
9862
10430
  customPomAttachments,
9863
10431
  customPomDir,
9864
10432
  requireCustomPomDir,
@@ -10117,6 +10685,7 @@ function createDevProcessorPlugin(options) {
10117
10685
  typescriptOutputStructure,
10118
10686
  csharp,
10119
10687
  generateFixtures,
10688
+ vueTestUtilsOutDir,
10120
10689
  customPomAttachments,
10121
10690
  projectRoot: projectRootRef.current,
10122
10691
  customPomDir,
@@ -10753,6 +11322,7 @@ function createVuePomGeneratorPlugins(options = {}) {
10753
11322
  typescriptOutputStructure: generationOptions?.playwright?.outputStructure,
10754
11323
  csharp: generationOptions?.csharp,
10755
11324
  generateFixtures,
11325
+ vueTestUtilsOutDir: generationOptions?.vueTestUtils ? generationOptions.vueTestUtils.outDir ?? "tests/unit/__generated__" : void 0,
10756
11326
  customPomAttachments: resolvedCustomPomAttachments,
10757
11327
  customPomDir: customPoms?.dir,
10758
11328
  requireCustomPomDir,
@@ -10787,6 +11357,7 @@ function createVuePomGeneratorPlugins(options = {}) {
10787
11357
  layoutDirs: isNuxt ? null : getLayoutDirs(),
10788
11358
  wrapperSearchRoots: isNuxt ? null : getWrapperSearchRoots(),
10789
11359
  outDir: resolvedGenerationOptions.outDir,
11360
+ vueTestUtilsOutDir: resolvedGenerationOptions.vueTestUtilsOutDir,
10790
11361
  testIdAttribute,
10791
11362
  routerType: resolvedGenerationOptions.routerType,
10792
11363
  vuePluginOwnership
@@ -10825,6 +11396,12 @@ function createVuePomGeneratorPlugins(options = {}) {
10825
11396
  }
10826
11397
  if (generationEnabled) {
10827
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
+ }
10828
11405
  assertOneOf(resolvedGenerationOptions.typescriptOutputStructure, ["aggregated", "split"], "[vue-pom-generator] generation.playwright.outputStructure");
10829
11406
  assertRouterModuleShims(resolvedGenerationOptions.routerModuleShims, "[vue-pom-generator] generation.router.moduleShims");
10830
11407
  if (!isNuxt && vueGenerationOptions?.router && resolvedGenerationOptions.routerType === "vue-router") {