@immense/vue-pom-generator 1.0.90 → 1.0.92

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.
Files changed (62) hide show
  1. package/README.md +88 -10
  2. package/RELEASE_NOTES.md +95 -62
  3. package/class-generation/base-page.ts +141 -59
  4. package/class-generation/diagnostics.ts +559 -0
  5. package/class-generation/index.ts +247 -128
  6. package/class-generation/playwright-types.ts +7 -11
  7. package/class-generation/pointer.ts +65 -18
  8. package/dist/class-generation/base-page.d.ts +19 -4
  9. package/dist/class-generation/base-page.d.ts.map +1 -1
  10. package/dist/class-generation/diagnostics.d.ts +110 -0
  11. package/dist/class-generation/diagnostics.d.ts.map +1 -0
  12. package/dist/class-generation/index.d.ts +4 -0
  13. package/dist/class-generation/index.d.ts.map +1 -1
  14. package/dist/class-generation/playwright-types.d.ts +3 -39
  15. package/dist/class-generation/playwright-types.d.ts.map +1 -1
  16. package/dist/class-generation/pointer.d.ts +10 -1
  17. package/dist/class-generation/pointer.d.ts.map +1 -1
  18. package/dist/eslint/index.cjs +52 -9
  19. package/dist/eslint/index.cjs.map +1 -1
  20. package/dist/eslint/index.d.ts +16 -7
  21. package/dist/eslint/index.d.ts.map +1 -1
  22. package/dist/eslint/index.mjs +52 -9
  23. package/dist/eslint/index.mjs.map +1 -1
  24. package/dist/index.cjs +728 -324
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.mjs +728 -324
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/manifest-generator.d.ts +10 -5
  29. package/dist/manifest-generator.d.ts.map +1 -1
  30. package/dist/method-generation.d.ts.map +1 -1
  31. package/dist/playwright/reporter.cjs +174 -0
  32. package/dist/playwright/reporter.cjs.map +1 -0
  33. package/dist/playwright/reporter.d.ts +13 -0
  34. package/dist/playwright/reporter.d.ts.map +1 -0
  35. package/dist/playwright/reporter.mjs +174 -0
  36. package/dist/playwright/reporter.mjs.map +1 -0
  37. package/dist/plugin/internal/build-plugin.d.ts +2 -0
  38. package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
  39. package/dist/plugin/internal/dev-plugin.d.ts +2 -0
  40. package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
  41. package/dist/plugin/internal-plugins.d.ts.map +1 -1
  42. package/dist/route-navigation-codegen.d.ts +40 -0
  43. package/dist/route-navigation-codegen.d.ts.map +1 -0
  44. package/dist/router-bridge.d.ts +15 -0
  45. package/dist/router-bridge.d.ts.map +1 -1
  46. package/dist/router.cjs +41 -1
  47. package/dist/router.cjs.map +1 -1
  48. package/dist/router.mjs +41 -1
  49. package/dist/router.mjs.map +1 -1
  50. package/dist/tests/broad/helpers/fake-runtime.d.ts +27 -3
  51. package/dist/tests/broad/helpers/fake-runtime.d.ts.map +1 -1
  52. package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts +16 -3
  53. package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts.map +1 -1
  54. package/dist/tests/method-generation.test.d.ts +2 -0
  55. package/dist/tests/method-generation.test.d.ts.map +1 -0
  56. package/dist/tests/playwright-diagnostics.test.d.ts +2 -0
  57. package/dist/tests/playwright-diagnostics.test.d.ts.map +1 -0
  58. package/dist/tests/playwright-reporter.test.d.ts +2 -0
  59. package/dist/tests/playwright-reporter.test.d.ts.map +1 -0
  60. package/dist/transform.d.ts.map +1 -1
  61. package/dist/vite.config.d.ts.map +1 -1
  62. package/package.json +8 -1
@@ -7,6 +7,23 @@ import { Callout } from "./callout";
7
7
  import type { CalloutRenderer } from "./callout";
8
8
  import { Pointer, type AfterPointerClick, type AfterPointerClickInfo, type PointerRenderer } from "./pointer";
9
9
 
10
+ const POM_ACTIVE_ACTION_REGISTRY = Symbol.for("@immense/vue-pom-generator.active-action-registry");
11
+
12
+ interface PomActiveActionRecord {
13
+ componentName?: string;
14
+ methodName: string;
15
+ expectedTestIds: readonly string[];
16
+ }
17
+
18
+ function setPomAction(page: object, action: PomActiveActionRecord): void {
19
+ const globalRecord = globalThis as typeof globalThis & {
20
+ [POM_ACTIVE_ACTION_REGISTRY]?: WeakMap<object, PomActiveActionRecord>;
21
+ };
22
+ const registry = globalRecord[POM_ACTIVE_ACTION_REGISTRY] ?? new WeakMap<object, PomActiveActionRecord>();
23
+ globalRecord[POM_ACTIVE_ACTION_REGISTRY] = registry;
24
+ registry.set(page, { ...action, expectedTestIds: [...action.expectedTestIds] });
25
+ }
26
+
10
27
  // Click instrumentation is optional for generated POMs.
11
28
  //
12
29
  // When enabled, POM click/fill helpers will wait for the app to emit
@@ -124,7 +141,7 @@ export class BasePage {
124
141
  * real `Page` at runtime.
125
142
  */
126
143
  protected get page(): Page {
127
- return this._page as unknown as Page;
144
+ return this._page as Page;
128
145
  }
129
146
 
130
147
  /**
@@ -252,6 +269,15 @@ export class BasePage {
252
269
  }
253
270
  }
254
271
 
272
+ private getAfterPointerClick(wait: boolean = true): AfterPointerClick | undefined {
273
+ if (!REQUIRE_CLICK_EVENT || !wait) return undefined;
274
+
275
+ return async ({ testId, instrumented }: AfterPointerClickInfo) => {
276
+ if (!testId || !instrumented) return;
277
+ await this.waitForTestIdClickEventAfter(testId);
278
+ };
279
+ }
280
+
255
281
  protected selectorForTestId(testId: string): string {
256
282
  return `[${this.testIdAttribute}="${testId}"]`;
257
283
  }
@@ -265,12 +291,55 @@ export class BasePage {
265
291
  return this.describeLocator(this.page.locator(this.selectorForTestId(testId)), description);
266
292
  }
267
293
 
294
+ protected async resolveVisibleTestIdLocator(
295
+ testIds: readonly string[],
296
+ description: string,
297
+ methodName: string,
298
+ componentName?: string,
299
+ ): Promise<Locator> {
300
+ this.recordPomAction(componentName, methodName, testIds);
301
+ const locators = testIds.map(testId => this.locatorByTestId(testId, description));
302
+ if (!locators.length) {
303
+ throw new Error(`[pom] ${methodName} has no candidate test ids.`);
304
+ }
305
+
306
+ try {
307
+ await Promise.any(locators.map(locator => locator.waitFor({ state: "visible", timeout: 5_000 })));
308
+ }
309
+ catch (error) {
310
+ throw new Error(
311
+ `[pom] ${methodName} could not find a visible element for any generated test id: ${testIds.join(", ")}`,
312
+ { cause: error },
313
+ );
314
+ }
315
+
316
+ for (const locator of locators) {
317
+ if (await locator.isVisible()) return locator;
318
+ }
319
+ return locators[0]!;
320
+ }
321
+
322
+ protected recordPomAction(
323
+ componentName: string | undefined,
324
+ methodName: string,
325
+ expectedTestIds: readonly string[],
326
+ ): void {
327
+ setPomAction(this.page, { componentName, methodName, expectedTestIds });
328
+ }
329
+
268
330
  protected locatorWithinTestIdByLabel(
269
331
  rootTestId: string,
270
332
  label: string,
271
333
  options?: { exact?: boolean; description?: string },
272
334
  ): Locator {
273
- const locator = this.locatorByTestId(rootTestId).getByLabel(label, { exact: options?.exact ?? true });
335
+ // Custom radio controls commonly render an invisible input beneath its visible
336
+ // associated <label>. getByLabel() correctly resolves the input, but clicking it
337
+ // then fails actionability because the label intercepts pointer events. Generated
338
+ // radio actions are user interactions, so click the visible labelled surface.
339
+ const locator = this.locatorByTestId(rootTestId)
340
+ .filter({ visible: true })
341
+ .first()
342
+ .getByText(label, { exact: options?.exact ?? true });
274
343
  return this.describeLocator(locator, options?.description);
275
344
  }
276
345
 
@@ -320,11 +389,11 @@ export class BasePage {
320
389
  // `getLocator` returns the narrowed `PwLocator` (so test doubles satisfy it), but each
321
390
  // value is a real Playwright `Locator` at runtime. Widen the record's value type so
322
391
  // generated keyed accessors can be passed to `expect(...)`.
323
- return new Proxy({}, handler) as unknown as Record<TKey, Locator>;
392
+ return new Proxy({}, handler) as Record<TKey, Locator>;
324
393
  }
325
394
 
326
395
  public async getObjectId(options?: { timeoutMs?: number }): Promise<ObjectId> {
327
- const timeoutMs = options?.timeoutMs ?? 10_000;
396
+ const timeoutMs = options?.timeoutMs ?? 5_000;
328
397
  const deadline = Date.now() + timeoutMs;
329
398
 
330
399
  while (true) {
@@ -529,25 +598,52 @@ export class BasePage {
529
598
  annotationText: string = "",
530
599
  wait: boolean = true,
531
600
  description?: string,
601
+ action?: { componentName?: string; methodName: string; preferAssociatedLabel?: boolean },
532
602
  ): Promise<void> {
533
- const locator = this.locatorByTestId(testId, description);
534
- await this.pointer.animateCursorToElement(locator, true, 200, annotationText, {
535
- afterClick: async ({ testId: clickedTestId, instrumented }: AfterPointerClickInfo) => {
536
- if (!wait) return;
537
- if (!clickedTestId || !instrumented) return;
538
- await this.waitForTestIdClickEventAfter(clickedTestId);
539
- },
540
- });
603
+ this.recordPomAction(action?.componentName, action?.methodName ?? description ?? "clickByTestId", [testId]);
604
+ const locator = this.locatorByTestId(testId, description).filter({ visible: true }).first();
605
+ let clickTarget = locator;
606
+ let activateWithKeyboard = false;
607
+ if (action?.preferAssociatedLabel) {
608
+ const visibleControl = locator;
609
+ const controlId = await visibleControl.getAttribute("id");
610
+ if (controlId) {
611
+ // Bootstrap custom controls often use an empty label whose painted ::before/::after
612
+ // pseudo-elements intercept the pointer. Playwright's visible filter can exclude that
613
+ // empty label even though its pseudo-element is the actual interaction surface, so first
614
+ // select the associated label by DOM presence and then choose pointer or keyboard activation.
615
+ const associatedLabel = this.page.locator(`label[for=${JSON.stringify(controlId)}]`).first();
616
+ if (await associatedLabel.count() > 0) {
617
+ if (await associatedLabel.isVisible()) {
618
+ clickTarget = associatedLabel;
619
+ }
620
+ else {
621
+ // An empty label can have a zero-size element box while its ::before checkbox/radio
622
+ // remains painted over the input. Pointer clicks cannot target either surface without
623
+ // force; Space is the native, actionability-checked keyboard activation for both.
624
+ activateWithKeyboard = true;
625
+ }
626
+ }
627
+ }
628
+ else {
629
+ clickTarget = visibleControl;
630
+ }
631
+ }
632
+ const afterClick = this.getAfterPointerClick(wait);
633
+ if (activateWithKeyboard) {
634
+ await this.pointer.animateCursorToElement(locator, false, 200, annotationText);
635
+ await locator.press("Space");
636
+ if (afterClick) {
637
+ await afterClick({ testId, instrumented: true });
638
+ }
639
+ return;
640
+ }
641
+ await this.pointer.animateCursorToElement(clickTarget, true, 200, annotationText, afterClick ? { afterClick } : undefined);
541
642
  }
542
643
 
543
644
  public async clickLocator(locator: PwLocator, annotationText: string = "", wait: boolean = true): Promise<void> {
544
- await this.pointer.animateCursorToElement(locator, true, 200, annotationText, {
545
- afterClick: async ({ testId: clickedTestId, instrumented }: AfterPointerClickInfo) => {
546
- if (!wait) return;
547
- if (!clickedTestId || !instrumented) return;
548
- await this.waitForTestIdClickEventAfter(clickedTestId);
549
- },
550
- });
645
+ const afterClick = this.getAfterPointerClick(wait);
646
+ await this.pointer.animateCursorToElement(locator, true, 200, annotationText, afterClick ? { afterClick } : undefined);
551
647
  }
552
648
 
553
649
  protected async clickWithinTestIdByLabel(
@@ -555,8 +651,9 @@ export class BasePage {
555
651
  label: string,
556
652
  annotationText: string = "",
557
653
  wait: boolean = true,
558
- options?: { exact?: boolean; description?: string },
654
+ options?: { exact?: boolean; description?: string; componentName?: string; methodName?: string },
559
655
  ): Promise<void> {
656
+ this.recordPomAction(options?.componentName, options?.methodName ?? options?.description ?? "clickWithinTestIdByLabel", [rootTestId]);
560
657
  const locator = this.locatorWithinTestIdByLabel(rootTestId, label, {
561
658
  exact: options?.exact,
562
659
  description: options?.description,
@@ -569,14 +666,12 @@ export class BasePage {
569
666
  text: string,
570
667
  annotationText: string = "",
571
668
  description?: string,
669
+ action?: { componentName?: string; methodName: string },
572
670
  ): Promise<void> {
573
- const locator = this.locatorByTestId(testId, description);
574
- await this.pointer.animateCursorToElementAndClickAndFill(locator, text, true, 200, annotationText, {
575
- afterClick: async ({ testId: clickedTestId, instrumented }: AfterPointerClickInfo) => {
576
- if (!clickedTestId || !instrumented) return;
577
- await this.waitForTestIdClickEventAfter(clickedTestId);
578
- },
579
- });
671
+ this.recordPomAction(action?.componentName, action?.methodName ?? description ?? "fillInputByTestId", [testId]);
672
+ const locator = this.locatorByTestId(testId, description).filter({ visible: true }).first();
673
+ const afterClick = this.getAfterPointerClick();
674
+ await this.pointer.animateCursorToElementAndClickAndFill(locator, text, true, 200, annotationText, afterClick ? { afterClick } : undefined);
580
675
  }
581
676
 
582
677
  /**
@@ -586,45 +681,32 @@ export class BasePage {
586
681
  protected async selectVSelectByTestId(
587
682
  testId: string,
588
683
  value: string,
589
- timeOut: number = 500,
590
684
  annotationText: string = "",
591
685
  description?: string,
686
+ action?: { componentName?: string; methodName: string },
592
687
  ): Promise<void> {
593
- const root = this.locatorByTestId(testId, description);
688
+ this.recordPomAction(action?.componentName, action?.methodName ?? description ?? "selectVSelectByTestId", [testId]);
689
+ const root = this.locatorByTestId(testId, description).filter({ visible: true }).first();
594
690
  const input = root.locator("input");
595
691
 
596
692
  await this.pointer.animateCursorToElement(input, false, 200, annotationText);
597
- await input.click({ force: true });
693
+ await input.click();
598
694
  await this.pointer.animateCursorToElementAndClickAndFill(input, value, false, 200, annotationText);
599
- await this.page.waitForTimeout(timeOut);
600
695
 
601
696
  const option = root.locator("ul.vs__dropdown-menu li[role='option']").first();
602
- if (await option.count()) {
603
- await this.pointer.animateCursorToElement(option, true, 200, annotationText, {
604
- afterClick: async ({ testId: clickedTestId, instrumented }: AfterPointerClickInfo) => {
605
- if (!clickedTestId || !instrumented) return;
606
- await this.waitForTestIdClickEventAfter(clickedTestId);
607
- },
608
- });
609
- }
697
+ await option.waitFor({ state: "visible", timeout: 5_000 });
698
+ const afterClick = this.getAfterPointerClick();
699
+ await this.pointer.animateCursorToElement(option, true, 200, annotationText, afterClick ? { afterClick } : undefined);
610
700
  }
611
701
 
612
702
  public async fillInputByLocator(locator: PwLocator, text: string, annotationText: string = ""): Promise<void> {
613
- await this.pointer.animateCursorToElementAndClickAndFill(locator, text, true, 200, annotationText, {
614
- afterClick: async ({ testId: clickedTestId, instrumented }: AfterPointerClickInfo) => {
615
- if (!clickedTestId || !instrumented) return;
616
- await this.waitForTestIdClickEventAfter(clickedTestId);
617
- },
618
- });
703
+ const afterClick = this.getAfterPointerClick();
704
+ await this.pointer.animateCursorToElementAndClickAndFill(locator, text, true, 200, annotationText, afterClick ? { afterClick } : undefined);
619
705
  }
620
706
 
621
707
  protected async clickByAriaLabel(ariaLabel: string, annotationText: string = ""): Promise<void> {
622
- await this.pointer.animateCursorToElement(`[aria-label="${ariaLabel}"]`, true, 200, annotationText, {
623
- afterClick: async ({ testId: clickedTestId, instrumented }: AfterPointerClickInfo) => {
624
- if (!clickedTestId || !instrumented) return;
625
- await this.waitForTestIdClickEventAfter(clickedTestId);
626
- },
627
- });
708
+ const afterClick = this.getAfterPointerClick();
709
+ await this.pointer.animateCursorToElement(`[aria-label="${ariaLabel}"]`, true, 200, annotationText, afterClick ? { afterClick } : undefined);
628
710
  }
629
711
 
630
712
  /**
@@ -642,7 +724,7 @@ export class BasePage {
642
724
  * @returns True if the element is visible, false otherwise
643
725
  */
644
726
  protected async isVisibleByTestId(testId: string): Promise<boolean> {
645
- return await this.page.isVisible(this.selectorForTestId(testId));
727
+ return this.locatorByTestId(testId).isVisible();
646
728
  }
647
729
 
648
730
  /**
@@ -651,18 +733,18 @@ export class BasePage {
651
733
  * @returns The text content of the element
652
734
  */
653
735
  protected async getTextByTestId(testId: string): Promise<string | null> {
654
- return await this.page.textContent(this.selectorForTestId(testId));
736
+ return this.locatorByTestId(testId).textContent();
655
737
  }
656
738
 
657
739
  /**
658
740
  * Waits for an element with the specified data-testid to be visible
659
741
  * @param testId The data-testid of the element to wait for
660
742
  * @param options Optional timeout and other options
661
- * @param options.timeout The maximum time to wait for the element to be visible (default is 3000ms)
743
+ * @param options.timeout The maximum time to wait for the element to be visible (default is 5000ms)
662
744
  * @returns A promise that resolves when the element is visible
663
745
  */
664
746
  protected async waitForTestId(testId: string, options?: { timeout?: number }): Promise<void> {
665
- await this.page.waitForSelector(this.selectorForTestId(testId), options);
747
+ await this.locatorByTestId(testId).waitFor({ state: "visible", timeout: options?.timeout ?? 5_000 });
666
748
  }
667
749
 
668
750
  /**
@@ -670,9 +752,9 @@ export class BasePage {
670
752
  * @param testId The data-testid of the element to hover over
671
753
  */
672
754
  protected async hoverByTestId(testId: string): Promise<void> {
673
- const selector = this.selectorForTestId(testId);
674
- await this.pointer.animateCursorToElement(selector, false, 200, "");
675
- await this.page.hover(selector);
755
+ const locator = this.locatorByTestId(testId);
756
+ await this.pointer.animateCursorToElement(locator, false, 200, "");
757
+ await locator.hover();
676
758
  }
677
759
 
678
760
  /**
@@ -681,6 +763,6 @@ export class BasePage {
681
763
  * @param value The value to select
682
764
  */
683
765
  protected async selectByTestId(testId: string, value: string): Promise<void> {
684
- await this.page.selectOption(this.selectorForTestId(testId), value);
766
+ await this.locatorByTestId(testId).selectOption(value);
685
767
  }
686
768
  }