@immense/vue-pom-generator 1.0.118 → 1.0.120
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/README.md +111 -2
- package/RELEASE_NOTES.md +29 -27
- package/class-generation/index.ts +136 -76
- package/dist/class-generation/index.d.ts +7 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +313 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +313 -171
- package/dist/index.mjs.map +1 -1
- package/dist/manifest-generator.d.ts +18 -0
- package/dist/manifest-generator.d.ts.map +1 -1
- package/dist/plugin/create-vue-pom-generator-plugins.d.ts.map +1 -1
- package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
- package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
- package/dist/plugin/path-utils.d.ts +1 -0
- package/dist/plugin/path-utils.d.ts.map +1 -1
- package/dist/plugin/resolved-generation-options.d.ts +2 -0
- package/dist/plugin/resolved-generation-options.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +14 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/router-introspection.d.ts +10 -1
- package/dist/router-introspection.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -488,6 +488,7 @@ Optional Playwright fixture output:
|
|
|
488
488
|
|
|
489
489
|
- `fixtures.g.ts` next to the POMs by default
|
|
490
490
|
- `pom-manifest.g.ts` — a Node-importable map from Vue source/test ids to generated methods
|
|
491
|
+
- `component-graph.json` — component usage and route edges, when `generation.playwright.componentGraph` is on (see [Component usage graph](#component-usage-graph-component-graphjson))
|
|
491
492
|
- or a custom directory / file path when configured
|
|
492
493
|
|
|
493
494
|
Optional C# output:
|
|
@@ -667,6 +668,46 @@ What it is not:
|
|
|
667
668
|
- a magic auto-discovery system that wires every helper into every page
|
|
668
669
|
- a replacement for `attachments`
|
|
669
670
|
|
|
671
|
+
### Registering custom POMs as fixtures (`customPoms.fixtures`)
|
|
672
|
+
|
|
673
|
+
Handwritten page-level POMs can be injected like generated ones. List their class names in `customPoms.fixtures`:
|
|
674
|
+
|
|
675
|
+
```ts
|
|
676
|
+
generation: {
|
|
677
|
+
playwright: {
|
|
678
|
+
fixtures: true,
|
|
679
|
+
customPoms: {
|
|
680
|
+
dir: "tests/playwright/pom/custom",
|
|
681
|
+
fixtures: ["SettingsPanel"],
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
```ts
|
|
688
|
+
// tests/playwright/pom/custom/SettingsPanel.ts
|
|
689
|
+
import type { Page } from "@playwright/test";
|
|
690
|
+
|
|
691
|
+
export class SettingsPanel {
|
|
692
|
+
constructor(private readonly page: Page) {}
|
|
693
|
+
|
|
694
|
+
async open() {
|
|
695
|
+
await this.page.getByRole("button", { name: "Settings" }).click();
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// any spec
|
|
700
|
+
test("opens settings", async ({ settingsPanel }) => {
|
|
701
|
+
await settingsPanel.open();
|
|
702
|
+
});
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
- each listed class must live in `<dir>/<ClassName>.ts` and be constructible as `new ClassName(page)`
|
|
706
|
+
- the fixture name follows the generated convention (`SettingsPanel` → `settingsPanel`), with the same per-test lifecycle
|
|
707
|
+
- the fixture is typed on `PomFixtures` (and `CustomPomFixtures`), so specs get autocomplete
|
|
708
|
+
- generation fails when a listed class has no file, is listed twice, when its fixture name collides with a generated or built-in fixture, or when `fixtures` is disabled
|
|
709
|
+
- helpers that are not listed (for example attachment helpers) are not registered
|
|
710
|
+
|
|
670
711
|
### `pom/overrides`
|
|
671
712
|
|
|
672
713
|
Default convention: sibling `overrides/` next to `customPoms.dir`
|
|
@@ -995,13 +1036,14 @@ export { expect };
|
|
|
995
1036
|
```
|
|
996
1037
|
|
|
997
1038
|
The module also exports the fixture types (`PomFixtures`, `GeneratedPageFixtures`,
|
|
998
|
-
`GeneratedComponentFixtures`, `PlaywrightOptions`, `PomFactory
|
|
999
|
-
for convenience.
|
|
1039
|
+
`GeneratedComponentFixtures`, `PlaywrightOptions`, `PomFactory`, plus `CustomPomFixtures`
|
|
1040
|
+
when `customPoms.fixtures` is set) and re-exports `expect` for convenience.
|
|
1000
1041
|
|
|
1001
1042
|
What it gives you:
|
|
1002
1043
|
|
|
1003
1044
|
- lower-camel-case fixtures for views (`UserListPage` → `userListPage`)
|
|
1004
1045
|
- lower-camel-case fixtures for component classes too
|
|
1046
|
+
- lower-camel-case fixtures for handwritten classes listed in `customPoms.fixtures`
|
|
1005
1047
|
- `pomFactory.create(Ctor)` for ad-hoc page-object construction inside tests
|
|
1006
1048
|
- an `animation` option that wires the generated runtime's pointer settings
|
|
1007
1049
|
- per-page `renderers` overrides so you can keep the simple default callout or swap in a custom pointer / callout overlay implementation such as the bundled `floating-ui-callout.ts` renderer
|
|
@@ -1135,6 +1177,64 @@ What it contains:
|
|
|
1135
1177
|
- for each component: source file, whether it is a view or component, sorted test ids, and rich entry metadata
|
|
1136
1178
|
- for each entry: test id, semantic name, inferred role, generated property name, generated action names, collected compiler metadata when available, and accessibility review metadata when available
|
|
1137
1179
|
|
|
1180
|
+
## Component usage graph (`component-graph.json`)
|
|
1181
|
+
|
|
1182
|
+
The manifest says what each component contains, not where it is used. Set `generation.playwright.componentGraph: true` (with `fixtures` on) to also write `component-graph.json` next to `pom-manifest.g.ts`. It holds the usage edges, so tools can work out which routes reach a component.
|
|
1183
|
+
|
|
1184
|
+
Schema (`version: 1`):
|
|
1185
|
+
|
|
1186
|
+
- `components` — keyed by source file, relative to the project root, with `/` separators
|
|
1187
|
+
- `name` — the generated component/class name (the key in `pom-manifest.g.ts`)
|
|
1188
|
+
- `uses` — source files of the project components this template uses. Tags resolve the same way as for POM generation (component name or file basename; kebab-case tags included). Tags that are not project components, such as built-ins and library components, are left out.
|
|
1189
|
+
- `routes` — one entry per route record from router introspection; empty when no router is configured
|
|
1190
|
+
- `path` — the path pattern as declared (`/users/:id`)
|
|
1191
|
+
- `name` — the route name, or `null`
|
|
1192
|
+
- `components` — source files the route renders: parent route components first, then the route's own components, named views included. Nuxt pages list their page file.
|
|
1193
|
+
|
|
1194
|
+
Keys and lists are sorted, so the file diffs cleanly. The `ComponentGraph` type is exported from the package.
|
|
1195
|
+
|
|
1196
|
+
```json
|
|
1197
|
+
{
|
|
1198
|
+
"version": 1,
|
|
1199
|
+
"components": {
|
|
1200
|
+
"src/components/NavBar.vue": { "name": "NavBar", "uses": ["src/components/users/UserAvatar.vue"] },
|
|
1201
|
+
"src/components/users/UserAvatar.vue": { "name": "UsersUserAvatar", "uses": [] },
|
|
1202
|
+
"src/layouts/AppShell.vue": { "name": "AppShell", "uses": ["src/components/NavBar.vue"] },
|
|
1203
|
+
"src/views/UserDetail.vue": { "name": "UserDetail", "uses": [] }
|
|
1204
|
+
},
|
|
1205
|
+
"routes": [
|
|
1206
|
+
{ "path": "/users", "name": null, "components": ["src/layouts/AppShell.vue"] },
|
|
1207
|
+
{ "path": "/users/:id", "name": "user-detail", "components": ["src/layouts/AppShell.vue", "src/views/UserDetail.vue"] }
|
|
1208
|
+
]
|
|
1209
|
+
}
|
|
1210
|
+
```
|
|
1211
|
+
|
|
1212
|
+
Routes that reach a component:
|
|
1213
|
+
|
|
1214
|
+
```ts
|
|
1215
|
+
import fs from "node:fs";
|
|
1216
|
+
import type { ComponentGraph } from "@immense/vue-pom-generator";
|
|
1217
|
+
|
|
1218
|
+
const graph: ComponentGraph = JSON.parse(fs.readFileSync("tests/playwright/__generated__/component-graph.json", "utf8"));
|
|
1219
|
+
|
|
1220
|
+
function routesReaching(file: string) {
|
|
1221
|
+
return graph.routes.filter((route) => {
|
|
1222
|
+
const seen = new Set<string>();
|
|
1223
|
+
const visit = (current: string): boolean => {
|
|
1224
|
+
if (current === file) return true;
|
|
1225
|
+
if (seen.has(current)) return false;
|
|
1226
|
+
seen.add(current);
|
|
1227
|
+
return (graph.components[current]?.uses ?? []).some(visit);
|
|
1228
|
+
};
|
|
1229
|
+
return route.components.some(visit);
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
routesReaching("src/components/users/UserAvatar.vue"); // both /users routes
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
Unnamed routes are placed in the route tree by resolving their own path pattern. Generation fails with an error if that pattern does not match itself (for example `/items/:id(\\d+)`). Name the route to fix it.
|
|
1237
|
+
|
|
1138
1238
|
## ESLint rules that actually ship
|
|
1139
1239
|
|
|
1140
1240
|
The package exports `@immense/vue-pom-generator/eslint`.
|
|
@@ -1545,6 +1645,15 @@ This object holds Playwright-specific additions on top of the generated TypeScri
|
|
|
1545
1645
|
- `"path"` — if the string ends in `.ts` / `.tsx` / `.mts` / `.cts`, it is treated as a file path; otherwise as an output directory
|
|
1546
1646
|
- `{ outDir }` — emit to a custom directory
|
|
1547
1647
|
|
|
1648
|
+
#### `generation.playwright.componentGraph`
|
|
1649
|
+
|
|
1650
|
+
- **What it does:** Writes `component-graph.json` next to `pom-manifest.g.ts`: what each component uses and what each route renders.
|
|
1651
|
+
- **Why it exists:** the manifest has no usage edges, so tools cannot tell which routes reach a component.
|
|
1652
|
+
- **Benefit:** one deterministic file that maps components and routes to source files.
|
|
1653
|
+
- **Without it:** no graph file is written. Other outputs are the same either way.
|
|
1654
|
+
- **Requires:** `generation.playwright.fixtures`. Routes need `generation.router` (or Nuxt).
|
|
1655
|
+
- **Schema:** see [Component usage graph](#component-usage-graph-component-graphjson).
|
|
1656
|
+
|
|
1548
1657
|
#### `generation.playwright.outputStructure`
|
|
1549
1658
|
|
|
1550
1659
|
- **What it does:** Chooses whether generated TypeScript POMs are emitted as one aggregate or split per class.
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
|
+
Range confirmed: exactly one commit (#87). Let me check the README additions for accurate option
|
|
2
|
+
details.
|
|
3
|
+
|
|
1
4
|
Highlights
|
|
2
5
|
|
|
3
|
-
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
6
|
+
- New opt-in component usage graph: set generation.playwright.componentGraph: true to emit
|
|
7
|
+
component-graph.json next to pom-manifest.g.ts
|
|
8
|
+
- The manifest describes what each component contains; the graph adds the usage edges so tools can
|
|
9
|
+
determine which routes reach a component
|
|
10
|
+
- components are keyed by project-relative source file with the generated name and the project
|
|
11
|
+
components each template uses; routes list path pattern, name, and rendered source files (parent
|
|
12
|
+
route components first, named views included; Nuxt pages list their page file)
|
|
13
|
+
- Keys and lists are sorted, so the file diffs cleanly; output is byte-identical when the option is
|
|
14
|
+
off
|
|
15
|
+
- Generation fails fast if the option is enabled without fixtures, or if an unnamed route's pattern
|
|
16
|
+
can't be resolved into the route tree
|
|
8
17
|
|
|
9
18
|
Changes
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Tests
|
|
24
|
-
|
|
25
|
-
- Added base-page tests covering default-renderer resolution in generated pages
|
|
26
|
-
(tests/base-page.test.ts)
|
|
20
|
+
- Manifest
|
|
21
|
+
- Emit component-graph.json (schema version: 1) when generation.playwright.componentGraph is on
|
|
22
|
+
with fixtures enabled, in both dev and build generation paths
|
|
23
|
+
- Export the ComponentGraph type from the package
|
|
24
|
+
- Shared internals
|
|
25
|
+
- Move the tag resolver used by class generation into manifest-generator.ts so both share it;
|
|
26
|
+
graph tags resolve with the same toPascalCase normalization as POM generation
|
|
27
|
+
- Nuxt route entries list componentFiles only when collectComponentFiles is on, matching the
|
|
28
|
+
vue-router branch
|
|
29
|
+
- Docs
|
|
30
|
+
- README: document the new option and component-graph.json schema with examples for tracing routes
|
|
31
|
+
that reach a component
|
|
27
32
|
|
|
28
33
|
Pull Requests Included
|
|
29
34
|
|
|
30
|
-
- ]8;id=md-
|
|
31
|
-
|
|
32
|
-
Only #85 falls within the v1.0.117..HEAD compare range (5 files, +109/−4); other PRs in the merge
|
|
33
|
-
window were already shipped in prior releases.
|
|
35
|
+
- ]8;id=md-1bbrzn7;https://github.com/immense/vue-pom-generator/pull/87#87 — feat(manifest): emit a component usage graph as JSON]8;;]8;; (@dkattan)]8;;
|
|
34
36
|
|
|
35
37
|
Testing
|
|
36
38
|
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
+
- Added coverage in tests/generate-vue-poms.test.ts and tests/router-introspection.test.ts for
|
|
40
|
+
graph emission, tag resolution, and route-tree handling.
|
|
39
41
|
|
|
@@ -9,7 +9,7 @@ import path from "node:path";
|
|
|
9
9
|
import process from "node:process";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { generateViewObjectModelMembers, generateViewObjectModelMethodContent } from "../method-generation";
|
|
12
|
-
import { generatePomManifestModule } from "../manifest-generator";
|
|
12
|
+
import { generateComponentGraphJson, generatePomManifestModule, normalizeTrackedComponentRef, resolveTrackedComponentRef } from "../manifest-generator";
|
|
13
13
|
import type { ElementMetadata } from "../metadata-collector";
|
|
14
14
|
import { writeGeneratedOutputs, type GeneratedFileOutput } from "../plugin/generated-outputs";
|
|
15
15
|
import {
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
type PomStringPattern,
|
|
33
33
|
} from "../pom-patterns";
|
|
34
34
|
import { buildPomLocatorDescription, stripPomActionPrefix } from "../pom-discoverability";
|
|
35
|
+
import type { RouterIntrospectionResult } from "../router-introspection";
|
|
35
36
|
import { introspectNuxtPages, parseRouterFileFromCwd } from "../router-introspection";
|
|
36
37
|
import {
|
|
37
38
|
addNamedImport,
|
|
@@ -279,7 +280,7 @@ function resolveVueSourcePath(
|
|
|
279
280
|
return candidates.find(candidate => fs.existsSync(candidate));
|
|
280
281
|
}
|
|
281
282
|
|
|
282
|
-
async function
|
|
283
|
+
async function introspectRouteMetaEntries(
|
|
283
284
|
projectRoot?: string,
|
|
284
285
|
routerEntry?: string,
|
|
285
286
|
routerType?: "vue-router" | "nuxt",
|
|
@@ -287,8 +288,9 @@ async function getRouteMetaByComponent(
|
|
|
287
288
|
pageDirs?: string[];
|
|
288
289
|
componentDirs?: string[];
|
|
289
290
|
layoutDirs?: string[];
|
|
291
|
+
collectComponentFiles?: boolean;
|
|
290
292
|
} = {},
|
|
291
|
-
): Promise<
|
|
293
|
+
): Promise<RouterIntrospectionResult["routeMetaEntries"]> {
|
|
292
294
|
const root = projectRoot ?? process.cwd();
|
|
293
295
|
const pageDirs = options.pageDirs?.length ? options.pageDirs : ["src/views"];
|
|
294
296
|
const pageDirsAbs = pageDirs.map(dir => path.isAbsolute(dir) ? dir : path.resolve(root, dir));
|
|
@@ -301,7 +303,7 @@ async function getRouteMetaByComponent(
|
|
|
301
303
|
const extraRoots = process.cwd() !== root ? [process.cwd()] : [];
|
|
302
304
|
|
|
303
305
|
const { routeMetaEntries } = routerType === "nuxt"
|
|
304
|
-
? await introspectNuxtPages(root, { pageDirs: pageDirsAbs })
|
|
306
|
+
? await introspectNuxtPages(root, { pageDirs: pageDirsAbs, collectComponentFiles: options.collectComponentFiles })
|
|
305
307
|
: await parseRouterFileFromCwd(resolveRouterEntry(root, routerEntry), {
|
|
306
308
|
componentNaming: {
|
|
307
309
|
projectRoot: root,
|
|
@@ -309,8 +311,12 @@ async function getRouteMetaByComponent(
|
|
|
309
311
|
sourceDirs,
|
|
310
312
|
extraRoots,
|
|
311
313
|
},
|
|
314
|
+
collectComponentFiles: options.collectComponentFiles,
|
|
312
315
|
});
|
|
316
|
+
return routeMetaEntries;
|
|
317
|
+
}
|
|
313
318
|
|
|
319
|
+
function buildRouteMetaByComponent(routeMetaEntries: RouterIntrospectionResult["routeMetaEntries"]): Record<string, RouteMeta> {
|
|
314
320
|
const map = new Map<string, RouteEntry[]>();
|
|
315
321
|
for (const entry of routeMetaEntries) {
|
|
316
322
|
const list = map.get(entry.componentName) ?? [];
|
|
@@ -800,6 +806,15 @@ export interface GenerateFilesOptions {
|
|
|
800
806
|
*/
|
|
801
807
|
customPomImportNameCollisionBehavior?: "error" | "alias";
|
|
802
808
|
|
|
809
|
+
/**
|
|
810
|
+
* Handwritten POM classes (by file/export name under customPomDir) to register as
|
|
811
|
+
* Playwright fixtures next to the generated ones. Requires `generateFixtures`.
|
|
812
|
+
*/
|
|
813
|
+
customPomFixtures?: string[];
|
|
814
|
+
|
|
815
|
+
/** Write `component-graph.json` next to the generated manifest. Requires `generateFixtures`. */
|
|
816
|
+
componentGraph?: boolean;
|
|
817
|
+
|
|
803
818
|
/**
|
|
804
819
|
* Handwritten POM helper attachments. These helpers are assumed to be present in the
|
|
805
820
|
* aggregated output (e.g. via `tests/playwright/pom/custom/*.ts` inlining), but we only attach them to
|
|
@@ -893,6 +908,8 @@ export async function generateFiles(
|
|
|
893
908
|
requireCustomPomDir,
|
|
894
909
|
customPomImportAliases,
|
|
895
910
|
customPomImportNameCollisionBehavior = "error",
|
|
911
|
+
customPomFixtures = [],
|
|
912
|
+
componentGraph = false,
|
|
896
913
|
testIdAttribute,
|
|
897
914
|
emitLanguages: emitLanguagesOverride,
|
|
898
915
|
typescriptOutputStructure = "aggregated",
|
|
@@ -919,14 +936,16 @@ export async function generateFiles(
|
|
|
919
936
|
throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
|
|
920
937
|
}
|
|
921
938
|
|
|
939
|
+
const routeMetaEntries = vueRouterFluentChaining && (!routeMetaByComponentOverride || componentGraph)
|
|
940
|
+
? await introspectRouteMetaEntries(projectRoot, routerEntry, routerType, {
|
|
941
|
+
pageDirs,
|
|
942
|
+
componentDirs,
|
|
943
|
+
layoutDirs,
|
|
944
|
+
collectComponentFiles: componentGraph,
|
|
945
|
+
})
|
|
946
|
+
: [];
|
|
922
947
|
const routeMetaByComponent = routeMetaByComponentOverride
|
|
923
|
-
?? (vueRouterFluentChaining
|
|
924
|
-
? await getRouteMetaByComponent(projectRoot, routerEntry, routerType, {
|
|
925
|
-
pageDirs,
|
|
926
|
-
componentDirs,
|
|
927
|
-
layoutDirs,
|
|
928
|
-
})
|
|
929
|
-
: undefined);
|
|
948
|
+
?? (vueRouterFluentChaining ? buildRouteMetaByComponent(routeMetaEntries) : undefined);
|
|
930
949
|
const emittableComponentHierarchyMap = componentHierarchyMap;
|
|
931
950
|
const generatedFiles: GeneratedFileOutput[] = [];
|
|
932
951
|
|
|
@@ -965,6 +984,8 @@ export async function generateFiles(
|
|
|
965
984
|
pomOutDir: outDir,
|
|
966
985
|
projectRoot,
|
|
967
986
|
customPomDir,
|
|
987
|
+
customPomFixtures,
|
|
988
|
+
componentGraphRoutes: componentGraph ? routeMetaEntries : undefined,
|
|
968
989
|
elementMetadata,
|
|
969
990
|
testIdAttribute,
|
|
970
991
|
});
|
|
@@ -1872,13 +1893,27 @@ function maybeGenerateFixtureRegistry(
|
|
|
1872
1893
|
pomOutDir: string;
|
|
1873
1894
|
projectRoot?: string;
|
|
1874
1895
|
customPomDir?: string;
|
|
1896
|
+
customPomFixtures: string[];
|
|
1897
|
+
/** Routes for `component-graph.json`; the graph is written only when set. */
|
|
1898
|
+
componentGraphRoutes?: RouterIntrospectionResult["routeMetaEntries"];
|
|
1875
1899
|
elementMetadata: Map<string, Map<string, ElementMetadata>>;
|
|
1876
1900
|
testIdAttribute?: string;
|
|
1877
1901
|
},
|
|
1878
1902
|
): GeneratedFileOutput[] {
|
|
1879
|
-
const { generateFixtures, pomOutDir } = options;
|
|
1880
|
-
if (!generateFixtures)
|
|
1903
|
+
const { generateFixtures, pomOutDir, customPomFixtures, componentGraphRoutes } = options;
|
|
1904
|
+
if (!generateFixtures) {
|
|
1905
|
+
if (customPomFixtures.length > 0) {
|
|
1906
|
+
throw new VuePomGeneratorError(
|
|
1907
|
+
"generation.playwright.customPoms.fixtures requires generation.playwright.fixtures to be enabled.",
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
if (componentGraphRoutes) {
|
|
1911
|
+
throw new VuePomGeneratorError(
|
|
1912
|
+
"generation.playwright.componentGraph requires generation.playwright.fixtures to be enabled.",
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1881
1915
|
return [];
|
|
1916
|
+
}
|
|
1882
1917
|
|
|
1883
1918
|
// generateFixtures accepts:
|
|
1884
1919
|
// - true: enable fixtures with defaults
|
|
@@ -1973,6 +2008,45 @@ function maybeGenerateFixtureRegistry(
|
|
|
1973
2008
|
ctorExpression: fixtureCtorExpression(name),
|
|
1974
2009
|
}));
|
|
1975
2010
|
|
|
2011
|
+
// Fixture name -> what already owns it, so collision errors can name the source.
|
|
2012
|
+
const takenFixtureNames = new Map<string, string>([
|
|
2013
|
+
...[...reservedPlaywrightFixtureNames, "pomSetup", "pomFactory", "pomDiagnosticsSetup"]
|
|
2014
|
+
.map(name => [name, "a built-in Playwright or vue-pom-generator fixture"] as const),
|
|
2015
|
+
...fixtureClassNames.map(name => [lowerFirst(name), `the generated fixture for "${name}"`] as const),
|
|
2016
|
+
]);
|
|
2017
|
+
const customCtorEntries = customPomFixtures.map((className, index) => {
|
|
2018
|
+
if (customPomFixtures.indexOf(className) !== index) {
|
|
2019
|
+
throw new VuePomGeneratorError(
|
|
2020
|
+
`Custom POM fixture class "${className}" is listed more than once in generation.playwright.customPoms.fixtures.\n`
|
|
2021
|
+
+ "Remove the duplicate entry.",
|
|
2022
|
+
);
|
|
2023
|
+
}
|
|
2024
|
+
const filePath = path.join(customPomDirAbs, `${className}.ts`);
|
|
2025
|
+
if (!fs.existsSync(filePath)) {
|
|
2026
|
+
throw new VuePomGeneratorError(
|
|
2027
|
+
`Custom POM fixture class "${className}" was not found.\n`
|
|
2028
|
+
+ `Expected file: ${filePath}\n`
|
|
2029
|
+
+ `Add the file or remove "${className}" from generation.playwright.customPoms.fixtures.`,
|
|
2030
|
+
);
|
|
2031
|
+
}
|
|
2032
|
+
const fixtureName = lowerFirst(className);
|
|
2033
|
+
const existingOwner = takenFixtureNames.get(fixtureName);
|
|
2034
|
+
if (existingOwner) {
|
|
2035
|
+
throw new VuePomGeneratorError(
|
|
2036
|
+
`Custom POM fixture "${fixtureName}" (from "${className}") collides with ${existingOwner}.\n`
|
|
2037
|
+
+ `Rename the class or remove it from generation.playwright.customPoms.fixtures.`,
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
takenFixtureNames.set(fixtureName, `the custom POM fixture for "${className}"`);
|
|
2041
|
+
return {
|
|
2042
|
+
className,
|
|
2043
|
+
fixtureName,
|
|
2044
|
+
ctorExpression: `${className}Custom`,
|
|
2045
|
+
importSpecifier: stripExtension(toPosixRelativePath(fixtureOutDirAbs, filePath)),
|
|
2046
|
+
};
|
|
2047
|
+
});
|
|
2048
|
+
const hasCustomFixtures = customCtorEntries.length > 0;
|
|
2049
|
+
|
|
1976
2050
|
const fixturesContent = renderSourceFile(fixtureFileName, (sourceFile) => {
|
|
1977
2051
|
sourceFile.addStatements("/** Generated Playwright fixtures (typed page objects). */");
|
|
1978
2052
|
|
|
@@ -2019,6 +2093,12 @@ function maybeGenerateFixtureRegistry(
|
|
|
2019
2093
|
namedImports: [{ name: entry.className, alias: entry.localIdentifier }],
|
|
2020
2094
|
});
|
|
2021
2095
|
}
|
|
2096
|
+
for (const entry of customCtorEntries) {
|
|
2097
|
+
addNamedImport(sourceFile, {
|
|
2098
|
+
moduleSpecifier: entry.importSpecifier,
|
|
2099
|
+
namedImports: [{ name: entry.className, alias: entry.ctorExpression }],
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2022
2102
|
|
|
2023
2103
|
sourceFile.addInterface({
|
|
2024
2104
|
isExported: true,
|
|
@@ -2060,36 +2140,27 @@ function maybeGenerateFixtureRegistry(
|
|
|
2060
2140
|
type: "{ pomDiagnosticsSetup: void }",
|
|
2061
2141
|
});
|
|
2062
2142
|
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
writer
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
writer.indent(() => {
|
|
2085
|
-
for (const entry of componentCtorEntries) {
|
|
2086
|
-
writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
|
|
2087
|
-
}
|
|
2088
|
-
});
|
|
2089
|
-
writer.write("} as const");
|
|
2090
|
-
},
|
|
2091
|
-
}],
|
|
2092
|
-
});
|
|
2143
|
+
const addCtorMap = (name: string, entries: ReadonlyArray<{ fixtureName: string; ctorExpression: string }>) => {
|
|
2144
|
+
sourceFile.addVariableStatement({
|
|
2145
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
2146
|
+
declarations: [{
|
|
2147
|
+
name,
|
|
2148
|
+
initializer: (writer) => {
|
|
2149
|
+
writer.write("{").newLine();
|
|
2150
|
+
writer.indent(() => {
|
|
2151
|
+
for (const entry of entries) {
|
|
2152
|
+
writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
|
|
2153
|
+
}
|
|
2154
|
+
});
|
|
2155
|
+
writer.write("} as const");
|
|
2156
|
+
},
|
|
2157
|
+
}],
|
|
2158
|
+
});
|
|
2159
|
+
};
|
|
2160
|
+
addCtorMap("pageCtors", pageCtorEntries);
|
|
2161
|
+
addCtorMap("componentCtors", componentCtorEntries);
|
|
2162
|
+
if (hasCustomFixtures)
|
|
2163
|
+
addCtorMap("customCtors", customCtorEntries);
|
|
2093
2164
|
|
|
2094
2165
|
sourceFile.addTypeAlias({
|
|
2095
2166
|
isExported: true,
|
|
@@ -2101,14 +2172,23 @@ function maybeGenerateFixtureRegistry(
|
|
|
2101
2172
|
name: "GeneratedComponentFixtures",
|
|
2102
2173
|
type: "{ [K in keyof typeof componentCtors]: InstanceType<(typeof componentCtors)[K]> }",
|
|
2103
2174
|
});
|
|
2175
|
+
if (hasCustomFixtures) {
|
|
2176
|
+
sourceFile.addTypeAlias({
|
|
2177
|
+
isExported: true,
|
|
2178
|
+
name: "CustomPomFixtures",
|
|
2179
|
+
type: "{ [K in keyof typeof customCtors]: InstanceType<(typeof customCtors)[K]> }",
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2104
2182
|
sourceFile.addTypeAlias({
|
|
2105
2183
|
isExported: true,
|
|
2106
2184
|
name: "PomFixtures",
|
|
2107
2185
|
docs: [{
|
|
2108
2186
|
description: "Every fixture contributed by the generator: the `animation` option, the internal\n"
|
|
2109
|
-
+ "`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM
|
|
2187
|
+
+ "`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM"
|
|
2188
|
+
+ (hasCustomFixtures ? "\nand per configured custom POM." : "."),
|
|
2110
2189
|
}],
|
|
2111
|
-
type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
|
|
2190
|
+
type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
|
|
2191
|
+
+ (hasCustomFixtures ? " & CustomPomFixtures" : ""),
|
|
2112
2192
|
});
|
|
2113
2193
|
|
|
2114
2194
|
sourceFile.addFunction({
|
|
@@ -2203,6 +2283,8 @@ function maybeGenerateFixtureRegistry(
|
|
|
2203
2283
|
writer.writeLine("},");
|
|
2204
2284
|
writer.writeLine("...createPomFixtures(pageCtors),");
|
|
2205
2285
|
writer.writeLine("...createPomFixtures(componentCtors),");
|
|
2286
|
+
if (hasCustomFixtures)
|
|
2287
|
+
writer.writeLine("...createPomFixtures(customCtors),");
|
|
2206
2288
|
});
|
|
2207
2289
|
writer.write(") as TestType<TTestArgs & PomFixtures, TWorkerArgs>;");
|
|
2208
2290
|
},
|
|
@@ -2248,6 +2330,12 @@ function maybeGenerateFixtureRegistry(
|
|
|
2248
2330
|
filePath: path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
2249
2331
|
content: manifestContent,
|
|
2250
2332
|
},
|
|
2333
|
+
...(componentGraphRoutes
|
|
2334
|
+
? [{
|
|
2335
|
+
filePath: path.resolve(fixtureOutDirAbs, "component-graph.json"),
|
|
2336
|
+
content: generateComponentGraphJson(componentHierarchyMap, componentGraphRoutes, root),
|
|
2337
|
+
}]
|
|
2338
|
+
: []),
|
|
2251
2339
|
diagnosticsRuntimeFile,
|
|
2252
2340
|
];
|
|
2253
2341
|
|
|
@@ -2266,36 +2354,8 @@ function prepareViewObjectModelClass(
|
|
|
2266
2354
|
testIdAttribute,
|
|
2267
2355
|
} = options;
|
|
2268
2356
|
|
|
2269
|
-
const normalizeTrackedComponentRef = (value: string): string => {
|
|
2270
|
-
return value.endsWith(".vue") ? value.slice(0, -4) : value;
|
|
2271
|
-
};
|
|
2272
|
-
|
|
2273
|
-
const resolveTrackedComponentRef = (value: string): string | null => {
|
|
2274
|
-
const normalizedValue = normalizeTrackedComponentRef(value);
|
|
2275
|
-
if (componentHierarchyMap.has(value)) {
|
|
2276
|
-
return value;
|
|
2277
|
-
}
|
|
2278
|
-
if (componentHierarchyMap.has(normalizedValue)) {
|
|
2279
|
-
return normalizedValue;
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
let match: string | null = null;
|
|
2283
|
-
for (const [candidateName, candidateDeps] of componentHierarchyMap.entries()) {
|
|
2284
|
-
const normalizedCandidate = normalizeTrackedComponentRef(candidateName);
|
|
2285
|
-
const candidateBaseName = path.parse(candidateDeps.filePath).name;
|
|
2286
|
-
if (normalizedCandidate !== normalizedValue && candidateBaseName !== normalizedValue) {
|
|
2287
|
-
continue;
|
|
2288
|
-
}
|
|
2289
|
-
if (match && match !== candidateName) {
|
|
2290
|
-
return null;
|
|
2291
|
-
}
|
|
2292
|
-
match = candidateName;
|
|
2293
|
-
}
|
|
2294
|
-
return match;
|
|
2295
|
-
};
|
|
2296
|
-
|
|
2297
2357
|
const hasGeneratedPomSurface = (value: string, seen = new Set<string>()): boolean => {
|
|
2298
|
-
const resolvedRef = resolveTrackedComponentRef(value);
|
|
2358
|
+
const resolvedRef = resolveTrackedComponentRef(value, componentHierarchyMap);
|
|
2299
2359
|
if (!resolvedRef || seen.has(resolvedRef)) {
|
|
2300
2360
|
return false;
|
|
2301
2361
|
}
|
|
@@ -2329,7 +2389,7 @@ function prepareViewObjectModelClass(
|
|
|
2329
2389
|
};
|
|
2330
2390
|
|
|
2331
2391
|
const resolveComponentInstance = (spec: PomComponentInstanceSpec): ResolvedComponentInstance | null => {
|
|
2332
|
-
const componentRef = resolveTrackedComponentRef(spec.componentName);
|
|
2392
|
+
const componentRef = resolveTrackedComponentRef(spec.componentName, componentHierarchyMap);
|
|
2333
2393
|
if (
|
|
2334
2394
|
!componentRef
|
|
2335
2395
|
|| isSelfReference(componentRef)
|
|
@@ -2469,7 +2529,7 @@ function prepareViewObjectModelClass(
|
|
|
2469
2529
|
const hasChildComponent = (needle: string) => {
|
|
2470
2530
|
const normalizedNeedle = normalizeTrackedComponentRef(needle);
|
|
2471
2531
|
for (const child of rawComponentRefsForInstances) {
|
|
2472
|
-
const resolvedChild = resolveTrackedComponentRef(child);
|
|
2532
|
+
const resolvedChild = resolveTrackedComponentRef(child, componentHierarchyMap);
|
|
2473
2533
|
if (normalizeTrackedComponentRef(child) === normalizedNeedle)
|
|
2474
2534
|
return true;
|
|
2475
2535
|
if (resolvedChild && normalizeTrackedComponentRef(resolvedChild) === normalizedNeedle)
|
|
@@ -86,6 +86,13 @@ export interface GenerateFilesOptions {
|
|
|
86
86
|
* - "alias": auto-alias colliding custom imports (e.g. PersonListPage -> PersonListPageCustom)
|
|
87
87
|
*/
|
|
88
88
|
customPomImportNameCollisionBehavior?: "error" | "alias";
|
|
89
|
+
/**
|
|
90
|
+
* Handwritten POM classes (by file/export name under customPomDir) to register as
|
|
91
|
+
* Playwright fixtures next to the generated ones. Requires `generateFixtures`.
|
|
92
|
+
*/
|
|
93
|
+
customPomFixtures?: string[];
|
|
94
|
+
/** Write `component-graph.json` next to the generated manifest. Requires `generateFixtures`. */
|
|
95
|
+
componentGraph?: boolean;
|
|
89
96
|
/**
|
|
90
97
|
* Handwritten POM helper attachments. These helpers are assumed to be present in the
|
|
91
98
|
* aggregated output (e.g. via `tests/playwright/pom/custom/*.ts` inlining), but we only attach them to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../class-generation/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkC,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAE5G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../class-generation/index.ts"],"names":[],"mappings":"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"}
|