@vitest/browser 4.0.5 → 4.0.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/client/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/index-DYO2mJ8d.js +53 -0
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{tester-BNxij3za.js → tester-C3iDyL-N.js} +3 -3
- package/dist/client/esm-client-injector.js +26 -15
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +7 -5
- package/dist/index.js +1 -1
- package/dist/state.js +274 -105
- package/jest-dom.d.ts +2 -2
- package/package.json +6 -6
- package/dist/client/__vitest__/assets/index-DOkKC3NI.js +0 -53
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
})();
|
|
24
24
|
</script>
|
|
25
25
|
<!-- !LOAD_METADATA! -->
|
|
26
|
-
<script type="module" src="./assets/index-
|
|
26
|
+
<script type="module" src="./assets/index-DYO2mJ8d.js"></script>
|
|
27
27
|
<link rel="stylesheet" href="./assets/index-COTh6lXR.css">
|
|
28
28
|
</head>
|
|
29
29
|
<body>
|
|
@@ -996,7 +996,7 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
|
|
|
996
996
|
};
|
|
997
997
|
importFile = async (filepath, mode) => {
|
|
998
998
|
let hash = this.hashMap.get(filepath);
|
|
999
|
-
if (!hash) {
|
|
999
|
+
if (mode === "setup" || !hash) {
|
|
1000
1000
|
hash = Date.now().toString();
|
|
1001
1001
|
this.hashMap.set(filepath, hash);
|
|
1002
1002
|
}
|
|
@@ -1037,7 +1037,7 @@ async function initiateRunner(state, mocker, config) {
|
|
|
1037
1037
|
config
|
|
1038
1038
|
});
|
|
1039
1039
|
cachedRunner = runner;
|
|
1040
|
-
onCancel
|
|
1040
|
+
onCancel((reason) => {
|
|
1041
1041
|
var _a;
|
|
1042
1042
|
(_a = runner.cancel) == null ? void 0 : _a.call(runner, reason);
|
|
1043
1043
|
});
|
|
@@ -2012,6 +2012,7 @@ async function prepareTestEnvironment(options) {
|
|
|
2012
2012
|
const state = getWorkerState();
|
|
2013
2013
|
state.metaEnv = __vite_import_meta_env__;
|
|
2014
2014
|
state.onCancel = onCancel;
|
|
2015
|
+
state.ctx.rpc = rpc2;
|
|
2015
2016
|
state.rpc = rpc2;
|
|
2016
2017
|
const interceptor = createModuleMockerInterceptor();
|
|
2017
2018
|
const mocker = new VitestBrowserClientMocker(
|
|
@@ -2115,7 +2116,6 @@ async function cleanup() {
|
|
|
2115
2116
|
if (contextSwitched) {
|
|
2116
2117
|
await rpc2.wdioSwitchContext("parent").catch((error) => unhandledError(error, "Cleanup Error"));
|
|
2117
2118
|
}
|
|
2118
|
-
state.environmentTeardownRun = true;
|
|
2119
2119
|
await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.browser.isolate }).catch((error) => {
|
|
2120
2120
|
return unhandledError(error, "Coverage Error");
|
|
2121
2121
|
});
|
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
__vitest_mocker__.prepare().finally(() => {
|
|
10
|
-
module().then(resolve, reject);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
moduleCache.set(promise, { promise, evaluated: false });
|
|
14
|
-
return promise.finally(() => moduleCache.delete(promise));
|
|
2
|
+
function wrapModule(moduleCallback) {
|
|
3
|
+
if (typeof moduleCallback !== "function") {
|
|
4
|
+
return moduleCallback
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
if (typeof __vitest_mocker__ === "undefined" || typeof __vitest_worker__ === 'undefined') {
|
|
8
|
+
return moduleCallback()
|
|
15
9
|
}
|
|
16
|
-
|
|
10
|
+
|
|
11
|
+
const { evaluatedModules } = __vitest_worker__
|
|
12
|
+
const moduleId = crypto.randomUUID()
|
|
13
|
+
const viteModule = evaluatedModules.ensureModule(moduleId, moduleId)
|
|
14
|
+
|
|
15
|
+
viteModule.evaluated = false
|
|
16
|
+
viteModule.promise = new Promise((resolve, reject) => {
|
|
17
|
+
__vitest_mocker__.prepare().finally(() => {
|
|
18
|
+
moduleCallback().then(resolve, reject)
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
return viteModule.promise.finally(() => {
|
|
22
|
+
viteModule.evaluated = true
|
|
23
|
+
viteModule.promise = undefined
|
|
24
|
+
|
|
25
|
+
evaluatedModules.idToModuleMap.delete(viteModule.id)
|
|
26
|
+
evaluatedModules.fileToModulesMap.delete(viteModule.file)
|
|
27
|
+
evaluatedModules.urlToIdModuleMap.delete(viteModule.url)
|
|
28
|
+
});
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
window.__vitest_browser_runner__ = {
|
|
20
32
|
wrapModule,
|
|
21
33
|
wrapDynamicImport: wrapModule,
|
|
22
34
|
disposeExceptionTracker: () => {},
|
|
23
|
-
moduleCache,
|
|
24
35
|
cleanups: [],
|
|
25
36
|
config: { __VITEST_CONFIG__ },
|
|
26
37
|
viteConfig: { __VITEST_VITE_CONFIG__ },
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" href="{__VITEST_FAVICON__}" type="image/svg+xml">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Vitest Browser Tester</title>
|
|
8
|
-
<script type="module" crossorigin src="/__vitest_browser__/tester-
|
|
8
|
+
<script type="module" crossorigin src="/__vitest_browser__/tester-C3iDyL-N.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-uxqdqUz8.js">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/dist/client.js
CHANGED
|
@@ -295,10 +295,10 @@ const HOST = [location.hostname, PORT].filter(Boolean).join(":");
|
|
|
295
295
|
const RPC_ID = PAGE_TYPE === "orchestrator" ? getBrowserState().sessionId : getBrowserState().testerId;
|
|
296
296
|
const METHOD = getBrowserState().method;
|
|
297
297
|
const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${getBrowserState().config.name || ""}&method=${METHOD}&token=${window.VITEST_API_TOKEN || "0"}`;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
298
|
+
const onCancelCallbacks = [];
|
|
299
|
+
function onCancel(callback) {
|
|
300
|
+
onCancelCallbacks.push(callback);
|
|
301
|
+
}
|
|
302
302
|
// ws connection can be established before the orchestrator is fully loaded
|
|
303
303
|
// in very rare cases in the preview provider
|
|
304
304
|
function waitForOrchestrator() {
|
|
@@ -329,7 +329,9 @@ function createClient() {
|
|
|
329
329
|
};
|
|
330
330
|
let onMessage;
|
|
331
331
|
ctx.rpc = createBirpc({
|
|
332
|
-
onCancel
|
|
332
|
+
async onCancel(reason) {
|
|
333
|
+
await Promise.all(onCancelCallbacks.map((fn) => fn(reason)));
|
|
334
|
+
},
|
|
333
335
|
async createTesters(options) {
|
|
334
336
|
const orchestrator = await waitForOrchestrator();
|
|
335
337
|
return orchestrator.createTesters(options);
|
package/dist/index.js
CHANGED
package/dist/state.js
CHANGED
|
@@ -1,111 +1,280 @@
|
|
|
1
1
|
(function () {
|
|
2
|
-
|
|
2
|
+
'use strict';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
5
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
6
|
+
const isWindows = typeof process < "u" && process.platform === "win32";
|
|
7
|
+
function unwrapId(id) {
|
|
8
|
+
return id.startsWith("/@id/") ? id.slice(5).replace("__x00__", "\0") : id;
|
|
9
|
+
}
|
|
10
|
+
const windowsSlashRE = /\\/g;
|
|
11
|
+
function slash(p) {
|
|
12
|
+
return p.replace(windowsSlashRE, "/");
|
|
13
|
+
}
|
|
14
|
+
const postfixRE = /[?#].*$/;
|
|
15
|
+
function cleanUrl(url) {
|
|
16
|
+
return url.replace(postfixRE, "");
|
|
17
|
+
}
|
|
18
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
19
|
+
function normalizeWindowsPath(input = "") {
|
|
20
|
+
return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
23
|
+
function cwd() {
|
|
24
|
+
return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
|
|
25
|
+
}
|
|
26
|
+
const resolve = function(...arguments_) {
|
|
27
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
28
|
+
let resolvedPath = "", resolvedAbsolute = false;
|
|
29
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
30
|
+
let path = index >= 0 ? arguments_[index] : cwd();
|
|
31
|
+
!path || path.length === 0 || (resolvedPath = `${path}/${resolvedPath}`, resolvedAbsolute = isAbsolute(path));
|
|
32
|
+
}
|
|
33
|
+
return resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute), resolvedAbsolute && !isAbsolute(resolvedPath) ? `/${resolvedPath}` : resolvedPath.length > 0 ? resolvedPath : ".";
|
|
34
|
+
};
|
|
35
|
+
function normalizeString(path, allowAboveRoot) {
|
|
36
|
+
let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
|
|
37
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
38
|
+
if (index < path.length) char = path[index];
|
|
39
|
+
else if (char === "/") break;
|
|
40
|
+
else char = "/";
|
|
41
|
+
if (char === "/") {
|
|
42
|
+
if (!(lastSlash === index - 1 || dots === 1)) if (dots === 2) {
|
|
43
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
44
|
+
if (res.length > 2) {
|
|
45
|
+
let lastSlashIndex = res.lastIndexOf("/");
|
|
46
|
+
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
|
47
|
+
continue;
|
|
48
|
+
} else if (res.length > 0) {
|
|
49
|
+
res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
|
54
|
+
} else res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
|
55
|
+
lastSlash = index, dots = 0;
|
|
56
|
+
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
|
57
|
+
}
|
|
58
|
+
return res;
|
|
59
|
+
}
|
|
60
|
+
const isAbsolute = function(p) {
|
|
61
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
62
|
+
}, decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8");
|
|
63
|
+
const posixResolve = resolve;
|
|
64
|
+
const intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
|
|
65
|
+
for (let i = 0; i < 64; i++) {
|
|
66
|
+
let c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(i);
|
|
67
|
+
intToChar[i] = c, charToInt[c] = i;
|
|
68
|
+
}
|
|
69
|
+
var DecodedMap = class {
|
|
70
|
+
_encoded;
|
|
71
|
+
_decoded;
|
|
72
|
+
_decodedMemo;
|
|
73
|
+
url;
|
|
74
|
+
version;
|
|
75
|
+
names = [];
|
|
76
|
+
resolvedSources;
|
|
77
|
+
constructor(map, from) {
|
|
78
|
+
this.map = map;
|
|
79
|
+
let { mappings, names, sources } = map;
|
|
80
|
+
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
function memoizedState() {
|
|
84
|
+
return {
|
|
85
|
+
lastKey: -1,
|
|
86
|
+
lastNeedle: -1,
|
|
87
|
+
lastIndex: -1
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = /* @__PURE__ */ RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`);
|
|
91
|
+
var EvaluatedModuleNode = class {
|
|
92
|
+
importers = /* @__PURE__ */ new Set();
|
|
93
|
+
imports = /* @__PURE__ */ new Set();
|
|
94
|
+
evaluated = false;
|
|
95
|
+
meta;
|
|
96
|
+
promise;
|
|
97
|
+
exports;
|
|
98
|
+
file;
|
|
99
|
+
map;
|
|
100
|
+
constructor(id, url) {
|
|
101
|
+
this.id = id, this.url = url, this.file = cleanUrl(id);
|
|
102
|
+
}
|
|
103
|
+
}, EvaluatedModules = class {
|
|
104
|
+
idToModuleMap = /* @__PURE__ */ new Map();
|
|
105
|
+
fileToModulesMap = /* @__PURE__ */ new Map();
|
|
106
|
+
urlToIdModuleMap = /* @__PURE__ */ new Map();
|
|
107
|
+
getModuleById(id) {
|
|
108
|
+
return this.idToModuleMap.get(id);
|
|
109
|
+
}
|
|
110
|
+
getModulesByFile(file) {
|
|
111
|
+
return this.fileToModulesMap.get(file);
|
|
112
|
+
}
|
|
113
|
+
getModuleByUrl(url) {
|
|
114
|
+
return this.urlToIdModuleMap.get(unwrapId(url));
|
|
115
|
+
}
|
|
116
|
+
ensureModule(id, url) {
|
|
117
|
+
if (id = normalizeModuleId(id), this.idToModuleMap.has(id)) {
|
|
118
|
+
let moduleNode$1 = this.idToModuleMap.get(id);
|
|
119
|
+
return this.urlToIdModuleMap.set(url, moduleNode$1), moduleNode$1;
|
|
120
|
+
}
|
|
121
|
+
let moduleNode = new EvaluatedModuleNode(id, url);
|
|
122
|
+
this.idToModuleMap.set(id, moduleNode), this.urlToIdModuleMap.set(url, moduleNode);
|
|
123
|
+
let fileModules = this.fileToModulesMap.get(moduleNode.file) || /* @__PURE__ */ new Set();
|
|
124
|
+
return fileModules.add(moduleNode), this.fileToModulesMap.set(moduleNode.file, fileModules), moduleNode;
|
|
125
|
+
}
|
|
126
|
+
invalidateModule(node) {
|
|
127
|
+
node.evaluated = false, node.meta = void 0, node.map = void 0, node.promise = void 0, node.exports = void 0, node.imports.clear();
|
|
128
|
+
}
|
|
129
|
+
getModuleSourceMapById(id) {
|
|
130
|
+
let mod = this.getModuleById(id);
|
|
131
|
+
if (!mod) return null;
|
|
132
|
+
if (mod.map) return mod.map;
|
|
133
|
+
if (!mod.meta || !("code" in mod.meta)) return null;
|
|
134
|
+
let pattern = `//# ${SOURCEMAPPING_URL}=data:application/json;base64,`, lastIndex = mod.meta.code.lastIndexOf(pattern);
|
|
135
|
+
if (lastIndex === -1) return null;
|
|
136
|
+
let mapString = MODULE_RUNNER_SOURCEMAPPING_REGEXP.exec(mod.meta.code.slice(lastIndex))?.[1];
|
|
137
|
+
return mapString ? (mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), mod.file), mod.map) : null;
|
|
138
|
+
}
|
|
139
|
+
clear() {
|
|
140
|
+
this.idToModuleMap.clear(), this.fileToModulesMap.clear(), this.urlToIdModuleMap.clear();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const prefixedBuiltins = new Set([
|
|
144
|
+
"node:sea",
|
|
145
|
+
"node:sqlite",
|
|
146
|
+
"node:test",
|
|
147
|
+
"node:test/reporters"
|
|
148
|
+
]);
|
|
149
|
+
function normalizeModuleId(file) {
|
|
150
|
+
if (prefixedBuiltins.has(file)) return file;
|
|
151
|
+
let unixFile = slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
152
|
+
return unixFile.replace(/^file:\/+/, isWindows ? "" : "/");
|
|
153
|
+
}
|
|
154
|
+
const customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/"; `
|
|
9
155
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
config,
|
|
17
|
-
projectName: config.name || "",
|
|
18
|
-
files: [],
|
|
19
|
-
environment: {
|
|
20
|
-
name: "browser",
|
|
21
|
-
options: null
|
|
22
|
-
},
|
|
23
|
-
providedContext: {},
|
|
24
|
-
invalidates: []
|
|
25
|
-
},
|
|
26
|
-
onCancel: null,
|
|
27
|
-
config,
|
|
28
|
-
environment: {
|
|
29
|
-
name: "browser",
|
|
30
|
-
viteEnvironment: "client",
|
|
31
|
-
setup() {
|
|
32
|
-
throw new Error("Not called in the browser");
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
onCleanup: (fn) => getBrowserState().cleanups.push(fn),
|
|
36
|
-
evaluatedModules: getBrowserState().evaluatedModules,
|
|
37
|
-
resolvingModules: getBrowserState().resolvingModules,
|
|
38
|
-
moduleExecutionInfo: new Map(),
|
|
39
|
-
metaEnv: null,
|
|
40
|
-
rpc: null,
|
|
41
|
-
durations: {
|
|
42
|
-
environment: 0,
|
|
43
|
-
prepare: performance.now()
|
|
44
|
-
},
|
|
45
|
-
providedContext: {}
|
|
46
|
-
};
|
|
47
|
-
// @ts-expect-error not typed global
|
|
48
|
-
globalThis.__vitest_browser__ = true;
|
|
49
|
-
// @ts-expect-error not typed global
|
|
50
|
-
globalThis.__vitest_worker__ = state;
|
|
51
|
-
getBrowserState().cdp = createCdp();
|
|
52
|
-
function rpc() {
|
|
53
|
-
return state.rpc;
|
|
54
|
-
}
|
|
55
|
-
function createCdp() {
|
|
56
|
-
const listenersMap = new WeakMap();
|
|
57
|
-
function getId(listener) {
|
|
58
|
-
const id = listenersMap.get(listener) || crypto.randomUUID();
|
|
59
|
-
listenersMap.set(listener, id);
|
|
60
|
-
return id;
|
|
61
|
-
}
|
|
62
|
-
const listeners = {};
|
|
63
|
-
const cdp = {
|
|
64
|
-
send(method, params) {
|
|
65
|
-
return rpc().sendCdpEvent(sessionId, method, params);
|
|
66
|
-
},
|
|
67
|
-
on(event, listener) {
|
|
68
|
-
const listenerId = getId(listener);
|
|
69
|
-
listeners[event] = listeners[event] || [];
|
|
70
|
-
listeners[event].push(listener);
|
|
71
|
-
rpc().trackCdpEvent(sessionId, "on", event, listenerId).catch(error);
|
|
72
|
-
return cdp;
|
|
73
|
-
},
|
|
74
|
-
once(event, listener) {
|
|
75
|
-
const listenerId = getId(listener);
|
|
76
|
-
const handler = (data) => {
|
|
77
|
-
listener(data);
|
|
78
|
-
cdp.off(event, listener);
|
|
79
|
-
};
|
|
80
|
-
listeners[event] = listeners[event] || [];
|
|
81
|
-
listeners[event].push(handler);
|
|
82
|
-
rpc().trackCdpEvent(sessionId, "once", event, listenerId).catch(error);
|
|
83
|
-
return cdp;
|
|
84
|
-
},
|
|
85
|
-
off(event, listener) {
|
|
86
|
-
const listenerId = getId(listener);
|
|
87
|
-
if (listeners[event]) {
|
|
88
|
-
listeners[event] = listeners[event].filter((l) => l !== listener);
|
|
89
|
-
}
|
|
90
|
-
rpc().trackCdpEvent(sessionId, "off", event, listenerId).catch(error);
|
|
91
|
-
return cdp;
|
|
92
|
-
},
|
|
93
|
-
emit(event, payload) {
|
|
94
|
-
if (listeners[event]) {
|
|
95
|
-
listeners[event].forEach((l) => {
|
|
96
|
-
try {
|
|
97
|
-
l(payload);
|
|
98
|
-
} catch (err) {
|
|
99
|
-
error(err);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
return cdp;
|
|
106
|
-
}
|
|
107
|
-
function error(err) {
|
|
108
|
-
window.dispatchEvent(new ErrorEvent("error", { error: err }));
|
|
156
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
157
|
+
if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
|
|
158
|
+
const data = specifier.slice(${JSON.stringify(customizationHookNamespace)}.length)
|
|
159
|
+
const [parsedSpecifier, parsedImporter] = JSON.parse(data)
|
|
160
|
+
specifier = parsedSpecifier
|
|
161
|
+
context.parentURL = parsedImporter
|
|
109
162
|
}
|
|
110
163
|
|
|
164
|
+
return nextResolve(specifier, context)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
`;
|
|
168
|
+
new Proxy({}, { get(_, p) {
|
|
169
|
+
throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
|
|
170
|
+
} });
|
|
171
|
+
|
|
172
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
173
|
+
function getBrowserState() {
|
|
174
|
+
// @ts-expect-error not typed global
|
|
175
|
+
return window.__vitest_browser_runner__;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const config = getBrowserState().config;
|
|
179
|
+
const sessionId = getBrowserState().sessionId;
|
|
180
|
+
const state = {
|
|
181
|
+
ctx: {
|
|
182
|
+
rpc: null,
|
|
183
|
+
pool: "browser",
|
|
184
|
+
workerId: 1,
|
|
185
|
+
config,
|
|
186
|
+
projectName: config.name || "",
|
|
187
|
+
files: [],
|
|
188
|
+
environment: {
|
|
189
|
+
name: "browser",
|
|
190
|
+
options: null
|
|
191
|
+
},
|
|
192
|
+
providedContext: {},
|
|
193
|
+
invalidates: []
|
|
194
|
+
},
|
|
195
|
+
onCancel: null,
|
|
196
|
+
config,
|
|
197
|
+
environment: {
|
|
198
|
+
name: "browser",
|
|
199
|
+
viteEnvironment: "client",
|
|
200
|
+
setup() {
|
|
201
|
+
throw new Error("Not called in the browser");
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
onCleanup: (fn) => getBrowserState().cleanups.push(fn),
|
|
205
|
+
evaluatedModules: new EvaluatedModules(),
|
|
206
|
+
resolvingModules: new Set(),
|
|
207
|
+
moduleExecutionInfo: new Map(),
|
|
208
|
+
metaEnv: null,
|
|
209
|
+
rpc: null,
|
|
210
|
+
durations: {
|
|
211
|
+
environment: 0,
|
|
212
|
+
prepare: performance.now()
|
|
213
|
+
},
|
|
214
|
+
providedContext: {}
|
|
215
|
+
};
|
|
216
|
+
// @ts-expect-error not typed global
|
|
217
|
+
globalThis.__vitest_browser__ = true;
|
|
218
|
+
// @ts-expect-error not typed global
|
|
219
|
+
globalThis.__vitest_worker__ = state;
|
|
220
|
+
getBrowserState().cdp = createCdp();
|
|
221
|
+
function rpc() {
|
|
222
|
+
return state.rpc;
|
|
223
|
+
}
|
|
224
|
+
function createCdp() {
|
|
225
|
+
const listenersMap = new WeakMap();
|
|
226
|
+
function getId(listener) {
|
|
227
|
+
const id = listenersMap.get(listener) || crypto.randomUUID();
|
|
228
|
+
listenersMap.set(listener, id);
|
|
229
|
+
return id;
|
|
230
|
+
}
|
|
231
|
+
const listeners = {};
|
|
232
|
+
const cdp = {
|
|
233
|
+
send(method, params) {
|
|
234
|
+
return rpc().sendCdpEvent(sessionId, method, params);
|
|
235
|
+
},
|
|
236
|
+
on(event, listener) {
|
|
237
|
+
const listenerId = getId(listener);
|
|
238
|
+
listeners[event] = listeners[event] || [];
|
|
239
|
+
listeners[event].push(listener);
|
|
240
|
+
rpc().trackCdpEvent(sessionId, "on", event, listenerId).catch(error);
|
|
241
|
+
return cdp;
|
|
242
|
+
},
|
|
243
|
+
once(event, listener) {
|
|
244
|
+
const listenerId = getId(listener);
|
|
245
|
+
const handler = (data) => {
|
|
246
|
+
listener(data);
|
|
247
|
+
cdp.off(event, listener);
|
|
248
|
+
};
|
|
249
|
+
listeners[event] = listeners[event] || [];
|
|
250
|
+
listeners[event].push(handler);
|
|
251
|
+
rpc().trackCdpEvent(sessionId, "once", event, listenerId).catch(error);
|
|
252
|
+
return cdp;
|
|
253
|
+
},
|
|
254
|
+
off(event, listener) {
|
|
255
|
+
const listenerId = getId(listener);
|
|
256
|
+
if (listeners[event]) {
|
|
257
|
+
listeners[event] = listeners[event].filter((l) => l !== listener);
|
|
258
|
+
}
|
|
259
|
+
rpc().trackCdpEvent(sessionId, "off", event, listenerId).catch(error);
|
|
260
|
+
return cdp;
|
|
261
|
+
},
|
|
262
|
+
emit(event, payload) {
|
|
263
|
+
if (listeners[event]) {
|
|
264
|
+
listeners[event].forEach((l) => {
|
|
265
|
+
try {
|
|
266
|
+
l(payload);
|
|
267
|
+
} catch (err) {
|
|
268
|
+
error(err);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
return cdp;
|
|
275
|
+
}
|
|
276
|
+
function error(err) {
|
|
277
|
+
window.dispatchEvent(new ErrorEvent("error", { error: err }));
|
|
278
|
+
}
|
|
279
|
+
|
|
111
280
|
})();
|
package/jest-dom.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Disable automatic exports.
|
|
2
2
|
|
|
3
3
|
import { ARIARole } from './aria-role.ts'
|
|
4
|
-
import { ScreenshotComparatorRegistry, ScreenshotMatcherOptions } from './context.js'
|
|
4
|
+
import { Locator, ScreenshotComparatorRegistry, ScreenshotMatcherOptions } from './context.js'
|
|
5
5
|
|
|
6
6
|
export interface TestingLibraryMatchers<E, R> {
|
|
7
7
|
/**
|
|
@@ -207,7 +207,7 @@ export interface TestingLibraryMatchers<E, R> {
|
|
|
207
207
|
* await expect.element(ancestor).not.toContainElement(nonExistentElement)
|
|
208
208
|
* @see https://vitest.dev/guide/browser/assertion-api#tocontainelement
|
|
209
209
|
*/
|
|
210
|
-
toContainElement(element: HTMLElement | SVGElement | null): R
|
|
210
|
+
toContainElement(element: HTMLElement | SVGElement | Locator | null): R
|
|
211
211
|
/**
|
|
212
212
|
* @description
|
|
213
213
|
* Assert whether a string representing a HTML element is contained in another element.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.7",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"providers"
|
|
52
52
|
],
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"vitest": "4.0.
|
|
54
|
+
"vitest": "4.0.7"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"magic-string": "^0.30.19",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"sirv": "^3.0.2",
|
|
61
61
|
"tinyrainbow": "^3.0.3",
|
|
62
62
|
"ws": "^8.18.3",
|
|
63
|
-
"@vitest/mocker": "4.0.
|
|
64
|
-
"@vitest/utils": "4.0.
|
|
63
|
+
"@vitest/mocker": "4.0.7",
|
|
64
|
+
"@vitest/utils": "4.0.7"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"ivya": "^1.7.0",
|
|
73
73
|
"mime": "^4.1.0",
|
|
74
74
|
"pathe": "^2.0.3",
|
|
75
|
-
"@vitest/runner": "4.0.
|
|
76
|
-
"vitest": "4.0.
|
|
75
|
+
"@vitest/runner": "4.0.7",
|
|
76
|
+
"vitest": "4.0.7"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"typecheck": "tsc -p ./src/client/tsconfig.json --noEmit",
|