@immense/vue-pom-generator 1.0.83 → 1.0.85

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 (51) hide show
  1. package/RELEASE_NOTES.md +57 -30
  2. package/class-generation/index.ts +234 -26
  3. package/class-generation/playwright-types.ts +120 -2
  4. package/dist/class-generation/index.d.ts +13 -0
  5. package/dist/class-generation/index.d.ts.map +1 -1
  6. package/dist/class-generation/playwright-types.d.ts +256 -2
  7. package/dist/class-generation/playwright-types.d.ts.map +1 -1
  8. package/dist/compiler-metadata-utils.d.ts.map +1 -1
  9. package/dist/eslint/index.cjs +16 -3
  10. package/dist/eslint/index.cjs.map +1 -1
  11. package/dist/eslint/index.mjs +16 -3
  12. package/dist/eslint/index.mjs.map +1 -1
  13. package/dist/eslint/no-raw-playwright-apis.d.ts.map +1 -1
  14. package/dist/eslint.config.d.ts.map +1 -1
  15. package/dist/index.cjs +163 -49
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.mjs +163 -49
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/pom-patterns.d.ts +28 -4
  20. package/dist/pom-patterns.d.ts.map +1 -1
  21. package/dist/router-introspection.d.ts +5 -0
  22. package/dist/router-introspection.d.ts.map +1 -1
  23. package/dist/tests/annotator-runtime-helpers.test.d.ts +2 -0
  24. package/dist/tests/annotator-runtime-helpers.test.d.ts.map +1 -0
  25. package/dist/tests/broad/accessibility-audit-ts.test.d.ts +2 -0
  26. package/dist/tests/broad/accessibility-audit-ts.test.d.ts.map +1 -0
  27. package/dist/tests/broad/class-generation-base-page-ts.test.d.ts +2 -0
  28. package/dist/tests/broad/class-generation-base-page-ts.test.d.ts.map +1 -0
  29. package/dist/tests/broad/compiler-metadata-utils-ts.test.d.ts +2 -0
  30. package/dist/tests/broad/compiler-metadata-utils-ts.test.d.ts.map +1 -0
  31. package/dist/tests/broad/helpers/fake-runtime.d.ts +162 -0
  32. package/dist/tests/broad/helpers/fake-runtime.d.ts.map +1 -0
  33. package/dist/tests/broad/manifest-generator-ts.test.d.ts +2 -0
  34. package/dist/tests/broad/manifest-generator-ts.test.d.ts.map +1 -0
  35. package/dist/tests/broad/metadata-collector-ts.test.d.ts +2 -0
  36. package/dist/tests/broad/metadata-collector-ts.test.d.ts.map +1 -0
  37. package/dist/tests/broad/plugin-logger-ts.test.d.ts +2 -0
  38. package/dist/tests/broad/plugin-logger-ts.test.d.ts.map +1 -0
  39. package/dist/tests/broad/plugin-resolved-generation-options-ts.test.d.ts +2 -0
  40. package/dist/tests/broad/plugin-resolved-generation-options-ts.test.d.ts.map +1 -0
  41. package/dist/tests/broad/plugin-runtime-annotator-format-ts.test.d.ts +2 -0
  42. package/dist/tests/broad/plugin-runtime-annotator-format-ts.test.d.ts.map +1 -0
  43. package/dist/tests/broad/typescript-codegen-ts.test.d.ts +2 -0
  44. package/dist/tests/broad/typescript-codegen-ts.test.d.ts.map +1 -0
  45. package/dist/tests/helpers/typed-mocks.d.ts +58 -0
  46. package/dist/tests/helpers/typed-mocks.d.ts.map +1 -0
  47. package/dist/transform.d.ts +36 -5
  48. package/dist/transform.d.ts.map +1 -1
  49. package/dist/utils.d.ts +261 -2
  50. package/dist/utils.d.ts.map +1 -1
  51. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -431,25 +431,11 @@ function pomMethodSignatureEquals(left, right) {
431
431
  function isParameterizedPomPattern(kind) {
432
432
  return kind === "parameterized";
433
433
  }
434
- function getTemplateVariables(formatted) {
435
- const out = [];
436
- const seen = /* @__PURE__ */ new Set();
437
- const matches = formatted.matchAll(/\$\{(\w+)\}/g);
438
- for (const match of matches) {
439
- const variableName = match[1];
440
- if (seen.has(variableName)) {
441
- continue;
442
- }
443
- seen.add(variableName);
444
- out.push(variableName);
445
- }
446
- return out;
447
- }
448
- function createPomStringPattern(formatted, patternKind) {
434
+ function createPomStringPattern(formatted, patternKind, templateVariables) {
449
435
  return {
450
436
  formatted,
451
437
  patternKind,
452
- templateVariables: getTemplateVariables(formatted)
438
+ templateVariables: [...templateVariables]
453
439
  };
454
440
  }
455
441
  function getPomPatternVariables(patterns, options = {}) {
@@ -1175,6 +1161,9 @@ function upperFirst(value) {
1175
1161
  }
1176
1162
  return value.charAt(0).toUpperCase() + value.slice(1);
1177
1163
  }
1164
+ function collapseWhitespace(value) {
1165
+ return value.replace(/\s+/g, " ").trim();
1166
+ }
1178
1167
  function isAsciiUppercaseLetterCode(code) {
1179
1168
  return code >= 65 && code <= 90;
1180
1169
  }
@@ -2849,13 +2838,15 @@ function safeMethodNameFromParts(parts) {
2849
2838
  function toPomKeyPattern(templateValue) {
2850
2839
  const { templateLiteral } = templateValue.parsedTemplate;
2851
2840
  let out = "";
2841
+ let hasExpression = false;
2852
2842
  for (let i = 0; i < templateLiteral.quasis.length; i += 1) {
2853
2843
  out += templateLiteral.quasis[i]?.value.raw ?? "";
2854
2844
  if (templateLiteral.expressions[i]) {
2855
2845
  out += "${key}";
2846
+ hasExpression = true;
2856
2847
  }
2857
2848
  }
2858
- return out;
2849
+ return { formatted: out, templateVariables: hasExpression ? ["key"] : [] };
2859
2850
  }
2860
2851
  function applyResolvedDataTestId(args) {
2861
2852
  const addHtmlAttribute = args.addHtmlAttribute ?? true;
@@ -2979,9 +2970,11 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
2979
2970
  };
2980
2971
  const normalizedRole = normalizeNativeRole(args.nativeRole) ?? "button";
2981
2972
  const targetPageObjectModelClass = entryOverrides.targetPageObjectModelClass;
2982
- const formattedDataTestIdForPom = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId) : dataTestId.value;
2973
+ const pomKeyPattern = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId) : null;
2974
+ const formattedDataTestIdForPom = dataTestId.kind === "template" ? pomKeyPattern.formatted : dataTestId.value;
2983
2975
  const selectorPatternKind = dataTestId.kind === "template" ? "parameterized" : "static";
2984
- const selectorPattern = createPomStringPattern(formattedDataTestIdForPom, selectorPatternKind);
2976
+ const selectorTemplateVariables = dataTestId.kind === "template" ? pomKeyPattern.templateVariables : [];
2977
+ const selectorPattern = createPomStringPattern(formattedDataTestIdForPom, selectorPatternKind, selectorTemplateVariables);
2985
2978
  const selectorIsParameterized = selectorPatternKind === "parameterized";
2986
2979
  const deriveBaseMethodNameFromHint = (hint) => {
2987
2980
  const hintRaw = (hint ?? "").trim();
@@ -3259,7 +3252,8 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3259
3252
  const dataTestIdEntry = {
3260
3253
  selectorValue: entryOverrides.selectorValue ?? createPomStringPattern(
3261
3254
  getAttributeValueText(dataTestId),
3262
- dataTestId.kind === "template" ? "parameterized" : "static"
3255
+ dataTestId.kind === "template" ? "parameterized" : "static",
3256
+ selectorTemplateVariables
3263
3257
  ),
3264
3258
  templateLiteral: entryOverrides.templateLiteral,
3265
3259
  targetPageObjectModelClass: entryOverrides.targetPageObjectModelClass
@@ -3486,8 +3480,8 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3486
3480
  name: generatedName2,
3487
3481
  selector: {
3488
3482
  kind: "withinTestIdByLabel",
3489
- rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind),
3490
- label: createPomStringPattern(label, "static"),
3483
+ rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind, selectorTemplateVariables),
3484
+ label: createPomStringPattern(label, "static", []),
3491
3485
  exact: true
3492
3486
  },
3493
3487
  parameters: [createPomParameterSpec("annotationText", `string = ""`)]
@@ -3508,8 +3502,8 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3508
3502
  name: generatedName,
3509
3503
  selector: {
3510
3504
  kind: "withinTestIdByLabel",
3511
- rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind),
3512
- label: createPomStringPattern("${value}", "parameterized"),
3505
+ rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind, selectorTemplateVariables),
3506
+ label: createPomStringPattern("${value}", "parameterized", ["value"]),
3513
3507
  exact: true
3514
3508
  },
3515
3509
  parameters: [
@@ -4545,6 +4539,9 @@ async function introspectNuxtPages(projectRoot, options = {}) {
4545
4539
  routePathMap.set(pathTemplate, componentName);
4546
4540
  routeMetaEntries.push({
4547
4541
  componentName,
4542
+ // Nuxt file-based routes are named by convention, but the static walk does not
4543
+ // recover those names — leave null so callers fall back to path-template navigation.
4544
+ name: null,
4548
4545
  pathTemplate,
4549
4546
  params,
4550
4547
  query: []
@@ -4638,6 +4635,7 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
4638
4635
  if (typeof pathTemplate === "string" && pathTemplate.length) {
4639
4636
  routeMetaEntries.push({
4640
4637
  componentName,
4638
+ name: typeof r.name === "string" && r.name.length ? r.name : null,
4641
4639
  pathTemplate,
4642
4640
  params: paramsMeta,
4643
4641
  query: queryKeys
@@ -4784,19 +4782,31 @@ async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, opt
4784
4782
  const map = /* @__PURE__ */ new Map();
4785
4783
  for (const entry of routeMetaEntries) {
4786
4784
  const list = map.get(entry.componentName) ?? [];
4787
- list.push({ template: entry.pathTemplate });
4785
+ list.push({ name: entry.name, template: entry.pathTemplate, params: entry.params });
4788
4786
  map.set(entry.componentName, list);
4789
4787
  }
4790
- const chooseRouteMeta = (entries) => {
4788
+ const dedupeRoutes = (entries) => {
4789
+ const seen = /* @__PURE__ */ new Set();
4790
+ const unique = [];
4791
+ for (const entry of entries) {
4792
+ if (seen.has(entry.template))
4793
+ continue;
4794
+ seen.add(entry.template);
4795
+ unique.push(entry);
4796
+ }
4797
+ return unique;
4798
+ };
4799
+ const choosePrimaryTemplate = (entries) => {
4791
4800
  if (!entries.length)
4792
4801
  return null;
4793
- return entries.slice().sort((a, b) => a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
4802
+ return entries.slice().sort((a, b) => a.template.length - b.template.length || a.template.localeCompare(b.template))[0].template;
4794
4803
  };
4795
4804
  const sorted = Array.from(map.entries()).sort((a, b) => a[0].localeCompare(b[0]));
4796
4805
  return Object.fromEntries(
4797
- sorted.map(([componentName, entries]) => {
4798
- const chosen = chooseRouteMeta(entries);
4799
- return chosen ? [componentName, chosen] : null;
4806
+ sorted.map(([componentName, rawEntries]) => {
4807
+ const routes = dedupeRoutes(rawEntries);
4808
+ const primaryTemplate = choosePrimaryTemplate(routes);
4809
+ return primaryTemplate ? [componentName, { template: primaryTemplate, routes }] : null;
4800
4810
  }).filter((entry) => !!entry)
4801
4811
  );
4802
4812
  }
@@ -4811,27 +4821,131 @@ function generateRouteProperty(routeMeta) {
4811
4821
  })
4812
4822
  ];
4813
4823
  }
4814
- function generateGoToSelfMethod(componentName) {
4824
+ function buildParamTypeString(params) {
4825
+ return `{ ${params.map((p) => `${p.name}${p.optional ? "?" : ""}: string | number`).join("; ")} }`;
4826
+ }
4827
+ function chooseParamlessRoute(routes) {
4828
+ const paramless = routes.filter((r) => r.params.length === 0);
4829
+ if (!paramless.length)
4830
+ return null;
4831
+ return paramless.slice().sort((a, b) => a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
4832
+ }
4833
+ function chooseParametrizedRoute(routes) {
4834
+ const parametrized = routes.filter((r) => r.params.length > 0);
4835
+ if (!parametrized.length)
4836
+ return null;
4837
+ return parametrized.slice().sort((a, b) => a.params.length - b.params.length || a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
4838
+ }
4839
+ const GOTO_RUNTIME_LINES = [
4840
+ "const runtimeEnv = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;",
4841
+ "const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;",
4842
+ "const resolvedUrl = runtimeBaseUrl ? new URL(targetUrl, runtimeBaseUrl).toString() : targetUrl;",
4843
+ "await this.page.goto(resolvedUrl);"
4844
+ ];
4845
+ const ROUTER_GLOBAL_NAME = "__appRouter";
4846
+ const pushBlock = (routeNameExpr, paramsExpr, nullable) => {
4847
+ const routerType = `{ ${ROUTER_GLOBAL_NAME}?: { push: (to: { name: string; params: Record<string, unknown> }) => Promise<unknown>; resolve: (to: { name: string; params: Record<string, unknown> }) => { href: string } } }`;
4848
+ const routeParamsLine = paramsExpr === "undefined" ? "const routeParams = {};" : nullable ? `const routeParams = Object.fromEntries(Object.entries(${paramsExpr} ?? {}).filter(([, v]) => v !== undefined));` : `const routeParams = Object.fromEntries(Object.entries(${paramsExpr}).filter(([, v]) => v !== undefined));`;
4849
+ return [
4850
+ routeParamsLine,
4851
+ `const isCold = await this.page.evaluate(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} === "undefined");`,
4852
+ `if (isCold) {`,
4853
+ ` await this.page.goto("/", { waitUntil: "commit" });`,
4854
+ ` await this.page.waitForFunction(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} !== "undefined", { timeout: 15000 });`,
4855
+ ` const href = await this.page.evaluate(({ name, params }) => (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.resolve({ name, params })?.href, { name: ${routeNameExpr}, params: routeParams });`,
4856
+ ` if (href) { await this.page.goto(href, { waitUntil: "domcontentloaded" }); }`,
4857
+ `} else {`,
4858
+ ` await this.page.evaluate(async ({ name, params }) => {`,
4859
+ ` await (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.push({ name, params });`,
4860
+ ` }, { name: ${routeNameExpr}, params: routeParams });`,
4861
+ `}`
4862
+ ];
4863
+ };
4864
+ function generateGoToMethod(componentName, routeMeta) {
4865
+ if (!routeMeta) {
4866
+ return [
4867
+ createClassMethod({
4868
+ name: "goTo",
4869
+ isAsync: true,
4870
+ statements: [
4871
+ `throw new Error("[pom] No router path found for component/page-object '${componentName}'.");`
4872
+ ]
4873
+ })
4874
+ ];
4875
+ }
4876
+ const paramless = chooseParamlessRoute(routeMeta.routes);
4877
+ const parametrized = chooseParametrizedRoute(routeMeta.routes);
4878
+ const hasParamless = paramless !== null;
4879
+ const hasParametrized = parametrized !== null;
4880
+ if (!hasParamless && !hasParametrized) {
4881
+ return [
4882
+ createClassMethod({
4883
+ name: "goTo",
4884
+ isAsync: true,
4885
+ statements: [
4886
+ `throw new Error("[pom] No router path found for component/page-object '${componentName}'.");`
4887
+ ]
4888
+ })
4889
+ ];
4890
+ }
4891
+ const paramStatements = (entry) => {
4892
+ const lines = [];
4893
+ for (const param of entry.params) {
4894
+ const token = getParamToken(param.name);
4895
+ if (param.optional) {
4896
+ lines.push(`targetUrl = params.${param.name} === undefined ? targetUrl.replaceAll(${JSON.stringify(`/${token}`)}, "") : targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
4897
+ } else {
4898
+ lines.push(`targetUrl = targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
4899
+ }
4900
+ }
4901
+ return lines;
4902
+ };
4903
+ if (hasParamless && !hasParametrized) {
4904
+ const route = paramless;
4905
+ return [
4906
+ createClassMethod({
4907
+ name: "goTo",
4908
+ isAsync: true,
4909
+ statements: route.name !== null ? pushBlock(JSON.stringify(route.name), "undefined", false) : [`const targetUrl = ${JSON.stringify(route.template)};`, ...GOTO_RUNTIME_LINES]
4910
+ })
4911
+ ];
4912
+ }
4913
+ const paramType = buildParamTypeString(parametrized.params);
4914
+ if (hasParametrized && !hasParamless) {
4915
+ const route = parametrized;
4916
+ const allOptional = route.params.every((p) => p.optional);
4917
+ return [
4918
+ createClassMethod({
4919
+ name: "goTo",
4920
+ isAsync: true,
4921
+ parameters: [{ name: "params", type: paramType, hasQuestionToken: allOptional }],
4922
+ statements: route.name !== null ? pushBlock(JSON.stringify(route.name), "params", allOptional) : [`let targetUrl = ${JSON.stringify(route.template)};`, ...paramStatements(route), ...GOTO_RUNTIME_LINES]
4923
+ })
4924
+ ];
4925
+ }
4926
+ const paramlessRoute = paramless;
4927
+ const parametrizedRoute = parametrized;
4928
+ const usePush = paramlessRoute.name !== null && parametrizedRoute.name !== null;
4815
4929
  return [
4816
4930
  createClassMethod({
4817
4931
  name: "goTo",
4818
4932
  isAsync: true,
4819
- statements: [
4820
- "await this.goToSelf();"
4821
- ]
4822
- }),
4823
- createClassMethod({
4824
- name: "goToSelf",
4825
- isAsync: true,
4826
- statements: [
4827
- `const route = ${componentName}.route;`,
4828
- "if (!route) {",
4829
- ` throw new Error("[pom] No router path found for component/page-object '${componentName}'.");`,
4933
+ overloads: [
4934
+ { parameters: [], returnType: "Promise<void>" },
4935
+ { parameters: [{ name: "params", type: paramType }], returnType: "Promise<void>" }
4936
+ ],
4937
+ parameters: [{ name: "params", type: paramType, hasQuestionToken: true }],
4938
+ statements: usePush ? pushBlock(
4939
+ `params ? ${JSON.stringify(parametrizedRoute.name)} : ${JSON.stringify(paramlessRoute.name)}`,
4940
+ "params",
4941
+ true
4942
+ ) : [
4943
+ `const template = params ? ${JSON.stringify(parametrizedRoute.template)} : ${JSON.stringify(paramlessRoute.template)};`,
4944
+ "let targetUrl = template;",
4945
+ `if (params) {`,
4946
+ ...paramStatements(parametrizedRoute).map((line) => ` ${line}`),
4830
4947
  "}",
4831
- "const runtimeEnv = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;",
4832
- "const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;",
4833
- "const targetUrl = runtimeBaseUrl ? new URL(route.template, runtimeBaseUrl).toString() : route.template;",
4834
- "await this.page.goto(targetUrl);"
4948
+ ...GOTO_RUNTIME_LINES
4835
4949
  ]
4836
4950
  })
4837
4951
  ];
@@ -5875,7 +5989,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
5875
5989
  if (isView && options.vueRouterFluentChaining) {
5876
5990
  const routeMeta = options.routeMetaByComponent?.[componentName] ?? null;
5877
5991
  members.push(...generateRouteProperty(routeMeta));
5878
- members.push(...generateGoToSelfMethod(className));
5992
+ members.push(...generateGoToMethod(className, routeMeta));
5879
5993
  }
5880
5994
  members.push(...generateMethodsContentForDependencies(componentName, dependencies));
5881
5995
  return {
@@ -9094,7 +9208,7 @@ function collectStaticTextContent(children) {
9094
9208
  const visit = (nodes) => {
9095
9209
  for (const node of nodes) {
9096
9210
  if (node.type === NodeTypes.TEXT) {
9097
- const text2 = node.content.replace(/\s+/g, " ").trim();
9211
+ const text2 = collapseWhitespace(node.content);
9098
9212
  if (text2) {
9099
9213
  parts.push(text2);
9100
9214
  }
@@ -9106,7 +9220,7 @@ function collectStaticTextContent(children) {
9106
9220
  }
9107
9221
  };
9108
9222
  visit(children);
9109
- const text = parts.join(" ").replace(/\s+/g, " ").trim();
9223
+ const text = collapseWhitespace(parts.join(" "));
9110
9224
  return text || void 0;
9111
9225
  }
9112
9226
  function tryCreateElementMetadata(args) {