@vitest/browser 4.0.0-beta.12 → 4.0.0-beta.13
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.js
CHANGED
|
@@ -4,7 +4,7 @@ import c from 'tinyrainbow';
|
|
|
4
4
|
import { isValidApiRequest, isFileServingAllowed, distDir, resolveApiServerConfig, resolveFsAllow, rolldownVersion, createDebugger, createViteLogger, createViteServer } from 'vitest/node';
|
|
5
5
|
import fs, { readFileSync, lstatSync, createReadStream, promises, existsSync } from 'node:fs';
|
|
6
6
|
import { createRequire } from 'node:module';
|
|
7
|
-
import { slash as slash$1, toArray, deepMerge, createDefer } from '@vitest/utils/helpers';
|
|
7
|
+
import { slash as slash$1, toArray, nanoid as nanoid$1, deepMerge, createDefer } from '@vitest/utils/helpers';
|
|
8
8
|
import MagicString from 'magic-string';
|
|
9
9
|
import sirv from 'sirv';
|
|
10
10
|
import { coverageConfigDefaults } from 'vitest/config';
|
|
@@ -22,7 +22,7 @@ import pm from 'pixelmatch';
|
|
|
22
22
|
import { WebSocketServer } from 'ws';
|
|
23
23
|
import { performance } from 'node:perf_hooks';
|
|
24
24
|
|
|
25
|
-
var version = "4.0.0-beta.
|
|
25
|
+
var version = "4.0.0-beta.13";
|
|
26
26
|
|
|
27
27
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
28
28
|
function normalizeWindowsPath(input = "") {
|
|
@@ -339,7 +339,7 @@ async function getBrowserProvider(options, project) {
|
|
|
339
339
|
if (!(name in providers)) {
|
|
340
340
|
throw new Error(`Unknown browser provider "${name}". Available providers: ${Object.keys(providers).join(", ")}.`);
|
|
341
341
|
}
|
|
342
|
-
return providers[name]().factory(project);
|
|
342
|
+
return providers[name](options.provider?.options).factory(project);
|
|
343
343
|
}
|
|
344
344
|
const supportedBrowsers = options.provider.supportedBrowser || [];
|
|
345
345
|
if (supportedBrowsers.length && !supportedBrowsers.includes(browser)) {
|
|
@@ -2394,8 +2394,12 @@ async function takeScreenshot(context, name, options) {
|
|
|
2394
2394
|
throw new Error(`Cannot take a screenshot without a test path`);
|
|
2395
2395
|
}
|
|
2396
2396
|
const path = resolveScreenshotPath(context.testPath, name, context.project.config, options.path);
|
|
2397
|
-
|
|
2398
|
-
|
|
2397
|
+
// playwright does not need a screenshot path if we don't intend to save it
|
|
2398
|
+
let savePath;
|
|
2399
|
+
if (options.save) {
|
|
2400
|
+
savePath = normalize(path);
|
|
2401
|
+
await mkdir(dirname(savePath), { recursive: true });
|
|
2402
|
+
}
|
|
2399
2403
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
2400
2404
|
const mask = options.mask?.map((selector) => context.iframe.locator(selector));
|
|
2401
2405
|
if (options.element) {
|
|
@@ -2404,7 +2408,7 @@ async function takeScreenshot(context, name, options) {
|
|
|
2404
2408
|
const buffer = await element.screenshot({
|
|
2405
2409
|
...config,
|
|
2406
2410
|
mask,
|
|
2407
|
-
path:
|
|
2411
|
+
path: savePath
|
|
2408
2412
|
});
|
|
2409
2413
|
return {
|
|
2410
2414
|
buffer,
|
|
@@ -2414,7 +2418,7 @@ async function takeScreenshot(context, name, options) {
|
|
|
2414
2418
|
const buffer = await context.iframe.locator("body").screenshot({
|
|
2415
2419
|
...options,
|
|
2416
2420
|
mask,
|
|
2417
|
-
path:
|
|
2421
|
+
path: savePath
|
|
2418
2422
|
});
|
|
2419
2423
|
return {
|
|
2420
2424
|
buffer,
|
|
@@ -2422,11 +2426,17 @@ async function takeScreenshot(context, name, options) {
|
|
|
2422
2426
|
};
|
|
2423
2427
|
}
|
|
2424
2428
|
if (context.provider instanceof WebdriverBrowserProvider) {
|
|
2429
|
+
// webdriverio needs a path, so if one is not already set we create a temporary one
|
|
2430
|
+
if (savePath === undefined) {
|
|
2431
|
+
savePath = resolve(context.project.tmpDir, nanoid$1());
|
|
2432
|
+
await mkdir(context.project.tmpDir, { recursive: true });
|
|
2433
|
+
}
|
|
2425
2434
|
const page = context.provider.browser;
|
|
2426
2435
|
const element = !options.element ? await page.$("body") : await page.$(`${options.element}`);
|
|
2427
2436
|
// webdriverio expects the path to contain the extension and only works with PNG files
|
|
2428
2437
|
const savePathWithExtension = savePath.endsWith(".png") ? savePath : `${savePath}.png`;
|
|
2429
|
-
|
|
2438
|
+
// there seems to be a bug in webdriverio, `X:/` gets appended to cwd, so we convert to `X:\`
|
|
2439
|
+
const buffer = await element.saveScreenshot(normalize$1(savePathWithExtension));
|
|
2430
2440
|
if (!options.save) {
|
|
2431
2441
|
await rm(savePathWithExtension, { force: true });
|
|
2432
2442
|
}
|
|
@@ -4082,6 +4092,11 @@ class BrowserPool {
|
|
|
4082
4092
|
return;
|
|
4083
4093
|
}
|
|
4084
4094
|
const provider = this.project.browser.provider;
|
|
4095
|
+
const browser = this.project.config.browser.name;
|
|
4096
|
+
if (shouldIgnoreDebugger(provider.name, browser)) {
|
|
4097
|
+
debug?.("[$s] ignoring debugger in %s browser because it is not supported", sessionId, browser);
|
|
4098
|
+
return;
|
|
4099
|
+
}
|
|
4085
4100
|
if (!provider.getCDPSession) {
|
|
4086
4101
|
throw new Error("Unable to set breakpoint, CDP not supported");
|
|
4087
4102
|
}
|
|
@@ -4094,6 +4109,12 @@ class BrowserPool {
|
|
|
4094
4109
|
});
|
|
4095
4110
|
}
|
|
4096
4111
|
}
|
|
4112
|
+
function shouldIgnoreDebugger(provider, browser) {
|
|
4113
|
+
if (provider === "webdriverio") {
|
|
4114
|
+
return browser !== "chrome" && browser !== "edge";
|
|
4115
|
+
}
|
|
4116
|
+
return browser !== "chromium";
|
|
4117
|
+
}
|
|
4097
4118
|
|
|
4098
4119
|
async function createBrowserServer(project, configFile, prePlugins = [], postPlugins = []) {
|
|
4099
4120
|
if (project.vitest.version !== version) {
|
|
@@ -31,7 +31,7 @@ interface PlaywrightProviderOptions {
|
|
|
31
31
|
*/
|
|
32
32
|
actionTimeout?: number;
|
|
33
33
|
}
|
|
34
|
-
declare function playwright(options?: PlaywrightProviderOptions): BrowserProviderOption
|
|
34
|
+
declare function playwright(options?: PlaywrightProviderOptions): BrowserProviderOption<PlaywrightProviderOptions>;
|
|
35
35
|
declare class PlaywrightBrowserProvider implements BrowserProvider {
|
|
36
36
|
private project;
|
|
37
37
|
private options;
|
|
@@ -12,6 +12,7 @@ function playwright(options = {}) {
|
|
|
12
12
|
return {
|
|
13
13
|
name: "playwright",
|
|
14
14
|
supportedBrowser: playwrightBrowsers,
|
|
15
|
+
options,
|
|
15
16
|
factory(project) {
|
|
16
17
|
return new PlaywrightBrowserProvider(project, options);
|
|
17
18
|
},
|
|
@@ -42,10 +43,10 @@ class PlaywrightBrowserProvider {
|
|
|
42
43
|
}
|
|
43
44
|
const promises = [];
|
|
44
45
|
for (const [trace, contextId] of this.pendingTraces.entries()) {
|
|
45
|
-
promises.push(() => {
|
|
46
|
+
promises.push((() => {
|
|
46
47
|
const context = this.contexts.get(contextId);
|
|
47
48
|
return context?.tracing.stopChunk({ path: trace });
|
|
48
|
-
});
|
|
49
|
+
})());
|
|
49
50
|
}
|
|
50
51
|
return Promise.allSettled(promises);
|
|
51
52
|
});
|
|
@@ -81,10 +82,11 @@ class PlaywrightBrowserProvider {
|
|
|
81
82
|
if (typeof options.trace === "object" && options.trace.tracesDir) {
|
|
82
83
|
launchOptions.tracesDir = options.trace?.tracesDir;
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
+
const inspector = this.project.vitest.config.inspector;
|
|
86
|
+
if (inspector.enabled) {
|
|
85
87
|
// NodeJS equivalent defaults: https://nodejs.org/en/learn/getting-started/debugging#enable-inspector
|
|
86
|
-
const port =
|
|
87
|
-
const host =
|
|
88
|
+
const port = inspector.port || 9229;
|
|
89
|
+
const host = inspector.host || "127.0.0.1";
|
|
88
90
|
launchOptions.args ||= [];
|
|
89
91
|
launchOptions.args.push(`--remote-debugging-port=${port}`);
|
|
90
92
|
launchOptions.args.push(`--remote-debugging-address=${host}`);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ScreenshotMatcherOptions, ScreenshotComparatorRegistry } from '@vitest/browser/context';
|
|
2
|
-
import { BrowserProviderOption, BrowserProvider, TestProject } from 'vitest/node';
|
|
2
|
+
import { BrowserProviderOption, BrowserProvider, TestProject, CDPSession } from 'vitest/node';
|
|
3
3
|
import { ClickOptions, DragAndDropOptions, remote } from 'webdriverio';
|
|
4
4
|
|
|
5
5
|
interface WebdriverProviderOptions extends Partial<Parameters<typeof remote>[0]> {}
|
|
6
|
-
declare function webdriverio(options?: WebdriverProviderOptions): BrowserProviderOption
|
|
6
|
+
declare function webdriverio(options?: WebdriverProviderOptions): BrowserProviderOption<WebdriverProviderOptions>;
|
|
7
7
|
declare class WebdriverBrowserProvider implements BrowserProvider {
|
|
8
8
|
name: "webdriverio";
|
|
9
9
|
supportsParallelism: boolean;
|
|
@@ -31,6 +31,7 @@ declare class WebdriverBrowserProvider implements BrowserProvider {
|
|
|
31
31
|
openPage(sessionId: string, url: string): Promise<void>;
|
|
32
32
|
private _throwIfClosing;
|
|
33
33
|
close(): Promise<void>;
|
|
34
|
+
getCDPSession(_sessionId: string): Promise<CDPSession>;
|
|
34
35
|
}
|
|
35
36
|
declare module "vitest/node" {
|
|
36
37
|
interface UserEventClickOptions extends ClickOptions {}
|
|
@@ -11,6 +11,7 @@ function webdriverio(options = {}) {
|
|
|
11
11
|
return {
|
|
12
12
|
name: "webdriverio",
|
|
13
13
|
supportedBrowser: webdriverBrowsers,
|
|
14
|
+
options,
|
|
14
15
|
factory(project) {
|
|
15
16
|
return new WebdriverBrowserProvider(project, options);
|
|
16
17
|
},
|
|
@@ -135,6 +136,19 @@ class WebdriverBrowserProvider {
|
|
|
135
136
|
capabilities[key] ??= {};
|
|
136
137
|
capabilities[key].args = args;
|
|
137
138
|
}
|
|
139
|
+
const inspector = this.project.vitest.config.inspector;
|
|
140
|
+
if (inspector.enabled && (browser === "chrome" || browser === "edge")) {
|
|
141
|
+
const key = browser === "chrome" ? "goog:chromeOptions" : "ms:edgeOptions";
|
|
142
|
+
const args = capabilities[key]?.args || [];
|
|
143
|
+
// NodeJS equivalent defaults: https://nodejs.org/en/learn/getting-started/debugging#enable-inspector
|
|
144
|
+
const port = inspector.port || 9229;
|
|
145
|
+
const host = inspector.host || "127.0.0.1";
|
|
146
|
+
args.push(`--remote-debugging-port=${port}`);
|
|
147
|
+
args.push(`--remote-debugging-address=${host}`);
|
|
148
|
+
this.project.vitest.logger.log(`Debugger listening on ws://${host}:${port}`);
|
|
149
|
+
capabilities[key] ??= {};
|
|
150
|
+
capabilities[key].args = args;
|
|
151
|
+
}
|
|
138
152
|
return capabilities;
|
|
139
153
|
}
|
|
140
154
|
async openPage(sessionId, url) {
|
|
@@ -166,6 +180,27 @@ class WebdriverBrowserProvider {
|
|
|
166
180
|
browser.sessionId = undefined;
|
|
167
181
|
this.browser = null;
|
|
168
182
|
}
|
|
183
|
+
async getCDPSession(_sessionId) {
|
|
184
|
+
return {
|
|
185
|
+
send: (method, params) => {
|
|
186
|
+
if (!this.browser) {
|
|
187
|
+
throw new Error(`The environment was torn down.`);
|
|
188
|
+
}
|
|
189
|
+
return this.browser.sendCommandAndGetResult(method, params ?? {}).catch((error) => {
|
|
190
|
+
return Promise.reject(new Error(`Failed to execute "${method}" command.`, { cause: error }));
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
on: () => {
|
|
194
|
+
throw new Error(`webdriverio provider doesn't support cdp.on()`);
|
|
195
|
+
},
|
|
196
|
+
once: () => {
|
|
197
|
+
throw new Error(`webdriverio provider doesn't support cdp.once()`);
|
|
198
|
+
},
|
|
199
|
+
off: () => {
|
|
200
|
+
throw new Error(`webdriverio provider doesn't support cdp.off()`);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
169
204
|
}
|
|
170
205
|
|
|
171
206
|
export { WebdriverBrowserProvider, webdriverio };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.13",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"playwright": "*",
|
|
60
60
|
"webdriverio": "^7.0.0 || ^8.0.0 || ^9.0.0",
|
|
61
|
-
"vitest": "4.0.0-beta.
|
|
61
|
+
"vitest": "4.0.0-beta.13"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"playwright": {
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"sirv": "^3.0.2",
|
|
81
81
|
"tinyrainbow": "^3.0.3",
|
|
82
82
|
"ws": "^8.18.3",
|
|
83
|
-
"@vitest/mocker": "4.0.0-beta.
|
|
84
|
-
"@vitest/utils": "4.0.0-beta.
|
|
83
|
+
"@vitest/mocker": "4.0.0-beta.13",
|
|
84
|
+
"@vitest/utils": "4.0.0-beta.13"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@types/pngjs": "^6.0.5",
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
"playwright": "^1.55.0",
|
|
96
96
|
"playwright-core": "^1.55.0",
|
|
97
97
|
"webdriverio": "^9.19.2",
|
|
98
|
-
"@vitest/runner": "4.0.0-beta.
|
|
99
|
-
"vitest": "4.0.0-beta.
|
|
98
|
+
"@vitest/runner": "4.0.0-beta.13",
|
|
99
|
+
"vitest": "4.0.0-beta.13"
|
|
100
100
|
},
|
|
101
101
|
"scripts": {
|
|
102
102
|
"typecheck": "tsc -p ./src/client/tsconfig.json --noEmit",
|