@immense/vue-pom-generator 1.0.96 → 1.0.98
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 +64 -0
- package/RELEASE_NOTES.md +21 -57
- package/class-generation/index.ts +315 -3
- package/class-generation/vue-test-utils-pom.ts +112 -0
- package/dist/class-generation/index.d.ts +2 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/class-generation/vue-test-utils-pom.d.ts +28 -0
- package/dist/class-generation/vue-test-utils-pom.d.ts.map +1 -0
- package/dist/index.cjs +259 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +259 -3
- package/dist/index.mjs.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/resolved-generation-options.d.ts +1 -0
- package/dist/plugin/resolved-generation-options.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +9 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/pom-discoverability.d.ts +0 -1
- package/dist/pom-discoverability.d.ts.map +1 -1
- package/dist/pom-params.d.ts +0 -6
- package/dist/pom-params.d.ts.map +1 -1
- package/dist/pom-patterns.d.ts +0 -3
- package/dist/pom-patterns.d.ts.map +1 -1
- package/dist/router-introspection.d.ts +0 -1
- package/dist/router-introspection.d.ts.map +1 -1
- package/dist/scripts/floating-ui-runtime-entry.d.ts +2 -0
- package/dist/scripts/floating-ui-runtime-entry.d.ts.map +1 -0
- package/dist/tests/broad/helpers/fake-runtime.d.ts +2 -6
- package/dist/tests/broad/helpers/fake-runtime.d.ts.map +1 -1
- package/dist/tests/vue-test-utils-pom.test.d.ts +2 -0
- package/dist/tests/vue-test-utils-pom.test.d.ts.map +1 -0
- package/dist/utils.d.ts +2 -14
- package/dist/utils.d.ts.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -794,6 +794,56 @@ identifier (for example `data-value`).
|
|
|
794
794
|
|
|
795
795
|
`data-pom-instance` is generator-owned. Do not author it in Vue templates.
|
|
796
796
|
|
|
797
|
+
## Vue Test Utils component objects
|
|
798
|
+
|
|
799
|
+
Enable `generation.vueTestUtils` to emit behavior-oriented component objects for mounted
|
|
800
|
+
Vue unit tests alongside the Playwright output:
|
|
801
|
+
|
|
802
|
+
```ts
|
|
803
|
+
vuePomGenerator({
|
|
804
|
+
generation: {
|
|
805
|
+
vueTestUtils: {},
|
|
806
|
+
},
|
|
807
|
+
});
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
The default output directory is `tests/unit/__generated__`. The consuming project must
|
|
811
|
+
install Vue Test Utils 2.x. The test remains responsible for mounting the component and
|
|
812
|
+
providing its plugins, props, stubs, and mocks:
|
|
813
|
+
|
|
814
|
+
```ts
|
|
815
|
+
import { mount } from "@vue/test-utils";
|
|
816
|
+
import { expect, test } from "vitest";
|
|
817
|
+
|
|
818
|
+
import DeploymentParametersForm from "@/components/DeploymentParametersForm.vue";
|
|
819
|
+
import { DeploymentParametersForm as DeploymentParametersFormPom } from "./__generated__";
|
|
820
|
+
|
|
821
|
+
test("requires an onboarding parameter", async () => {
|
|
822
|
+
const wrapper = mount(DeploymentParametersForm, { /* project-specific mount options */ });
|
|
823
|
+
const form = new DeploymentParametersFormPom(wrapper);
|
|
824
|
+
|
|
825
|
+
await form
|
|
826
|
+
.DynamicFormField(parameterName)
|
|
827
|
+
.OnboardingOption
|
|
828
|
+
.OverridePolicyOptions
|
|
829
|
+
.selectByValue(ParameterOverridePolicy.Require);
|
|
830
|
+
|
|
831
|
+
expect(form.DynamicFormField(parameterName).wrapper.text()).toContain("Required");
|
|
832
|
+
});
|
|
833
|
+
```
|
|
834
|
+
|
|
835
|
+
The Vue templates mounted by the test must be compiled with the same
|
|
836
|
+
`createVuePomGeneratorPlugins(...)` configuration (normally by sharing the Vite plugins
|
|
837
|
+
with Vitest). That compilation injects the generator-owned `data-pom-instance` scoping
|
|
838
|
+
markers used by semantic component chains.
|
|
839
|
+
|
|
840
|
+
These generated objects reuse the same semantic instance names, keyed scopes, named-slot
|
|
841
|
+
projections, and action names as the Playwright POMs. They expose actions such as
|
|
842
|
+
`clickSave()`, `typeName(text)`, and `selectByValue(value)`, not a generated assertion DSL
|
|
843
|
+
or the raw Vue component ancestry. Each object exposes its scoped Vue Test Utils `wrapper`
|
|
844
|
+
for assertions and uncommon interactions. This keeps assertions in Vitest/VTU while
|
|
845
|
+
preventing selectors in the test from escaping the intended component instance.
|
|
846
|
+
|
|
797
847
|
## Playwright fixtures: actual behavior and caveats
|
|
798
848
|
|
|
799
849
|
When `generation.playwright.fixtures` is enabled, the generator emits a strongly typed Playwright fixture module.
|
|
@@ -1306,6 +1356,20 @@ If omitted, router introspection is off.
|
|
|
1306
1356
|
- `Record<string, fn>` for explicit shim implementations
|
|
1307
1357
|
- **Not supported:** wildcard `*` exports
|
|
1308
1358
|
|
|
1359
|
+
### `generation.vueTestUtils`
|
|
1360
|
+
|
|
1361
|
+
- **What it does:** Emits behavior-oriented component objects for Vue Test Utils.
|
|
1362
|
+
- **Why it exists:** unit tests can use the same semantic instance names and generated actions as browser tests without copying test-id selectors.
|
|
1363
|
+
- **Benefit:** selectors stay compiler-derived while the test continues to own mounting and assertions.
|
|
1364
|
+
- **Without it:** no Vue Test Utils files are generated.
|
|
1365
|
+
- **Default output:** `tests/unit/__generated__`.
|
|
1366
|
+
- **Requirement:** the consuming project must provide Vue Test Utils 2.x.
|
|
1367
|
+
|
|
1368
|
+
#### `generation.vueTestUtils.outDir`
|
|
1369
|
+
|
|
1370
|
+
- **What it does:** Overrides the Vue Test Utils generated-file directory.
|
|
1371
|
+
- **Without it:** defaults to `tests/unit/__generated__`.
|
|
1372
|
+
|
|
1309
1373
|
### `generation.playwright`
|
|
1310
1374
|
|
|
1311
1375
|
This object holds Playwright-specific additions on top of the generated TypeScript classes.
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,77 +1,41 @@
|
|
|
1
|
-
|
|
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:
|
|
1
|
+
v1.0.98
|
|
14
2
|
|
|
15
3
|
Highlights
|
|
16
4
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
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.
|
|
5
|
+
- Cleared all outstanding Knip findings — removed unused exports, simplified configuration, and
|
|
6
|
+
extracted a dedicated floating-UI runtime entry point
|
|
7
|
+
- Net reduction of 32 lines across 11 files; one new entry-point file added
|
|
8
|
+
- No behavioral changes; cleanup and tooling hygiene only
|
|
32
9
|
|
|
33
10
|
Changes
|
|
34
11
|
|
|
35
|
-
|
|
12
|
+
Knip configuration
|
|
36
13
|
|
|
37
|
-
-
|
|
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.
|
|
14
|
+
- Simplified knip.json rules (reduced from 11 lines to a leaner set)
|
|
47
15
|
|
|
48
|
-
|
|
16
|
+
Dead-code removal
|
|
49
17
|
|
|
50
|
-
-
|
|
51
|
-
|
|
18
|
+
- Removed unused exports from pom-discoverability.ts (4 deletions)
|
|
19
|
+
- Trimmed tests/broad/helpers/fake-runtime.ts (21 lines reduced)
|
|
20
|
+
- Trimmed scripts/bundle-floating-ui-runtime.mjs (21 lines reduced)
|
|
52
21
|
|
|
53
|
-
|
|
22
|
+
New file
|
|
54
23
|
|
|
55
|
-
- Added
|
|
56
|
-
|
|
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.
|
|
24
|
+
- Added scripts/floating-ui-runtime-entry.ts — extracted dedicated entry point for the floating-UI
|
|
25
|
+
runtime bundler
|
|
60
26
|
|
|
61
|
-
|
|
27
|
+
Minor cleanup
|
|
62
28
|
|
|
63
|
-
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
selectors.
|
|
29
|
+
- pom-params.ts, pom-patterns.ts, router-introspection.ts, utils.ts — small adjustments to satisfy
|
|
30
|
+
Knip
|
|
31
|
+
- package.json / package-lock.json — updated entry-point wiring
|
|
67
32
|
|
|
68
33
|
Pull Requests Included
|
|
69
34
|
|
|
70
|
-
- ]8;id=md-
|
|
35
|
+
- #61 Clear Knip findings — by @dkattan (]8;id=md-ce60fz;https://github.com/immense/vue-pom-generator/pull/61link]8;;]8;;)]8;;
|
|
71
36
|
|
|
72
37
|
Testing
|
|
73
38
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
producing 643 POMs / 1,443 selectors.
|
|
39
|
+
No new tests added; changes are code cleanup, configuration, and build-script refactoring only.
|
|
40
|
+
Existing test suite continues to cover the affected modules.
|
|
77
41
|
|
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
PomExtraClickMethodSpec,
|
|
61
61
|
PomPrimarySpec,
|
|
62
62
|
PomSelectorSpec,
|
|
63
|
+
buildPomGeneratedActionName,
|
|
63
64
|
toPascalCase,
|
|
64
65
|
upperFirst,
|
|
65
66
|
} from "../utils";
|
|
@@ -684,7 +685,9 @@ function generateMethodMembersFromPom(
|
|
|
684
685
|
);
|
|
685
686
|
}
|
|
686
687
|
|
|
687
|
-
function
|
|
688
|
+
function getUniquePrimaryPomSpecs(
|
|
689
|
+
dependencies: IComponentDependencies,
|
|
690
|
+
): Array<{ pom: PomPrimarySpec; target: string | undefined }> {
|
|
688
691
|
const entries = Array.from(dependencies.dataTestIdSet ?? []);
|
|
689
692
|
const primarySpecsAll = entries
|
|
690
693
|
.map(e => ({ pom: e.pom, target: e.targetPageObjectModelClass }))
|
|
@@ -696,7 +699,7 @@ function generateMethodsContentForDependencies(componentName: string, dependenci
|
|
|
696
699
|
// It's possible to end up with multiple IDataTestId entries that carry identical `pom` specs.
|
|
697
700
|
// When we emit from IR, we must de-dupe here to avoid duplicate getters/methods.
|
|
698
701
|
const seenPrimaryKeys = new Set<string>();
|
|
699
|
-
|
|
702
|
+
return primarySpecsAll.filter(({ pom, target }) => {
|
|
700
703
|
const alternates = (pom.alternateSelectors ?? [])
|
|
701
704
|
.slice()
|
|
702
705
|
.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
@@ -716,6 +719,10 @@ function generateMethodsContentForDependencies(componentName: string, dependenci
|
|
|
716
719
|
seenPrimaryKeys.add(key);
|
|
717
720
|
return true;
|
|
718
721
|
});
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function generateMethodsContentForDependencies(componentName: string, dependencies: IComponentDependencies): TypeScriptClassMember[] {
|
|
725
|
+
const primarySpecs = getUniquePrimaryPomSpecs(dependencies);
|
|
719
726
|
|
|
720
727
|
const extras = (dependencies.pomExtraMethods ?? [])
|
|
721
728
|
.slice()
|
|
@@ -759,6 +766,9 @@ export interface GenerateFilesOptions {
|
|
|
759
766
|
*/
|
|
760
767
|
generateFixtures?: boolean | string | { outDir?: string };
|
|
761
768
|
|
|
769
|
+
/** Generate Vue Test Utils component objects in this directory when set. */
|
|
770
|
+
vueTestUtilsOutDir?: string;
|
|
771
|
+
|
|
762
772
|
/**
|
|
763
773
|
* Project root used for resolving conventional paths (e.g. src/views, tests/playwright/pom/custom).
|
|
764
774
|
* Defaults to process.cwd() for backwards compatibility.
|
|
@@ -881,6 +891,7 @@ export async function generateFiles(
|
|
|
881
891
|
const {
|
|
882
892
|
outDir: outDirOverride,
|
|
883
893
|
generateFixtures,
|
|
894
|
+
vueTestUtilsOutDir,
|
|
884
895
|
customPomAttachments = [],
|
|
885
896
|
projectRoot,
|
|
886
897
|
customPomDir,
|
|
@@ -906,6 +917,9 @@ export async function generateFiles(
|
|
|
906
917
|
: ["ts"];
|
|
907
918
|
|
|
908
919
|
const outDir = outDirOverride ?? "./pom";
|
|
920
|
+
if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
|
|
921
|
+
throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
|
|
922
|
+
}
|
|
909
923
|
|
|
910
924
|
const routeMetaByComponent = routeMetaByComponentOverride
|
|
911
925
|
?? (vueRouterFluentChaining
|
|
@@ -976,12 +990,310 @@ export async function generateFiles(
|
|
|
976
990
|
}
|
|
977
991
|
}
|
|
978
992
|
|
|
993
|
+
if (vueTestUtilsOutDir) {
|
|
994
|
+
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
995
|
+
emittableComponentHierarchyMap,
|
|
996
|
+
vueTestUtilsOutDir,
|
|
997
|
+
{ testIdAttribute },
|
|
998
|
+
);
|
|
999
|
+
for (const file of vueTestUtilsFiles) {
|
|
1000
|
+
writeGeneratedFile(file);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
979
1004
|
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFilePaths);
|
|
980
1005
|
for (const file of gitattributesFiles) {
|
|
981
1006
|
createFile(file.filePath, file.content);
|
|
982
1007
|
}
|
|
983
1008
|
}
|
|
984
1009
|
|
|
1010
|
+
const VUE_TEST_UTILS_OMITTED_PARAMETERS = new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
1011
|
+
|
|
1012
|
+
function getVueTestUtilsParameters(
|
|
1013
|
+
parameters: PomParameterSpec[],
|
|
1014
|
+
patterns: PomStringPattern[],
|
|
1015
|
+
options: { omit?: string[] } = {},
|
|
1016
|
+
) {
|
|
1017
|
+
return orderPomPatternParameters(parameters, patterns, options)
|
|
1018
|
+
.filter(parameter => !VUE_TEST_UTILS_OMITTED_PARAMETERS.has(parameter.name));
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
function getVueTestUtilsPrimaryMembers(primary: PomPrimarySpec): TypeScriptClassMember[] {
|
|
1022
|
+
if (primary.emitPrimary === false) {
|
|
1023
|
+
return [];
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const selectors = uniquePomStringPatterns(primary.selector, primary.alternateSelectors);
|
|
1027
|
+
const parameters = getVueTestUtilsParameters(primary.parameters, selectors);
|
|
1028
|
+
const actionName = buildPomGeneratedActionName(primary);
|
|
1029
|
+
const selectorExpressions = selectors.map(selector => toTypeScriptPomPatternExpression(selector));
|
|
1030
|
+
const targetExpression = selectorExpressions.length === 1
|
|
1031
|
+
? `this.getByTestId(${selectorExpressions[0]})`
|
|
1032
|
+
: `this.getByAnyTestId([${selectorExpressions.join(", ")}])`;
|
|
1033
|
+
|
|
1034
|
+
let actionStatement: string;
|
|
1035
|
+
switch (primary.nativeRole) {
|
|
1036
|
+
case "input":
|
|
1037
|
+
actionStatement = `await ${targetExpression}.setValue(text);`;
|
|
1038
|
+
break;
|
|
1039
|
+
case "select":
|
|
1040
|
+
actionStatement = `await ${targetExpression}.setValue(value);`;
|
|
1041
|
+
break;
|
|
1042
|
+
case "vselect":
|
|
1043
|
+
actionStatement = selectors.length === 1
|
|
1044
|
+
? `await this.selectVSelectByTestId(${selectorExpressions[0]}, value);`
|
|
1045
|
+
: `await this.selectVSelectByAnyTestId([${selectorExpressions.join(", ")}], value);`;
|
|
1046
|
+
break;
|
|
1047
|
+
case "radio":
|
|
1048
|
+
actionStatement = `await ${targetExpression}.setValue();`;
|
|
1049
|
+
break;
|
|
1050
|
+
default:
|
|
1051
|
+
actionStatement = `await ${targetExpression}.trigger("click");`;
|
|
1052
|
+
break;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
return [createClassMethod({
|
|
1056
|
+
name: actionName,
|
|
1057
|
+
isAsync: true,
|
|
1058
|
+
parameters: toTypeScriptPomParameterStructures(parameters),
|
|
1059
|
+
statements: [actionStatement],
|
|
1060
|
+
})];
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
function getVueTestUtilsExtraMembers(extra: PomExtraClickMethodSpec): TypeScriptClassMember[] {
|
|
1064
|
+
if (extra.kind !== "click") {
|
|
1065
|
+
return [];
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
const patterns = extra.selector.kind === "testId"
|
|
1069
|
+
? [extra.selector.testId]
|
|
1070
|
+
: [extra.selector.rootTestId, extra.selector.label];
|
|
1071
|
+
const parameters = getVueTestUtilsParameters(extra.parameters, patterns, {
|
|
1072
|
+
omit: extra.keyLiteral === undefined ? [] : ["key"],
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
return [createClassMethod({
|
|
1076
|
+
name: extra.name,
|
|
1077
|
+
isAsync: true,
|
|
1078
|
+
parameters: toTypeScriptPomParameterStructures(parameters),
|
|
1079
|
+
statements: (writer) => {
|
|
1080
|
+
if (extra.keyLiteral !== undefined) {
|
|
1081
|
+
writer.writeLine(`const key = ${JSON.stringify(extra.keyLiteral)};`);
|
|
1082
|
+
}
|
|
1083
|
+
if (extra.selector.kind === "testId") {
|
|
1084
|
+
writer.writeLine(`await this.clickByTestId(${toTypeScriptPomPatternExpression(extra.selector.testId)});`);
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
writer.writeLine(
|
|
1088
|
+
`await this.clickWithinTestIdByLabel(${toTypeScriptPomPatternExpression(extra.selector.rootTestId)}, `
|
|
1089
|
+
+ `${toTypeScriptPomPatternExpression(extra.selector.label)}, ${extra.selector.exact ?? false});`,
|
|
1090
|
+
);
|
|
1091
|
+
},
|
|
1092
|
+
})];
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
function getVueTestUtilsComponentMembers(
|
|
1096
|
+
componentInstances: ResolvedComponentInstance[],
|
|
1097
|
+
projectedComponentInstances: ResolvedProjectedComponentInstance[],
|
|
1098
|
+
testIdAttribute: string,
|
|
1099
|
+
): TypeScriptClassMember[] {
|
|
1100
|
+
const members: TypeScriptClassMember[] = [];
|
|
1101
|
+
|
|
1102
|
+
for (const instance of componentInstances) {
|
|
1103
|
+
if (instance.parameters.length === 0) {
|
|
1104
|
+
members.push(createClassGetter({
|
|
1105
|
+
name: instance.instanceName,
|
|
1106
|
+
returnType: instance.className,
|
|
1107
|
+
statements: [
|
|
1108
|
+
`return new ${instance.className}(this.getComponentInstance(${toTypeScriptPomPatternExpression(instance.selector)}));`,
|
|
1109
|
+
],
|
|
1110
|
+
}));
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
members.push(createClassMethod({
|
|
1115
|
+
name: instance.instanceName,
|
|
1116
|
+
parameters: toTypeScriptPomParameterStructures(instance.parameters),
|
|
1117
|
+
returnType: instance.className,
|
|
1118
|
+
statements: [
|
|
1119
|
+
`return new ${instance.className}(this.getComponentInstance(${toTypeScriptPomPatternExpression(instance.selector)}));`,
|
|
1120
|
+
],
|
|
1121
|
+
}));
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
for (const projection of projectedComponentInstances) {
|
|
1125
|
+
const projectedPropertiesType = projection.contents.length > 0
|
|
1126
|
+
? ` & { ${projection.contents.map(content => `readonly ${content.instanceName}: ${content.className}`).join("; ")} }`
|
|
1127
|
+
: "";
|
|
1128
|
+
const statements = (writer: TypeScriptWriter) => {
|
|
1129
|
+
writer.writeLine(`const ownerRoot = this.getComponentInstance(${toTypeScriptPomPatternExpression(projection.owner.selector)});`);
|
|
1130
|
+
writer.writeLine(`const root = this.getComponentInstance(${toTypeScriptPomPatternExpression(projection.target.selector)}, ownerRoot);`);
|
|
1131
|
+
writer.writeLine(`const instance = new ${projection.target.className}(root);`);
|
|
1132
|
+
if (projection.contents.length === 0) {
|
|
1133
|
+
writer.writeLine("return instance;");
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
writer.writeLine("return Object.assign(instance, {");
|
|
1137
|
+
writer.indent(() => {
|
|
1138
|
+
for (const content of projection.contents) {
|
|
1139
|
+
writer.writeLine(
|
|
1140
|
+
`${content.instanceName}: new ${content.className}(this.getComponentInstance(`
|
|
1141
|
+
+ `${toTypeScriptPomPatternExpression(content.selector)}, root)),`,
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
writer.writeLine("});");
|
|
1146
|
+
};
|
|
1147
|
+
const returnType = `${projection.target.className}${projectedPropertiesType}`;
|
|
1148
|
+
members.push(projection.target.parameters.length > 0
|
|
1149
|
+
? createClassMethod({
|
|
1150
|
+
name: projection.target.instanceName,
|
|
1151
|
+
parameters: toTypeScriptPomParameterStructures(projection.target.parameters),
|
|
1152
|
+
returnType,
|
|
1153
|
+
statements,
|
|
1154
|
+
})
|
|
1155
|
+
: createClassGetter({
|
|
1156
|
+
name: projection.target.instanceName,
|
|
1157
|
+
returnType,
|
|
1158
|
+
statements,
|
|
1159
|
+
}));
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
members.push(createClassConstructor({
|
|
1163
|
+
parameters: [{ name: "wrapper", type: "VueTestUtilsPomRoot" }],
|
|
1164
|
+
statements: (writer) => {
|
|
1165
|
+
writer.writeLine(`super(wrapper, { testIdAttribute: ${JSON.stringify(testIdAttribute)} });`);
|
|
1166
|
+
},
|
|
1167
|
+
}));
|
|
1168
|
+
|
|
1169
|
+
return members;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function generateVueTestUtilsContent(
|
|
1173
|
+
componentName: string,
|
|
1174
|
+
dependencies: IComponentDependencies,
|
|
1175
|
+
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
1176
|
+
outputDir: string,
|
|
1177
|
+
runtimePath: string,
|
|
1178
|
+
generatedFilePathByComponent: Map<string, string>,
|
|
1179
|
+
testIdAttribute: string,
|
|
1180
|
+
): string {
|
|
1181
|
+
const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
|
|
1182
|
+
outputStructure: "split",
|
|
1183
|
+
outputDir,
|
|
1184
|
+
testIdAttribute,
|
|
1185
|
+
});
|
|
1186
|
+
const runtimeImport = stripExtension(toPosixRelativePath(outputDir, runtimePath));
|
|
1187
|
+
const sourceRel = toPosixRelativePath(outputDir, dependencies.filePath);
|
|
1188
|
+
const componentImports = Array.from(prepared.componentRefsForInstances)
|
|
1189
|
+
.map((componentRef) => {
|
|
1190
|
+
const className = componentRef.endsWith(".vue") ? componentRef.slice(0, -4) : componentRef;
|
|
1191
|
+
const filePath = generatedFilePathByComponent.get(className);
|
|
1192
|
+
return filePath ? { className, moduleSpecifier: stripExtension(toPosixRelativePath(outputDir, filePath)) } : null;
|
|
1193
|
+
})
|
|
1194
|
+
.filter((value): value is { className: string; moduleSpecifier: string } => !!value)
|
|
1195
|
+
.sort((left, right) => left.className.localeCompare(right.className));
|
|
1196
|
+
|
|
1197
|
+
const members = [
|
|
1198
|
+
...getVueTestUtilsComponentMembers(
|
|
1199
|
+
prepared.directComponentInstances,
|
|
1200
|
+
prepared.projectedComponentInstances,
|
|
1201
|
+
testIdAttribute,
|
|
1202
|
+
),
|
|
1203
|
+
...getUniquePrimaryPomSpecs(dependencies)
|
|
1204
|
+
.flatMap(({ pom }) => getVueTestUtilsPrimaryMembers(pom)),
|
|
1205
|
+
...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers),
|
|
1206
|
+
];
|
|
1207
|
+
|
|
1208
|
+
return renderSourceFile(`${componentName}.vtu.g.ts`, (sourceFile) => {
|
|
1209
|
+
addNamedImport(sourceFile, {
|
|
1210
|
+
moduleSpecifier: runtimeImport,
|
|
1211
|
+
namedImports: ["VueTestUtilsPom"],
|
|
1212
|
+
});
|
|
1213
|
+
addNamedImport(sourceFile, {
|
|
1214
|
+
moduleSpecifier: runtimeImport,
|
|
1215
|
+
namedImports: ["VueTestUtilsPomRoot"],
|
|
1216
|
+
isTypeOnly: true,
|
|
1217
|
+
});
|
|
1218
|
+
for (const componentImport of componentImports) {
|
|
1219
|
+
addNamedImport(sourceFile, {
|
|
1220
|
+
moduleSpecifier: componentImport.moduleSpecifier,
|
|
1221
|
+
namedImports: [componentImport.className],
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
const declaration = sourceFile.addClass({
|
|
1226
|
+
name: prepared.className,
|
|
1227
|
+
isExported: true,
|
|
1228
|
+
extends: "VueTestUtilsPom",
|
|
1229
|
+
docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`],
|
|
1230
|
+
});
|
|
1231
|
+
for (const member of members) {
|
|
1232
|
+
addClassMember(declaration, member);
|
|
1233
|
+
}
|
|
1234
|
+
}, {
|
|
1235
|
+
prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
function generateVueTestUtilsFiles(
|
|
1240
|
+
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
1241
|
+
outDir: string,
|
|
1242
|
+
options: { testIdAttribute?: string } = {},
|
|
1243
|
+
): GeneratedFileOutput[] {
|
|
1244
|
+
const base = ensureDir(outDir);
|
|
1245
|
+
const testIdAttribute = options.testIdAttribute?.trim() || "data-testid";
|
|
1246
|
+
const entries = Array.from(componentHierarchyMap.entries())
|
|
1247
|
+
.sort((left, right) => left[0].localeCompare(right[0]));
|
|
1248
|
+
const generatedFilePathByComponent = new Map(
|
|
1249
|
+
entries.map(([componentName]) => [componentName, path.join(base, `${componentName}.vtu.g.ts`)]),
|
|
1250
|
+
);
|
|
1251
|
+
const runtimePath = path.join(base, "_pom-runtime", "vue-test-utils-pom.ts");
|
|
1252
|
+
const files: GeneratedFileOutput[] = entries.map(([componentName, dependencies]) => {
|
|
1253
|
+
const filePath = generatedFilePathByComponent.get(componentName)!;
|
|
1254
|
+
return {
|
|
1255
|
+
filePath,
|
|
1256
|
+
content: generateVueTestUtilsContent(
|
|
1257
|
+
componentName,
|
|
1258
|
+
dependencies,
|
|
1259
|
+
componentHierarchyMap,
|
|
1260
|
+
path.dirname(filePath),
|
|
1261
|
+
runtimePath,
|
|
1262
|
+
generatedFilePathByComponent,
|
|
1263
|
+
testIdAttribute,
|
|
1264
|
+
),
|
|
1265
|
+
};
|
|
1266
|
+
});
|
|
1267
|
+
const [runtimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
1268
|
+
absolutePath: resolvePluginAsset("../class-generation/vue-test-utils-pom.ts"),
|
|
1269
|
+
description: "vue-test-utils-pom.ts",
|
|
1270
|
+
outputPath: runtimePath,
|
|
1271
|
+
}]);
|
|
1272
|
+
if (!runtimeFile) {
|
|
1273
|
+
throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
|
|
1274
|
+
}
|
|
1275
|
+
const indexContent = renderSourceFile("index.ts", (sourceFile) => {
|
|
1276
|
+
addExportAll(sourceFile, stripExtension(toPosixRelativePath(base, runtimePath)));
|
|
1277
|
+
for (const [, filePath] of generatedFilePathByComponent) {
|
|
1278
|
+
addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
|
|
1279
|
+
}
|
|
1280
|
+
}, {
|
|
1281
|
+
prefixText: buildFilePrefix({
|
|
1282
|
+
eslintDisableSortImports: true,
|
|
1283
|
+
commentLines: [
|
|
1284
|
+
"Vue Test Utils POM exports",
|
|
1285
|
+
"DO NOT MODIFY BY HAND",
|
|
1286
|
+
],
|
|
1287
|
+
}),
|
|
1288
|
+
});
|
|
1289
|
+
|
|
1290
|
+
return [
|
|
1291
|
+
...files,
|
|
1292
|
+
{ filePath: path.join(base, "index.ts"), content: indexContent },
|
|
1293
|
+
runtimeFile,
|
|
1294
|
+
];
|
|
1295
|
+
}
|
|
1296
|
+
|
|
985
1297
|
async function generateSplitTypeScriptFiles(
|
|
986
1298
|
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
987
1299
|
vueFilesPathMap: Map<string, string>,
|
|
@@ -2819,7 +3131,7 @@ function getRuntimeGeneratedAssetSpecs(baseDir: string, basePageClassPath: strin
|
|
|
2819
3131
|
const runtimeClassGenSourceDir = resolvePluginAsset("../class-generation");
|
|
2820
3132
|
const runtimeClassGenFiles = fs.readdirSync(runtimeClassGenSourceDir)
|
|
2821
3133
|
.filter(file => file.endsWith(".ts"))
|
|
2822
|
-
.filter(file =>
|
|
3134
|
+
.filter(file => !["base-page.ts", "diagnostics.ts", "index.ts", "vue-test-utils-pom.ts"].includes(file))
|
|
2823
3135
|
.sort((left, right) => left.localeCompare(right));
|
|
2824
3136
|
|
|
2825
3137
|
return [
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { DOMWrapper, type VueWrapper } from "@vue/test-utils";
|
|
2
|
+
|
|
3
|
+
export type VueTestUtilsPomRoot = DOMWrapper<Element> | VueWrapper;
|
|
4
|
+
|
|
5
|
+
export interface VueTestUtilsPomOptions {
|
|
6
|
+
testIdAttribute?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Behavior-oriented runtime for generated Vue Test Utils component objects.
|
|
11
|
+
*
|
|
12
|
+
* Generated objects scope every lookup to `wrapper`; consumers can use that wrapper
|
|
13
|
+
* directly for assertions that do not warrant a generated behavior method.
|
|
14
|
+
*/
|
|
15
|
+
export class VueTestUtilsPom {
|
|
16
|
+
public readonly wrapper: VueTestUtilsPomRoot;
|
|
17
|
+
private readonly testIdAttribute: string;
|
|
18
|
+
|
|
19
|
+
public constructor(wrapper: VueTestUtilsPomRoot, options: VueTestUtilsPomOptions = {}) {
|
|
20
|
+
this.wrapper = wrapper;
|
|
21
|
+
this.testIdAttribute = (options.testIdAttribute ?? "data-testid").trim() || "data-testid";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected getByTestId(testId: string): DOMWrapper<Element> {
|
|
25
|
+
return this.getInScope(this.wrapper, this.selectorFor(this.testIdAttribute, testId));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected getByAnyTestId(testIds: readonly string[]): DOMWrapper<Element> {
|
|
29
|
+
for (const testId of testIds) {
|
|
30
|
+
const candidate = this.findInScope(this.wrapper, this.selectorFor(this.testIdAttribute, testId));
|
|
31
|
+
if (candidate) {
|
|
32
|
+
return candidate;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new Error(`[vue-pom-generator] None of the generated test ids were found: ${testIds.join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected getComponentInstance(instanceId: string, within?: VueTestUtilsPomRoot): DOMWrapper<Element> {
|
|
40
|
+
return this.getInScope(
|
|
41
|
+
within ?? this.wrapper,
|
|
42
|
+
this.selectorFor("data-pom-instance", instanceId),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected async clickByTestId(testId: string): Promise<void> {
|
|
47
|
+
await this.getByTestId(testId).trigger("click");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected async selectVSelectByTestId(testId: string, value: string): Promise<void> {
|
|
51
|
+
await this.selectVSelect(this.getByTestId(testId), value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected async selectVSelectByAnyTestId(testIds: readonly string[], value: string): Promise<void> {
|
|
55
|
+
await this.selectVSelect(this.getByAnyTestId(testIds), value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async selectVSelect(root: DOMWrapper<Element>, value: string): Promise<void> {
|
|
59
|
+
const input = root.get<HTMLInputElement>("input");
|
|
60
|
+
await input.trigger("click");
|
|
61
|
+
await input.setValue(value);
|
|
62
|
+
await root.get("ul.vs__dropdown-menu li[role='option']").trigger("click");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected async clickWithinTestIdByLabel(
|
|
66
|
+
rootTestId: string,
|
|
67
|
+
labelText: string,
|
|
68
|
+
exact: boolean = false,
|
|
69
|
+
): Promise<void> {
|
|
70
|
+
const labels = this.getByTestId(rootTestId).findAll("label");
|
|
71
|
+
const matchingLabels = labels.filter((label) => {
|
|
72
|
+
const text = label.text().trim();
|
|
73
|
+
return exact ? text === labelText : text.includes(labelText);
|
|
74
|
+
});
|
|
75
|
+
if (matchingLabels.length !== 1) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`[vue-pom-generator] Expected one label ${JSON.stringify(labelText)} within ${JSON.stringify(rootTestId)}, found ${matchingLabels.length}.`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const input = matchingLabels[0]!.find<HTMLInputElement>("input");
|
|
82
|
+
if (input.exists()) {
|
|
83
|
+
await input.setValue();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
await matchingLabels[0]!.trigger("click");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private getInScope(root: VueTestUtilsPomRoot, selector: string): DOMWrapper<Element> {
|
|
91
|
+
const candidate = this.findInScope(root, selector);
|
|
92
|
+
if (candidate) {
|
|
93
|
+
return candidate;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Delegate the missing-element error to VTU so callers receive its DOM snapshot.
|
|
97
|
+
return root.get<Element>(selector) as DOMWrapper<Element>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private findInScope(root: VueTestUtilsPomRoot, selector: string): DOMWrapper<Element> | null {
|
|
101
|
+
if (root.element instanceof Element && root.element.matches(selector)) {
|
|
102
|
+
return new DOMWrapper(root.element);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const candidate = root.find<Element>(selector);
|
|
106
|
+
return candidate.exists() ? candidate : null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private selectorFor(attribute: string, value: string): string {
|
|
110
|
+
return `[${attribute}=${JSON.stringify(value)}]`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -53,6 +53,8 @@ export interface GenerateFilesOptions {
|
|
|
53
53
|
generateFixtures?: boolean | string | {
|
|
54
54
|
outDir?: string;
|
|
55
55
|
};
|
|
56
|
+
/** Generate Vue Test Utils component objects in this directory when set. */
|
|
57
|
+
vueTestUtilsOutDir?: string;
|
|
56
58
|
/**
|
|
57
59
|
* Project root used for resolving conventional paths (e.g. src/views, tests/playwright/pom/custom).
|
|
58
60
|
* Defaults to process.cwd() for backwards compatibility.
|