@immense/vue-pom-generator 1.0.117 → 1.0.119

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/dist/index.cjs CHANGED
@@ -262,6 +262,7 @@ function resolveGenerationSupportOptions(options) {
262
262
  requireCustomPomDir: options.requireCustomPomDir ?? false,
263
263
  customPomImportAliases: options.customPomImportAliases,
264
264
  customPomImportNameCollisionBehavior: options.customPomImportNameCollisionBehavior ?? "error",
265
+ customPomFixtures: options.customPomFixtures ?? [],
265
266
  nameCollisionBehavior: options.nameCollisionBehavior ?? "error",
266
267
  missingSemanticNameBehavior: options.missingSemanticNameBehavior ?? "error",
267
268
  existingIdBehavior: options.existingIdBehavior ?? "error",
@@ -5944,6 +5945,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5944
5945
  requireCustomPomDir,
5945
5946
  customPomImportAliases,
5946
5947
  customPomImportNameCollisionBehavior = "error",
5948
+ customPomFixtures = [],
5947
5949
  testIdAttribute,
5948
5950
  emitLanguages: emitLanguagesOverride,
5949
5951
  typescriptOutputStructure = "aggregated",
@@ -6003,6 +6005,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
6003
6005
  pomOutDir: outDir,
6004
6006
  projectRoot,
6005
6007
  customPomDir,
6008
+ customPomFixtures,
6006
6009
  elementMetadata,
6007
6010
  testIdAttribute
6008
6011
  });
@@ -6715,9 +6718,15 @@ function generateAggregatedCSharpFiles(componentHierarchyMap, outDir, options =
6715
6718
  return [{ filePath: outputFile, content: chunks.join("\n") }];
6716
6719
  }
6717
6720
  function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6718
- const { generateFixtures, pomOutDir } = options;
6719
- if (!generateFixtures)
6721
+ const { generateFixtures, pomOutDir, customPomFixtures } = options;
6722
+ if (!generateFixtures) {
6723
+ if (customPomFixtures.length > 0) {
6724
+ throw new VuePomGeneratorError(
6725
+ "generation.playwright.customPoms.fixtures requires generation.playwright.fixtures to be enabled."
6726
+ );
6727
+ }
6720
6728
  return [];
6729
+ }
6721
6730
  const defaultFixtureOutDirRel = pomOutDir;
6722
6731
  const fixtureOutRel = typeof generateFixtures === "string" ? generateFixtures : typeof generateFixtures === "object" && generateFixtures?.outDir ? generateFixtures.outDir : defaultFixtureOutDirRel;
6723
6732
  const looksLikeFilePath = fixtureOutRel.endsWith(".ts") || fixtureOutRel.endsWith(".tsx") || fixtureOutRel.endsWith(".mts") || fixtureOutRel.endsWith(".cts");
@@ -6776,6 +6785,42 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6776
6785
  fixtureName: lowerFirst(name),
6777
6786
  ctorExpression: fixtureCtorExpression(name)
6778
6787
  }));
6788
+ const takenFixtureNames = new Map([
6789
+ ...[...reservedPlaywrightFixtureNames, "pomSetup", "pomFactory", "pomDiagnosticsSetup"].map((name) => [name, "a built-in Playwright or vue-pom-generator fixture"]),
6790
+ ...fixtureClassNames.map((name) => [lowerFirst(name), `the generated fixture for "${name}"`])
6791
+ ]);
6792
+ const customCtorEntries = customPomFixtures.map((className, index) => {
6793
+ if (customPomFixtures.indexOf(className) !== index) {
6794
+ throw new VuePomGeneratorError(
6795
+ `Custom POM fixture class "${className}" is listed more than once in generation.playwright.customPoms.fixtures.
6796
+ Remove the duplicate entry.`
6797
+ );
6798
+ }
6799
+ const filePath = path.join(customPomDirAbs, `${className}.ts`);
6800
+ if (!fs.existsSync(filePath)) {
6801
+ throw new VuePomGeneratorError(
6802
+ `Custom POM fixture class "${className}" was not found.
6803
+ Expected file: ${filePath}
6804
+ Add the file or remove "${className}" from generation.playwright.customPoms.fixtures.`
6805
+ );
6806
+ }
6807
+ const fixtureName = lowerFirst(className);
6808
+ const existingOwner = takenFixtureNames.get(fixtureName);
6809
+ if (existingOwner) {
6810
+ throw new VuePomGeneratorError(
6811
+ `Custom POM fixture "${fixtureName}" (from "${className}") collides with ${existingOwner}.
6812
+ Rename the class or remove it from generation.playwright.customPoms.fixtures.`
6813
+ );
6814
+ }
6815
+ takenFixtureNames.set(fixtureName, `the custom POM fixture for "${className}"`);
6816
+ return {
6817
+ className,
6818
+ fixtureName,
6819
+ ctorExpression: `${className}Custom`,
6820
+ importSpecifier: stripExtension(toPosixRelativePath(fixtureOutDirAbs, filePath))
6821
+ };
6822
+ });
6823
+ const hasCustomFixtures = customCtorEntries.length > 0;
6779
6824
  const fixturesContent = renderSourceFile(fixtureFileName, (sourceFile) => {
6780
6825
  sourceFile.addStatements("/** Generated Playwright fixtures (typed page objects). */");
6781
6826
  addNamedImport(sourceFile, {
@@ -6815,6 +6860,12 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6815
6860
  namedImports: [{ name: entry.className, alias: entry.localIdentifier }]
6816
6861
  });
6817
6862
  }
6863
+ for (const entry of customCtorEntries) {
6864
+ addNamedImport(sourceFile, {
6865
+ moduleSpecifier: entry.importSpecifier,
6866
+ namedImports: [{ name: entry.className, alias: entry.ctorExpression }]
6867
+ });
6868
+ }
6818
6869
  sourceFile.addInterface({
6819
6870
  isExported: true,
6820
6871
  name: "PlaywrightOptions",
@@ -6854,36 +6905,27 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6854
6905
  name: "PomDiagnosticsSetupFixture",
6855
6906
  type: "{ pomDiagnosticsSetup: void }"
6856
6907
  });
6857
- sourceFile.addVariableStatement({
6858
- declarationKind: tsMorph.VariableDeclarationKind.Const,
6859
- declarations: [{
6860
- name: "pageCtors",
6861
- initializer: (writer) => {
6862
- writer.write("{").newLine();
6863
- writer.indent(() => {
6864
- for (const entry of pageCtorEntries) {
6865
- writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
6866
- }
6867
- });
6868
- writer.write("} as const");
6869
- }
6870
- }]
6871
- });
6872
- sourceFile.addVariableStatement({
6873
- declarationKind: tsMorph.VariableDeclarationKind.Const,
6874
- declarations: [{
6875
- name: "componentCtors",
6876
- initializer: (writer) => {
6877
- writer.write("{").newLine();
6878
- writer.indent(() => {
6879
- for (const entry of componentCtorEntries) {
6880
- writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
6881
- }
6882
- });
6883
- writer.write("} as const");
6884
- }
6885
- }]
6886
- });
6908
+ const addCtorMap = (name, entries) => {
6909
+ sourceFile.addVariableStatement({
6910
+ declarationKind: tsMorph.VariableDeclarationKind.Const,
6911
+ declarations: [{
6912
+ name,
6913
+ initializer: (writer) => {
6914
+ writer.write("{").newLine();
6915
+ writer.indent(() => {
6916
+ for (const entry of entries) {
6917
+ writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
6918
+ }
6919
+ });
6920
+ writer.write("} as const");
6921
+ }
6922
+ }]
6923
+ });
6924
+ };
6925
+ addCtorMap("pageCtors", pageCtorEntries);
6926
+ addCtorMap("componentCtors", componentCtorEntries);
6927
+ if (hasCustomFixtures)
6928
+ addCtorMap("customCtors", customCtorEntries);
6887
6929
  sourceFile.addTypeAlias({
6888
6930
  isExported: true,
6889
6931
  name: "GeneratedPageFixtures",
@@ -6894,13 +6936,20 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6894
6936
  name: "GeneratedComponentFixtures",
6895
6937
  type: "{ [K in keyof typeof componentCtors]: InstanceType<(typeof componentCtors)[K]> }"
6896
6938
  });
6939
+ if (hasCustomFixtures) {
6940
+ sourceFile.addTypeAlias({
6941
+ isExported: true,
6942
+ name: "CustomPomFixtures",
6943
+ type: "{ [K in keyof typeof customCtors]: InstanceType<(typeof customCtors)[K]> }"
6944
+ });
6945
+ }
6897
6946
  sourceFile.addTypeAlias({
6898
6947
  isExported: true,
6899
6948
  name: "PomFixtures",
6900
6949
  docs: [{
6901
- description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM."
6950
+ description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM" + (hasCustomFixtures ? "\nand per configured custom POM." : ".")
6902
6951
  }],
6903
- type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
6952
+ type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures" + (hasCustomFixtures ? " & CustomPomFixtures" : "")
6904
6953
  });
6905
6954
  sourceFile.addFunction({
6906
6955
  name: "makePomFixture",
@@ -6989,6 +7038,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6989
7038
  writer.writeLine("},");
6990
7039
  writer.writeLine("...createPomFixtures(pageCtors),");
6991
7040
  writer.writeLine("...createPomFixtures(componentCtors),");
7041
+ if (hasCustomFixtures)
7042
+ writer.writeLine("...createPomFixtures(customCtors),");
6992
7043
  });
6993
7044
  writer.write(") as TestType<TTestArgs & PomFixtures, TWorkerArgs>;");
6994
7045
  }
@@ -8184,6 +8235,7 @@ function createBuildProcessorPlugin(options) {
8184
8235
  requireCustomPomDir,
8185
8236
  customPomImportAliases,
8186
8237
  customPomImportNameCollisionBehavior,
8238
+ customPomFixtures,
8187
8239
  testIdAttribute,
8188
8240
  routerAwarePoms,
8189
8241
  routerType,
@@ -8334,6 +8386,7 @@ function createBuildProcessorPlugin(options) {
8334
8386
  requireCustomPomDir,
8335
8387
  customPomImportAliases,
8336
8388
  customPomImportNameCollisionBehavior,
8389
+ customPomFixtures,
8337
8390
  testIdAttribute,
8338
8391
  vueRouterFluentChaining: routerAwarePoms,
8339
8392
  routerEntry: getResolvedRouterEntry(),
@@ -10714,6 +10767,7 @@ function createDevProcessorPlugin(options) {
10714
10767
  requireCustomPomDir,
10715
10768
  customPomImportAliases,
10716
10769
  customPomImportNameCollisionBehavior,
10770
+ customPomFixtures,
10717
10771
  nameCollisionBehavior,
10718
10772
  missingSemanticNameBehavior,
10719
10773
  existingIdBehavior,
@@ -10976,6 +11030,7 @@ function createDevProcessorPlugin(options) {
10976
11030
  requireCustomPomDir,
10977
11031
  customPomImportAliases,
10978
11032
  customPomImportNameCollisionBehavior,
11033
+ customPomFixtures,
10979
11034
  pageDirs: getPageDirs(),
10980
11035
  componentDirs: getComponentDirs(),
10981
11036
  layoutDirs: getLayoutDirs(),
@@ -11611,7 +11666,8 @@ function createGeneratorPlugins(options, generationOnly, projectRoot = process.c
11611
11666
  const customPoms = generationOptions?.playwright?.customPoms;
11612
11667
  const resolvedCustomPomAttachments = customPoms?.attachments ?? [];
11613
11668
  const resolvedCustomPomImportAliases = customPoms?.importAliases;
11614
- const requireCustomPomDir = customPoms?.dir !== void 0 || resolvedCustomPomAttachments.length > 0 || Object.keys(resolvedCustomPomImportAliases ?? {}).length > 0;
11669
+ const resolvedCustomPomFixtures = customPoms?.fixtures ?? [];
11670
+ const requireCustomPomDir = customPoms?.dir !== void 0 || resolvedCustomPomAttachments.length > 0 || resolvedCustomPomFixtures.length > 0 || Object.keys(resolvedCustomPomImportAliases ?? {}).length > 0;
11615
11671
  const resolvedGenerationOptions = resolveGenerationSupportOptions({
11616
11672
  outDir: generationOptions?.outDir,
11617
11673
  emitLanguages: generationOptions?.emit,
@@ -11624,6 +11680,7 @@ function createGeneratorPlugins(options, generationOnly, projectRoot = process.c
11624
11680
  requireCustomPomDir,
11625
11681
  customPomImportAliases: resolvedCustomPomImportAliases,
11626
11682
  customPomImportNameCollisionBehavior: customPoms?.importNameCollisionBehavior,
11683
+ customPomFixtures: resolvedCustomPomFixtures,
11627
11684
  nameCollisionBehavior: generationOptions?.nameCollisionBehavior,
11628
11685
  missingSemanticNameBehavior: generationOptions?.missingSemanticNameBehavior,
11629
11686
  existingIdBehavior: resolvedInjectionOptions.existingIdBehavior,