@allwright.dev/vitest 0.0.55 → 0.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/README.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  Vitest fixtures for allwright with Playwright-style `browser` and `page` injection, plus Android mobile fixtures for hybrid tests.
4
4
 
5
+ Wrap the Vitest configuration with `allwrightVitestConfig`. It starts Allwright once before workers run and shuts it down once after the complete test run. Existing user global setup files remain supported and run after Allwright starts, then tear down before Allwright stops.
6
+
7
+ ```ts
8
+ import { allwrightVitestConfig } from "@allwright.dev/vitest/config";
9
+ import { defineConfig } from "vitest/config";
10
+
11
+ export default allwrightVitestConfig(defineConfig({
12
+ test: {
13
+ globalSetup: ["./test/my-global-setup.ts"],
14
+ },
15
+ }));
16
+ ```
17
+
5
18
  Install:
6
19
 
7
20
  ```bash
@@ -54,11 +67,11 @@ suites:
54
67
  Vitest can override or select from that shared config without switching to a Vitest-specific file:
55
68
 
56
69
  ```ts
57
- import { test } from "@allwright.dev/vitest";
70
+ import { expect, test as base } from "@allwright.dev/vitest";
58
71
 
59
- test.use({
60
- allwright: {
61
- suite: "smoke"
72
+ const test = base.extend({
73
+ allwright: async ({}, use) => {
74
+ await use({ suite: "smoke" });
62
75
  }
63
76
  });
64
77
  ```
@@ -66,21 +79,24 @@ test.use({
66
79
  Android fixtures are available alongside the web fixtures:
67
80
 
68
81
  ```ts
69
- import { test } from "@allwright.dev/vitest";
70
-
71
- test.use({
72
- allwright: {
73
- android: {
74
- launchOptions: {
75
- apkPath: "/absolute/path/to/app.apk",
76
- appId: "com.example.airticket",
82
+ import { expect, test as base } from "@allwright.dev/vitest";
83
+
84
+ const test = base.extend({
85
+ allwright: async ({}, use) => {
86
+ await use({
87
+ android: {
88
+ launchOptions: {
89
+ apkPath: "/absolute/path/to/app.apk",
90
+ appId: "com.example.airticket",
91
+ },
77
92
  },
78
- },
93
+ });
79
94
  },
80
95
  });
81
96
 
82
97
  test("android only", async ({ androidApp }) => {
83
98
  await androidApp.fill('xpath=//*[@text="Email"]', "user@example.com");
99
+ await expect(androidApp.locator('xpath=//*[@text="Email"]')).toHaveText("user@example.com");
84
100
  });
85
101
 
86
102
  test("hybrid web and android", async ({ page, androidApp }) => {
@@ -99,3 +115,5 @@ Available fixtures:
99
115
  - `androidApp`: launched Android app page
100
116
 
101
117
  `androidApp` launches using `allwright.android.launchOptions` first, then falls back to `config.mobile.android`.
118
+
119
+ Android apps and locators support the Android-applicable action and expectation subset: `click`, `count`, `focus`, `fill`, `press`, `textContent`, `innerText`, `waitForSelector`, and `screenshot`. `expect(androidApp)` and `expect(androidApp.locator(...))` provide `toHaveText`, `toContainText`, `toHaveCount`, and `toBeVisible` with the same retry controls as web fixtures. Hover and highlight remain web-only.
@@ -0,0 +1,2 @@
1
+ import type { UserConfig } from "vitest/config";
2
+ export declare function allwrightVitestConfig<T extends UserConfig>(config: T): T;
package/dist/config.js ADDED
@@ -0,0 +1,20 @@
1
+ import { fileURLToPath } from "node:url";
2
+ const allwrightGlobalSetup = fileURLToPath(new URL("./global-setup.js", import.meta.url));
3
+ export function allwrightVitestConfig(config) {
4
+ const configuredGlobalSetup = config.test?.globalSetup;
5
+ const globalSetup = [
6
+ allwrightGlobalSetup,
7
+ ...(Array.isArray(configuredGlobalSetup)
8
+ ? configuredGlobalSetup
9
+ : configuredGlobalSetup
10
+ ? [configuredGlobalSetup]
11
+ : []),
12
+ ];
13
+ return {
14
+ ...config,
15
+ test: {
16
+ ...config.test,
17
+ globalSetup,
18
+ },
19
+ };
20
+ }
@@ -0,0 +1,2 @@
1
+ export declare function setup(): Promise<void>;
2
+ export declare function teardown(): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import { ping, resolveConfig, setServerAddr, shutdown } from "@allwright.dev/core";
2
+ export async function setup() {
3
+ const config = resolveConfig();
4
+ if (config.serverAddr) {
5
+ setServerAddr(config.serverAddr);
6
+ }
7
+ await ping();
8
+ }
9
+ export async function teardown() {
10
+ await shutdown();
11
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type MobileAndroidConnectOptions, type MobileAndroidDevice, type MobileAndroidLaunchOptions, type MobileAndroidApp, type Browser, type BrowserKind, type LaunchOptions, type Locator, type Page, type WaitForSelectorOptions } from "@allwright.dev/core";
1
+ import { type MobileAndroidConnectOptions, type MobileAndroidDevice, type MobileAndroidLaunchOptions, type MobileAndroidApp, type Browser, type BrowserKind, type LaunchOptions, type Locator, type MobileAndroidLocator, 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;
@@ -48,8 +48,8 @@ interface LazyResource<T> {
48
48
  realized(): boolean;
49
49
  }
50
50
  export declare const test: import("vitest").TestAPI<{
51
- page: Page;
52
51
  browser: Browser;
52
+ page: Page;
53
53
  android: MobileAndroidDevice;
54
54
  androidApp: MobileAndroidApp;
55
55
  allwright: AllwrightVitestOptions;
@@ -61,6 +61,8 @@ type VitestMatcherReturn = ReturnType<VitestExpect>;
61
61
  interface AllwrightExpect extends VitestExpect {
62
62
  (actual: Page): PageExpectMatchers;
63
63
  (actual: Locator): LocatorExpectMatchers;
64
+ (actual: MobileAndroidApp): PageExpectMatchers;
65
+ (actual: MobileAndroidLocator): LocatorExpectMatchers;
64
66
  <T>(actual: T): VitestMatcherReturn;
65
67
  }
66
68
  export declare const expect: AllwrightExpect;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { launchConfiguredBrowser, mobile, resolveConfig, setServerAddr, shutdown, } from "@allwright.dev/core";
1
+ import { launchConfiguredBrowser, mobile, resolveConfig, setServerAddr, } from "@allwright.dev/core";
2
2
  import { expect as vitestExpect, test as base } from "vitest";
3
3
  const DEFAULT_ANDROID_CONNECT_TIMEOUT_MS = 30_000;
4
4
  const DEFAULT_ANDROID_LAUNCH_TIMEOUT_MS = 60_000;
@@ -218,9 +218,27 @@ function createLazyAndroidApp(appResource) {
218
218
  async click(selector, options) {
219
219
  return (await appResource.get()).click(selector, options);
220
220
  },
221
+ async count(selector, options) {
222
+ return (await appResource.get()).count(selector, options);
223
+ },
224
+ async focus(selector, options) {
225
+ return (await appResource.get()).focus(selector, options);
226
+ },
221
227
  async fill(selector, value, options) {
222
228
  return (await appResource.get()).fill(selector, value, options);
223
229
  },
230
+ async press(selector, key, options) {
231
+ return (await appResource.get()).press(selector, key, options);
232
+ },
233
+ async textContent(selector, options) {
234
+ return (await appResource.get()).textContent(selector, options);
235
+ },
236
+ async innerText(selector, options) {
237
+ return (await appResource.get()).innerText(selector, options);
238
+ },
239
+ async waitForSelector(selector, options) {
240
+ return (await appResource.get()).waitForSelector(selector, options);
241
+ },
224
242
  async screenshot(options) {
225
243
  return (await appResource.get()).screenshot(options);
226
244
  },
@@ -238,9 +256,27 @@ function createLazyAndroidLocator(appResource, selectorFactory) {
238
256
  async click(options) {
239
257
  return (await appResource.get()).locator(await selectorFactory()).click(options);
240
258
  },
259
+ async count(options) {
260
+ return (await appResource.get()).locator(await selectorFactory()).count(options);
261
+ },
262
+ async focus(options) {
263
+ return (await appResource.get()).locator(await selectorFactory()).focus(options);
264
+ },
241
265
  async fill(value, options) {
242
266
  return (await appResource.get()).locator(await selectorFactory()).fill(value, options);
243
267
  },
268
+ async press(key, options) {
269
+ return (await appResource.get()).locator(await selectorFactory()).press(key, options);
270
+ },
271
+ async textContent(options) {
272
+ return (await appResource.get()).locator(await selectorFactory()).textContent(options);
273
+ },
274
+ async innerText(options) {
275
+ return (await appResource.get()).locator(await selectorFactory()).innerText(options);
276
+ },
277
+ async waitFor(options) {
278
+ return (await appResource.get()).locator(await selectorFactory()).waitFor(options);
279
+ },
244
280
  locator(selector) {
245
281
  return createLazyAndroidLocator(appResource, async () => (await appResource.get()).locator(await selectorFactory()).locator(selector).selector);
246
282
  },
@@ -282,9 +318,8 @@ export const test = base.extend({
282
318
  finally {
283
319
  activeExpectDefaults = {};
284
320
  if (browserResource.realized()) {
285
- await browserResource.get().then((resolved) => resolved.close()).catch(() => undefined);
321
+ await browserResource.get().then((resolved) => resolved.close());
286
322
  }
287
- await shutdown();
288
323
  }
289
324
  },
290
325
  _androidResource: async ({ allwright }, use) => {
@@ -293,12 +328,7 @@ export const test = base.extend({
293
328
  setServerAddr(config.serverAddr);
294
329
  }
295
330
  const androidResource = createLazyResource(async () => mobile.android.connect(resolveAndroidConnectOptions(config, allwright)));
296
- try {
297
- await use(androidResource);
298
- }
299
- finally {
300
- await shutdown();
301
- }
331
+ await use(androidResource);
302
332
  },
303
333
  browser: async ({ _browserResource }, use) => {
304
334
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allwright.dev/vitest",
3
- "version": "0.0.55",
3
+ "version": "0.0.58",
4
4
  "description": "Vitest fixtures for the allwright TypeScript client.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,6 +25,14 @@
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
27
  "import": "./dist/index.js"
28
+ },
29
+ "./config": {
30
+ "types": "./dist/config.d.ts",
31
+ "import": "./dist/config.js"
32
+ },
33
+ "./global-setup": {
34
+ "types": "./dist/global-setup.d.ts",
35
+ "import": "./dist/global-setup.js"
28
36
  }
29
37
  },
30
38
  "files": [
@@ -39,7 +47,7 @@
39
47
  "prepublishOnly": "bun run build"
40
48
  },
41
49
  "dependencies": {
42
- "@allwright.dev/core": "0.0.55"
50
+ "@allwright.dev/core": "0.0.58"
43
51
  },
44
52
  "devDependencies": {
45
53
  "typescript": "^5.9.2",