@immense/vue-pom-generator 1.0.95 → 1.0.96
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 +60 -0
- package/RELEASE_NOTES.md +65 -18
- package/class-generation/base-page.ts +18 -2
- package/class-generation/index.ts +249 -45
- package/dist/class-generation/base-page.d.ts +6 -0
- package/dist/class-generation/base-page.d.ts.map +1 -1
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +366 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +367 -46
- package/dist/index.mjs.map +1 -1
- package/dist/playwright/runtime.cjs +12 -2
- package/dist/playwright/runtime.cjs.map +1 -1
- package/dist/playwright/runtime.mjs +12 -2
- package/dist/playwright/runtime.mjs.map +1 -1
- package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts +2 -0
- package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts.map +1 -1
- package/dist/tests/fixtures/generated-tsc/base-page.minimal.d.ts +2 -0
- package/dist/tests/fixtures/generated-tsc/base-page.minimal.d.ts.map +1 -1
- package/dist/tests/semantic-component-instances.test.d.ts +2 -0
- package/dist/tests/semantic-component-instances.test.d.ts.map +1 -0
- package/dist/transform.d.ts.map +1 -1
- package/dist/utils.d.ts +40 -12
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -734,6 +734,66 @@ Actual current rules:
|
|
|
734
734
|
|
|
735
735
|
Without `flatten`, helper composition still works; you just call through the helper property explicitly.
|
|
736
736
|
|
|
737
|
+
## Semantic, scoped component instances
|
|
738
|
+
|
|
739
|
+
Generated TypeScript POMs model component **invocations**, not only component types. Each
|
|
740
|
+
addressable invocation receives a generator-owned `data-pom-instance` marker on the DOM
|
|
741
|
+
root that accepts Vue fallthrough attributes. The child POM is rooted at that marker, so
|
|
742
|
+
identical controls in two component instances cannot accidentally select each other.
|
|
743
|
+
|
|
744
|
+
Instance names come from author-visible semantics, in this order:
|
|
745
|
+
|
|
746
|
+
1. a static accessible name (`aria-label`, `label`, `title`, or `name`)
|
|
747
|
+
2. the identifier bound to `:options`
|
|
748
|
+
3. the `v-model` / `:model-value` identifier
|
|
749
|
+
4. the component tag as the fallback
|
|
750
|
+
|
|
751
|
+
The generator tries those candidates in order. If an earlier invocation already owns a
|
|
752
|
+
semantic candidate, the later invocation uses its next candidate instead. For example, a
|
|
753
|
+
dialog titled `RDP Password` can own `RdpPassword` while its nested copy-input falls back
|
|
754
|
+
to `CopyToClipboardInput`. Repeated structural wrappers with no unique candidate are
|
|
755
|
+
omitted from composition; their ordinary generated controls are unaffected.
|
|
756
|
+
|
|
757
|
+
Static invocations become properties. Repeated invocations with a stable `:key` become
|
|
758
|
+
methods whose argument selects the instance:
|
|
759
|
+
|
|
760
|
+
```vue
|
|
761
|
+
<DynamicFormField
|
|
762
|
+
v-for="parameter in parameters"
|
|
763
|
+
:key="parameter.name"
|
|
764
|
+
:parameter="parameter"
|
|
765
|
+
/>
|
|
766
|
+
|
|
767
|
+
<ImmyRadioGroup
|
|
768
|
+
aria-label="Override policy options"
|
|
769
|
+
:options="overridePolicyOptions"
|
|
770
|
+
/>
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
```ts
|
|
774
|
+
form
|
|
775
|
+
.DynamicFormField(parameterName)
|
|
776
|
+
.OnboardingOption
|
|
777
|
+
.OverridePolicyOptions
|
|
778
|
+
.selectByValue(ParameterOverridePolicy.Require);
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
Named slot content is projected onto the component instance that receives the slot. That
|
|
782
|
+
is why the example can expose `OnboardingOption` beneath `DynamicFormField` even when an
|
|
783
|
+
intermediate form component forwards the slot. The generator only emits this projection
|
|
784
|
+
when the receiving boundary and every attached child have one statically provable scope.
|
|
785
|
+
Keyed slot owners and keyed projected content fail generation instead of producing a
|
|
786
|
+
misleading API. Components that do not forward the marker to a DOM root are omitted from
|
|
787
|
+
component-instance composition rather than falling back to page-wide selectors; their
|
|
788
|
+
own standalone fixture is still generated normally.
|
|
789
|
+
|
|
790
|
+
When `injection.optionKeyAttribute` maps a radio component to `"value"`, its generated
|
|
791
|
+
selection API uses the domain term directly: `selectByValue(value)`. Other configured
|
|
792
|
+
attribute names retain `key` when the HTML attribute name is not a valid public TypeScript
|
|
793
|
+
identifier (for example `data-value`).
|
|
794
|
+
|
|
795
|
+
`data-pom-instance` is generator-owned. Do not author it in Vue templates.
|
|
796
|
+
|
|
737
797
|
## Playwright fixtures: actual behavior and caveats
|
|
738
798
|
|
|
739
799
|
When `generation.playwright.fixtures` is enabled, the generator emits a strongly typed Playwright fixture module.
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,30 +1,77 @@
|
|
|
1
|
+
I'll verify the actual commits in the release range and gather details about the changes before
|
|
2
|
+
writing the notes.
|
|
3
|
+
|
|
4
|
+
Let me examine the actual diff to understand the changes precisely.
|
|
5
|
+
|
|
6
|
+
Let me check the remaining changed files for completeness.
|
|
7
|
+
|
|
8
|
+
Let me verify the release tag and confirm only PR #59 is in range.
|
|
9
|
+
|
|
10
|
+
Let me verify whether PR #58 is already in v1.0.95 or if it's part of this release.
|
|
11
|
+
|
|
12
|
+
I now have full clarity. v1.0.95 was tagged at PR #58's merge commit, so only PR #59 is new in
|
|
13
|
+
v1.0.96. Here are the release notes:
|
|
14
|
+
|
|
1
15
|
Highlights
|
|
2
16
|
|
|
3
|
-
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
17
|
+
- Scoped component instances: Generated POMs now model individual Vue component invocations — not
|
|
18
|
+
just component types — each rooted at a generator-owned data-pom-instance marker, eliminating
|
|
19
|
+
cross-instance selector collisions.
|
|
20
|
+
- Semantic instance naming: Instance names are inferred from accessible names (aria-label, label,
|
|
21
|
+
title, name), :options bindings, v-model/:model-value identifiers, and component tags, with earlier
|
|
22
|
+
invocations claiming candidates first.
|
|
23
|
+
- Keyed instance accessors: Static invocations become properties; repeated invocations with a
|
|
24
|
+
stable :key become methods that accept a key argument to select the instance.
|
|
25
|
+
- Named-slot projection: Slot content is projected onto the receiving component instance, enabling
|
|
26
|
+
fluent chains like form.DynamicFormField(parameterName).OnboardingOption.
|
|
27
|
+
- selectByValue(value) API: Radio wrappers configured with optionKeyAttribute: "value" now emit a
|
|
28
|
+
domain-term selectByValue(value) selection method.
|
|
29
|
+
- Fail-fast safety: Components that can't forward the scope marker are omitted from composition
|
|
30
|
+
rather than falling back to page-wide selectors; ambiguous names and incompatible keyed-slot
|
|
31
|
+
projections throw clear errors.
|
|
8
32
|
|
|
9
33
|
Changes
|
|
10
34
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
to
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
Component instance generation
|
|
36
|
+
|
|
37
|
+
- Added data-pom-instance marker injection and scoped child POM rooting in transform.ts (instance
|
|
38
|
+
detection, name-candidate inference, keyed/static classification, slot-outlet tracking).
|
|
39
|
+
- Added component-instance resolution, uniqueness checking, and named-slot projection in
|
|
40
|
+
class-generation/index.ts, generating properties for static instances and parameterized methods for
|
|
41
|
+
keyed instances.
|
|
42
|
+
- Added componentInstanceLocator and locatorInScope helpers to BasePage; BasePageOptions now
|
|
43
|
+
accepts an optional root locator that scopes every generated selector in a component POM.
|
|
44
|
+
- Updated utils.ts toPomKeyPattern to accept a configurable parameter name (defaulting to key), and
|
|
45
|
+
added selectorParameterName support so optionKeyAttribute surfaces the attribute name (e.g. value)
|
|
46
|
+
in the public API.
|
|
47
|
+
|
|
48
|
+
Documentation
|
|
49
|
+
|
|
50
|
+
- Added a new "Semantic, scoped component instances" section to README.md covering marker behavior,
|
|
51
|
+
naming priority, keyed vs. static accessors, slot projection, and selectByValue.
|
|
52
|
+
|
|
53
|
+
Tests
|
|
54
|
+
|
|
55
|
+
- Added tests/semantic-component-instances.test.ts (189 lines) covering
|
|
56
|
+
keyed/slot-projected/semantically-named component chains.
|
|
57
|
+
- Updated base-page.test.ts, class-generation-coverage.test.ts, generated-tsc.test.ts,
|
|
58
|
+
transform.test.ts, and tsc fixtures (base-page.full.ts, base-page.minimal.ts) for the new scoping
|
|
59
|
+
and instance APIs.
|
|
60
|
+
|
|
61
|
+
Breaking Changes
|
|
62
|
+
|
|
63
|
+
- Generated child POM properties now use semantic invocation names and scoped roots. Consumers must
|
|
64
|
+
regenerate POMs and update affected call sites. Components that cannot forward the generator-owned
|
|
65
|
+
data-pom-instance scope marker are omitted from composition instead of falling back to page-wide
|
|
66
|
+
selectors.
|
|
21
67
|
|
|
22
68
|
Pull Requests Included
|
|
23
69
|
|
|
24
|
-
-
|
|
70
|
+
- ]8;id=md-1e4xfa4;https://github.com/immense/vue-pom-generator/pull/59#59 feat!: generate scoped component instances]8;;]8;; — by @dkattan]8;;
|
|
25
71
|
|
|
26
72
|
Testing
|
|
27
73
|
|
|
28
|
-
|
|
29
|
-
tests
|
|
74
|
+
Validated with npm test (419 passed), npm run typecheck, npm run lint (0 errors), npm run build,
|
|
75
|
+
Playwright integration tests (3 passed), npm run smoke:pack, and a real-world frontend build
|
|
76
|
+
producing 643 POMs / 1,443 selectors.
|
|
30
77
|
|
|
@@ -75,6 +75,8 @@ export type Fluent<T extends object> = DeepFluent<T, T> & PromiseLike<T>;
|
|
|
75
75
|
export type ValueFluent<T> = DeepValueFluent<T> & PromiseLike<T>;
|
|
76
76
|
|
|
77
77
|
export interface BasePageOptions {
|
|
78
|
+
/** Locator that scopes every generated selector in this component POM. */
|
|
79
|
+
root?: PwLocator;
|
|
78
80
|
renderers?: {
|
|
79
81
|
callout?: CalloutRenderer;
|
|
80
82
|
pointer?: PointerRenderer;
|
|
@@ -133,6 +135,7 @@ export class BasePage {
|
|
|
133
135
|
* etc. for JS/DOM elements the generator can't key.
|
|
134
136
|
*/
|
|
135
137
|
private readonly _page: PwPage;
|
|
138
|
+
private readonly _root?: PwLocator;
|
|
136
139
|
|
|
137
140
|
/**
|
|
138
141
|
* Playwright's full `Page`, exposed to subclasses. This is the single,
|
|
@@ -149,6 +152,7 @@ export class BasePage {
|
|
|
149
152
|
*/
|
|
150
153
|
public constructor(page: PwPage, options?: BasePageOptions) {
|
|
151
154
|
this._page = page;
|
|
155
|
+
this._root = options?.root;
|
|
152
156
|
this.testIdAttribute = (options?.testIdAttribute || "data-testid").trim() || "data-testid";
|
|
153
157
|
|
|
154
158
|
const pointerRenderer = options?.renderers?.pointer;
|
|
@@ -287,8 +291,20 @@ export class BasePage {
|
|
|
287
291
|
return normalizedDescription ? locator.describe(normalizedDescription) : locator;
|
|
288
292
|
}
|
|
289
293
|
|
|
294
|
+
private locatorInScope(selector: string, within?: PwLocator): Locator {
|
|
295
|
+
const root = within ?? this._root;
|
|
296
|
+
return (root ? root.locator(selector) : this._page.locator(selector)) as Locator;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Resolve a generated component-instance marker inside this POM's current scope. */
|
|
300
|
+
protected componentInstanceLocator(instanceId: string, within?: PwLocator): Locator {
|
|
301
|
+
return this.locatorInScope(`[data-pom-instance=${JSON.stringify(instanceId)}]`, within)
|
|
302
|
+
.filter({ visible: true })
|
|
303
|
+
.first();
|
|
304
|
+
}
|
|
305
|
+
|
|
290
306
|
protected locatorByTestId(testId: string, description?: string): Locator {
|
|
291
|
-
return this.describeLocator(this.
|
|
307
|
+
return this.describeLocator(this.locatorInScope(this.selectorForTestId(testId)), description);
|
|
292
308
|
}
|
|
293
309
|
|
|
294
310
|
protected async resolveVisibleTestIdLocator(
|
|
@@ -612,7 +628,7 @@ export class BasePage {
|
|
|
612
628
|
// pseudo-elements intercept the pointer. Playwright's visible filter can exclude that
|
|
613
629
|
// empty label even though its pseudo-element is the actual interaction surface, so first
|
|
614
630
|
// select the associated label by DOM presence and then choose pointer or keyboard activation.
|
|
615
|
-
const associatedLabel = this.
|
|
631
|
+
const associatedLabel = this.locatorInScope(`label[for=${JSON.stringify(controlId)}]`).first();
|
|
616
632
|
if (await associatedLabel.count() > 0) {
|
|
617
633
|
if (await associatedLabel.isVisible()) {
|
|
618
634
|
clickTarget = associatedLabel;
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
isParameterizedPomPattern,
|
|
27
27
|
orderPomPatternParameters,
|
|
28
28
|
toCSharpPomPatternExpression,
|
|
29
|
+
toTypeScriptPomPatternExpression,
|
|
29
30
|
uniquePomStringPatterns,
|
|
30
31
|
type PomStringPattern,
|
|
31
32
|
} from "../pom-patterns";
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
buildCommentBlock,
|
|
38
39
|
buildFilePrefix,
|
|
39
40
|
createClassConstructor,
|
|
41
|
+
createClassGetter,
|
|
40
42
|
createClassMethod,
|
|
41
43
|
createClassProperty,
|
|
42
44
|
renderSourceFile,
|
|
@@ -49,10 +51,12 @@ import {
|
|
|
49
51
|
type PropertyDeclarationStructure,
|
|
50
52
|
type TypeScriptClassMember,
|
|
51
53
|
type TypeScriptSourceFile,
|
|
54
|
+
type TypeScriptWriter,
|
|
52
55
|
} from "../typescript-codegen";
|
|
53
56
|
import {
|
|
54
57
|
IComponentDependencies,
|
|
55
58
|
IDataTestId,
|
|
59
|
+
PomComponentInstanceSpec,
|
|
56
60
|
PomExtraClickMethodSpec,
|
|
57
61
|
PomPrimarySpec,
|
|
58
62
|
PomSelectorSpec,
|
|
@@ -70,6 +74,17 @@ import {
|
|
|
70
74
|
|
|
71
75
|
void setPlaywrightAnimationOptions;
|
|
72
76
|
|
|
77
|
+
interface ResolvedComponentInstance extends PomComponentInstanceSpec {
|
|
78
|
+
componentRef: string;
|
|
79
|
+
className: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface ResolvedProjectedComponentInstance {
|
|
83
|
+
owner: ResolvedComponentInstance;
|
|
84
|
+
target: ResolvedComponentInstance;
|
|
85
|
+
contents: ResolvedComponentInstance[];
|
|
86
|
+
}
|
|
87
|
+
|
|
73
88
|
export { generateViewObjectModelMethodContent };
|
|
74
89
|
|
|
75
90
|
const GENERATED_GITATTRIBUTES_BLOCK_START = "# BEGIN vue-pom-generator generated files";
|
|
@@ -2002,28 +2017,149 @@ function prepareViewObjectModelClass(
|
|
|
2002
2017
|
return Array.from(nestedRefs).some(child => hasGeneratedPomSurface(child, nextSeen));
|
|
2003
2018
|
};
|
|
2004
2019
|
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
: childrenComponentSet;
|
|
2008
|
-
// A component may render itself recursively (e.g. a tree/list that nests same-named
|
|
2009
|
-
// children). Without this guard the generator emits `this.<SelfName> = new <SelfName>(page)`
|
|
2010
|
-
// in the constructor, which infinitely recurses the moment any POM transitively
|
|
2011
|
-
// instantiates this class. A self-reference is never a useful child instance (it would
|
|
2012
|
-
// just re-wrap the same page), so drop it before it becomes a property + ctor assignment.
|
|
2020
|
+
// Recursive component invocations cannot become eager child POM instances without
|
|
2021
|
+
// infinitely constructing themselves.
|
|
2013
2022
|
const ownClassName = toPascalCaseLocal(componentName);
|
|
2014
2023
|
const isSelfReference = (ref: string): boolean => {
|
|
2015
2024
|
return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
|
|
2016
2025
|
};
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
const
|
|
2020
|
-
if (
|
|
2021
|
-
|
|
2026
|
+
|
|
2027
|
+
const resolveComponentInstance = (spec: PomComponentInstanceSpec): ResolvedComponentInstance | null => {
|
|
2028
|
+
const componentRef = resolveTrackedComponentRef(spec.componentName);
|
|
2029
|
+
if (
|
|
2030
|
+
!componentRef
|
|
2031
|
+
|| isSelfReference(componentRef)
|
|
2032
|
+
|| !hasGeneratedPomSurface(componentRef, new Set([componentName]))
|
|
2033
|
+
) {
|
|
2034
|
+
return null;
|
|
2022
2035
|
}
|
|
2023
|
-
|
|
2036
|
+
|
|
2037
|
+
return {
|
|
2038
|
+
...spec,
|
|
2039
|
+
componentRef,
|
|
2040
|
+
className: normalizeTrackedComponentRef(componentRef),
|
|
2041
|
+
};
|
|
2042
|
+
};
|
|
2043
|
+
|
|
2044
|
+
const uniqueInstances = (
|
|
2045
|
+
instances: ResolvedComponentInstance[],
|
|
2046
|
+
ownerName: string,
|
|
2047
|
+
): ResolvedComponentInstance[] => {
|
|
2048
|
+
const byPublicName = new Map<string, ResolvedComponentInstance>();
|
|
2049
|
+
for (const instance of instances) {
|
|
2050
|
+
const existing = byPublicName.get(instance.instanceName);
|
|
2051
|
+
if (!existing) {
|
|
2052
|
+
byPublicName.set(instance.instanceName, instance);
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
const sameInvocationShape = existing.componentRef === instance.componentRef
|
|
2057
|
+
&& JSON.stringify(existing.selector) === JSON.stringify(instance.selector)
|
|
2058
|
+
&& JSON.stringify(existing.parameters) === JSON.stringify(instance.parameters);
|
|
2059
|
+
if (sameInvocationShape) {
|
|
2060
|
+
continue;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
throw new VuePomGeneratorError(
|
|
2064
|
+
`Semantic component instance name ${JSON.stringify(instance.instanceName)} is ambiguous in ${ownerName}.\n`
|
|
2065
|
+
+ `It refers to both <${existing.componentName}> and <${instance.componentName}>.\n\n`
|
|
2066
|
+
+ "Fix: give the invocations distinct accessible names or distinct semantic model/options bindings.",
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
2069
|
+
return Array.from(byPublicName.values());
|
|
2070
|
+
};
|
|
2071
|
+
|
|
2072
|
+
const allInvocationSpecs = dependencies.componentInstances ?? [];
|
|
2073
|
+
const directComponentInstances = uniqueInstances(
|
|
2074
|
+
allInvocationSpecs
|
|
2075
|
+
.filter(spec => !spec.suppliedSlot)
|
|
2076
|
+
.map(resolveComponentInstance)
|
|
2077
|
+
.filter((instance): instance is ResolvedComponentInstance => !!instance),
|
|
2078
|
+
componentName,
|
|
2079
|
+
);
|
|
2080
|
+
|
|
2081
|
+
const projectedComponentInstances: ResolvedProjectedComponentInstance[] = [];
|
|
2082
|
+
for (const owner of directComponentInstances) {
|
|
2083
|
+
const ownerDependencies = componentHierarchyMap.get(owner.componentRef);
|
|
2084
|
+
if (!ownerDependencies?.slotOutlets?.length) {
|
|
2024
2085
|
continue;
|
|
2025
2086
|
}
|
|
2026
|
-
|
|
2087
|
+
|
|
2088
|
+
const suppliedBySlot = new Map<string, ResolvedComponentInstance[]>();
|
|
2089
|
+
for (const suppliedSpec of allInvocationSpecs) {
|
|
2090
|
+
if (suppliedSpec.suppliedSlot?.ownerSourceId !== owner.sourceId) {
|
|
2091
|
+
continue;
|
|
2092
|
+
}
|
|
2093
|
+
const supplied = resolveComponentInstance(suppliedSpec);
|
|
2094
|
+
if (!supplied) {
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
const values = suppliedBySlot.get(suppliedSpec.suppliedSlot.name) ?? [];
|
|
2098
|
+
values.push(supplied);
|
|
2099
|
+
suppliedBySlot.set(suppliedSpec.suppliedSlot.name, values);
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
for (const [slotName, rawContents] of suppliedBySlot) {
|
|
2103
|
+
const outletTargetIds = new Set(
|
|
2104
|
+
ownerDependencies.slotOutlets
|
|
2105
|
+
.filter(outlet => outlet.name === slotName)
|
|
2106
|
+
.map(outlet => outlet.targetSourceId),
|
|
2107
|
+
);
|
|
2108
|
+
const targetInstances = uniqueInstances(
|
|
2109
|
+
(ownerDependencies.componentInstances ?? [])
|
|
2110
|
+
.filter(spec => outletTargetIds.has(spec.sourceId))
|
|
2111
|
+
.map(resolveComponentInstance)
|
|
2112
|
+
.filter((instance): instance is ResolvedComponentInstance => !!instance),
|
|
2113
|
+
`${owner.className} slot ${JSON.stringify(slotName)}`,
|
|
2114
|
+
);
|
|
2115
|
+
const contents = uniqueInstances(rawContents, `${componentName} slot ${JSON.stringify(slotName)}`);
|
|
2116
|
+
for (const target of targetInstances) {
|
|
2117
|
+
if (owner.parameters.length > 0) {
|
|
2118
|
+
throw new VuePomGeneratorError(
|
|
2119
|
+
`Cannot project slot ${JSON.stringify(slotName)} through keyed component instance ${owner.instanceName} in ${componentName}.\n`
|
|
2120
|
+
+ "The owner and projected target require distinct key scopes, which cannot be represented by one unambiguous generated accessor.",
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
2123
|
+
const keyedContent = contents.find(content => content.parameters.length > 0);
|
|
2124
|
+
if (keyedContent) {
|
|
2125
|
+
throw new VuePomGeneratorError(
|
|
2126
|
+
`Cannot attach keyed slot content ${keyedContent.instanceName} as a property of ${target.instanceName} in ${componentName}.\n`
|
|
2127
|
+
+ "Move the repetition to the receiving component boundary so the generator can expose it as a keyed accessor.",
|
|
2128
|
+
);
|
|
2129
|
+
}
|
|
2130
|
+
const existingProjection = projectedComponentInstances.find((projection) => {
|
|
2131
|
+
return projection.owner.sourceId === owner.sourceId
|
|
2132
|
+
&& projection.target.instanceName === target.instanceName
|
|
2133
|
+
&& projection.target.componentRef === target.componentRef
|
|
2134
|
+
&& JSON.stringify(projection.target.selector) === JSON.stringify(target.selector);
|
|
2135
|
+
});
|
|
2136
|
+
if (existingProjection) {
|
|
2137
|
+
existingProjection.contents = uniqueInstances(
|
|
2138
|
+
[...existingProjection.contents, ...contents],
|
|
2139
|
+
`${componentName} projected ${target.instanceName}`,
|
|
2140
|
+
);
|
|
2141
|
+
continue;
|
|
2142
|
+
}
|
|
2143
|
+
projectedComponentInstances.push({ owner, target, contents });
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
const rawComponentRefsForInstances = usedComponentSet?.size
|
|
2149
|
+
? usedComponentSet
|
|
2150
|
+
: childrenComponentSet;
|
|
2151
|
+
const componentRefsForInstances = new Set<string>();
|
|
2152
|
+
for (const instance of directComponentInstances) {
|
|
2153
|
+
if (!isSelfReference(instance.componentRef)) {
|
|
2154
|
+
componentRefsForInstances.add(instance.componentRef);
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
for (const projection of projectedComponentInstances) {
|
|
2158
|
+
for (const instance of [projection.owner, projection.target, ...projection.contents]) {
|
|
2159
|
+
if (!isSelfReference(instance.componentRef)) {
|
|
2160
|
+
componentRefsForInstances.add(instance.componentRef);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2027
2163
|
}
|
|
2028
2164
|
|
|
2029
2165
|
const hasChildComponent = (needle: string) => {
|
|
@@ -2078,8 +2214,19 @@ function prepareViewObjectModelClass(
|
|
|
2078
2214
|
: [];
|
|
2079
2215
|
|
|
2080
2216
|
const className = toPascalCaseLocal(componentName);
|
|
2081
|
-
const childInstancePropertyNames =
|
|
2082
|
-
.map(
|
|
2217
|
+
const childInstancePropertyNames = [
|
|
2218
|
+
...directComponentInstances.map(instance => instance.instanceName),
|
|
2219
|
+
...projectedComponentInstances.map(projection => projection.target.instanceName),
|
|
2220
|
+
];
|
|
2221
|
+
const duplicateChildInstanceName = childInstancePropertyNames.find((name, index) => {
|
|
2222
|
+
return childInstancePropertyNames.indexOf(name) !== index;
|
|
2223
|
+
});
|
|
2224
|
+
if (duplicateChildInstanceName) {
|
|
2225
|
+
throw new VuePomGeneratorError(
|
|
2226
|
+
`Semantic component instance ${JSON.stringify(duplicateChildInstanceName)} would be emitted more than once in ${componentName}.\n`
|
|
2227
|
+
+ "Fix: give direct and slot-projected instances distinct accessible names or semantic bindings.",
|
|
2228
|
+
);
|
|
2229
|
+
}
|
|
2083
2230
|
const blockedViewPassthroughMethodNames = new Set(
|
|
2084
2231
|
attachmentsForThisClass
|
|
2085
2232
|
.filter(a => a.flatten)
|
|
@@ -2093,24 +2240,24 @@ function prepareViewObjectModelClass(
|
|
|
2093
2240
|
|
|
2094
2241
|
const members: TypeScriptClassMember[] = [];
|
|
2095
2242
|
if (isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0 || widgetInstances.length > 0)) {
|
|
2096
|
-
members.push(...getComponentInstances(
|
|
2097
|
-
members.push(getConstructor(
|
|
2243
|
+
members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass, widgetInstances));
|
|
2244
|
+
members.push(getConstructor(directComponentInstances, attachmentsForThisClass, widgetInstances, { testIdAttribute }));
|
|
2098
2245
|
}
|
|
2099
2246
|
if (!isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0)) {
|
|
2100
|
-
members.push(...getComponentInstances(
|
|
2101
|
-
members.push(getConstructor(
|
|
2247
|
+
members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass));
|
|
2248
|
+
members.push(getConstructor(directComponentInstances, attachmentsForThisClass, [], { testIdAttribute }));
|
|
2102
2249
|
}
|
|
2103
2250
|
|
|
2104
2251
|
members.push(
|
|
2105
2252
|
...getAttachmentPassthroughMethods(componentName, dependencies, attachmentsForThisClass, reservedAttachmentPassthroughNames),
|
|
2106
2253
|
);
|
|
2107
2254
|
|
|
2108
|
-
if (isView &&
|
|
2255
|
+
if (isView && directComponentInstances.length === 1) {
|
|
2109
2256
|
members.push(
|
|
2110
2257
|
...getViewPassthroughMethods(
|
|
2111
2258
|
componentName,
|
|
2112
2259
|
dependencies,
|
|
2113
|
-
|
|
2260
|
+
directComponentInstances,
|
|
2114
2261
|
componentHierarchyMap,
|
|
2115
2262
|
blockedViewPassthroughMethodNames,
|
|
2116
2263
|
),
|
|
@@ -2128,6 +2275,8 @@ function prepareViewObjectModelClass(
|
|
|
2128
2275
|
return {
|
|
2129
2276
|
className,
|
|
2130
2277
|
componentRefsForInstances,
|
|
2278
|
+
directComponentInstances,
|
|
2279
|
+
projectedComponentInstances,
|
|
2131
2280
|
attachmentsForThisClass,
|
|
2132
2281
|
widgetInstances,
|
|
2133
2282
|
isView,
|
|
@@ -2235,7 +2384,10 @@ function generateViewObjectModelContent(
|
|
|
2235
2384
|
addNamedImport(sourceFile, {
|
|
2236
2385
|
moduleSpecifier: "@playwright/test",
|
|
2237
2386
|
isTypeOnly: true,
|
|
2238
|
-
namedImports: [
|
|
2387
|
+
namedImports: [
|
|
2388
|
+
{ name: "Locator", alias: "PwLocator" },
|
|
2389
|
+
{ name: "Page", alias: "PwPage" },
|
|
2390
|
+
],
|
|
2239
2391
|
});
|
|
2240
2392
|
}
|
|
2241
2393
|
|
|
@@ -2273,7 +2425,7 @@ function generateViewObjectModelContent(
|
|
|
2273
2425
|
function getViewPassthroughMethods(
|
|
2274
2426
|
viewName: string,
|
|
2275
2427
|
viewDependencies: IComponentDependencies,
|
|
2276
|
-
|
|
2428
|
+
componentInstances: ResolvedComponentInstance[],
|
|
2277
2429
|
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
2278
2430
|
blockedMethodNames: Set<string> = new Set(),
|
|
2279
2431
|
) {
|
|
@@ -2282,8 +2434,8 @@ function getViewPassthroughMethods(
|
|
|
2282
2434
|
// methodName -> candidates
|
|
2283
2435
|
const methodToChildren = new Map<string, Array<{ childProp: string; signature: PomMethodSignature }>>();
|
|
2284
2436
|
|
|
2285
|
-
for (const
|
|
2286
|
-
const childDeps = componentHierarchyMap.get(
|
|
2437
|
+
for (const instance of componentInstances) {
|
|
2438
|
+
const childDeps = componentHierarchyMap.get(instance.componentRef);
|
|
2287
2439
|
if (!childDeps || !childDeps.dataTestIdSet?.size)
|
|
2288
2440
|
continue;
|
|
2289
2441
|
|
|
@@ -2292,7 +2444,7 @@ function getViewPassthroughMethods(
|
|
|
2292
2444
|
continue;
|
|
2293
2445
|
|
|
2294
2446
|
// Property name matches how we emit instance fields (strip .vue if present).
|
|
2295
|
-
const childProp =
|
|
2447
|
+
const childProp = instance.instanceName;
|
|
2296
2448
|
|
|
2297
2449
|
for (const [name, sig] of methods.entries()) {
|
|
2298
2450
|
if (!sig)
|
|
@@ -3234,8 +3386,8 @@ function getWidgetInstancesForView(
|
|
|
3234
3386
|
}
|
|
3235
3387
|
|
|
3236
3388
|
function getComponentInstances(
|
|
3237
|
-
|
|
3238
|
-
|
|
3389
|
+
componentInstances: ResolvedComponentInstance[],
|
|
3390
|
+
projectedComponentInstances: ResolvedProjectedComponentInstance[],
|
|
3239
3391
|
attachmentsForThisView: Array<{ className: string; propertyName: string }> = [],
|
|
3240
3392
|
widgetInstances: WidgetInstance[] = [],
|
|
3241
3393
|
) {
|
|
@@ -3255,31 +3407,83 @@ function getComponentInstances(
|
|
|
3255
3407
|
}));
|
|
3256
3408
|
}
|
|
3257
3409
|
|
|
3258
|
-
|
|
3259
|
-
if (
|
|
3260
|
-
const childName = child.split(".vue")[0];
|
|
3410
|
+
for (const instance of componentInstances) {
|
|
3411
|
+
if (instance.parameters.length === 0) {
|
|
3261
3412
|
declarations.push(createClassProperty({
|
|
3262
|
-
name:
|
|
3263
|
-
type:
|
|
3413
|
+
name: instance.instanceName,
|
|
3414
|
+
type: instance.className,
|
|
3264
3415
|
}));
|
|
3416
|
+
continue;
|
|
3265
3417
|
}
|
|
3266
|
-
|
|
3418
|
+
|
|
3419
|
+
declarations.push(createClassMethod({
|
|
3420
|
+
name: instance.instanceName,
|
|
3421
|
+
parameters: toTypeScriptPomParameterStructures(instance.parameters),
|
|
3422
|
+
returnType: instance.className,
|
|
3423
|
+
statements: (writer) => {
|
|
3424
|
+
writer.writeLine(`const root = this.componentInstanceLocator(${toTypeScriptPomPatternExpression(instance.selector)});`);
|
|
3425
|
+
writer.writeLine(`return new ${instance.className}(this.page, root);`);
|
|
3426
|
+
},
|
|
3427
|
+
}));
|
|
3428
|
+
}
|
|
3429
|
+
|
|
3430
|
+
for (const projection of projectedComponentInstances) {
|
|
3431
|
+
const projectedPropertiesType = projection.contents.length > 0
|
|
3432
|
+
? ` & { ${projection.contents.map(content => `readonly ${content.instanceName}: ${content.className}`).join("; ")} }`
|
|
3433
|
+
: "";
|
|
3434
|
+
const statements = (writer: TypeScriptWriter) => {
|
|
3435
|
+
const ownerSelector = toTypeScriptPomPatternExpression(projection.owner.selector);
|
|
3436
|
+
const targetSelector = toTypeScriptPomPatternExpression(projection.target.selector);
|
|
3437
|
+
writer.writeLine(`const ownerRoot = this.componentInstanceLocator(${ownerSelector});`);
|
|
3438
|
+
writer.writeLine(`const root = this.componentInstanceLocator(${targetSelector}, ownerRoot);`);
|
|
3439
|
+
writer.writeLine(`const instance = new ${projection.target.className}(this.page, root);`);
|
|
3440
|
+
if (projection.contents.length === 0) {
|
|
3441
|
+
writer.writeLine("return instance;");
|
|
3442
|
+
return;
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
writer.writeLine("return Object.assign(instance, {");
|
|
3446
|
+
writer.indent(() => {
|
|
3447
|
+
for (const content of projection.contents) {
|
|
3448
|
+
const contentSelector = toTypeScriptPomPatternExpression(content.selector);
|
|
3449
|
+
writer.writeLine(`${content.instanceName}: new ${content.className}(this.page, this.componentInstanceLocator(${contentSelector}, root)),`);
|
|
3450
|
+
}
|
|
3451
|
+
});
|
|
3452
|
+
writer.writeLine("});");
|
|
3453
|
+
};
|
|
3454
|
+
const returnType = `${projection.target.className}${projectedPropertiesType}`;
|
|
3455
|
+
|
|
3456
|
+
declarations.push(projection.target.parameters.length > 0
|
|
3457
|
+
? createClassMethod({
|
|
3458
|
+
name: projection.target.instanceName,
|
|
3459
|
+
parameters: toTypeScriptPomParameterStructures(projection.target.parameters),
|
|
3460
|
+
returnType,
|
|
3461
|
+
statements,
|
|
3462
|
+
})
|
|
3463
|
+
: createClassGetter({
|
|
3464
|
+
name: projection.target.instanceName,
|
|
3465
|
+
returnType,
|
|
3466
|
+
statements,
|
|
3467
|
+
}));
|
|
3468
|
+
}
|
|
3267
3469
|
|
|
3268
3470
|
return declarations;
|
|
3269
3471
|
}
|
|
3270
3472
|
|
|
3271
3473
|
function getConstructor(
|
|
3272
|
-
|
|
3273
|
-
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
3474
|
+
componentInstances: ResolvedComponentInstance[],
|
|
3274
3475
|
attachmentsForThisView: Array<{ className: string; propertyName: string }> = [],
|
|
3275
3476
|
widgetInstances: WidgetInstance[] = [],
|
|
3276
3477
|
options?: { testIdAttribute?: string },
|
|
3277
3478
|
) {
|
|
3278
3479
|
const attr = (options?.testIdAttribute ?? "data-testid").trim() || "data-testid";
|
|
3279
3480
|
return createClassConstructor({
|
|
3280
|
-
parameters: [
|
|
3481
|
+
parameters: [
|
|
3482
|
+
{ name: "page", type: "PwPage" },
|
|
3483
|
+
{ name: "root", type: "PwLocator", hasQuestionToken: true },
|
|
3484
|
+
],
|
|
3281
3485
|
statements: (writer) => {
|
|
3282
|
-
writer.writeLine(`super(page, { testIdAttribute: ${JSON.stringify(attr)} });`);
|
|
3486
|
+
writer.writeLine(`super(page, { root, testIdAttribute: ${JSON.stringify(attr)} });`);
|
|
3283
3487
|
|
|
3284
3488
|
for (const a of attachmentsForThisView) {
|
|
3285
3489
|
// Hand-written (custom) POMs are declared against Playwright's full `Page`.
|
|
@@ -3292,12 +3496,12 @@ function getConstructor(
|
|
|
3292
3496
|
writer.writeLine(`this.${w.propertyName} = new ${w.className}(this.page, ${JSON.stringify(w.testId)});`);
|
|
3293
3497
|
}
|
|
3294
3498
|
|
|
3295
|
-
|
|
3296
|
-
if (
|
|
3297
|
-
const
|
|
3298
|
-
writer.writeLine(`this.${
|
|
3499
|
+
for (const instance of componentInstances) {
|
|
3500
|
+
if (instance.parameters.length === 0) {
|
|
3501
|
+
const selector = toTypeScriptPomPatternExpression(instance.selector);
|
|
3502
|
+
writer.writeLine(`this.${instance.instanceName} = new ${instance.className}(page, this.componentInstanceLocator(${selector}));`);
|
|
3299
3503
|
}
|
|
3300
|
-
}
|
|
3504
|
+
}
|
|
3301
3505
|
},
|
|
3302
3506
|
});
|
|
3303
3507
|
}
|