@immense/vue-pom-generator 1.0.57 → 1.0.58

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.mjs CHANGED
@@ -63,6 +63,21 @@ function createLogger(options) {
63
63
  };
64
64
  }
65
65
  const requireFromModule = createRequire(import.meta.url);
66
+ function resolveNuxtKitEntry(cwd) {
67
+ const attemptResolvers = [
68
+ createRequire(path.resolve(cwd, "package.json")),
69
+ requireFromModule
70
+ ];
71
+ let lastError;
72
+ for (const resolver of attemptResolvers) {
73
+ try {
74
+ return resolver.resolve("@nuxt/kit");
75
+ } catch (error) {
76
+ lastError = error instanceof Error ? error : new Error(String(error));
77
+ }
78
+ }
79
+ throw lastError ?? new Error("Unknown module resolution error");
80
+ }
66
81
  function toUniqueResolvedPaths(paths) {
67
82
  return Array.from(new Set(paths.map((value) => path.resolve(value))));
68
83
  }
@@ -173,7 +188,7 @@ async function loadNuxtProjectDiscovery(cwd = process.cwd()) {
173
188
  let loadNuxtConfig;
174
189
  let getLayerDirectories;
175
190
  try {
176
- const nuxtKitEntry = requireFromModule.resolve("@nuxt/kit");
191
+ const nuxtKitEntry = resolveNuxtKitEntry(cwd);
177
192
  ({ loadNuxtConfig, getLayerDirectories } = await import(pathToFileURL(nuxtKitEntry).href));
178
193
  } catch (error) {
179
194
  throw new TypeError(
@@ -362,7 +377,14 @@ function generateClickMethod(methodName, formattedDataTestId, alternateFormatted
362
377
  const candidatesExpr = [formattedDataTestId, ...alternates].map(testIdExpression).join(", ");
363
378
  const clickMethod = createAsyncMethod(
364
379
  name,
365
- hasParam(params, "key") ? [...baseParameters, createInlineParameter("wait", { type: "boolean", initializer: "true" })] : [createInlineParameter("wait", { type: "boolean", initializer: "true" })],
380
+ hasParam(params, "key") ? [
381
+ ...baseParameters,
382
+ createInlineParameter("wait", { type: "boolean", initializer: "true" }),
383
+ createInlineParameter("annotationText", { type: "string", initializer: '""' })
384
+ ] : [
385
+ createInlineParameter("wait", { type: "boolean", initializer: "true" }),
386
+ createInlineParameter("annotationText", { type: "string", initializer: '""' })
387
+ ],
366
388
  (writer) => {
367
389
  writer.writeLine(`const candidates = [${candidatesExpr}] as const;`);
368
390
  writer.writeLine("let lastError: unknown;");
@@ -370,7 +392,7 @@ function generateClickMethod(methodName, formattedDataTestId, alternateFormatted
370
392
  writer.writeLine("const locator = this.locatorByTestId(testId);");
371
393
  writer.write("try ").block(() => {
372
394
  writer.write("if (await locator.count()) ").block(() => {
373
- writer.writeLine('await this.clickLocator(locator, "", wait);');
395
+ writer.writeLine("await this.clickLocator(locator, annotationText, wait);");
374
396
  writer.writeLine("return;");
375
397
  });
376
398
  });
@@ -381,10 +403,10 @@ function generateClickMethod(methodName, formattedDataTestId, alternateFormatted
381
403
  writer.writeLine(`throw (lastError instanceof Error) ? lastError : new Error("[pom] Failed to click any candidate locator for ${name}.");`);
382
404
  }
383
405
  );
384
- const noWaitArgs = argsForForward ? `${argsForForward}, false` : "false";
406
+ const noWaitArgs = argsForForward ? `${argsForForward}, false, annotationText` : "false, annotationText";
385
407
  const noWaitMethod = createAsyncMethod(
386
408
  noWaitName,
387
- hasParam(params, "key") ? baseParameters : [],
409
+ hasParam(params, "key") ? [...baseParameters, createInlineParameter("annotationText", { type: "string", initializer: '""' })] : [createInlineParameter("annotationText", { type: "string", initializer: '""' })],
388
410
  (writer) => {
389
411
  writer.writeLine(`await this.${name}(${noWaitArgs});`);
390
412
  }
@@ -393,21 +415,44 @@ function generateClickMethod(methodName, formattedDataTestId, alternateFormatted
393
415
  }
394
416
  if (hasParam(params, "key")) {
395
417
  return [
396
- createAsyncMethod(name, [...baseParameters, createInlineParameter("wait", { type: "boolean", initializer: "true" })], (writer) => {
397
- writer.writeLine(`await this.clickByTestId(\`${formattedDataTestId}\`, "", wait);`);
398
- }),
399
- createAsyncMethod(noWaitName, baseParameters, (writer) => {
400
- writer.writeLine(`await this.${name}(${argsForForward}, false);`);
401
- })
418
+ createAsyncMethod(
419
+ name,
420
+ [
421
+ ...baseParameters,
422
+ createInlineParameter("wait", { type: "boolean", initializer: "true" }),
423
+ createInlineParameter("annotationText", { type: "string", initializer: '""' })
424
+ ],
425
+ (writer) => {
426
+ writer.writeLine(`await this.clickByTestId(\`${formattedDataTestId}\`, annotationText, wait);`);
427
+ }
428
+ ),
429
+ createAsyncMethod(
430
+ noWaitName,
431
+ [...baseParameters, createInlineParameter("annotationText", { type: "string", initializer: '""' })],
432
+ (writer) => {
433
+ writer.writeLine(`await this.${name}(${argsForForward}, false, annotationText);`);
434
+ }
435
+ )
402
436
  ];
403
437
  }
404
438
  return [
405
- createAsyncMethod(name, [createInlineParameter("wait", { type: "boolean", initializer: "true" })], (writer) => {
406
- writer.writeLine(`await this.clickByTestId("${formattedDataTestId}", "", wait);`);
407
- }),
408
- createAsyncMethod(noWaitName, [], (writer) => {
409
- writer.writeLine(`await this.${name}(false);`);
410
- })
439
+ createAsyncMethod(
440
+ name,
441
+ [
442
+ createInlineParameter("wait", { type: "boolean", initializer: "true" }),
443
+ createInlineParameter("annotationText", { type: "string", initializer: '""' })
444
+ ],
445
+ (writer) => {
446
+ writer.writeLine(`await this.clickByTestId("${formattedDataTestId}", annotationText, wait);`);
447
+ }
448
+ ),
449
+ createAsyncMethod(
450
+ noWaitName,
451
+ [createInlineParameter("annotationText", { type: "string", initializer: '""' })],
452
+ (writer) => {
453
+ writer.writeLine(`await this.${name}(false, annotationText);`);
454
+ }
455
+ )
411
456
  ];
412
457
  }
413
458
  function generateRadioMethod(methodName, formattedDataTestId) {
@@ -2852,10 +2897,13 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
2852
2897
  formattedDataTestId: formattedDataTestIdForPom
2853
2898
  },
2854
2899
  keyLiteral: rawValue,
2855
- params: { wait: "boolean = true" }
2900
+ params: { wait: "boolean = true", annotationText: 'string = ""' }
2856
2901
  });
2857
2902
  if (added) {
2858
- registerGeneratedMethodSignature(generatedName, { params: `wait: boolean = true`, argNames: ["wait"] });
2903
+ registerGeneratedMethodSignature(generatedName, {
2904
+ params: `wait: boolean = true, annotationText: string = ""`,
2905
+ argNames: ["wait", "annotationText"]
2906
+ });
2859
2907
  }
2860
2908
  }
2861
2909
  return;
@@ -8019,6 +8067,13 @@ function tryCreateElementMetadata(args) {
8019
8067
  };
8020
8068
  return metadata;
8021
8069
  }
8070
+ function resolveCompilerSfcParse(compilerSfc) {
8071
+ const parse2 = compilerSfc.parse ?? compilerSfc.default?.parse;
8072
+ if (typeof parse2 !== "function") {
8073
+ throw new TypeError("[vue-pom-generator] Failed to resolve @vue/compiler-sfc.parse.");
8074
+ }
8075
+ return parse2;
8076
+ }
8022
8077
  function extractMetadataAfterTransform(ast, componentName, elementMetadata, semanticNameMap, testIdAttribute) {
8023
8078
  const componentMetadata = /* @__PURE__ */ new Map();
8024
8079
  function traverseNode(node) {
@@ -8215,7 +8270,8 @@ function createVuePluginWithTestIds(options) {
8215
8270
  }
8216
8271
  const componentName = getComponentNameFromPath(cleanPath);
8217
8272
  loggerRef.current.debug(`Collecting metadata for ${cleanPath} (component: ${componentName})`);
8218
- const { parse: parse2 } = await import("@vue/compiler-sfc");
8273
+ const compilerSfc = await import("@vue/compiler-sfc");
8274
+ const parse2 = resolveCompilerSfcParse(compilerSfc);
8219
8275
  const compilerDom2 = await import("@vue/compiler-dom");
8220
8276
  const compile = compilerDom2.compile;
8221
8277
  const { descriptor } = parse2(code, { filename: cleanPath });