@vitest/browser 3.2.5 → 3.2.7
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 +31 -3
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ManualMockedModule, RedirectedModule, AutomockedModule, AutospiedModule, MockerRegistry } from '@vitest/mocker';
|
|
2
2
|
import { dynamicImportPlugin, ServerMockResolver, interceptorPlugin } from '@vitest/mocker/node';
|
|
3
3
|
import c from 'tinyrainbow';
|
|
4
|
-
import { getFilePoolName, distDir, resolveApiServerConfig, resolveFsAllow,
|
|
4
|
+
import { isFileServingAllowed, getFilePoolName, distDir, resolveApiServerConfig, resolveFsAllow, createDebugger, isValidApiRequest, createViteLogger, createViteServer } from 'vitest/node';
|
|
5
5
|
import fs, { readFileSync, lstatSync, promises, existsSync } from 'node:fs';
|
|
6
6
|
import { createRequire } from 'node:module';
|
|
7
7
|
import { slash as slash$1, toArray, createDefer } from '@vitest/utils';
|
|
@@ -19,7 +19,7 @@ import { WebSocketServer } from 'ws';
|
|
|
19
19
|
import * as nodeos from 'node:os';
|
|
20
20
|
import { performance } from 'node:perf_hooks';
|
|
21
21
|
|
|
22
|
-
var version = "3.2.
|
|
22
|
+
var version = "3.2.7";
|
|
23
23
|
|
|
24
24
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
25
25
|
function normalizeWindowsPath(input = "") {
|
|
@@ -324,6 +324,17 @@ const stringify = (value, replacer, space) => {
|
|
|
324
324
|
function replacer(code, values) {
|
|
325
325
|
return code.replace(/\{\s*(\w+)\s*\}/g, (_, key) => values[key] ?? _);
|
|
326
326
|
}
|
|
327
|
+
function assertBrowserFileAccess(project, path) {
|
|
328
|
+
const normalized = slash(path);
|
|
329
|
+
if (!isFileServingAllowed(normalized, project.vite) && !isFileServingAllowed(normalized, project.vitest.server)) {
|
|
330
|
+
throw new Error(`Access denied to "${path}". See Vite config documentation for "server.fs": https://vitejs.dev/config/server-options.html#server-fs-strict.`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function assertBrowserApiWrite(project, path) {
|
|
334
|
+
if (!project.config.browser.api.allowWrite || !project.vitest.config.api.allowWrite) {
|
|
335
|
+
throw new Error(`Cannot modify file "${path}". File writing is disabled because server is exposed to the internet, see https://vitest.dev/config/browser/api.`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
327
338
|
const builtinProviders = [
|
|
328
339
|
"webdriverio",
|
|
329
340
|
"playwright",
|
|
@@ -2382,6 +2393,10 @@ const screenshot = async (context, name, options = {}) => {
|
|
|
2382
2393
|
}
|
|
2383
2394
|
const path = options.path ? resolve(dirname(context.testPath), options.path) : resolveScreenshotPath(context.testPath, name, context.project.config);
|
|
2384
2395
|
const savePath = normalize$1(path);
|
|
2396
|
+
if (options.save) {
|
|
2397
|
+
assertBrowserApiWrite(context.project, savePath);
|
|
2398
|
+
assertBrowserFileAccess(context.project, savePath);
|
|
2399
|
+
}
|
|
2385
2400
|
await mkdir(dirname(path), { recursive: true });
|
|
2386
2401
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
2387
2402
|
if (options.element) {
|
|
@@ -2518,7 +2533,9 @@ const upload = async (context, selector, files, options) => {
|
|
|
2518
2533
|
const { iframe } = context;
|
|
2519
2534
|
const playwrightFiles = files.map((file) => {
|
|
2520
2535
|
if (typeof file === "string") {
|
|
2521
|
-
|
|
2536
|
+
const filepath = resolve(root, file);
|
|
2537
|
+
assertBrowserFileAccess(context.project, filepath);
|
|
2538
|
+
return filepath;
|
|
2522
2539
|
}
|
|
2523
2540
|
return {
|
|
2524
2541
|
name: file.name,
|
|
@@ -2536,6 +2553,7 @@ const upload = async (context, selector, files, options) => {
|
|
|
2536
2553
|
const element = context.browser.$(selector);
|
|
2537
2554
|
for (const file of files) {
|
|
2538
2555
|
const filepath = resolve(root, file);
|
|
2556
|
+
assertBrowserFileAccess(context.project, filepath);
|
|
2539
2557
|
const remoteFilePath = await context.browser.uploadFile(filepath);
|
|
2540
2558
|
await element.addValue(remoteFilePath);
|
|
2541
2559
|
}
|
|
@@ -3119,6 +3137,16 @@ function setupBrowserRpc(globalServer, defaultMockerRegistry) {
|
|
|
3119
3137
|
}
|
|
3120
3138
|
},
|
|
3121
3139
|
async onTaskAnnotate(id, annotation) {
|
|
3140
|
+
const attachment = annotation.attachment;
|
|
3141
|
+
if (attachment?.path && !attachment.path.startsWith("http://") && !attachment.path.startsWith("https://")) {
|
|
3142
|
+
// attachment files are copied into `attachmentsDir`, so confine
|
|
3143
|
+
// client-supplied paths to Vite's `server.fs` boundary
|
|
3144
|
+
checkFileAccess(resolve(project.config.root, attachment.path));
|
|
3145
|
+
if (!canWrite(project)) {
|
|
3146
|
+
annotation.attachment = undefined;
|
|
3147
|
+
vitest.logger.error(`[vitest] Cannot record annotation attachment because file writing is disabled. See https://vitest.dev/config/browser/api.`);
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3122
3150
|
return vitest._testRun.annotate(id, annotation);
|
|
3123
3151
|
},
|
|
3124
3152
|
async onTaskUpdate(method, packs, events) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.2.
|
|
4
|
+
"version": "3.2.7",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"playwright": "*",
|
|
68
68
|
"webdriverio": "^7.0.0 || ^8.0.0 || ^9.0.0",
|
|
69
|
-
"vitest": "3.2.
|
|
69
|
+
"vitest": "3.2.7"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"playwright": {
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"sirv": "^3.0.1",
|
|
87
87
|
"tinyrainbow": "^2.0.0",
|
|
88
88
|
"ws": "^8.18.2",
|
|
89
|
-
"@vitest/
|
|
90
|
-
"@vitest/
|
|
89
|
+
"@vitest/utils": "3.2.7",
|
|
90
|
+
"@vitest/mocker": "3.2.7"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@types/ws": "^8.18.1",
|
|
@@ -103,10 +103,10 @@
|
|
|
103
103
|
"playwright-core": "^1.53.0",
|
|
104
104
|
"safaridriver": "^1.0.0",
|
|
105
105
|
"webdriverio": "^9.15.0",
|
|
106
|
-
"@vitest/runner": "3.2.
|
|
107
|
-
"@vitest/ui": "3.2.
|
|
108
|
-
"
|
|
109
|
-
"vitest": "3.2.
|
|
106
|
+
"@vitest/runner": "3.2.7",
|
|
107
|
+
"@vitest/ui": "3.2.7",
|
|
108
|
+
"vitest": "3.2.7",
|
|
109
|
+
"@vitest/ws-client": "3.2.7"
|
|
110
110
|
},
|
|
111
111
|
"scripts": {
|
|
112
112
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|