@allwright.dev/vitest 0.0.25 → 0.0.26

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Page, type Browser, type LaunchOptions, type WaitForSelectorOptions } from "@allwright.dev/core";
1
+ import { Locator, Page, type Browser, type LaunchOptions, type WaitForSelectorOptions } from "@allwright.dev/core";
2
2
  import { expect as vitestExpect } from "vitest";
3
3
  export interface AllwrightVitestOptions {
4
4
  launchOptions?: LaunchOptions;
@@ -26,6 +26,12 @@ export interface PageExpectMatchers {
26
26
  toHaveCount(selector: string, expected: number, options?: RetryExpectationOptions): Promise<void>;
27
27
  toBeVisible(selector: string, options?: VisibleExpectationOptions): Promise<void>;
28
28
  }
29
+ export interface LocatorExpectMatchers {
30
+ toHaveText(expected: string | RegExp, options?: TextExpectationOptions): Promise<void>;
31
+ toContainText(expected: string | RegExp, options?: TextExpectationOptions): Promise<void>;
32
+ toHaveCount(expected: number, options?: RetryExpectationOptions): Promise<void>;
33
+ toBeVisible(options?: VisibleExpectationOptions): Promise<void>;
34
+ }
29
35
  export declare const test: import("vitest").TestAPI<{
30
36
  browser: Browser;
31
37
  page: Page;
@@ -35,8 +41,9 @@ type VitestExpect = typeof vitestExpect;
35
41
  type VitestMatcherReturn = ReturnType<VitestExpect>;
36
42
  interface AllwrightExpect extends VitestExpect {
37
43
  (actual: Page): PageExpectMatchers;
44
+ (actual: Locator): LocatorExpectMatchers;
38
45
  <T>(actual: T): VitestMatcherReturn;
39
46
  }
40
47
  export declare const expect: AllwrightExpect;
41
48
  export { vitestExpect };
42
- export type { Browser, LaunchOptions, Page };
49
+ export type { Browser, LaunchOptions, Locator, Page };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { chromium, setServerAddr, shutdown, Page, } from "@allwright.dev/core";
1
+ import { chromium, setServerAddr, shutdown, Locator, Page, } from "@allwright.dev/core";
2
2
  import { expect as vitestExpect, test as base } from "vitest";
3
3
  export const test = base.extend({
4
4
  allwright: async ({}, use) => {
@@ -26,6 +26,9 @@ const DEFAULT_EXPECT_INTERVAL_MS = 100;
26
26
  function isPage(value) {
27
27
  return value instanceof Page;
28
28
  }
29
+ function isLocator(value) {
30
+ return value instanceof Locator;
31
+ }
29
32
  async function retryExpectation(callback, options = {}) {
30
33
  const timeoutMs = options.timeoutMs ?? DEFAULT_EXPECT_TIMEOUT_MS;
31
34
  const intervalMs = options.intervalMs ?? DEFAULT_EXPECT_INTERVAL_MS;
@@ -85,7 +88,49 @@ function createPageExpect(page) {
85
88
  },
86
89
  };
87
90
  }
91
+ function createLocatorExpect(locator) {
92
+ return {
93
+ async toHaveText(expected, options = {}) {
94
+ await retryExpectation(async () => {
95
+ const result = await locator.textContent(options.command ?? {});
96
+ if (expected instanceof RegExp) {
97
+ vitestExpect(result.text).toMatch(expected);
98
+ return;
99
+ }
100
+ vitestExpect(result.text).toBe(expected);
101
+ }, options);
102
+ },
103
+ async toContainText(expected, options = {}) {
104
+ await retryExpectation(async () => {
105
+ const result = await locator.textContent(options.command ?? {});
106
+ if (expected instanceof RegExp) {
107
+ vitestExpect(result.text).toMatch(expected);
108
+ return;
109
+ }
110
+ vitestExpect(result.text).toContain(expected);
111
+ }, options);
112
+ },
113
+ async toHaveCount(expected, options = {}) {
114
+ await retryExpectation(async () => {
115
+ const result = await locator.count({});
116
+ vitestExpect(result.count).toBe(expected);
117
+ }, options);
118
+ },
119
+ async toBeVisible(options = {}) {
120
+ await retryExpectation(async () => {
121
+ const result = await locator.waitFor({
122
+ visible: true,
123
+ ...(options.command ?? {}),
124
+ });
125
+ vitestExpect(result.visible).toBe(true);
126
+ }, options);
127
+ },
128
+ };
129
+ }
88
130
  const expectImpl = ((actual) => {
131
+ if (isLocator(actual)) {
132
+ return createLocatorExpect(actual);
133
+ }
89
134
  if (isPage(actual)) {
90
135
  return createPageExpect(actual);
91
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allwright.dev/vitest",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "Vitest fixtures for the allwright TypeScript client.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,7 +39,7 @@
39
39
  "prepublishOnly": "npm run build"
40
40
  },
41
41
  "dependencies": {
42
- "@allwright.dev/core": "0.0.25"
42
+ "@allwright.dev/core": "0.0.26"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.9.2",