@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.mjs CHANGED
@@ -9,7 +9,7 @@ import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
9
9
  import { parseExpression, parse } from "@babel/parser";
10
10
  import { NodeTypes, stringifyExpression, ConstantTypes, createSimpleExpression, ElementTypes } from "@vue/compiler-core";
11
11
  import { Project, QuoteKind, NewLineKind, IndentationText, CodeBlockWriter, StructureKind, VariableDeclarationKind } from "ts-morph";
12
- import { isArrayExpression, isStringLiteral, isTemplateLiteral, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isIdentifier, isExpressionStatement, isObjectExpression, isFile, isArrowFunctionExpression, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isAssignmentPattern, isRestElement, isObjectPattern, isObjectProperty, isProgram, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral } from "@babel/types";
12
+ import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isProgram, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral } from "@babel/types";
13
13
  import { performance } from "node:perf_hooks";
14
14
  import vue from "@vitejs/plugin-vue";
15
15
  import { autoUpdate, computePosition, offset, autoPlacement, shift, arrow } from "@floating-ui/dom";
@@ -1478,6 +1478,31 @@ function tryGetTemplateSlotScopeKeyInfo(expression) {
1478
1478
  const candidateExpression = bindingNode ? tryGetSlotScopeKeyCandidate(bindingNode)?.expression ?? null : null;
1479
1479
  return candidateExpression ? toResolvedKeyInfo(candidateExpression) : null;
1480
1480
  }
1481
+ function tryExtractSlotScopeVariableNames(expression) {
1482
+ const bindingNode = tryGetTemplateSlotScopeBindingNode(expression);
1483
+ if (!bindingNode) {
1484
+ return [];
1485
+ }
1486
+ if (isIdentifier(bindingNode)) {
1487
+ return [bindingNode.name];
1488
+ }
1489
+ if (!isObjectPattern(bindingNode)) {
1490
+ return [];
1491
+ }
1492
+ const names = [];
1493
+ for (const property of bindingNode.properties) {
1494
+ if (isRestElement(property)) {
1495
+ const argName = tryGetBindingIdentifierName(property.argument);
1496
+ if (argName) names.push(argName);
1497
+ } else if (isObjectProperty(property)) {
1498
+ const bindingName = tryGetBindingIdentifierName(property.value) ?? tryGetBindingIdentifierName(property.key);
1499
+ if (bindingName) {
1500
+ names.push(bindingName);
1501
+ }
1502
+ }
1503
+ }
1504
+ return names;
1505
+ }
1481
1506
  function nodeHasToDirective(node) {
1482
1507
  const toDirective = findDirectiveByName(node, "bind", "to");
1483
1508
  if (toDirective?.exp) {
@@ -1660,12 +1685,21 @@ function getStaticIdOrNameHint(node) {
1660
1685
  return identifier;
1661
1686
  }
1662
1687
  function getContainedInSlotDataKeyInfo(node, hierarchyMap2) {
1688
+ const templateNode = getContainedInSlotTemplateNode(node, hierarchyMap2);
1689
+ if (templateNode) {
1690
+ const slotScopeExpression = findTemplateSlotScopeExpression(templateNode);
1691
+ if (slotScopeExpression) {
1692
+ return tryGetTemplateSlotScopeKeyInfo(slotScopeExpression);
1693
+ }
1694
+ }
1695
+ return null;
1696
+ }
1697
+ function getContainedInSlotTemplateNode(node, hierarchyMap2) {
1663
1698
  let parent = getParent(hierarchyMap2, node);
1664
1699
  while (parent) {
1665
1700
  if (parent.type === NodeTypes.ELEMENT && parent.tag === "template") {
1666
- const slotScopeExpression = findTemplateSlotScopeExpression(parent);
1667
- if (slotScopeExpression) {
1668
- return tryGetTemplateSlotScopeKeyInfo(slotScopeExpression);
1701
+ if (findTemplateSlotScopeExpression(parent)) {
1702
+ return parent;
1669
1703
  }
1670
1704
  }
1671
1705
  parent = getParent(hierarchyMap2, parent);
@@ -5451,15 +5485,16 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
5451
5485
  sourceFile.addStatements("/** Generated Playwright fixtures (typed page objects). */");
5452
5486
  addNamedImport(sourceFile, {
5453
5487
  moduleSpecifier: "@playwright/test",
5454
- namedImports: [
5455
- "expect",
5456
- { name: "test", alias: "base" }
5457
- ]
5488
+ namedImports: ["expect"]
5458
5489
  });
5459
5490
  addNamedImport(sourceFile, {
5460
5491
  moduleSpecifier: "@playwright/test",
5461
5492
  isTypeOnly: true,
5462
- namedImports: [{ name: "Page", alias: "PwPage" }]
5493
+ namedImports: [
5494
+ { name: "Page", alias: "PwPage" },
5495
+ "PlaywrightTestArgs",
5496
+ "TestType"
5497
+ ]
5463
5498
  });
5464
5499
  sourceFile.addImportDeclaration({
5465
5500
  namespaceImport: "Pom",
@@ -5543,6 +5578,14 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
5543
5578
  name: "GeneratedComponentFixtures",
5544
5579
  type: "{ [K in keyof typeof componentCtors]: InstanceType<(typeof componentCtors)[K]> }"
5545
5580
  });
5581
+ sourceFile.addTypeAlias({
5582
+ isExported: true,
5583
+ name: "PomFixtures",
5584
+ docs: [{
5585
+ description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM."
5586
+ }],
5587
+ type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
5588
+ });
5546
5589
  sourceFile.addFunction({
5547
5590
  name: "makePomFixture",
5548
5591
  typeParameters: [{ name: "T" }],
@@ -5565,43 +5608,61 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
5565
5608
  "return out as any;"
5566
5609
  ]
5567
5610
  });
5568
- sourceFile.addVariableStatement({
5569
- declarationKind: VariableDeclarationKind.Const,
5570
- declarations: [{
5571
- name: "test",
5572
- initializer: (writer) => {
5573
- writer.write("base.extend<PlaywrightOptions & PomSetupFixture & PomFactoryFixture & GeneratedPageFixtures & GeneratedComponentFixtures>(");
5574
- writer.block(() => {
5575
- writer.writeLine("animation: [{");
5576
- writer.indent(() => {
5577
- writer.writeLine('pointer: { durationMilliseconds: 250, transitionStyle: "ease-in-out", clickDelayMilliseconds: 0 },');
5578
- writer.writeLine("keyboard: { typeDelayMilliseconds: 100 },");
5579
- });
5580
- writer.writeLine("}, { option: true }],");
5581
- writer.writeLine("pomSetup: [async ({ animation }, use) => {");
5582
- writer.indent(() => {
5583
- writer.writeLine("Pom.setPlaywrightAnimationOptions(animation);");
5584
- writer.writeLine("await use();");
5585
- });
5586
- writer.writeLine("}, { auto: true }],");
5587
- writer.writeLine("pomFactory: async ({ page }, use) => {");
5611
+ sourceFile.addStatements([
5612
+ "/**",
5613
+ " * Attach the generated POM fixtures to a project-owned Playwright `test`.",
5614
+ " *",
5615
+ " * This generator deliberately does not export a `test` of its own. Projects should own",
5616
+ " * exactly one `test` object so project-wide fixtures (console-error capture, error-overlay",
5617
+ " * detection, auth, ...) are inherited by every spec. Compose it once in a project module:",
5618
+ " *",
5619
+ " * const base = playwrightTest.extend({ ...project-wide fixtures... });",
5620
+ " * export const test = withPomFixtures(base);",
5621
+ " *",
5622
+ " * Then have every spec import `test` from that module.",
5623
+ " */"
5624
+ ].join("\n"));
5625
+ sourceFile.addFunction({
5626
+ isExported: true,
5627
+ name: "withPomFixtures",
5628
+ typeParameters: [
5629
+ { name: "TTestArgs", constraint: "PlaywrightTestArgs" },
5630
+ { name: "TWorkerArgs", constraint: "object" }
5631
+ ],
5632
+ parameters: [{ name: "base", type: "TestType<TTestArgs, TWorkerArgs>" }],
5633
+ returnType: "TestType<TTestArgs & PomFixtures, TWorkerArgs>",
5634
+ statements: (writer) => {
5635
+ writer.write("return base.extend<PomFixtures>(");
5636
+ writer.block(() => {
5637
+ writer.writeLine("animation: [{");
5638
+ writer.indent(() => {
5639
+ writer.writeLine('pointer: { durationMilliseconds: 250, transitionStyle: "ease-in-out", clickDelayMilliseconds: 0 },');
5640
+ writer.writeLine("keyboard: { typeDelayMilliseconds: 100 },");
5641
+ });
5642
+ writer.writeLine("}, { option: true }],");
5643
+ writer.writeLine("pomSetup: [async ({ animation }: PomFixtures, use: (r: void) => Promise<void>) => {");
5644
+ writer.indent(() => {
5645
+ writer.writeLine("Pom.setPlaywrightAnimationOptions(animation);");
5646
+ writer.writeLine("await use();");
5647
+ });
5648
+ writer.writeLine("}, { auto: true }],");
5649
+ writer.writeLine("pomFactory: async ({ page }: { page: PwPage }, use: (r: PomFactory) => Promise<void>) => {");
5650
+ writer.indent(() => {
5651
+ writer.writeLine("await use({");
5588
5652
  writer.indent(() => {
5589
- writer.writeLine("await use({");
5590
- writer.indent(() => {
5591
- writer.writeLine("create: <T>(ctor: PomConstructor<T>) => new ctor(page),");
5592
- });
5593
- writer.writeLine("});");
5653
+ writer.writeLine("create: <T>(ctor: PomConstructor<T>) => new ctor(page),");
5594
5654
  });
5595
- writer.writeLine("},");
5596
- writer.writeLine("...createPomFixtures(pageCtors),");
5597
- writer.writeLine("...createPomFixtures(componentCtors),");
5655
+ writer.writeLine("});");
5598
5656
  });
5599
- writer.write(")");
5600
- }
5601
- }]
5657
+ writer.writeLine("},");
5658
+ writer.writeLine("...createPomFixtures(pageCtors),");
5659
+ writer.writeLine("...createPomFixtures(componentCtors),");
5660
+ });
5661
+ writer.write(") as TestType<TTestArgs & PomFixtures, TWorkerArgs>;");
5662
+ }
5602
5663
  });
5603
5664
  sourceFile.addExportDeclaration({
5604
- namedExports: ["test", "expect"]
5665
+ namedExports: ["expect"]
5605
5666
  });
5606
5667
  }, {
5607
5668
  prefixText: buildFilePrefix({
@@ -5651,9 +5712,16 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
5651
5712
  return match;
5652
5713
  };
5653
5714
  const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
5715
+ const ownClassName = toPascalCaseLocal(componentName);
5716
+ const isSelfReference = (ref) => {
5717
+ return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
5718
+ };
5654
5719
  const componentRefsForInstances = /* @__PURE__ */ new Set();
5655
5720
  for (const ref of rawComponentRefsForInstances) {
5656
5721
  const resolvedRef = resolveTrackedComponentRef(ref) ?? normalizeTrackedComponentRef(ref);
5722
+ if (isSelfReference(resolvedRef)) {
5723
+ continue;
5724
+ }
5657
5725
  const resolvedDependencies = componentHierarchyMap.get(resolvedRef);
5658
5726
  if (!resolvedDependencies?.dataTestIdSet.size) {
5659
5727
  continue;
@@ -7218,6 +7286,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7218
7286
  const vueFilesPathMap = options.vueFilesPathMap;
7219
7287
  const wrapperSearchRoots = options.wrapperSearchRoots ?? [];
7220
7288
  const annotatorMetadata = options.annotatorMetadata ?? null;
7289
+ const crossFileKeyRegistry = options.crossFileKeyRegistry;
7221
7290
  const safeRealpath2 = (p) => {
7222
7291
  try {
7223
7292
  return fs.existsSync(p) ? fs.realpathSync(p) : p;
@@ -7347,12 +7416,37 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7347
7416
  };
7348
7417
  if (isComponentLikeTag(element.tag)) {
7349
7418
  dependencies.usedComponentSet.add(element.tag);
7419
+ if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
7420
+ const findSlotTemplate = () => {
7421
+ const gp = context.grandParent;
7422
+ if (gp?.type === NodeTypes.ELEMENT && gp.tag === "template") {
7423
+ return gp;
7424
+ }
7425
+ return getContainedInSlotTemplateNode(element, hierarchyMap);
7426
+ };
7427
+ const slotTemplate = findSlotTemplate();
7428
+ if (slotTemplate) {
7429
+ const slotScopeExpression = findTemplateSlotScopeExpression(slotTemplate);
7430
+ if (slotScopeExpression) {
7431
+ const slotVarNames = tryExtractSlotScopeVariableNames(slotScopeExpression);
7432
+ if (slotVarNames.length > 0) {
7433
+ for (const prop of element.props) {
7434
+ if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && slotVarNames.includes(prop.exp.content)) {
7435
+ const propName = prop.arg.content;
7436
+ crossFileKeyRegistry.set(element.tag, propName);
7437
+ break;
7438
+ }
7439
+ }
7440
+ }
7441
+ }
7442
+ }
7443
+ }
7350
7444
  }
7351
7445
  if (!nativeWrappers[element.tag]) {
7352
7446
  const inferred = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, wrapperSearchRoots);
7353
7447
  if (inferred?.role) {
7354
7448
  nativeWrappers[element.tag] = { role: inferred.role, inferred: true };
7355
- } else if (element.tag.endsWith("Button") || element.tag === "AylaButton") {
7449
+ } else if (element.tag.endsWith("Button")) {
7356
7450
  nativeWrappers[element.tag] = { role: "button" };
7357
7451
  } else if (element.tag === "DxDataGrid") {
7358
7452
  nativeWrappers[element.tag] = { role: "grid" };
@@ -7365,7 +7459,18 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7365
7459
  if (vForKeyInfo) {
7366
7460
  return vForKeyInfo;
7367
7461
  }
7368
- return getContainedInSlotDataKeyInfo(element, hierarchyMap);
7462
+ const slotKeyInfo = getContainedInSlotDataKeyInfo(element, hierarchyMap);
7463
+ if (slotKeyInfo) {
7464
+ return slotKeyInfo;
7465
+ }
7466
+ if (crossFileKeyRegistry) {
7467
+ const propName = crossFileKeyRegistry.get(componentName);
7468
+ if (propName) {
7469
+ const fallbackExpr = buildSlotScopeFallbackKeyExpression(propName);
7470
+ return toResolvedKeyInfo(fallbackExpr, fallbackExpr);
7471
+ }
7472
+ }
7473
+ return null;
7369
7474
  };
7370
7475
  const bestKeyInfo = getBestAvailableKeyInfo();
7371
7476
  const bestKeyPlaceholder = bestKeyInfo?.selectorFragment ?? null;
@@ -7713,6 +7818,7 @@ function isLessRich(candidate, previous) {
7713
7818
  function createBuildProcessorPlugin(options) {
7714
7819
  const {
7715
7820
  componentHierarchyMap,
7821
+ crossFileKeyRegistry,
7716
7822
  vueFilesPathMap,
7717
7823
  getPageDirs,
7718
7824
  getComponentDirs,
@@ -7855,7 +7961,8 @@ function createBuildProcessorPlugin(options) {
7855
7961
  missingSemanticNameBehavior,
7856
7962
  warn: (message) => loggerRef.current.warn(message),
7857
7963
  vueFilesPathMap,
7858
- wrapperSearchRoots: getWrapperSearchRoots()
7964
+ wrapperSearchRoots: getWrapperSearchRoots(),
7965
+ crossFileKeyRegistry
7859
7966
  }
7860
7967
  )
7861
7968
  ]
@@ -8178,6 +8285,7 @@ function createDevProcessorPlugin(options) {
8178
8285
  }
8179
8286
  const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
8180
8287
  const provisionalHierarchy = /* @__PURE__ */ new Map();
8288
+ const provisionalKeyRegistry = /* @__PURE__ */ new Map();
8181
8289
  const provisionalVuePathMap = new Map(targetVuePathMap);
8182
8290
  provisionalVuePathMap.set(componentName, absolutePath);
8183
8291
  compilerDom.compile(template, {
@@ -8205,7 +8313,8 @@ function createDevProcessorPlugin(options) {
8205
8313
  testIdAttribute,
8206
8314
  warn: (message) => loggerRef.current.warn(message),
8207
8315
  vueFilesPathMap: provisionalVuePathMap,
8208
- wrapperSearchRoots: getWrapperSearchRoots()
8316
+ wrapperSearchRoots: getWrapperSearchRoots(),
8317
+ crossFileKeyRegistry: provisionalKeyRegistry
8209
8318
  }
8210
8319
  )
8211
8320
  ]
@@ -8729,6 +8838,7 @@ ${code}`,
8729
8838
  function createInternalPlugins(options) {
8730
8839
  const {
8731
8840
  componentHierarchyMap,
8841
+ crossFileKeyRegistry,
8732
8842
  elementMetadata,
8733
8843
  vueFilesPathMap,
8734
8844
  nativeWrappers,
@@ -8784,6 +8894,7 @@ function createInternalPlugins(options) {
8784
8894
  const normalizedBasePagePath = path.posix.normalize(basePageClassPath);
8785
8895
  const tsProcessor = createBuildProcessorPlugin({
8786
8896
  componentHierarchyMap,
8897
+ crossFileKeyRegistry,
8787
8898
  vueFilesPathMap,
8788
8899
  getPageDirs,
8789
8900
  getComponentDirs,
@@ -9009,6 +9120,7 @@ function createVuePluginWithTestIds(options) {
9009
9120
  elementMetadata,
9010
9121
  semanticNameMap,
9011
9122
  componentHierarchyMap,
9123
+ crossFileKeyRegistry,
9012
9124
  vueFilesPathMap,
9013
9125
  excludedComponents,
9014
9126
  getViewsDirAbs,
@@ -9078,7 +9190,8 @@ function createVuePluginWithTestIds(options) {
9078
9190
  warn: (message) => loggerRef.current.warn(message),
9079
9191
  vueFilesPathMap,
9080
9192
  wrapperSearchRoots: getWrapperSearchRoots(),
9081
- annotatorMetadata
9193
+ annotatorMetadata,
9194
+ crossFileKeyRegistry
9082
9195
  }
9083
9196
  )
9084
9197
  );
@@ -9134,7 +9247,8 @@ function createVuePluginWithTestIds(options) {
9134
9247
  warn: (message) => loggerRef.current.warn(message),
9135
9248
  vueFilesPathMap,
9136
9249
  wrapperSearchRoots: getWrapperSearchRoots(),
9137
- annotatorMetadata
9250
+ annotatorMetadata,
9251
+ crossFileKeyRegistry
9138
9252
  }
9139
9253
  );
9140
9254
  perFileTransform.set(componentName, transform);
@@ -9378,6 +9492,7 @@ function getSharedGeneratorState(key) {
9378
9492
  elementMetadata: /* @__PURE__ */ new Map(),
9379
9493
  semanticNameMap: /* @__PURE__ */ new Map(),
9380
9494
  componentHierarchyMap: /* @__PURE__ */ new Map(),
9495
+ crossFileKeyRegistry: /* @__PURE__ */ new Map(),
9381
9496
  vueFilesPathMap: /* @__PURE__ */ new Map()
9382
9497
  };
9383
9498
  sharedGeneratorStateRegistry.set(key, state);
@@ -9592,7 +9707,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9592
9707
  };
9593
9708
  const getViewsDirAbs = () => resolveFromProjectRoot(projectRootRef.current, getViewsDir());
9594
9709
  const getWrapperSearchRootsAbs = () => getWrapperSearchRoots().map((root) => resolveFromProjectRoot(projectRootRef.current, root));
9595
- const { elementMetadata, semanticNameMap, componentHierarchyMap, vueFilesPathMap } = sharedState;
9710
+ const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
9596
9711
  const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
9597
9712
  vueOptions,
9598
9713
  existingIdBehavior: resolvedGenerationOptions.existingIdBehavior,
@@ -9602,6 +9717,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9602
9717
  elementMetadata,
9603
9718
  semanticNameMap,
9604
9719
  componentHierarchyMap,
9720
+ crossFileKeyRegistry,
9605
9721
  vueFilesPathMap,
9606
9722
  excludedComponents,
9607
9723
  getViewsDirAbs,
@@ -9619,6 +9735,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9619
9735
  templateCompilerOptionsForResolvedPlugin = templateCompilerOptions;
9620
9736
  const internalPlugins = createInternalPlugins({
9621
9737
  componentHierarchyMap,
9738
+ crossFileKeyRegistry,
9622
9739
  elementMetadata,
9623
9740
  vueFilesPathMap,
9624
9741
  nativeWrappers,