@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.cjs CHANGED
@@ -472,25 +472,11 @@ function pomMethodSignatureEquals(left, right) {
472
472
  function isParameterizedPomPattern(kind) {
473
473
  return kind === "parameterized";
474
474
  }
475
- function getTemplateVariables(formatted) {
476
- const out = [];
477
- const seen = /* @__PURE__ */ new Set();
478
- const matches = formatted.matchAll(/\$\{(\w+)\}/g);
479
- for (const match of matches) {
480
- const variableName = match[1];
481
- if (seen.has(variableName)) {
482
- continue;
483
- }
484
- seen.add(variableName);
485
- out.push(variableName);
486
- }
487
- return out;
488
- }
489
- function createPomStringPattern(formatted, patternKind) {
475
+ function createPomStringPattern(formatted, patternKind, templateVariables) {
490
476
  return {
491
477
  formatted,
492
478
  patternKind,
493
- templateVariables: getTemplateVariables(formatted)
479
+ templateVariables: [...templateVariables]
494
480
  };
495
481
  }
496
482
  function getPomPatternVariables(patterns, options = {}) {
@@ -1216,6 +1202,9 @@ function upperFirst(value) {
1216
1202
  }
1217
1203
  return value.charAt(0).toUpperCase() + value.slice(1);
1218
1204
  }
1205
+ function collapseWhitespace(value) {
1206
+ return value.replace(/\s+/g, " ").trim();
1207
+ }
1219
1208
  function isAsciiUppercaseLetterCode(code) {
1220
1209
  return code >= 65 && code <= 90;
1221
1210
  }
@@ -2890,13 +2879,15 @@ function safeMethodNameFromParts(parts) {
2890
2879
  function toPomKeyPattern(templateValue) {
2891
2880
  const { templateLiteral } = templateValue.parsedTemplate;
2892
2881
  let out = "";
2882
+ let hasExpression = false;
2893
2883
  for (let i = 0; i < templateLiteral.quasis.length; i += 1) {
2894
2884
  out += templateLiteral.quasis[i]?.value.raw ?? "";
2895
2885
  if (templateLiteral.expressions[i]) {
2896
2886
  out += "${key}";
2887
+ hasExpression = true;
2897
2888
  }
2898
2889
  }
2899
- return out;
2890
+ return { formatted: out, templateVariables: hasExpression ? ["key"] : [] };
2900
2891
  }
2901
2892
  function applyResolvedDataTestId(args) {
2902
2893
  const addHtmlAttribute = args.addHtmlAttribute ?? true;
@@ -3020,9 +3011,11 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3020
3011
  };
3021
3012
  const normalizedRole = normalizeNativeRole(args.nativeRole) ?? "button";
3022
3013
  const targetPageObjectModelClass = entryOverrides.targetPageObjectModelClass;
3023
- const formattedDataTestIdForPom = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId) : dataTestId.value;
3014
+ const pomKeyPattern = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId) : null;
3015
+ const formattedDataTestIdForPom = dataTestId.kind === "template" ? pomKeyPattern.formatted : dataTestId.value;
3024
3016
  const selectorPatternKind = dataTestId.kind === "template" ? "parameterized" : "static";
3025
- const selectorPattern = createPomStringPattern(formattedDataTestIdForPom, selectorPatternKind);
3017
+ const selectorTemplateVariables = dataTestId.kind === "template" ? pomKeyPattern.templateVariables : [];
3018
+ const selectorPattern = createPomStringPattern(formattedDataTestIdForPom, selectorPatternKind, selectorTemplateVariables);
3026
3019
  const selectorIsParameterized = selectorPatternKind === "parameterized";
3027
3020
  const deriveBaseMethodNameFromHint = (hint) => {
3028
3021
  const hintRaw = (hint ?? "").trim();
@@ -3300,7 +3293,8 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3300
3293
  const dataTestIdEntry = {
3301
3294
  selectorValue: entryOverrides.selectorValue ?? createPomStringPattern(
3302
3295
  getAttributeValueText(dataTestId),
3303
- dataTestId.kind === "template" ? "parameterized" : "static"
3296
+ dataTestId.kind === "template" ? "parameterized" : "static",
3297
+ selectorTemplateVariables
3304
3298
  ),
3305
3299
  templateLiteral: entryOverrides.templateLiteral,
3306
3300
  targetPageObjectModelClass: entryOverrides.targetPageObjectModelClass
@@ -3527,8 +3521,8 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3527
3521
  name: generatedName2,
3528
3522
  selector: {
3529
3523
  kind: "withinTestIdByLabel",
3530
- rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind),
3531
- label: createPomStringPattern(label, "static"),
3524
+ rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind, selectorTemplateVariables),
3525
+ label: createPomStringPattern(label, "static", []),
3532
3526
  exact: true
3533
3527
  },
3534
3528
  parameters: [createPomParameterSpec("annotationText", `string = ""`)]
@@ -3549,8 +3543,8 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3549
3543
  name: generatedName,
3550
3544
  selector: {
3551
3545
  kind: "withinTestIdByLabel",
3552
- rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind),
3553
- label: createPomStringPattern("${value}", "parameterized"),
3546
+ rootTestId: createPomStringPattern(wrapperTestId, selectorPatternKind, selectorTemplateVariables),
3547
+ label: createPomStringPattern("${value}", "parameterized", ["value"]),
3554
3548
  exact: true
3555
3549
  },
3556
3550
  parameters: [
@@ -4586,6 +4580,9 @@ async function introspectNuxtPages(projectRoot, options = {}) {
4586
4580
  routePathMap.set(pathTemplate, componentName);
4587
4581
  routeMetaEntries.push({
4588
4582
  componentName,
4583
+ // Nuxt file-based routes are named by convention, but the static walk does not
4584
+ // recover those names — leave null so callers fall back to path-template navigation.
4585
+ name: null,
4589
4586
  pathTemplate,
4590
4587
  params,
4591
4588
  query: []
@@ -4679,6 +4676,7 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
4679
4676
  if (typeof pathTemplate === "string" && pathTemplate.length) {
4680
4677
  routeMetaEntries.push({
4681
4678
  componentName,
4679
+ name: typeof r.name === "string" && r.name.length ? r.name : null,
4682
4680
  pathTemplate,
4683
4681
  params: paramsMeta,
4684
4682
  query: queryKeys
@@ -4825,19 +4823,31 @@ async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, opt
4825
4823
  const map = /* @__PURE__ */ new Map();
4826
4824
  for (const entry of routeMetaEntries) {
4827
4825
  const list = map.get(entry.componentName) ?? [];
4828
- list.push({ template: entry.pathTemplate });
4826
+ list.push({ name: entry.name, template: entry.pathTemplate, params: entry.params });
4829
4827
  map.set(entry.componentName, list);
4830
4828
  }
4831
- const chooseRouteMeta = (entries) => {
4829
+ const dedupeRoutes = (entries) => {
4830
+ const seen = /* @__PURE__ */ new Set();
4831
+ const unique = [];
4832
+ for (const entry of entries) {
4833
+ if (seen.has(entry.template))
4834
+ continue;
4835
+ seen.add(entry.template);
4836
+ unique.push(entry);
4837
+ }
4838
+ return unique;
4839
+ };
4840
+ const choosePrimaryTemplate = (entries) => {
4832
4841
  if (!entries.length)
4833
4842
  return null;
4834
- return entries.slice().sort((a, b) => a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
4843
+ return entries.slice().sort((a, b) => a.template.length - b.template.length || a.template.localeCompare(b.template))[0].template;
4835
4844
  };
4836
4845
  const sorted = Array.from(map.entries()).sort((a, b) => a[0].localeCompare(b[0]));
4837
4846
  return Object.fromEntries(
4838
- sorted.map(([componentName, entries]) => {
4839
- const chosen = chooseRouteMeta(entries);
4840
- return chosen ? [componentName, chosen] : null;
4847
+ sorted.map(([componentName, rawEntries]) => {
4848
+ const routes = dedupeRoutes(rawEntries);
4849
+ const primaryTemplate = choosePrimaryTemplate(routes);
4850
+ return primaryTemplate ? [componentName, { template: primaryTemplate, routes }] : null;
4841
4851
  }).filter((entry) => !!entry)
4842
4852
  );
4843
4853
  }
@@ -4852,27 +4862,131 @@ function generateRouteProperty(routeMeta) {
4852
4862
  })
4853
4863
  ];
4854
4864
  }
4855
- function generateGoToSelfMethod(componentName) {
4865
+ function buildParamTypeString(params) {
4866
+ return `{ ${params.map((p) => `${p.name}${p.optional ? "?" : ""}: string | number`).join("; ")} }`;
4867
+ }
4868
+ function chooseParamlessRoute(routes) {
4869
+ const paramless = routes.filter((r) => r.params.length === 0);
4870
+ if (!paramless.length)
4871
+ return null;
4872
+ return paramless.slice().sort((a, b) => a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
4873
+ }
4874
+ function chooseParametrizedRoute(routes) {
4875
+ const parametrized = routes.filter((r) => r.params.length > 0);
4876
+ if (!parametrized.length)
4877
+ return null;
4878
+ return parametrized.slice().sort((a, b) => a.params.length - b.params.length || a.template.length - b.template.length || a.template.localeCompare(b.template))[0];
4879
+ }
4880
+ const GOTO_RUNTIME_LINES = [
4881
+ "const runtimeEnv = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;",
4882
+ "const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;",
4883
+ "const resolvedUrl = runtimeBaseUrl ? new URL(targetUrl, runtimeBaseUrl).toString() : targetUrl;",
4884
+ "await this.page.goto(resolvedUrl);"
4885
+ ];
4886
+ const ROUTER_GLOBAL_NAME = "__appRouter";
4887
+ const pushBlock = (routeNameExpr, paramsExpr, nullable) => {
4888
+ 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 } } }`;
4889
+ 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));`;
4890
+ return [
4891
+ routeParamsLine,
4892
+ `const isCold = await this.page.evaluate(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} === "undefined");`,
4893
+ `if (isCold) {`,
4894
+ ` await this.page.goto("/", { waitUntil: "commit" });`,
4895
+ ` await this.page.waitForFunction(() => typeof (globalThis as { ${ROUTER_GLOBAL_NAME}?: unknown }).${ROUTER_GLOBAL_NAME} !== "undefined", { timeout: 15000 });`,
4896
+ ` const href = await this.page.evaluate(({ name, params }) => (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.resolve({ name, params })?.href, { name: ${routeNameExpr}, params: routeParams });`,
4897
+ ` if (href) { await this.page.goto(href, { waitUntil: "domcontentloaded" }); }`,
4898
+ `} else {`,
4899
+ ` await this.page.evaluate(async ({ name, params }) => {`,
4900
+ ` await (globalThis as ${routerType}).${ROUTER_GLOBAL_NAME}?.push({ name, params });`,
4901
+ ` }, { name: ${routeNameExpr}, params: routeParams });`,
4902
+ `}`
4903
+ ];
4904
+ };
4905
+ function generateGoToMethod(componentName, routeMeta) {
4906
+ if (!routeMeta) {
4907
+ return [
4908
+ createClassMethod({
4909
+ name: "goTo",
4910
+ isAsync: true,
4911
+ statements: [
4912
+ `throw new Error("[pom] No router path found for component/page-object '${componentName}'.");`
4913
+ ]
4914
+ })
4915
+ ];
4916
+ }
4917
+ const paramless = chooseParamlessRoute(routeMeta.routes);
4918
+ const parametrized = chooseParametrizedRoute(routeMeta.routes);
4919
+ const hasParamless = paramless !== null;
4920
+ const hasParametrized = parametrized !== null;
4921
+ if (!hasParamless && !hasParametrized) {
4922
+ return [
4923
+ createClassMethod({
4924
+ name: "goTo",
4925
+ isAsync: true,
4926
+ statements: [
4927
+ `throw new Error("[pom] No router path found for component/page-object '${componentName}'.");`
4928
+ ]
4929
+ })
4930
+ ];
4931
+ }
4932
+ const paramStatements = (entry) => {
4933
+ const lines = [];
4934
+ for (const param of entry.params) {
4935
+ const token = getParamToken(param.name);
4936
+ if (param.optional) {
4937
+ lines.push(`targetUrl = params.${param.name} === undefined ? targetUrl.replaceAll(${JSON.stringify(`/${token}`)}, "") : targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
4938
+ } else {
4939
+ lines.push(`targetUrl = targetUrl.replaceAll(${JSON.stringify(token)}, String(params.${param.name}));`);
4940
+ }
4941
+ }
4942
+ return lines;
4943
+ };
4944
+ if (hasParamless && !hasParametrized) {
4945
+ const route = paramless;
4946
+ return [
4947
+ createClassMethod({
4948
+ name: "goTo",
4949
+ isAsync: true,
4950
+ statements: route.name !== null ? pushBlock(JSON.stringify(route.name), "undefined", false) : [`const targetUrl = ${JSON.stringify(route.template)};`, ...GOTO_RUNTIME_LINES]
4951
+ })
4952
+ ];
4953
+ }
4954
+ const paramType = buildParamTypeString(parametrized.params);
4955
+ if (hasParametrized && !hasParamless) {
4956
+ const route = parametrized;
4957
+ const allOptional = route.params.every((p) => p.optional);
4958
+ return [
4959
+ createClassMethod({
4960
+ name: "goTo",
4961
+ isAsync: true,
4962
+ parameters: [{ name: "params", type: paramType, hasQuestionToken: allOptional }],
4963
+ statements: route.name !== null ? pushBlock(JSON.stringify(route.name), "params", allOptional) : [`let targetUrl = ${JSON.stringify(route.template)};`, ...paramStatements(route), ...GOTO_RUNTIME_LINES]
4964
+ })
4965
+ ];
4966
+ }
4967
+ const paramlessRoute = paramless;
4968
+ const parametrizedRoute = parametrized;
4969
+ const usePush = paramlessRoute.name !== null && parametrizedRoute.name !== null;
4856
4970
  return [
4857
4971
  createClassMethod({
4858
4972
  name: "goTo",
4859
4973
  isAsync: true,
4860
- statements: [
4861
- "await this.goToSelf();"
4862
- ]
4863
- }),
4864
- createClassMethod({
4865
- name: "goToSelf",
4866
- isAsync: true,
4867
- statements: [
4868
- `const route = ${componentName}.route;`,
4869
- "if (!route) {",
4870
- ` throw new Error("[pom] No router path found for component/page-object '${componentName}'.");`,
4974
+ overloads: [
4975
+ { parameters: [], returnType: "Promise<void>" },
4976
+ { parameters: [{ name: "params", type: paramType }], returnType: "Promise<void>" }
4977
+ ],
4978
+ parameters: [{ name: "params", type: paramType, hasQuestionToken: true }],
4979
+ statements: usePush ? pushBlock(
4980
+ `params ? ${JSON.stringify(parametrizedRoute.name)} : ${JSON.stringify(paramlessRoute.name)}`,
4981
+ "params",
4982
+ true
4983
+ ) : [
4984
+ `const template = params ? ${JSON.stringify(parametrizedRoute.template)} : ${JSON.stringify(paramlessRoute.template)};`,
4985
+ "let targetUrl = template;",
4986
+ `if (params) {`,
4987
+ ...paramStatements(parametrizedRoute).map((line) => ` ${line}`),
4871
4988
  "}",
4872
- "const runtimeEnv = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;",
4873
- "const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;",
4874
- "const targetUrl = runtimeBaseUrl ? new URL(route.template, runtimeBaseUrl).toString() : route.template;",
4875
- "await this.page.goto(targetUrl);"
4989
+ ...GOTO_RUNTIME_LINES
4876
4990
  ]
4877
4991
  })
4878
4992
  ];
@@ -5916,7 +6030,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
5916
6030
  if (isView && options.vueRouterFluentChaining) {
5917
6031
  const routeMeta = options.routeMetaByComponent?.[componentName] ?? null;
5918
6032
  members.push(...generateRouteProperty(routeMeta));
5919
- members.push(...generateGoToSelfMethod(className));
6033
+ members.push(...generateGoToMethod(className, routeMeta));
5920
6034
  }
5921
6035
  members.push(...generateMethodsContentForDependencies(componentName, dependencies));
5922
6036
  return {
@@ -9135,7 +9249,7 @@ function collectStaticTextContent(children) {
9135
9249
  const visit = (nodes) => {
9136
9250
  for (const node of nodes) {
9137
9251
  if (node.type === compilerCore.NodeTypes.TEXT) {
9138
- const text2 = node.content.replace(/\s+/g, " ").trim();
9252
+ const text2 = collapseWhitespace(node.content);
9139
9253
  if (text2) {
9140
9254
  parts.push(text2);
9141
9255
  }
@@ -9147,7 +9261,7 @@ function collectStaticTextContent(children) {
9147
9261
  }
9148
9262
  };
9149
9263
  visit(children);
9150
- const text = parts.join(" ").replace(/\s+/g, " ").trim();
9264
+ const text = collapseWhitespace(parts.join(" "));
9151
9265
  return text || void 0;
9152
9266
  }
9153
9267
  function tryCreateElementMetadata(args) {