@immense/vue-pom-generator 1.0.77 → 1.0.79

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.cjs CHANGED
@@ -1519,6 +1519,31 @@ function tryGetTemplateSlotScopeKeyInfo(expression) {
1519
1519
  const candidateExpression = bindingNode ? tryGetSlotScopeKeyCandidate(bindingNode)?.expression ?? null : null;
1520
1520
  return candidateExpression ? toResolvedKeyInfo(candidateExpression) : null;
1521
1521
  }
1522
+ function tryExtractSlotScopeVariableNames(expression) {
1523
+ const bindingNode = tryGetTemplateSlotScopeBindingNode(expression);
1524
+ if (!bindingNode) {
1525
+ return [];
1526
+ }
1527
+ if (types.isIdentifier(bindingNode)) {
1528
+ return [bindingNode.name];
1529
+ }
1530
+ if (!types.isObjectPattern(bindingNode)) {
1531
+ return [];
1532
+ }
1533
+ const names = [];
1534
+ for (const property of bindingNode.properties) {
1535
+ if (types.isRestElement(property)) {
1536
+ const argName = tryGetBindingIdentifierName(property.argument);
1537
+ if (argName) names.push(argName);
1538
+ } else if (types.isObjectProperty(property)) {
1539
+ const bindingName = tryGetBindingIdentifierName(property.value) ?? tryGetBindingIdentifierName(property.key);
1540
+ if (bindingName) {
1541
+ names.push(bindingName);
1542
+ }
1543
+ }
1544
+ }
1545
+ return names;
1546
+ }
1522
1547
  function nodeHasToDirective(node) {
1523
1548
  const toDirective = findDirectiveByName(node, "bind", "to");
1524
1549
  if (toDirective?.exp) {
@@ -1701,12 +1726,21 @@ function getStaticIdOrNameHint(node) {
1701
1726
  return identifier;
1702
1727
  }
1703
1728
  function getContainedInSlotDataKeyInfo(node, hierarchyMap2) {
1729
+ const templateNode = getContainedInSlotTemplateNode(node, hierarchyMap2);
1730
+ if (templateNode) {
1731
+ const slotScopeExpression = findTemplateSlotScopeExpression(templateNode);
1732
+ if (slotScopeExpression) {
1733
+ return tryGetTemplateSlotScopeKeyInfo(slotScopeExpression);
1734
+ }
1735
+ }
1736
+ return null;
1737
+ }
1738
+ function getContainedInSlotTemplateNode(node, hierarchyMap2) {
1704
1739
  let parent = getParent(hierarchyMap2, node);
1705
1740
  while (parent) {
1706
1741
  if (parent.type === compilerCore.NodeTypes.ELEMENT && parent.tag === "template") {
1707
- const slotScopeExpression = findTemplateSlotScopeExpression(parent);
1708
- if (slotScopeExpression) {
1709
- return tryGetTemplateSlotScopeKeyInfo(slotScopeExpression);
1742
+ if (findTemplateSlotScopeExpression(parent)) {
1743
+ return parent;
1710
1744
  }
1711
1745
  }
1712
1746
  parent = getParent(hierarchyMap2, parent);
@@ -5492,15 +5526,16 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
5492
5526
  sourceFile.addStatements("/** Generated Playwright fixtures (typed page objects). */");
5493
5527
  addNamedImport(sourceFile, {
5494
5528
  moduleSpecifier: "@playwright/test",
5495
- namedImports: [
5496
- "expect",
5497
- { name: "test", alias: "base" }
5498
- ]
5529
+ namedImports: ["expect"]
5499
5530
  });
5500
5531
  addNamedImport(sourceFile, {
5501
5532
  moduleSpecifier: "@playwright/test",
5502
5533
  isTypeOnly: true,
5503
- namedImports: [{ name: "Page", alias: "PwPage" }]
5534
+ namedImports: [
5535
+ { name: "Page", alias: "PwPage" },
5536
+ "PlaywrightTestArgs",
5537
+ "TestType"
5538
+ ]
5504
5539
  });
5505
5540
  sourceFile.addImportDeclaration({
5506
5541
  namespaceImport: "Pom",
@@ -5584,6 +5619,14 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
5584
5619
  name: "GeneratedComponentFixtures",
5585
5620
  type: "{ [K in keyof typeof componentCtors]: InstanceType<(typeof componentCtors)[K]> }"
5586
5621
  });
5622
+ sourceFile.addTypeAlias({
5623
+ isExported: true,
5624
+ name: "PomFixtures",
5625
+ docs: [{
5626
+ description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM."
5627
+ }],
5628
+ type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
5629
+ });
5587
5630
  sourceFile.addFunction({
5588
5631
  name: "makePomFixture",
5589
5632
  typeParameters: [{ name: "T" }],
@@ -5606,43 +5649,61 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
5606
5649
  "return out as any;"
5607
5650
  ]
5608
5651
  });
5609
- sourceFile.addVariableStatement({
5610
- declarationKind: tsMorph.VariableDeclarationKind.Const,
5611
- declarations: [{
5612
- name: "test",
5613
- initializer: (writer) => {
5614
- writer.write("base.extend<PlaywrightOptions & PomSetupFixture & PomFactoryFixture & GeneratedPageFixtures & GeneratedComponentFixtures>(");
5615
- writer.block(() => {
5616
- writer.writeLine("animation: [{");
5617
- writer.indent(() => {
5618
- writer.writeLine('pointer: { durationMilliseconds: 250, transitionStyle: "ease-in-out", clickDelayMilliseconds: 0 },');
5619
- writer.writeLine("keyboard: { typeDelayMilliseconds: 100 },");
5620
- });
5621
- writer.writeLine("}, { option: true }],");
5622
- writer.writeLine("pomSetup: [async ({ animation }, use) => {");
5623
- writer.indent(() => {
5624
- writer.writeLine("Pom.setPlaywrightAnimationOptions(animation);");
5625
- writer.writeLine("await use();");
5626
- });
5627
- writer.writeLine("}, { auto: true }],");
5628
- writer.writeLine("pomFactory: async ({ page }, use) => {");
5652
+ sourceFile.addStatements([
5653
+ "/**",
5654
+ " * Attach the generated POM fixtures to a project-owned Playwright `test`.",
5655
+ " *",
5656
+ " * This generator deliberately does not export a `test` of its own. Projects should own",
5657
+ " * exactly one `test` object so project-wide fixtures (console-error capture, error-overlay",
5658
+ " * detection, auth, ...) are inherited by every spec. Compose it once in a project module:",
5659
+ " *",
5660
+ " * const base = playwrightTest.extend({ ...project-wide fixtures... });",
5661
+ " * export const test = withPomFixtures(base);",
5662
+ " *",
5663
+ " * Then have every spec import `test` from that module.",
5664
+ " */"
5665
+ ].join("\n"));
5666
+ sourceFile.addFunction({
5667
+ isExported: true,
5668
+ name: "withPomFixtures",
5669
+ typeParameters: [
5670
+ { name: "TTestArgs", constraint: "PlaywrightTestArgs" },
5671
+ { name: "TWorkerArgs", constraint: "object" }
5672
+ ],
5673
+ parameters: [{ name: "base", type: "TestType<TTestArgs, TWorkerArgs>" }],
5674
+ returnType: "TestType<TTestArgs & PomFixtures, TWorkerArgs>",
5675
+ statements: (writer) => {
5676
+ writer.write("return base.extend<PomFixtures>(");
5677
+ writer.block(() => {
5678
+ writer.writeLine("animation: [{");
5679
+ writer.indent(() => {
5680
+ writer.writeLine('pointer: { durationMilliseconds: 250, transitionStyle: "ease-in-out", clickDelayMilliseconds: 0 },');
5681
+ writer.writeLine("keyboard: { typeDelayMilliseconds: 100 },");
5682
+ });
5683
+ writer.writeLine("}, { option: true }],");
5684
+ writer.writeLine("pomSetup: [async ({ animation }: PomFixtures, use: (r: void) => Promise<void>) => {");
5685
+ writer.indent(() => {
5686
+ writer.writeLine("Pom.setPlaywrightAnimationOptions(animation);");
5687
+ writer.writeLine("await use();");
5688
+ });
5689
+ writer.writeLine("}, { auto: true }],");
5690
+ writer.writeLine("pomFactory: async ({ page }: { page: PwPage }, use: (r: PomFactory) => Promise<void>) => {");
5691
+ writer.indent(() => {
5692
+ writer.writeLine("await use({");
5629
5693
  writer.indent(() => {
5630
- writer.writeLine("await use({");
5631
- writer.indent(() => {
5632
- writer.writeLine("create: <T>(ctor: PomConstructor<T>) => new ctor(page),");
5633
- });
5634
- writer.writeLine("});");
5694
+ writer.writeLine("create: <T>(ctor: PomConstructor<T>) => new ctor(page),");
5635
5695
  });
5636
- writer.writeLine("},");
5637
- writer.writeLine("...createPomFixtures(pageCtors),");
5638
- writer.writeLine("...createPomFixtures(componentCtors),");
5696
+ writer.writeLine("});");
5639
5697
  });
5640
- writer.write(")");
5641
- }
5642
- }]
5698
+ writer.writeLine("},");
5699
+ writer.writeLine("...createPomFixtures(pageCtors),");
5700
+ writer.writeLine("...createPomFixtures(componentCtors),");
5701
+ });
5702
+ writer.write(") as TestType<TTestArgs & PomFixtures, TWorkerArgs>;");
5703
+ }
5643
5704
  });
5644
5705
  sourceFile.addExportDeclaration({
5645
- namedExports: ["test", "expect"]
5706
+ namedExports: ["expect"]
5646
5707
  });
5647
5708
  }, {
5648
5709
  prefixText: buildFilePrefix({
@@ -5692,9 +5753,16 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
5692
5753
  return match;
5693
5754
  };
5694
5755
  const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
5756
+ const ownClassName = toPascalCaseLocal(componentName);
5757
+ const isSelfReference = (ref) => {
5758
+ return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
5759
+ };
5695
5760
  const componentRefsForInstances = /* @__PURE__ */ new Set();
5696
5761
  for (const ref of rawComponentRefsForInstances) {
5697
5762
  const resolvedRef = resolveTrackedComponentRef(ref) ?? normalizeTrackedComponentRef(ref);
5763
+ if (isSelfReference(resolvedRef)) {
5764
+ continue;
5765
+ }
5698
5766
  const resolvedDependencies = componentHierarchyMap.get(resolvedRef);
5699
5767
  if (!resolvedDependencies?.dataTestIdSet.size) {
5700
5768
  continue;
@@ -7259,6 +7327,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7259
7327
  const vueFilesPathMap = options.vueFilesPathMap;
7260
7328
  const wrapperSearchRoots = options.wrapperSearchRoots ?? [];
7261
7329
  const annotatorMetadata = options.annotatorMetadata ?? null;
7330
+ const crossFileKeyRegistry = options.crossFileKeyRegistry;
7262
7331
  const safeRealpath2 = (p) => {
7263
7332
  try {
7264
7333
  return fs.existsSync(p) ? fs.realpathSync(p) : p;
@@ -7388,12 +7457,37 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7388
7457
  };
7389
7458
  if (isComponentLikeTag(element.tag)) {
7390
7459
  dependencies.usedComponentSet.add(element.tag);
7460
+ if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
7461
+ const findSlotTemplate = () => {
7462
+ const gp = context.grandParent;
7463
+ if (gp?.type === compilerCore.NodeTypes.ELEMENT && gp.tag === "template") {
7464
+ return gp;
7465
+ }
7466
+ return getContainedInSlotTemplateNode(element, hierarchyMap);
7467
+ };
7468
+ const slotTemplate = findSlotTemplate();
7469
+ if (slotTemplate) {
7470
+ const slotScopeExpression = findTemplateSlotScopeExpression(slotTemplate);
7471
+ if (slotScopeExpression) {
7472
+ const slotVarNames = tryExtractSlotScopeVariableNames(slotScopeExpression);
7473
+ if (slotVarNames.length > 0) {
7474
+ for (const prop of element.props) {
7475
+ if (prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.exp?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && slotVarNames.includes(prop.exp.content)) {
7476
+ const propName = prop.arg.content;
7477
+ crossFileKeyRegistry.set(element.tag, propName);
7478
+ break;
7479
+ }
7480
+ }
7481
+ }
7482
+ }
7483
+ }
7484
+ }
7391
7485
  }
7392
7486
  if (!nativeWrappers[element.tag]) {
7393
7487
  const inferred = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, wrapperSearchRoots);
7394
7488
  if (inferred?.role) {
7395
7489
  nativeWrappers[element.tag] = { role: inferred.role, inferred: true };
7396
- } else if (element.tag.endsWith("Button") || element.tag === "AylaButton") {
7490
+ } else if (element.tag.endsWith("Button")) {
7397
7491
  nativeWrappers[element.tag] = { role: "button" };
7398
7492
  } else if (element.tag === "DxDataGrid") {
7399
7493
  nativeWrappers[element.tag] = { role: "grid" };
@@ -7406,7 +7500,18 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7406
7500
  if (vForKeyInfo) {
7407
7501
  return vForKeyInfo;
7408
7502
  }
7409
- return getContainedInSlotDataKeyInfo(element, hierarchyMap);
7503
+ const slotKeyInfo = getContainedInSlotDataKeyInfo(element, hierarchyMap);
7504
+ if (slotKeyInfo) {
7505
+ return slotKeyInfo;
7506
+ }
7507
+ if (crossFileKeyRegistry) {
7508
+ const propName = crossFileKeyRegistry.get(componentName);
7509
+ if (propName) {
7510
+ const fallbackExpr = buildSlotScopeFallbackKeyExpression(propName);
7511
+ return toResolvedKeyInfo(fallbackExpr, fallbackExpr);
7512
+ }
7513
+ }
7514
+ return null;
7410
7515
  };
7411
7516
  const bestKeyInfo = getBestAvailableKeyInfo();
7412
7517
  const bestKeyPlaceholder = bestKeyInfo?.selectorFragment ?? null;
@@ -7754,6 +7859,7 @@ function isLessRich(candidate, previous) {
7754
7859
  function createBuildProcessorPlugin(options) {
7755
7860
  const {
7756
7861
  componentHierarchyMap,
7862
+ crossFileKeyRegistry,
7757
7863
  vueFilesPathMap,
7758
7864
  getPageDirs,
7759
7865
  getComponentDirs,
@@ -7896,7 +8002,8 @@ function createBuildProcessorPlugin(options) {
7896
8002
  missingSemanticNameBehavior,
7897
8003
  warn: (message) => loggerRef.current.warn(message),
7898
8004
  vueFilesPathMap,
7899
- wrapperSearchRoots: getWrapperSearchRoots()
8005
+ wrapperSearchRoots: getWrapperSearchRoots(),
8006
+ crossFileKeyRegistry
7900
8007
  }
7901
8008
  )
7902
8009
  ]
@@ -8219,6 +8326,7 @@ function createDevProcessorPlugin(options) {
8219
8326
  }
8220
8327
  const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
8221
8328
  const provisionalHierarchy = /* @__PURE__ */ new Map();
8329
+ const provisionalKeyRegistry = /* @__PURE__ */ new Map();
8222
8330
  const provisionalVuePathMap = new Map(targetVuePathMap);
8223
8331
  provisionalVuePathMap.set(componentName, absolutePath);
8224
8332
  compilerDom__namespace.compile(template, {
@@ -8246,7 +8354,8 @@ function createDevProcessorPlugin(options) {
8246
8354
  testIdAttribute,
8247
8355
  warn: (message) => loggerRef.current.warn(message),
8248
8356
  vueFilesPathMap: provisionalVuePathMap,
8249
- wrapperSearchRoots: getWrapperSearchRoots()
8357
+ wrapperSearchRoots: getWrapperSearchRoots(),
8358
+ crossFileKeyRegistry: provisionalKeyRegistry
8250
8359
  }
8251
8360
  )
8252
8361
  ]
@@ -8770,6 +8879,7 @@ ${code}`,
8770
8879
  function createInternalPlugins(options) {
8771
8880
  const {
8772
8881
  componentHierarchyMap,
8882
+ crossFileKeyRegistry,
8773
8883
  elementMetadata,
8774
8884
  vueFilesPathMap,
8775
8885
  nativeWrappers,
@@ -8825,6 +8935,7 @@ function createInternalPlugins(options) {
8825
8935
  const normalizedBasePagePath = path.posix.normalize(basePageClassPath);
8826
8936
  const tsProcessor = createBuildProcessorPlugin({
8827
8937
  componentHierarchyMap,
8938
+ crossFileKeyRegistry,
8828
8939
  vueFilesPathMap,
8829
8940
  getPageDirs,
8830
8941
  getComponentDirs,
@@ -9050,6 +9161,7 @@ function createVuePluginWithTestIds(options) {
9050
9161
  elementMetadata,
9051
9162
  semanticNameMap,
9052
9163
  componentHierarchyMap,
9164
+ crossFileKeyRegistry,
9053
9165
  vueFilesPathMap,
9054
9166
  excludedComponents,
9055
9167
  getViewsDirAbs,
@@ -9119,7 +9231,8 @@ function createVuePluginWithTestIds(options) {
9119
9231
  warn: (message) => loggerRef.current.warn(message),
9120
9232
  vueFilesPathMap,
9121
9233
  wrapperSearchRoots: getWrapperSearchRoots(),
9122
- annotatorMetadata
9234
+ annotatorMetadata,
9235
+ crossFileKeyRegistry
9123
9236
  }
9124
9237
  )
9125
9238
  );
@@ -9175,7 +9288,8 @@ function createVuePluginWithTestIds(options) {
9175
9288
  warn: (message) => loggerRef.current.warn(message),
9176
9289
  vueFilesPathMap,
9177
9290
  wrapperSearchRoots: getWrapperSearchRoots(),
9178
- annotatorMetadata
9291
+ annotatorMetadata,
9292
+ crossFileKeyRegistry
9179
9293
  }
9180
9294
  );
9181
9295
  perFileTransform.set(componentName, transform);
@@ -9419,6 +9533,7 @@ function getSharedGeneratorState(key) {
9419
9533
  elementMetadata: /* @__PURE__ */ new Map(),
9420
9534
  semanticNameMap: /* @__PURE__ */ new Map(),
9421
9535
  componentHierarchyMap: /* @__PURE__ */ new Map(),
9536
+ crossFileKeyRegistry: /* @__PURE__ */ new Map(),
9422
9537
  vueFilesPathMap: /* @__PURE__ */ new Map()
9423
9538
  };
9424
9539
  sharedGeneratorStateRegistry.set(key, state);
@@ -9633,7 +9748,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9633
9748
  };
9634
9749
  const getViewsDirAbs = () => resolveFromProjectRoot(projectRootRef.current, getViewsDir());
9635
9750
  const getWrapperSearchRootsAbs = () => getWrapperSearchRoots().map((root) => resolveFromProjectRoot(projectRootRef.current, root));
9636
- const { elementMetadata, semanticNameMap, componentHierarchyMap, vueFilesPathMap } = sharedState;
9751
+ const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
9637
9752
  const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
9638
9753
  vueOptions,
9639
9754
  existingIdBehavior: resolvedGenerationOptions.existingIdBehavior,
@@ -9643,6 +9758,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9643
9758
  elementMetadata,
9644
9759
  semanticNameMap,
9645
9760
  componentHierarchyMap,
9761
+ crossFileKeyRegistry,
9646
9762
  vueFilesPathMap,
9647
9763
  excludedComponents,
9648
9764
  getViewsDirAbs,
@@ -9660,6 +9776,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9660
9776
  templateCompilerOptionsForResolvedPlugin = templateCompilerOptions;
9661
9777
  const internalPlugins = createInternalPlugins({
9662
9778
  componentHierarchyMap,
9779
+ crossFileKeyRegistry,
9663
9780
  elementMetadata,
9664
9781
  vueFilesPathMap,
9665
9782
  nativeWrappers,