@allwright.dev/vitest 0.0.26 → 0.0.28
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 +43 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +48 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Vitest fixtures for allwright with Playwright-style `browser` and `page` injection.
|
|
4
4
|
|
|
5
|
+
Install:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D vitest @allwright.dev/vitest
|
|
9
|
+
```
|
|
10
|
+
|
|
5
11
|
```ts
|
|
6
12
|
import { expect, test } from "@allwright.dev/vitest";
|
|
7
13
|
|
|
@@ -11,3 +17,40 @@ test("opens a page", async ({ page }) => {
|
|
|
11
17
|
expect(title.text).toContain("Example");
|
|
12
18
|
});
|
|
13
19
|
```
|
|
20
|
+
|
|
21
|
+
A checked-in example spec also lives in [examples/basic.spec.ts](./examples/basic.spec.ts).
|
|
22
|
+
|
|
23
|
+
The fixture package reads the shared stack-agnostic config format through `@allwright.dev/core`.
|
|
24
|
+
Use `allwright.config.yaml` by default, or `allwright.config.json` if you prefer. Both follow the same root schema in `allwright.schema.json`.
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
schemaVersion: 1
|
|
28
|
+
|
|
29
|
+
server:
|
|
30
|
+
addr: 127.0.0.1:50051
|
|
31
|
+
|
|
32
|
+
browser:
|
|
33
|
+
name: firefox
|
|
34
|
+
binary: /Applications/Firefox.app/Contents/MacOS/firefox
|
|
35
|
+
|
|
36
|
+
expect:
|
|
37
|
+
timeoutMs: 7000
|
|
38
|
+
intervalMs: 100
|
|
39
|
+
|
|
40
|
+
suites:
|
|
41
|
+
smoke:
|
|
42
|
+
browser:
|
|
43
|
+
name: chromium
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Vitest can override or select from that shared config without switching to a Vitest-specific file:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { test } from "@allwright.dev/vitest";
|
|
50
|
+
|
|
51
|
+
test.use({
|
|
52
|
+
allwright: {
|
|
53
|
+
suite: "smoke"
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
9
|
-
|
|
8
|
+
const config = resolveVitestConfig(allwright);
|
|
9
|
+
if (config.serverAddr) {
|
|
10
|
+
setServerAddr(config.serverAddr);
|
|
10
11
|
}
|
|
11
|
-
|
|
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
|
|
30
|
+
return !!value && typeof value === "object" && typeof value.locator === "function";
|
|
28
31
|
}
|
|
29
32
|
function isLocator(value) {
|
|
30
|
-
return value
|
|
33
|
+
return (!!value &&
|
|
34
|
+
typeof value === "object" &&
|
|
35
|
+
typeof value.page === "object" &&
|
|
36
|
+
typeof value.click === "function");
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
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.
|
|
3
|
+
"version": "0.0.28",
|
|
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.
|
|
42
|
+
"@allwright.dev/core": "0.0.28"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.9.2",
|