@immense/vue-pom-generator 1.0.3
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/AGENTS.md +37 -0
- package/README.md +171 -0
- package/class-generation/BasePage.ts +569 -0
- package/class-generation/Pointer.ts +124 -0
- package/class-generation/index.ts +1691 -0
- package/dist/index.cjs +5163 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +5124 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
- package/sequence-diagram.md +200 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This repository is often edited by automated coding agents.
|
|
4
|
+
|
|
5
|
+
## Hard rules (do not ignore)
|
|
6
|
+
|
|
7
|
+
- **Do not add fallback code paths**.
|
|
8
|
+
- No "try X, else Y" compatibility behavior.
|
|
9
|
+
- No silent recovery or alternate behavior to preserve legacy callers.
|
|
10
|
+
- If something is invalid, **fail fast** (throw/error) or update all call sites.
|
|
11
|
+
|
|
12
|
+
- **Do not add deprecation fallbacks / compatibility shims**.
|
|
13
|
+
- No deprecated aliases (e.g., exporting old names alongside new names).
|
|
14
|
+
- No transitional wrappers that keep previous behavior alive.
|
|
15
|
+
- No "deprecated" exports kept for downstream compatibility unless explicitly requested.
|
|
16
|
+
|
|
17
|
+
- If a change is breaking, **make it fully breaking**:
|
|
18
|
+
- Rename/remove the symbol.
|
|
19
|
+
- Update every internal usage.
|
|
20
|
+
- Update tests.
|
|
21
|
+
- Update generated typings/artifacts as needed.
|
|
22
|
+
|
|
23
|
+
## When you think a fallback is needed
|
|
24
|
+
|
|
25
|
+
Stop and ask for guidance instead of implementing a fallback. Explain:
|
|
26
|
+
|
|
27
|
+
- what would break,
|
|
28
|
+
- which consumers/call sites are affected,
|
|
29
|
+
- and what the clean breaking change would look like.
|
|
30
|
+
|
|
31
|
+
## Scope
|
|
32
|
+
|
|
33
|
+
These rules apply to:
|
|
34
|
+
|
|
35
|
+
- TypeScript/JavaScript source,
|
|
36
|
+
- tests,
|
|
37
|
+
- build outputs checked into the repo (e.g. `dist/*.d.ts`) when they must be edited.
|
package/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# @immense/vue-pom-generator
|
|
2
|
+
|
|
3
|
+
Vite plugin for Vue 3 apps that:
|
|
4
|
+
|
|
5
|
+
- Injects stable `data-testid` attributes into interactive elements during Vue template compilation
|
|
6
|
+
- Generates Page Object Model (POM) classes for views/components (Playwright-focused by default)
|
|
7
|
+
|
|
8
|
+
Why you might want it:
|
|
9
|
+
|
|
10
|
+
- **Less brittle end-to-end tests**: selectors stay stable even if markup/layout shifts.
|
|
11
|
+
- **Less boilerplate**: POM generation keeps tests readable and centralized.
|
|
12
|
+
- **Not just testing**: a consistent attribute can also help analytics/user-tracking tooling and ad-hoc automation.
|
|
13
|
+
|
|
14
|
+
## Install (npm)
|
|
15
|
+
|
|
16
|
+
Package: `@immense/vue-pom-generator`
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @immense/vue-pom-generator
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Exported entrypoint: `createVuePomGeneratorPlugins()`.
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
`createVuePomGeneratorPlugins(options)` accepts a `VuePomGeneratorPluginOptions` object, grouped into:
|
|
29
|
+
|
|
30
|
+
- `injection`: how `data-testid` (or your chosen attribute) is derived/injected
|
|
31
|
+
- `generation`: how Page Object Models (POMs) and Playwright helpers are generated
|
|
32
|
+
|
|
33
|
+
The generator emits an aggregated output under `generation.outDir` (default `tests/playwright/generated`):
|
|
34
|
+
|
|
35
|
+
- `tests/playwright/generated/page-object-models.g.ts` (generated; do not edit)
|
|
36
|
+
- `tests/playwright/generated/index.ts` (generated stable barrel)
|
|
37
|
+
|
|
38
|
+
If `generation.playwright.fixtures` is enabled, it also emits:
|
|
39
|
+
|
|
40
|
+
- `tests/playwright/generated/fixtures.g.ts` (generated; do not edit)
|
|
41
|
+
|
|
42
|
+
### Vite config example
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { defineConfig } from "vite";
|
|
46
|
+
import vue from "@vitejs/plugin-vue";
|
|
47
|
+
import { createVuePomGeneratorPlugins } from "@immense/vue-pom-generator";
|
|
48
|
+
|
|
49
|
+
export default defineConfig(() => {
|
|
50
|
+
const vueOptions = {
|
|
51
|
+
script: { defineModel: true, propsDestructure: true },
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
plugins: [
|
|
56
|
+
...createVuePomGeneratorPlugins({
|
|
57
|
+
vueOptions,
|
|
58
|
+
logging: { verbosity: "info" },
|
|
59
|
+
|
|
60
|
+
injection: {
|
|
61
|
+
// Attribute to inject/read as the test id (default: data-testid)
|
|
62
|
+
attribute: "data-testid",
|
|
63
|
+
|
|
64
|
+
// Used to classify Vue files as "views" vs components (default: src/views)
|
|
65
|
+
viewsDir: "src/views",
|
|
66
|
+
|
|
67
|
+
// Optional: wrapper semantics for design-system components
|
|
68
|
+
nativeWrappers: {
|
|
69
|
+
ImmyButton: { role: "button" },
|
|
70
|
+
ImmyInput: { role: "input" },
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// Optional: opt specific components out of injection
|
|
74
|
+
excludeComponents: ["ImmyButton"],
|
|
75
|
+
|
|
76
|
+
// Optional: preserve/overwrite/error when an author already set the attribute
|
|
77
|
+
existingIdBehavior: "preserve",
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
generation: {
|
|
81
|
+
// Default: tests/playwright/generated
|
|
82
|
+
outDir: "tests/playwright/generated",
|
|
83
|
+
|
|
84
|
+
// Controls how to handle duplicate generated member names within a single POM class.
|
|
85
|
+
// - "error": fail compilation
|
|
86
|
+
// - "warn": warn and suffix
|
|
87
|
+
// - "suffix": suffix silently (default)
|
|
88
|
+
nameCollisionBehavior: "suffix",
|
|
89
|
+
|
|
90
|
+
// Enable router introspection. When provided, router-aware POM helpers are generated.
|
|
91
|
+
router: { entry: "src/router.ts" },
|
|
92
|
+
|
|
93
|
+
playwright: {
|
|
94
|
+
fixtures: true,
|
|
95
|
+
customPoms: {
|
|
96
|
+
// Default: tests/playwright/pom/custom
|
|
97
|
+
dir: "tests/playwright/pom/custom",
|
|
98
|
+
importAliases: { ImmyCheckBox: "CheckboxWidget" },
|
|
99
|
+
attachments: [
|
|
100
|
+
{
|
|
101
|
+
className: "ConfirmationModal",
|
|
102
|
+
propertyName: "confirmationModal",
|
|
103
|
+
attachWhenUsesComponents: ["Page"],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
vue(vueOptions),
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Notes:
|
|
117
|
+
|
|
118
|
+
- **Injection is enabled by plugin inclusion** (there is no longer an `injection.enabled` flag).
|
|
119
|
+
- **Generation is enabled by default** and can be disabled via `generation: false`.
|
|
120
|
+
- **Router-aware POM helpers are enabled** when `generation.router.entry` is provided (the generator will introspect your router).
|
|
121
|
+
|
|
122
|
+
### `generation.router.entry: string`
|
|
123
|
+
|
|
124
|
+
Controls where router introspection loads your Vue Router definition from (used for `:to` analysis and navigation helper generation).
|
|
125
|
+
|
|
126
|
+
Resolution:
|
|
127
|
+
|
|
128
|
+
- relative paths are resolved relative to Vite's resolved `config.root`
|
|
129
|
+
- absolute paths are used as-is
|
|
130
|
+
|
|
131
|
+
This file must export a **default router factory function** (e.g. `export default makeRouter`).
|
|
132
|
+
|
|
133
|
+
### `generation.playwright.fixtures: boolean | string | { outDir?: string }`
|
|
134
|
+
|
|
135
|
+
When enabled, the generator emits a concrete, strongly typed Playwright fixture module so tests can do:
|
|
136
|
+
|
|
137
|
+
- `test("...", async ({ preferencesPage }) => { ... })`
|
|
138
|
+
|
|
139
|
+
Forms:
|
|
140
|
+
|
|
141
|
+
- `true`: enable with defaults
|
|
142
|
+
- `"path"`: enable and write under this directory (or file, if it ends in `.ts`/`.tsx`/`.mts`/`.cts`)
|
|
143
|
+
- `{ outDir }`: enable and write fixture outputs under a custom directory
|
|
144
|
+
|
|
145
|
+
Defaults:
|
|
146
|
+
|
|
147
|
+
- when `true`: writes `fixtures.g.ts` alongside generated POMs (under `generation.outDir`)
|
|
148
|
+
|
|
149
|
+
### Vite config example
|
|
150
|
+
|
|
151
|
+
- `nativeWrappers` describes common wrapper components (e.g. design-system buttons/inputs)
|
|
152
|
+
- `customPom` groups handwritten helper wiring and conditional attachments
|
|
153
|
+
- `testIdAttribute` lets you use a different attribute name (e.g. `data-qa`, `data-cy`)
|
|
154
|
+
|
|
155
|
+
### Notes for Playwright users
|
|
156
|
+
|
|
157
|
+
This package emits Playwright-oriented helpers (e.g. `page.getByTestId(...)`).
|
|
158
|
+
|
|
159
|
+
If you change Playwright's `testIdAttribute`, make sure the app actually renders the same attribute.
|
|
160
|
+
|
|
161
|
+
### Migration helper: `injection.existingIdBehavior`
|
|
162
|
+
|
|
163
|
+
When cleaning up a codebase that already has a mix of manually-authored test ids and generated ones:
|
|
164
|
+
|
|
165
|
+
- `"preserve"` (default): leave author-provided ids untouched
|
|
166
|
+
- `"overwrite"`: replace existing ids with generated ids
|
|
167
|
+
- `"error"`: throw when an existing id is detected (useful for incremental cleanup)
|
|
168
|
+
|
|
169
|
+
## Sequence diagram
|
|
170
|
+
|
|
171
|
+
See: [`sequence-diagram.md`](./sequence-diagram.md)
|