@immense/vue-pom-generator 1.0.106 → 1.0.108
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 +54 -0
- package/RELEASE_NOTES.md +36 -24
- package/class-generation/index.ts +111 -190
- package/dist/class-generation/index.d.ts +3 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +775 -707
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +776 -708
- package/dist/index.mjs.map +1 -1
- package/dist/manifest-generator.d.ts +2 -1
- package/dist/manifest-generator.d.ts.map +1 -1
- package/dist/plugin/create-vue-pom-generator-plugins.d.ts +2 -0
- package/dist/plugin/create-vue-pom-generator-plugins.d.ts.map +1 -1
- package/dist/plugin/generate-vue-poms.d.ts +10 -0
- package/dist/plugin/generate-vue-poms.d.ts.map +1 -0
- package/dist/plugin/generated-outputs.d.ts +7 -0
- package/dist/plugin/generated-outputs.d.ts.map +1 -0
- package/dist/plugin/internal/build-plugin.d.ts +3 -10
- 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/internal-plugins.d.ts +2 -1
- package/dist/plugin/internal-plugins.d.ts.map +1 -1
- package/dist/plugin/vue-plugin.d.ts +1 -0
- package/dist/plugin/vue-plugin.d.ts.map +1 -1
- package/dist/tests/generate-vue-poms.test.d.ts +2 -0
- package/dist/tests/generate-vue-poms.test.d.ts.map +1 -0
- package/dist/tests/generated-outputs.test.d.ts +2 -0
- package/dist/tests/generated-outputs.test.d.ts.map +1 -0
- package/dist/tests/incremental-generation.test.d.ts +2 -0
- package/dist/tests/incremental-generation.test.d.ts.map +1 -0
- package/dist/typescript-codegen.d.ts +14 -1
- package/dist/typescript-codegen.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ import { fileURLToPath } from "node:url";
|
|
|
11
11
|
import { generateViewObjectModelMembers, generateViewObjectModelMethodContent } from "../method-generation";
|
|
12
12
|
import { generatePomManifestModule } from "../manifest-generator";
|
|
13
13
|
import type { ElementMetadata } from "../metadata-collector";
|
|
14
|
+
import { writeGeneratedOutputs, type GeneratedFileOutput } from "../plugin/generated-outputs";
|
|
14
15
|
import {
|
|
15
16
|
createPomMethodSignature,
|
|
16
17
|
createPomParameterSpec,
|
|
@@ -33,7 +34,6 @@ import {
|
|
|
33
34
|
import { buildPomLocatorDescription, stripPomActionPrefix } from "../pom-discoverability";
|
|
34
35
|
import { introspectNuxtPages, parseRouterFileFromCwd } from "../router-introspection";
|
|
35
36
|
import {
|
|
36
|
-
addExportAll,
|
|
37
37
|
addNamedImport,
|
|
38
38
|
buildCommentBlock,
|
|
39
39
|
buildFilePrefix,
|
|
@@ -41,17 +41,14 @@ import {
|
|
|
41
41
|
createClassGetter,
|
|
42
42
|
createClassMethod,
|
|
43
43
|
createClassProperty,
|
|
44
|
+
createClassDeclaration,
|
|
44
45
|
renderSourceFile,
|
|
46
|
+
renderStructuredSourceFile,
|
|
45
47
|
StructureKind,
|
|
46
48
|
VariableDeclarationKind,
|
|
47
|
-
type ConstructorDeclarationStructure,
|
|
48
|
-
type GetAccessorDeclarationStructure,
|
|
49
|
-
type MethodDeclarationStructure,
|
|
50
|
-
type OptionalKind,
|
|
51
|
-
type PropertyDeclarationStructure,
|
|
52
49
|
type TypeScriptClassMember,
|
|
53
|
-
type TypeScriptSourceFile,
|
|
54
50
|
type TypeScriptWriter,
|
|
51
|
+
type TypeScriptRenderCache,
|
|
55
52
|
} from "../typescript-codegen";
|
|
56
53
|
import {
|
|
57
54
|
IComponentDependencies,
|
|
@@ -741,6 +738,8 @@ function generateMethodsContentForDependencies(componentName: string, dependenci
|
|
|
741
738
|
}
|
|
742
739
|
|
|
743
740
|
export interface GenerateFilesOptions {
|
|
741
|
+
/** Per-dev-server rendering cache. Omitted for stateless one-shot/build generation. */
|
|
742
|
+
renderCache?: TypeScriptRenderCache;
|
|
744
743
|
/**
|
|
745
744
|
* Output directory for generated files.
|
|
746
745
|
*
|
|
@@ -847,6 +846,7 @@ export interface GenerateFilesOptions {
|
|
|
847
846
|
}
|
|
848
847
|
|
|
849
848
|
interface BaseGenerateContentOptions {
|
|
849
|
+
renderCache?: TypeScriptRenderCache;
|
|
850
850
|
/** Directory the generated .g.ts file will live in (used for relative imports). Defaults to the Vue file's directory. */
|
|
851
851
|
outputDir?: string;
|
|
852
852
|
|
|
@@ -877,11 +877,6 @@ type GenerateContentOptions
|
|
|
877
877
|
| { outputStructure?: "split" }
|
|
878
878
|
);
|
|
879
879
|
|
|
880
|
-
interface GeneratedFileOutput {
|
|
881
|
-
filePath: string;
|
|
882
|
-
content: string;
|
|
883
|
-
}
|
|
884
|
-
|
|
885
880
|
export async function generateFiles(
|
|
886
881
|
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
887
882
|
vueFilesPathMap: Map<string, string>,
|
|
@@ -891,7 +886,7 @@ export async function generateFiles(
|
|
|
891
886
|
const {
|
|
892
887
|
outDir: outDirOverride,
|
|
893
888
|
generateFixtures,
|
|
894
|
-
vueTestUtilsOutDir,
|
|
889
|
+
vueTestUtilsOutDir: vueTestUtilsOutDirOverride,
|
|
895
890
|
customPomAttachments = [],
|
|
896
891
|
projectRoot,
|
|
897
892
|
customPomDir,
|
|
@@ -910,13 +905,16 @@ export async function generateFiles(
|
|
|
910
905
|
layoutDirs,
|
|
911
906
|
routeMetaByComponent: routeMetaByComponentOverride,
|
|
912
907
|
elementMetadata = new Map<string, Map<string, ElementMetadata>>(),
|
|
908
|
+
renderCache,
|
|
913
909
|
} = options;
|
|
914
910
|
|
|
915
911
|
const emitLanguages: Array<"ts" | "csharp"> = emitLanguagesOverride?.length
|
|
916
912
|
? emitLanguagesOverride
|
|
917
913
|
: ["ts"];
|
|
918
914
|
|
|
919
|
-
const
|
|
915
|
+
const root = projectRoot ?? process.cwd();
|
|
916
|
+
const outDir = path.resolve(root, outDirOverride ?? "./pom");
|
|
917
|
+
const vueTestUtilsOutDir = vueTestUtilsOutDirOverride ? path.resolve(root, vueTestUtilsOutDirOverride) : undefined;
|
|
920
918
|
if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
|
|
921
919
|
throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
|
|
922
920
|
}
|
|
@@ -930,16 +928,12 @@ export async function generateFiles(
|
|
|
930
928
|
})
|
|
931
929
|
: undefined);
|
|
932
930
|
const emittableComponentHierarchyMap = componentHierarchyMap;
|
|
933
|
-
const
|
|
934
|
-
const writeGeneratedFile = (file: GeneratedFileOutput) => {
|
|
935
|
-
const resolvedFilePath = path.resolve(file.filePath);
|
|
936
|
-
createFile(resolvedFilePath, file.content);
|
|
937
|
-
generatedFilePaths.push(resolvedFilePath);
|
|
938
|
-
};
|
|
931
|
+
const generatedFiles: GeneratedFileOutput[] = [];
|
|
939
932
|
|
|
940
933
|
if (emitLanguages.includes("ts")) {
|
|
941
934
|
const files = typescriptOutputStructure === "split"
|
|
942
935
|
? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
936
|
+
renderCache,
|
|
943
937
|
customPomAttachments,
|
|
944
938
|
projectRoot,
|
|
945
939
|
customPomDir,
|
|
@@ -951,6 +945,7 @@ export async function generateFiles(
|
|
|
951
945
|
vueRouterFluentChaining,
|
|
952
946
|
})
|
|
953
947
|
: await generateAggregatedFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
948
|
+
renderCache,
|
|
954
949
|
customPomAttachments,
|
|
955
950
|
projectRoot,
|
|
956
951
|
customPomDir,
|
|
@@ -962,11 +957,10 @@ export async function generateFiles(
|
|
|
962
957
|
routeMetaByComponent,
|
|
963
958
|
vueRouterFluentChaining,
|
|
964
959
|
});
|
|
965
|
-
|
|
966
|
-
writeGeneratedFile(file);
|
|
967
|
-
}
|
|
960
|
+
generatedFiles.push(...files);
|
|
968
961
|
|
|
969
962
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
963
|
+
renderCache,
|
|
970
964
|
generateFixtures,
|
|
971
965
|
pomOutDir: outDir,
|
|
972
966
|
projectRoot,
|
|
@@ -974,9 +968,7 @@ export async function generateFiles(
|
|
|
974
968
|
elementMetadata,
|
|
975
969
|
testIdAttribute,
|
|
976
970
|
});
|
|
977
|
-
|
|
978
|
-
writeGeneratedFile(fixtureRegistryFile);
|
|
979
|
-
}
|
|
971
|
+
generatedFiles.push(...fixtureRegistryFiles);
|
|
980
972
|
}
|
|
981
973
|
|
|
982
974
|
if (emitLanguages.includes("csharp")) {
|
|
@@ -985,26 +977,21 @@ export async function generateFiles(
|
|
|
985
977
|
testIdAttribute,
|
|
986
978
|
csharp,
|
|
987
979
|
});
|
|
988
|
-
|
|
989
|
-
writeGeneratedFile(file);
|
|
990
|
-
}
|
|
980
|
+
generatedFiles.push(...csFiles);
|
|
991
981
|
}
|
|
992
982
|
|
|
993
983
|
if (vueTestUtilsOutDir) {
|
|
994
984
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
995
985
|
emittableComponentHierarchyMap,
|
|
996
986
|
vueTestUtilsOutDir,
|
|
997
|
-
{ testIdAttribute },
|
|
987
|
+
{ testIdAttribute, renderCache },
|
|
998
988
|
);
|
|
999
|
-
|
|
1000
|
-
writeGeneratedFile(file);
|
|
1001
|
-
}
|
|
989
|
+
generatedFiles.push(...vueTestUtilsFiles);
|
|
1002
990
|
}
|
|
1003
991
|
|
|
1004
|
-
const gitattributesFiles = buildGeneratedGitAttributesFiles(
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
}
|
|
992
|
+
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map(file => file.filePath));
|
|
993
|
+
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
994
|
+
renderCache?.retain(new Set(generatedFiles.map(file => file.filePath)));
|
|
1008
995
|
}
|
|
1009
996
|
|
|
1010
997
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
@@ -1177,6 +1164,7 @@ function generateVueTestUtilsContent(
|
|
|
1177
1164
|
runtimePath: string,
|
|
1178
1165
|
generatedFilePathByComponent: Map<string, string>,
|
|
1179
1166
|
testIdAttribute: string,
|
|
1167
|
+
renderCache?: TypeScriptRenderCache,
|
|
1180
1168
|
): string {
|
|
1181
1169
|
const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
|
|
1182
1170
|
outputStructure: "split",
|
|
@@ -1205,41 +1193,36 @@ function generateVueTestUtilsContent(
|
|
|
1205
1193
|
...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers),
|
|
1206
1194
|
];
|
|
1207
1195
|
|
|
1208
|
-
return
|
|
1209
|
-
|
|
1196
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.vtu.g.ts`), {
|
|
1197
|
+
statements: [{
|
|
1198
|
+
kind: StructureKind.ImportDeclaration,
|
|
1210
1199
|
moduleSpecifier: runtimeImport,
|
|
1211
1200
|
namedImports: ["VueTestUtilsPom"],
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1201
|
+
}, {
|
|
1202
|
+
kind: StructureKind.ImportDeclaration,
|
|
1214
1203
|
moduleSpecifier: runtimeImport,
|
|
1215
1204
|
namedImports: ["VueTestUtilsPomRoot"],
|
|
1216
1205
|
isTypeOnly: true,
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
const declaration = sourceFile.addClass({
|
|
1206
|
+
}, ...componentImports.map(componentImport => ({
|
|
1207
|
+
kind: StructureKind.ImportDeclaration as const,
|
|
1208
|
+
moduleSpecifier: componentImport.moduleSpecifier,
|
|
1209
|
+
namedImports: [componentImport.className],
|
|
1210
|
+
})), createClassDeclaration({
|
|
1226
1211
|
name: prepared.className,
|
|
1227
1212
|
isExported: true,
|
|
1228
1213
|
extends: "VueTestUtilsPom",
|
|
1229
1214
|
docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`],
|
|
1230
|
-
})
|
|
1231
|
-
for (const member of members) {
|
|
1232
|
-
addClassMember(declaration, member);
|
|
1233
|
-
}
|
|
1215
|
+
}, members)],
|
|
1234
1216
|
}, {
|
|
1235
1217
|
prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
|
|
1218
|
+
cache: renderCache,
|
|
1236
1219
|
});
|
|
1237
1220
|
}
|
|
1238
1221
|
|
|
1239
1222
|
function generateVueTestUtilsFiles(
|
|
1240
1223
|
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
1241
1224
|
outDir: string,
|
|
1242
|
-
options: { testIdAttribute?: string } = {},
|
|
1225
|
+
options: { testIdAttribute?: string; renderCache?: TypeScriptRenderCache } = {},
|
|
1243
1226
|
): GeneratedFileOutput[] {
|
|
1244
1227
|
const base = ensureDir(outDir);
|
|
1245
1228
|
const testIdAttribute = options.testIdAttribute?.trim() || "data-testid";
|
|
@@ -1261,6 +1244,7 @@ function generateVueTestUtilsFiles(
|
|
|
1261
1244
|
runtimePath,
|
|
1262
1245
|
generatedFilePathByComponent,
|
|
1263
1246
|
testIdAttribute,
|
|
1247
|
+
options.renderCache,
|
|
1264
1248
|
),
|
|
1265
1249
|
};
|
|
1266
1250
|
});
|
|
@@ -1272,12 +1256,13 @@ function generateVueTestUtilsFiles(
|
|
|
1272
1256
|
if (!runtimeFile) {
|
|
1273
1257
|
throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
|
|
1274
1258
|
}
|
|
1275
|
-
const indexContent =
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1259
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
1260
|
+
statements: [
|
|
1261
|
+
stripExtension(toPosixRelativePath(base, runtimePath)),
|
|
1262
|
+
...Array.from(generatedFilePathByComponent.values(), filePath => `./${stripExtension(path.basename(filePath))}`),
|
|
1263
|
+
].map(moduleSpecifier => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier })),
|
|
1280
1264
|
}, {
|
|
1265
|
+
cache: options.renderCache,
|
|
1281
1266
|
prefixText: buildFilePrefix({
|
|
1282
1267
|
eslintDisableSortImports: true,
|
|
1283
1268
|
commentLines: [
|
|
@@ -1300,6 +1285,7 @@ async function generateSplitTypeScriptFiles(
|
|
|
1300
1285
|
basePageClassPath: string,
|
|
1301
1286
|
outDir: string,
|
|
1302
1287
|
options: {
|
|
1288
|
+
renderCache?: TypeScriptRenderCache;
|
|
1303
1289
|
customPomAttachments?: GenerateFilesOptions["customPomAttachments"];
|
|
1304
1290
|
projectRoot?: GenerateFilesOptions["projectRoot"];
|
|
1305
1291
|
customPomDir?: GenerateFilesOptions["customPomDir"];
|
|
@@ -1359,6 +1345,7 @@ async function generateSplitTypeScriptFiles(
|
|
|
1359
1345
|
}
|
|
1360
1346
|
|
|
1361
1347
|
const content = generateViewObjectModelContent(name, deps, componentHierarchyMap, vueFilesPathMap, runtimeBasePagePath, {
|
|
1348
|
+
renderCache: options.renderCache,
|
|
1362
1349
|
outputDir: path.dirname(filePath),
|
|
1363
1350
|
outputStructure: "split",
|
|
1364
1351
|
customPomAttachments: options.customPomAttachments ?? [],
|
|
@@ -1390,6 +1377,8 @@ async function generateSplitTypeScriptFiles(
|
|
|
1390
1377
|
const members = composed?.members ?? getDefaultStubMembers();
|
|
1391
1378
|
|
|
1392
1379
|
const content = renderSplitStubPomContent({
|
|
1380
|
+
filePath,
|
|
1381
|
+
renderCache: options.renderCache,
|
|
1393
1382
|
className: targetClassName,
|
|
1394
1383
|
basePageImportSpecifier,
|
|
1395
1384
|
childImports,
|
|
@@ -1401,14 +1390,15 @@ async function generateSplitTypeScriptFiles(
|
|
|
1401
1390
|
|
|
1402
1391
|
const runtimeAssetSpecs = getRuntimeGeneratedAssetSpecs(base, basePageClassPath);
|
|
1403
1392
|
const runtimeFiles = buildRuntimeGeneratedFilesFromSpecs(runtimeAssetSpecs);
|
|
1404
|
-
const indexContent =
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
}
|
|
1393
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
1394
|
+
statements: [
|
|
1395
|
+
...runtimeAssetSpecs.map(spec => stripExtension(toPosixRelativePath(base, spec.outputPath))),
|
|
1396
|
+
...Array.from(generatedTsFilePathByComponent.entries())
|
|
1397
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
1398
|
+
.map(([, filePath]) => `./${stripExtension(path.basename(filePath))}`),
|
|
1399
|
+
].map(moduleSpecifier => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier })),
|
|
1411
1400
|
}, {
|
|
1401
|
+
cache: options.renderCache,
|
|
1412
1402
|
prefixText: buildFilePrefix({
|
|
1413
1403
|
eslintDisableSortImports: true,
|
|
1414
1404
|
commentLines: [
|
|
@@ -1877,6 +1867,7 @@ function generateAggregatedCSharpFiles(
|
|
|
1877
1867
|
function maybeGenerateFixtureRegistry(
|
|
1878
1868
|
componentHierarchyMap: Map<string, IComponentDependencies>,
|
|
1879
1869
|
options: {
|
|
1870
|
+
renderCache?: TypeScriptRenderCache;
|
|
1880
1871
|
generateFixtures: GenerateFilesOptions["generateFixtures"];
|
|
1881
1872
|
pomOutDir: string;
|
|
1882
1873
|
projectRoot?: string;
|
|
@@ -2236,7 +2227,8 @@ function maybeGenerateFixtureRegistry(
|
|
|
2236
2227
|
const manifestContent = generatePomManifestModule(
|
|
2237
2228
|
componentHierarchyMap,
|
|
2238
2229
|
options.elementMetadata,
|
|
2239
|
-
manifestFileName,
|
|
2230
|
+
path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
2231
|
+
options.renderCache,
|
|
2240
2232
|
);
|
|
2241
2233
|
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
2242
2234
|
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
@@ -2696,45 +2688,33 @@ function generateViewObjectModelContent(
|
|
|
2696
2688
|
generatedImports.sort((a, b) => a.className.localeCompare(b.className));
|
|
2697
2689
|
|
|
2698
2690
|
const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}\n`;
|
|
2699
|
-
return
|
|
2700
|
-
|
|
2691
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.g.ts`), {
|
|
2692
|
+
statements: [{
|
|
2693
|
+
kind: StructureKind.ImportDeclaration,
|
|
2701
2694
|
moduleSpecifier: "@playwright/test",
|
|
2702
2695
|
isTypeOnly: true,
|
|
2703
2696
|
namedImports: [
|
|
2704
2697
|
{ name: "Locator", alias: "PwLocator" },
|
|
2705
2698
|
{ name: "Page", alias: "PwPage" },
|
|
2706
2699
|
],
|
|
2707
|
-
}
|
|
2708
|
-
|
|
2709
|
-
addNamedImport(sourceFile, {
|
|
2700
|
+
}, {
|
|
2701
|
+
kind: StructureKind.ImportDeclaration,
|
|
2710
2702
|
moduleSpecifier: basePageImportSpecifier,
|
|
2711
2703
|
namedImports: ["BasePage", "Fluent"],
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
for (const generatedImport of generatedImports) {
|
|
2722
|
-
addNamedImport(sourceFile, {
|
|
2723
|
-
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
2724
|
-
namedImports: [generatedImport.className],
|
|
2725
|
-
});
|
|
2726
|
-
}
|
|
2727
|
-
|
|
2728
|
-
const classDeclaration = sourceFile.addClass({
|
|
2704
|
+
}, ...customImports.map(customImport => ({
|
|
2705
|
+
kind: StructureKind.ImportDeclaration as const,
|
|
2706
|
+
moduleSpecifier: customImport.moduleSpecifier,
|
|
2707
|
+
namedImports: [{ name: customImport.name, alias: customImport.alias }],
|
|
2708
|
+
})), ...generatedImports.map(generatedImport => ({
|
|
2709
|
+
kind: StructureKind.ImportDeclaration as const,
|
|
2710
|
+
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
2711
|
+
namedImports: [generatedImport.className],
|
|
2712
|
+
})), createClassDeclaration({
|
|
2729
2713
|
name: prepared.className,
|
|
2730
2714
|
isExported: true,
|
|
2731
2715
|
extends: "BasePage",
|
|
2732
|
-
})
|
|
2733
|
-
|
|
2734
|
-
for (const member of prepared.members) {
|
|
2735
|
-
addClassMember(classDeclaration, member);
|
|
2736
|
-
}
|
|
2737
|
-
}, { prefixText });
|
|
2716
|
+
}, prepared.members)],
|
|
2717
|
+
}, { prefixText, cache: options.renderCache });
|
|
2738
2718
|
}
|
|
2739
2719
|
|
|
2740
2720
|
function getViewPassthroughMethods(
|
|
@@ -3017,6 +2997,8 @@ function getDefaultStubMembers(): TypeScriptClassMember[] {
|
|
|
3017
2997
|
}
|
|
3018
2998
|
|
|
3019
2999
|
function renderSplitStubPomContent(options: {
|
|
3000
|
+
filePath: string;
|
|
3001
|
+
renderCache?: TypeScriptRenderCache;
|
|
3020
3002
|
className: string;
|
|
3021
3003
|
basePageImportSpecifier: string;
|
|
3022
3004
|
childImports: Array<{ className: string; importPath: string }>;
|
|
@@ -3033,37 +3015,32 @@ function renderSplitStubPomContent(options: {
|
|
|
3033
3015
|
],
|
|
3034
3016
|
});
|
|
3035
3017
|
|
|
3036
|
-
return
|
|
3018
|
+
return renderStructuredSourceFile(options.filePath, {
|
|
3037
3019
|
// Stub ctors take Playwright's full `Page` (aliased `PwPage`), matching non-stub generated
|
|
3038
3020
|
// POMs — stubs are constructed with `new Stub(this.page)` where `this.page` is `Page`.
|
|
3039
|
-
|
|
3021
|
+
statements: [{
|
|
3022
|
+
kind: StructureKind.ImportDeclaration,
|
|
3040
3023
|
moduleSpecifier: "@playwright/test",
|
|
3041
3024
|
isTypeOnly: true,
|
|
3042
3025
|
namedImports: [{ name: "Page", alias: "PwPage" }],
|
|
3043
|
-
}
|
|
3044
|
-
|
|
3026
|
+
}, {
|
|
3027
|
+
kind: StructureKind.ImportDeclaration,
|
|
3045
3028
|
moduleSpecifier: options.basePageImportSpecifier,
|
|
3046
3029
|
namedImports: ["BasePage"],
|
|
3047
|
-
}
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
3055
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
3056
|
-
"did not have any generated test ids in this build.",
|
|
3057
|
-
]).trimEnd());
|
|
3058
|
-
const classDeclaration = sourceFile.addClass({
|
|
3030
|
+
}, ...options.childImports.map(childImport => ({
|
|
3031
|
+
kind: StructureKind.ImportDeclaration as const,
|
|
3032
|
+
moduleSpecifier: childImport.importPath,
|
|
3033
|
+
namedImports: [childImport.className],
|
|
3034
|
+
})), createClassDeclaration({
|
|
3059
3035
|
name: options.className,
|
|
3060
3036
|
isExported: true,
|
|
3061
3037
|
extends: "BasePage",
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3038
|
+
leadingTrivia: buildCommentBlock([
|
|
3039
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
3040
|
+
"did not have any generated test ids in this build.",
|
|
3041
|
+
]),
|
|
3042
|
+
}, options.members)],
|
|
3043
|
+
}, { prefixText, cache: options.renderCache });
|
|
3067
3044
|
}
|
|
3068
3045
|
|
|
3069
3046
|
function getChildImportSpecifiers(
|
|
@@ -3086,42 +3063,6 @@ function getChildImportSpecifiers(
|
|
|
3086
3063
|
.sort((a, b) => a.className.localeCompare(b.className));
|
|
3087
3064
|
}
|
|
3088
3065
|
|
|
3089
|
-
function isConstructorMember(member: TypeScriptClassMember): member is OptionalKind<ConstructorDeclarationStructure> {
|
|
3090
|
-
return member.kind === StructureKind.Constructor;
|
|
3091
|
-
}
|
|
3092
|
-
|
|
3093
|
-
function isGetterMember(member: TypeScriptClassMember): member is OptionalKind<GetAccessorDeclarationStructure> {
|
|
3094
|
-
return member.kind === StructureKind.GetAccessor;
|
|
3095
|
-
}
|
|
3096
|
-
|
|
3097
|
-
function isMethodMember(member: TypeScriptClassMember): member is OptionalKind<MethodDeclarationStructure> {
|
|
3098
|
-
return member.kind === StructureKind.Method;
|
|
3099
|
-
}
|
|
3100
|
-
|
|
3101
|
-
function isPropertyMember(member: TypeScriptClassMember): member is OptionalKind<PropertyDeclarationStructure> {
|
|
3102
|
-
return member.kind === StructureKind.Property;
|
|
3103
|
-
}
|
|
3104
|
-
|
|
3105
|
-
function addClassMember(classDeclaration: ReturnType<TypeScriptSourceFile["addClass"]>, member: TypeScriptClassMember): void {
|
|
3106
|
-
if (isConstructorMember(member)) {
|
|
3107
|
-
classDeclaration.addConstructor(member);
|
|
3108
|
-
return;
|
|
3109
|
-
}
|
|
3110
|
-
if (isGetterMember(member)) {
|
|
3111
|
-
classDeclaration.addGetAccessor(member);
|
|
3112
|
-
return;
|
|
3113
|
-
}
|
|
3114
|
-
if (isMethodMember(member)) {
|
|
3115
|
-
classDeclaration.addMethod(member);
|
|
3116
|
-
return;
|
|
3117
|
-
}
|
|
3118
|
-
if (isPropertyMember(member)) {
|
|
3119
|
-
classDeclaration.addProperty(member);
|
|
3120
|
-
return;
|
|
3121
|
-
}
|
|
3122
|
-
throw new Error(`Unsupported class member structure: ${String(member)}`);
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
3066
|
interface RuntimeGeneratedAssetSpec {
|
|
3126
3067
|
absolutePath: string;
|
|
3127
3068
|
description: string;
|
|
@@ -3377,6 +3318,7 @@ async function generateAggregatedFiles(
|
|
|
3377
3318
|
basePageClassPath: string,
|
|
3378
3319
|
outDir: string,
|
|
3379
3320
|
options: {
|
|
3321
|
+
renderCache?: TypeScriptRenderCache;
|
|
3380
3322
|
customPomAttachments?: GenerateFilesOptions["customPomAttachments"];
|
|
3381
3323
|
projectRoot?: GenerateFilesOptions["projectRoot"];
|
|
3382
3324
|
customPomDir?: GenerateFilesOptions["customPomDir"];
|
|
@@ -3513,33 +3455,22 @@ async function generateAggregatedFiles(
|
|
|
3513
3455
|
],
|
|
3514
3456
|
});
|
|
3515
3457
|
|
|
3516
|
-
return
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
for (const entry of [...classes, ...stubs]) {
|
|
3522
|
-
if (entry.isStub) {
|
|
3523
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
3524
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
3525
|
-
"did not have any generated test ids in this build.",
|
|
3526
|
-
]).trimEnd());
|
|
3527
|
-
}
|
|
3528
|
-
else {
|
|
3529
|
-
sourceFile.addStatements(entry.doc);
|
|
3530
|
-
}
|
|
3531
|
-
|
|
3532
|
-
const classDeclaration = sourceFile.addClass({
|
|
3458
|
+
return renderStructuredSourceFile(path.join(outputDir, "page-object-models.g.ts"), {
|
|
3459
|
+
statements: [
|
|
3460
|
+
...imports,
|
|
3461
|
+
...[...classes, ...stubs].map(entry => createClassDeclaration({
|
|
3533
3462
|
name: entry.className,
|
|
3534
3463
|
isExported: true,
|
|
3535
3464
|
extends: "BasePage",
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3465
|
+
leadingTrivia: entry.isStub
|
|
3466
|
+
? buildCommentBlock([
|
|
3467
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
3468
|
+
"did not have any generated test ids in this build.",
|
|
3469
|
+
])
|
|
3470
|
+
: `${entry.doc}\n`,
|
|
3471
|
+
}, entry.members)),
|
|
3472
|
+
],
|
|
3473
|
+
}, { prefixText, cache: options.renderCache });
|
|
3543
3474
|
};
|
|
3544
3475
|
|
|
3545
3476
|
const base = ensureDir(outDir);
|
|
@@ -3547,9 +3478,10 @@ async function generateAggregatedFiles(
|
|
|
3547
3478
|
const content = makeAggregatedContent(path.dirname(outputFile), [...views, ...components]);
|
|
3548
3479
|
|
|
3549
3480
|
const indexFile = path.join(base, "index.ts");
|
|
3550
|
-
const indexContent =
|
|
3551
|
-
|
|
3481
|
+
const indexContent = renderStructuredSourceFile(indexFile, {
|
|
3482
|
+
statements: [{ kind: StructureKind.ExportDeclaration, moduleSpecifier: "./page-object-models.g" }],
|
|
3552
3483
|
}, {
|
|
3484
|
+
cache: options.renderCache,
|
|
3553
3485
|
prefixText: buildFilePrefix({
|
|
3554
3486
|
eslintDisableSortImports: true,
|
|
3555
3487
|
commentLines: [
|
|
@@ -3570,17 +3502,6 @@ async function generateAggregatedFiles(
|
|
|
3570
3502
|
];
|
|
3571
3503
|
}
|
|
3572
3504
|
|
|
3573
|
-
function createFile(filePath: string, content: string) {
|
|
3574
|
-
const dir = path.dirname(filePath);
|
|
3575
|
-
if (!fs.existsSync(dir)) {
|
|
3576
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
3577
|
-
}
|
|
3578
|
-
if (fs.existsSync(filePath)) {
|
|
3579
|
-
fs.unlinkSync(filePath);
|
|
3580
|
-
}
|
|
3581
|
-
fs.writeFileSync(filePath, content);
|
|
3582
|
-
}
|
|
3583
|
-
|
|
3584
3505
|
function lowerFirst(value: string): string {
|
|
3585
3506
|
if (!value)
|
|
3586
3507
|
return value;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { generateViewObjectModelMethodContent } from "../method-generation";
|
|
2
2
|
import type { ElementMetadata } from "../metadata-collector";
|
|
3
|
+
import { type TypeScriptRenderCache } from "../typescript-codegen";
|
|
3
4
|
import { IComponentDependencies } from "../utils";
|
|
4
5
|
export { generateViewObjectModelMethodContent };
|
|
5
6
|
interface RouteParamMeta {
|
|
@@ -28,6 +29,8 @@ interface CustomPomAttachment {
|
|
|
28
29
|
}
|
|
29
30
|
export type TypeScriptOutputStructure = "aggregated" | "split";
|
|
30
31
|
export interface GenerateFilesOptions {
|
|
32
|
+
/** Per-dev-server rendering cache. Omitted for stateless one-shot/build generation. */
|
|
33
|
+
renderCache?: TypeScriptRenderCache;
|
|
31
34
|
/**
|
|
32
35
|
* Output directory for generated files.
|
|
33
36
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../class-generation/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkC,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAE5G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../class-generation/index.ts"],"names":[],"mappings":"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"}
|