@immense/vue-pom-generator 1.0.84 → 1.0.86
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/RELEASE_NOTES.md +48 -52
- package/class-generation/base-page.ts +37 -10
- package/class-generation/index.ts +246 -28
- package/class-generation/playwright-types.ts +11 -3
- package/dist/class-generation/base-page.d.ts +24 -7
- package/dist/class-generation/base-page.d.ts.map +1 -1
- package/dist/class-generation/index.d.ts +13 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/class-generation/playwright-types.d.ts +9 -2
- package/dist/class-generation/playwright-types.d.ts.map +1 -1
- package/dist/eslint/index.cjs +16 -3
- package/dist/eslint/index.cjs.map +1 -1
- package/dist/eslint/index.mjs +16 -3
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/eslint/no-raw-playwright-apis.d.ts.map +1 -1
- package/dist/index.cjs +145 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +145 -25
- package/dist/index.mjs.map +1 -1
- package/dist/router-introspection.d.ts +5 -0
- package/dist/router-introspection.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4580,6 +4580,9 @@ async function introspectNuxtPages(projectRoot, options = {}) {
|
|
|
4580
4580
|
routePathMap.set(pathTemplate, componentName);
|
|
4581
4581
|
routeMetaEntries.push({
|
|
4582
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,
|
|
4583
4586
|
pathTemplate,
|
|
4584
4587
|
params,
|
|
4585
4588
|
query: []
|
|
@@ -4673,6 +4676,7 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
4673
4676
|
if (typeof pathTemplate === "string" && pathTemplate.length) {
|
|
4674
4677
|
routeMetaEntries.push({
|
|
4675
4678
|
componentName,
|
|
4679
|
+
name: typeof r.name === "string" && r.name.length ? r.name : null,
|
|
4676
4680
|
pathTemplate,
|
|
4677
4681
|
params: paramsMeta,
|
|
4678
4682
|
query: queryKeys
|
|
@@ -4819,19 +4823,31 @@ async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, opt
|
|
|
4819
4823
|
const map = /* @__PURE__ */ new Map();
|
|
4820
4824
|
for (const entry of routeMetaEntries) {
|
|
4821
4825
|
const list = map.get(entry.componentName) ?? [];
|
|
4822
|
-
list.push({ template: entry.pathTemplate });
|
|
4826
|
+
list.push({ name: entry.name, template: entry.pathTemplate, params: entry.params });
|
|
4823
4827
|
map.set(entry.componentName, list);
|
|
4824
4828
|
}
|
|
4825
|
-
const
|
|
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) => {
|
|
4826
4841
|
if (!entries.length)
|
|
4827
4842
|
return null;
|
|
4828
|
-
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;
|
|
4829
4844
|
};
|
|
4830
4845
|
const sorted = Array.from(map.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
4831
4846
|
return Object.fromEntries(
|
|
4832
|
-
sorted.map(([componentName,
|
|
4833
|
-
const
|
|
4834
|
-
|
|
4847
|
+
sorted.map(([componentName, rawEntries]) => {
|
|
4848
|
+
const routes = dedupeRoutes(rawEntries);
|
|
4849
|
+
const primaryTemplate = choosePrimaryTemplate(routes);
|
|
4850
|
+
return primaryTemplate ? [componentName, { template: primaryTemplate, routes }] : null;
|
|
4835
4851
|
}).filter((entry) => !!entry)
|
|
4836
4852
|
);
|
|
4837
4853
|
}
|
|
@@ -4846,27 +4862,131 @@ function generateRouteProperty(routeMeta) {
|
|
|
4846
4862
|
})
|
|
4847
4863
|
];
|
|
4848
4864
|
}
|
|
4849
|
-
function
|
|
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;
|
|
4850
4970
|
return [
|
|
4851
4971
|
createClassMethod({
|
|
4852
4972
|
name: "goTo",
|
|
4853
4973
|
isAsync: true,
|
|
4854
|
-
|
|
4855
|
-
"
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
`
|
|
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}`),
|
|
4865
4988
|
"}",
|
|
4866
|
-
|
|
4867
|
-
"const runtimeBaseUrl = runtimeEnv?.PLAYWRIGHT_RUNTIME_BASE_URL ?? runtimeEnv?.PLAYWRIGHT_TEST_BASE_URL ?? runtimeEnv?.VITE_PLAYWRIGHT_BASE_URL;",
|
|
4868
|
-
"const targetUrl = runtimeBaseUrl ? new URL(route.template, runtimeBaseUrl).toString() : route.template;",
|
|
4869
|
-
"await this.page.goto(targetUrl);"
|
|
4989
|
+
...GOTO_RUNTIME_LINES
|
|
4870
4990
|
]
|
|
4871
4991
|
})
|
|
4872
4992
|
];
|
|
@@ -5910,7 +6030,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
5910
6030
|
if (isView && options.vueRouterFluentChaining) {
|
|
5911
6031
|
const routeMeta = options.routeMetaByComponent?.[componentName] ?? null;
|
|
5912
6032
|
members.push(...generateRouteProperty(routeMeta));
|
|
5913
|
-
members.push(...
|
|
6033
|
+
members.push(...generateGoToMethod(className, routeMeta));
|
|
5914
6034
|
}
|
|
5915
6035
|
members.push(...generateMethodsContentForDependencies(componentName, dependencies));
|
|
5916
6036
|
return {
|
|
@@ -6755,10 +6875,10 @@ function getConstructor(childrenComponent, componentHierarchyMap, attachmentsFor
|
|
|
6755
6875
|
statements: (writer) => {
|
|
6756
6876
|
writer.writeLine(`super(page, { testIdAttribute: ${JSON.stringify(attr)} });`);
|
|
6757
6877
|
for (const a of attachmentsForThisView) {
|
|
6758
|
-
writer.writeLine(`this.${a.propertyName} = new ${a.className}(page, this);`);
|
|
6878
|
+
writer.writeLine(`this.${a.propertyName} = new ${a.className}(this.page, this);`);
|
|
6759
6879
|
}
|
|
6760
6880
|
for (const w of widgetInstances) {
|
|
6761
|
-
writer.writeLine(`this.${w.propertyName} = new ${w.className}(page, ${JSON.stringify(w.testId)});`);
|
|
6881
|
+
writer.writeLine(`this.${w.propertyName} = new ${w.className}(this.page, ${JSON.stringify(w.testId)});`);
|
|
6762
6882
|
}
|
|
6763
6883
|
childrenComponent.forEach((child) => {
|
|
6764
6884
|
if (componentHierarchyMap.has(child) && componentHierarchyMap.get(child)?.dataTestIdSet.size) {
|