@allwright.dev/vitest 0.0.25 → 0.0.27

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 CHANGED
@@ -11,3 +11,38 @@ test("opens a page", async ({ page }) => {
11
11
  expect(title.text).toContain("Example");
12
12
  });
13
13
  ```
14
+
15
+ The fixture package reads the shared stack-agnostic config format through `@allwright.dev/core`.
16
+ Use `allwright.config.yaml` by default, or `allwright.config.json` if you prefer. Both follow the same root schema in `allwright.schema.json`.
17
+
18
+ ```yaml
19
+ schemaVersion: 1
20
+
21
+ server:
22
+ addr: 127.0.0.1:50051
23
+
24
+ browser:
25
+ name: firefox
26
+ binary: /Applications/Firefox.app/Contents/MacOS/firefox
27
+
28
+ expect:
29
+ timeoutMs: 7000
30
+ intervalMs: 100
31
+
32
+ suites:
33
+ smoke:
34
+ browser:
35
+ name: chromium
36
+ ```
37
+
38
+ Vitest can override or select from that shared config without switching to a Vitest-specific file:
39
+
40
+ ```ts
41
+ import { test } from "@allwright.dev/vitest";
42
+
43
+ test.use({
44
+ allwright: {
45
+ suite: "smoke"
46
+ }
47
+ });
48
+ ```
package/dist/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { Page, type Browser, type LaunchOptions, type WaitForSelectorOptions } from "@allwright.dev/core";
1
+ import { type Browser, type BrowserKind, type LaunchOptions, type Locator, type Page, type WaitForSelectorOptions } from "@allwright.dev/core";
2
2
  import { expect as vitestExpect } from "vitest";
3
3
  export interface AllwrightVitestOptions {
4
4
  launchOptions?: LaunchOptions;
5
5
  serverAddr?: string;
6
+ browser?: BrowserKind;
7
+ browserBinary?: string;
8
+ configFile?: string;
9
+ suite?: string;
6
10
  }
7
11
  export interface AllwrightVitestFixtures {
8
12
  browser: Browser;
@@ -26,6 +30,12 @@ export interface PageExpectMatchers {
26
30
  toHaveCount(selector: string, expected: number, options?: RetryExpectationOptions): Promise<void>;
27
31
  toBeVisible(selector: string, options?: VisibleExpectationOptions): Promise<void>;
28
32
  }
33
+ export interface LocatorExpectMatchers {
34
+ toHaveText(expected: string | RegExp, options?: TextExpectationOptions): Promise<void>;
35
+ toContainText(expected: string | RegExp, options?: TextExpectationOptions): Promise<void>;
36
+ toHaveCount(expected: number, options?: RetryExpectationOptions): Promise<void>;
37
+ toBeVisible(options?: VisibleExpectationOptions): Promise<void>;
38
+ }
29
39
  export declare const test: import("vitest").TestAPI<{
30
40
  browser: Browser;
31
41
  page: Page;
@@ -35,8 +45,9 @@ type VitestExpect = typeof vitestExpect;
35
45
  type VitestMatcherReturn = ReturnType<VitestExpect>;
36
46
  interface AllwrightExpect extends VitestExpect {
37
47
  (actual: Page): PageExpectMatchers;
48
+ (actual: Locator): LocatorExpectMatchers;
38
49
  <T>(actual: T): VitestMatcherReturn;
39
50
  }
40
51
  export declare const expect: AllwrightExpect;
41
52
  export { vitestExpect };
42
- export type { Browser, LaunchOptions, Page };
53
+ export type { Browser, LaunchOptions, Locator, Page };
package/dist/index.js CHANGED
@@ -1,18 +1,21 @@
1
- import { chromium, setServerAddr, shutdown, Page, } from "@allwright.dev/core";
1
+ import { launchConfiguredBrowser, resolveConfig, setServerAddr, shutdown, } 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) => {
5
5
  await use({});
6
6
  },
7
7
  browser: async ({ allwright }, use) => {
8
- if (allwright.serverAddr) {
9
- setServerAddr(allwright.serverAddr);
8
+ const config = resolveVitestConfig(allwright);
9
+ if (config.serverAddr) {
10
+ setServerAddr(config.serverAddr);
10
11
  }
11
- const browser = await chromium.launch(allwright.launchOptions ?? {});
12
+ activeExpectDefaults = config.expect;
13
+ const browser = await launchConfiguredBrowser(config);
12
14
  try {
13
15
  await use(browser);
14
16
  }
15
17
  finally {
18
+ activeExpectDefaults = {};
16
19
  await browser.close().catch(() => undefined);
17
20
  await shutdown();
18
21
  }
@@ -24,11 +27,38 @@ export const test = base.extend({
24
27
  const DEFAULT_EXPECT_TIMEOUT_MS = 5_000;
25
28
  const DEFAULT_EXPECT_INTERVAL_MS = 100;
26
29
  function isPage(value) {
27
- return value instanceof Page;
30
+ return !!value && typeof value === "object" && typeof value.locator === "function";
28
31
  }
29
- async function retryExpectation(callback, options = {}) {
30
- const timeoutMs = options.timeoutMs ?? DEFAULT_EXPECT_TIMEOUT_MS;
31
- const intervalMs = options.intervalMs ?? DEFAULT_EXPECT_INTERVAL_MS;
32
+ function isLocator(value) {
33
+ return (!!value &&
34
+ typeof value === "object" &&
35
+ typeof value.page === "object" &&
36
+ typeof value.click === "function");
37
+ }
38
+ function resolveVitestConfig(options) {
39
+ const config = resolveConfig({
40
+ configFile: options.configFile,
41
+ suite: options.suite,
42
+ });
43
+ return {
44
+ ...config,
45
+ serverAddr: options.serverAddr ?? config.serverAddr,
46
+ browserName: options.browser ?? config.browserName,
47
+ browserBinary: options.browserBinary ?? config.browserBinary,
48
+ launchOptions: {
49
+ ...config.launchOptions,
50
+ ...(options.launchOptions ?? {}),
51
+ browserBinary: options.launchOptions?.browserBinary ??
52
+ options.browserBinary ??
53
+ config.browserBinary ??
54
+ config.launchOptions.browserBinary,
55
+ },
56
+ expect: config.expect,
57
+ };
58
+ }
59
+ async function retryExpectation(callback, options = {}, defaults = {}) {
60
+ const timeoutMs = options.timeoutMs ?? defaults.timeoutMs ?? DEFAULT_EXPECT_TIMEOUT_MS;
61
+ const intervalMs = options.intervalMs ?? defaults.intervalMs ?? DEFAULT_EXPECT_INTERVAL_MS;
32
62
  const deadline = Date.now() + timeoutMs;
33
63
  let lastError;
34
64
  while (Date.now() <= deadline) {
@@ -56,7 +86,7 @@ function createPageExpect(page) {
56
86
  return;
57
87
  }
58
88
  vitestExpect(result.text).toBe(expected);
59
- }, options);
89
+ }, options, currentExpectDefaults());
60
90
  },
61
91
  async toContainText(selector, expected, options = {}) {
62
92
  await retryExpectation(async () => {
@@ -66,13 +96,13 @@ function createPageExpect(page) {
66
96
  return;
67
97
  }
68
98
  vitestExpect(result.text).toContain(expected);
69
- }, options);
99
+ }, options, currentExpectDefaults());
70
100
  },
71
101
  async toHaveCount(selector, expected, options = {}) {
72
102
  await retryExpectation(async () => {
73
103
  const result = await page.count(selector, {});
74
104
  vitestExpect(result.count).toBe(expected);
75
- }, options);
105
+ }, options, currentExpectDefaults());
76
106
  },
77
107
  async toBeVisible(selector, options = {}) {
78
108
  await retryExpectation(async () => {
@@ -81,11 +111,57 @@ function createPageExpect(page) {
81
111
  ...(options.command ?? {}),
82
112
  });
83
113
  vitestExpect(result.visible).toBe(true);
84
- }, options);
114
+ }, options, currentExpectDefaults());
85
115
  },
86
116
  };
87
117
  }
118
+ function createLocatorExpect(locator) {
119
+ return {
120
+ async toHaveText(expected, options = {}) {
121
+ await retryExpectation(async () => {
122
+ const result = await locator.textContent(options.command ?? {});
123
+ if (expected instanceof RegExp) {
124
+ vitestExpect(result.text).toMatch(expected);
125
+ return;
126
+ }
127
+ vitestExpect(result.text).toBe(expected);
128
+ }, options, currentExpectDefaults());
129
+ },
130
+ async toContainText(expected, options = {}) {
131
+ await retryExpectation(async () => {
132
+ const result = await locator.textContent(options.command ?? {});
133
+ if (expected instanceof RegExp) {
134
+ vitestExpect(result.text).toMatch(expected);
135
+ return;
136
+ }
137
+ vitestExpect(result.text).toContain(expected);
138
+ }, options, currentExpectDefaults());
139
+ },
140
+ async toHaveCount(expected, options = {}) {
141
+ await retryExpectation(async () => {
142
+ const result = await locator.count({});
143
+ vitestExpect(result.count).toBe(expected);
144
+ }, options, currentExpectDefaults());
145
+ },
146
+ async toBeVisible(options = {}) {
147
+ await retryExpectation(async () => {
148
+ const result = await locator.waitFor({
149
+ visible: true,
150
+ ...(options.command ?? {}),
151
+ });
152
+ vitestExpect(result.visible).toBe(true);
153
+ }, options, currentExpectDefaults());
154
+ },
155
+ };
156
+ }
157
+ let activeExpectDefaults = {};
158
+ function currentExpectDefaults() {
159
+ return activeExpectDefaults;
160
+ }
88
161
  const expectImpl = ((actual) => {
162
+ if (isLocator(actual)) {
163
+ return createLocatorExpect(actual);
164
+ }
89
165
  if (isPage(actual)) {
90
166
  return createPageExpect(actual);
91
167
  }
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.27",
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.27"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.9.2",