@immense/vue-pom-generator 1.0.96 → 1.0.97
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 +54 -51
- 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/tests/vue-test-utils-pom.test.d.ts +2 -0
- package/dist/tests/vue-test-utils-pom.test.d.ts.map +1 -0
- package/package.json +4 -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,80 @@
|
|
|
1
|
-
I'll verify
|
|
2
|
-
|
|
1
|
+
I'll verify which PRs actually fall within the release window by querying their merge timestamps
|
|
2
|
+
from GitHub.
|
|
3
3
|
|
|
4
|
-
Let me
|
|
4
|
+
Let me use the GitHub MCP tools to find PRs merged in the time window.
|
|
5
5
|
|
|
6
|
-
Let me check the
|
|
6
|
+
Now I have merge timestamps. Let me convert the window to UTC and check the git log to confirm which
|
|
7
|
+
commits are actually in range.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
PR #59 was part of v1.0.96. Only PR #60 is in v1.0.97. Let me examine the actual changes to write
|
|
10
|
+
accurate notes.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
I now have a complete understanding of the changes. Only PR #60 is in this release (PR #59 was part
|
|
13
|
+
of v1.0.96, confirmed by git log). Let me generate the release notes.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
v1.0.96. Here are the release notes:
|
|
15
|
+
Release Notes — v1.0.97
|
|
14
16
|
|
|
15
17
|
Highlights
|
|
16
18
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
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.
|
|
19
|
+
- New: Vue Test Utils component object generation — emit behavior-oriented POM objects for mounted
|
|
20
|
+
Vue unit tests alongside existing Playwright output
|
|
21
|
+
- Generated VTU objects reuse the same semantic instance names, keyed scopes, named-slot
|
|
22
|
+
projections, and action names as Playwright POMs
|
|
23
|
+
- Tests own mounting and assertions; selectors stay compiler-derived via data-pom-instance scoping
|
|
24
|
+
markers
|
|
25
|
+
- New opt-in generation.vueTestUtils config with configurable output directory (defaults to
|
|
26
|
+
tests/unit/__generated__)
|
|
27
|
+
- Full test coverage added: unit tests for the runtime class, type-checking of generated files, and
|
|
28
|
+
packed-plugin smoke checks
|
|
32
29
|
|
|
33
30
|
Changes
|
|
34
31
|
|
|
35
|
-
|
|
32
|
+
Vue Test Utils POM Generation
|
|
36
33
|
|
|
37
|
-
- Added
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
in the public API.
|
|
34
|
+
- Added class-generation/vue-test-utils-pom.ts — VueTestUtilsPom base class exposing getByTestId,
|
|
35
|
+
getByAnyTestId, getComponentInstance, clickByTestId, selectVSelectByTestId, and a public wrapper for
|
|
36
|
+
consumer assertions
|
|
37
|
+
- Added generateVueTestUtilsFiles and supporting helpers (getVueTestUtilsPrimaryMembers,
|
|
38
|
+
getVueTestUtilsExtraMembers, getVueTestUtilsParameters) to class-generation/index.ts
|
|
39
|
+
- Generated actions include clickSave(), typeName(text), selectByValue(value), and v-select
|
|
40
|
+
interactions — no generated assertion DSL or raw component ancestry exposed
|
|
41
|
+
- Refactored getUniquePrimaryPomSpecs out of generateMethodsContentForDependencies for
|
|
42
|
+
deduplication reuse
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
Configuration & Plugin Wiring
|
|
45
|
+
|
|
46
|
+
- Added generation.vueTestUtils option (with outDir) to VuePomGeneratorPluginOptions in
|
|
47
|
+
plugin/types.ts
|
|
48
|
+
- Added vueTestUtilsOutDir to ResolvedGenerationSupportOptions in
|
|
49
|
+
plugin/resolved-generation-options.ts
|
|
50
|
+
- Wired the option through create-vue-pom-generator-plugins.ts, build-plugin.ts, and dev-plugin.ts
|
|
51
|
+
- Validation: fails fast if vueTestUtils.outDir is empty or matches generation.outDir
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
naming priority, keyed vs. static accessors, slot projection, and selectByValue.
|
|
53
|
+
Dependencies
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
- Added @vue/test-utils (^2.4.11), @vue/server-renderer, and vue (3.5.27) as devDependencies
|
|
56
|
+
|
|
57
|
+
Documentation
|
|
54
58
|
|
|
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.
|
|
59
|
+
- Added full README section covering setup, usage example, and the generation.vueTestUtils.outDir
|
|
60
|
+
reference
|
|
60
61
|
|
|
61
62
|
Breaking Changes
|
|
62
63
|
|
|
63
|
-
|
|
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.
|
|
64
|
+
None. Vue Test Utils generation is opt-in; existing Playwright-only behavior is unchanged.
|
|
67
65
|
|
|
68
66
|
Pull Requests Included
|
|
69
67
|
|
|
70
|
-
- ]8;id=md-
|
|
68
|
+
- ]8;id=md-c46er0;https://github.com/immense/vue-pom-generator/pull/60#60 — Generate Vue Test Utils component objects]8;;]8;; (@dkattan)]8;;
|
|
71
69
|
|
|
72
70
|
Testing
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
- New tests/vue-test-utils-pom.test.ts (157 lines) exercises the VueTestUtilsPom runtime against
|
|
73
|
+
mounted components (radio groups, keyed scoped instances, v-selects, inputs, buttons)
|
|
74
|
+
- Extended tests/semantic-component-instances.test.ts to generate Vue Test Utils files and
|
|
75
|
+
type-check them with tsc --noEmit
|
|
76
|
+
- Extended tests/options.test.ts to verify default acceptance and fail-fast on empty outDir
|
|
77
|
+
- Extended tests/resolved-generation-options.test.ts for vueTestUtilsOutDir resolution
|
|
78
|
+
- Extended scripts/packed-smoke-check.mjs to build through the packed Vite plugin, emit VTU output,
|
|
79
|
+
and type-check generated files including the copied runtime
|
|
77
80
|
|
|
@@ -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 [
|