@allwright.dev/vitest 0.0.26 → 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 { Locator, 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;
package/dist/index.js CHANGED
@@ -1,18 +1,21 @@
1
- import { chromium, setServerAddr, shutdown, Locator, 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,14 +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
32
  function isLocator(value) {
30
- return value instanceof Locator;
33
+ return (!!value &&
34
+ typeof value === "object" &&
35
+ typeof value.page === "object" &&
36
+ typeof value.click === "function");
31
37
  }
32
- async function retryExpectation(callback, options = {}) {
33
- const timeoutMs = options.timeoutMs ?? DEFAULT_EXPECT_TIMEOUT_MS;
34
- const intervalMs = options.intervalMs ?? DEFAULT_EXPECT_INTERVAL_MS;
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;
35
62
  const deadline = Date.now() + timeoutMs;
36
63
  let lastError;
37
64
  while (Date.now() <= deadline) {
@@ -59,7 +86,7 @@ function createPageExpect(page) {
59
86
  return;
60
87
  }
61
88
  vitestExpect(result.text).toBe(expected);
62
- }, options);
89
+ }, options, currentExpectDefaults());
63
90
  },
64
91
  async toContainText(selector, expected, options = {}) {
65
92
  await retryExpectation(async () => {
@@ -69,13 +96,13 @@ function createPageExpect(page) {
69
96
  return;
70
97
  }
71
98
  vitestExpect(result.text).toContain(expected);
72
- }, options);
99
+ }, options, currentExpectDefaults());
73
100
  },
74
101
  async toHaveCount(selector, expected, options = {}) {
75
102
  await retryExpectation(async () => {
76
103
  const result = await page.count(selector, {});
77
104
  vitestExpect(result.count).toBe(expected);
78
- }, options);
105
+ }, options, currentExpectDefaults());
79
106
  },
80
107
  async toBeVisible(selector, options = {}) {
81
108
  await retryExpectation(async () => {
@@ -84,7 +111,7 @@ function createPageExpect(page) {
84
111
  ...(options.command ?? {}),
85
112
  });
86
113
  vitestExpect(result.visible).toBe(true);
87
- }, options);
114
+ }, options, currentExpectDefaults());
88
115
  },
89
116
  };
90
117
  }
@@ -98,7 +125,7 @@ function createLocatorExpect(locator) {
98
125
  return;
99
126
  }
100
127
  vitestExpect(result.text).toBe(expected);
101
- }, options);
128
+ }, options, currentExpectDefaults());
102
129
  },
103
130
  async toContainText(expected, options = {}) {
104
131
  await retryExpectation(async () => {
@@ -108,13 +135,13 @@ function createLocatorExpect(locator) {
108
135
  return;
109
136
  }
110
137
  vitestExpect(result.text).toContain(expected);
111
- }, options);
138
+ }, options, currentExpectDefaults());
112
139
  },
113
140
  async toHaveCount(expected, options = {}) {
114
141
  await retryExpectation(async () => {
115
142
  const result = await locator.count({});
116
143
  vitestExpect(result.count).toBe(expected);
117
- }, options);
144
+ }, options, currentExpectDefaults());
118
145
  },
119
146
  async toBeVisible(options = {}) {
120
147
  await retryExpectation(async () => {
@@ -123,10 +150,14 @@ function createLocatorExpect(locator) {
123
150
  ...(options.command ?? {}),
124
151
  });
125
152
  vitestExpect(result.visible).toBe(true);
126
- }, options);
153
+ }, options, currentExpectDefaults());
127
154
  },
128
155
  };
129
156
  }
157
+ let activeExpectDefaults = {};
158
+ function currentExpectDefaults() {
159
+ return activeExpectDefaults;
160
+ }
130
161
  const expectImpl = ((actual) => {
131
162
  if (isLocator(actual)) {
132
163
  return createLocatorExpect(actual);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allwright.dev/vitest",
3
- "version": "0.0.26",
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.26"
42
+ "@allwright.dev/core": "0.0.27"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.9.2",