@vitest/browser 1.2.2 → 1.3.0
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/__vitest__/assets/index-AUm0OrLY.js +35 -0
- package/dist/client/__vitest__/assets/index-iPSQW1bz.css +1 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/main-zbvBuTsR.js +98 -0
- package/dist/client/__vitest_browser__/{index-30Y0Db8-.js → rpc-aQLc-7Wy.js} +122 -487
- package/dist/client/__vitest_browser__/tester-W7irZcd1.js +438 -0
- package/dist/client/esm-client-injector.js +61 -0
- package/dist/client/index.html +5 -52
- package/dist/client/tester.html +25 -0
- package/dist/index.js +217 -28
- package/dist/providers.js +0 -18
- package/package.json +13 -13
- package/dist/client/__vitest__/assets/index-0EYobN63.js +0 -35
- package/dist/client/__vitest__/assets/index-b8y7ovCb.css +0 -1
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { i as importId, d as rpc, g as getConfig, _ as __vitePreload, b as channel, a as getBrowserState, c as client, l as loadSafeRpc, o as onCancel } from "./rpc-aQLc-7Wy.js";
|
|
8
|
+
function showPopupWarning(name, value, defaultValue) {
|
|
9
|
+
return (...params) => {
|
|
10
|
+
const formatedParams = params.map((p) => JSON.stringify(p)).join(", ");
|
|
11
|
+
console.warn(`Vitest encountered a \`${name}(${formatedParams})\` call that it cannot handle by default, so it returned \`${value}\`. Read more in https://vitest.dev/guide/browser#thread-blocking-dialogs.
|
|
12
|
+
If needed, mock the \`${name}\` call manually like:
|
|
13
|
+
|
|
14
|
+
\`\`\`
|
|
15
|
+
import { expect, vi } from "vitest"
|
|
16
|
+
|
|
17
|
+
vi.spyOn(window, "${name}")${defaultValue ? `.mockReturnValue(${JSON.stringify(defaultValue)})` : ""}
|
|
18
|
+
${name}(${formatedParams})
|
|
19
|
+
expect(${name}).toHaveBeenCalledWith(${formatedParams})
|
|
20
|
+
\`\`\``);
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function setupDialogsSpy() {
|
|
25
|
+
globalThis.alert = showPopupWarning("alert", void 0);
|
|
26
|
+
globalThis.confirm = showPopupWarning("confirm", false, true);
|
|
27
|
+
globalThis.prompt = showPopupWarning("prompt", null, "your value");
|
|
28
|
+
}
|
|
29
|
+
const { Date: Date$1, console: console$1 } = globalThis;
|
|
30
|
+
async function setupConsoleLogSpy() {
|
|
31
|
+
const { stringify, format, inspect } = await importId("vitest/utils");
|
|
32
|
+
const { log, info, error, dir, dirxml, trace, time, timeEnd, timeLog, warn, debug: debug2, count, countReset } = console$1;
|
|
33
|
+
const formatInput = (input) => {
|
|
34
|
+
if (input instanceof Node)
|
|
35
|
+
return stringify(input);
|
|
36
|
+
return format(input);
|
|
37
|
+
};
|
|
38
|
+
const processLog = (args) => args.map(formatInput).join(" ");
|
|
39
|
+
const sendLog = (type, content) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
if (content.startsWith("[vite]"))
|
|
42
|
+
return;
|
|
43
|
+
const unknownTestId = "__vitest__unknown_test__";
|
|
44
|
+
const taskId = ((_b = (_a = globalThis.__vitest_worker__) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
45
|
+
rpc().sendLog({
|
|
46
|
+
content,
|
|
47
|
+
time: Date$1.now(),
|
|
48
|
+
taskId,
|
|
49
|
+
type,
|
|
50
|
+
size: content.length
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const stdout = (base) => (...args) => {
|
|
54
|
+
sendLog("stdout", processLog(args));
|
|
55
|
+
return base(...args);
|
|
56
|
+
};
|
|
57
|
+
const stderr = (base) => (...args) => {
|
|
58
|
+
sendLog("stderr", processLog(args));
|
|
59
|
+
return base(...args);
|
|
60
|
+
};
|
|
61
|
+
console$1.log = stdout(log);
|
|
62
|
+
console$1.debug = stdout(debug2);
|
|
63
|
+
console$1.info = stdout(info);
|
|
64
|
+
console$1.error = stderr(error);
|
|
65
|
+
console$1.warn = stderr(warn);
|
|
66
|
+
console$1.dir = (item, options) => {
|
|
67
|
+
sendLog("stdout", inspect(item, options));
|
|
68
|
+
return dir(item, options);
|
|
69
|
+
};
|
|
70
|
+
console$1.dirxml = (...args) => {
|
|
71
|
+
sendLog("stdout", processLog(args));
|
|
72
|
+
return dirxml(...args);
|
|
73
|
+
};
|
|
74
|
+
console$1.trace = (...args) => {
|
|
75
|
+
const content = processLog(args);
|
|
76
|
+
const error2 = new Error("Trace");
|
|
77
|
+
const stack = (error2.stack || "").split("\n").slice(2).join("\n");
|
|
78
|
+
sendLog("stdout", `${content}
|
|
79
|
+
${stack}`);
|
|
80
|
+
return trace(...args);
|
|
81
|
+
};
|
|
82
|
+
const timeLabels = {};
|
|
83
|
+
console$1.time = (label = "default") => {
|
|
84
|
+
const now = performance.now();
|
|
85
|
+
time(label);
|
|
86
|
+
timeLabels[label] = now;
|
|
87
|
+
};
|
|
88
|
+
console$1.timeLog = (label = "default") => {
|
|
89
|
+
timeLog(label);
|
|
90
|
+
if (!(label in timeLabels))
|
|
91
|
+
sendLog("stderr", `Timer "${label}" does not exist`);
|
|
92
|
+
else
|
|
93
|
+
sendLog("stdout", `${label}: ${timeLabels[label]} ms`);
|
|
94
|
+
};
|
|
95
|
+
console$1.timeEnd = (label = "default") => {
|
|
96
|
+
const end = performance.now();
|
|
97
|
+
timeEnd(label);
|
|
98
|
+
const start = timeLabels[label];
|
|
99
|
+
if (!(label in timeLabels)) {
|
|
100
|
+
sendLog("stderr", `Timer "${label}" does not exist`);
|
|
101
|
+
} else if (start) {
|
|
102
|
+
const duration = end - start;
|
|
103
|
+
sendLog("stdout", `${label}: ${duration} ms`);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const countLabels = {};
|
|
107
|
+
console$1.count = (label = "default") => {
|
|
108
|
+
const counter = (countLabels[label] ?? 0) + 1;
|
|
109
|
+
countLabels[label] = counter;
|
|
110
|
+
sendLog("stdout", `${label}: ${counter}`);
|
|
111
|
+
return count(label);
|
|
112
|
+
};
|
|
113
|
+
console$1.countReset = (label = "default") => {
|
|
114
|
+
countLabels[label] = 0;
|
|
115
|
+
return countReset(label);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
class BrowserSnapshotEnvironment {
|
|
119
|
+
getVersion() {
|
|
120
|
+
return "1";
|
|
121
|
+
}
|
|
122
|
+
getHeader() {
|
|
123
|
+
return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
|
|
124
|
+
}
|
|
125
|
+
readSnapshotFile(filepath) {
|
|
126
|
+
return rpc().readSnapshotFile(filepath);
|
|
127
|
+
}
|
|
128
|
+
saveSnapshotFile(filepath, snapshot) {
|
|
129
|
+
return rpc().saveSnapshotFile(filepath, snapshot);
|
|
130
|
+
}
|
|
131
|
+
resolvePath(filepath) {
|
|
132
|
+
return rpc().resolveSnapshotPath(filepath);
|
|
133
|
+
}
|
|
134
|
+
resolveRawPath(testPath, rawPath) {
|
|
135
|
+
return rpc().resolveSnapshotRawPath(testPath, rawPath);
|
|
136
|
+
}
|
|
137
|
+
removeSnapshotFile(filepath) {
|
|
138
|
+
return rpc().removeSnapshotFile(filepath);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const browserHashMap = /* @__PURE__ */ new Map();
|
|
142
|
+
function createBrowserRunner(runnerClass, coverageModule) {
|
|
143
|
+
return class BrowserTestRunner extends runnerClass {
|
|
144
|
+
constructor(options) {
|
|
145
|
+
super(options.config);
|
|
146
|
+
__publicField(this, "config");
|
|
147
|
+
__publicField(this, "hashMap", browserHashMap);
|
|
148
|
+
__publicField(this, "onAfterRunTask", async (task) => {
|
|
149
|
+
var _a, _b, _c;
|
|
150
|
+
await ((_a = super.onAfterRunTask) == null ? void 0 : _a.call(this, task));
|
|
151
|
+
if (this.config.bail && ((_b = task.result) == null ? void 0 : _b.state) === "fail") {
|
|
152
|
+
const previousFailures = await rpc().getCountOfFailedTests();
|
|
153
|
+
const currentFailures = 1 + previousFailures;
|
|
154
|
+
if (currentFailures >= this.config.bail) {
|
|
155
|
+
rpc().onCancel("test-failure");
|
|
156
|
+
(_c = this.onCancel) == null ? void 0 : _c.call(this, "test-failure");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
__publicField(this, "onAfterRunFiles", async (files) => {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
await ((_a = super.onAfterRunFiles) == null ? void 0 : _a.call(this, files));
|
|
163
|
+
const coverage = await ((_b = coverageModule == null ? void 0 : coverageModule.takeCoverage) == null ? void 0 : _b.call(coverageModule));
|
|
164
|
+
if (coverage) {
|
|
165
|
+
await rpc().onAfterSuiteRun({
|
|
166
|
+
coverage,
|
|
167
|
+
transformMode: "web",
|
|
168
|
+
projectName: this.config.name
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
__publicField(this, "onCollected", (files) => {
|
|
173
|
+
return rpc().onCollected(files);
|
|
174
|
+
});
|
|
175
|
+
__publicField(this, "onTaskUpdate", (task) => {
|
|
176
|
+
return rpc().onTaskUpdate(task);
|
|
177
|
+
});
|
|
178
|
+
__publicField(this, "importFile", async (filepath) => {
|
|
179
|
+
let [test, hash] = this.hashMap.get(filepath) ?? [false, ""];
|
|
180
|
+
if (hash === "") {
|
|
181
|
+
hash = Date.now().toString();
|
|
182
|
+
this.hashMap.set(filepath, [false, hash]);
|
|
183
|
+
}
|
|
184
|
+
const base = this.config.base || "/";
|
|
185
|
+
const prefix = `${base}${/^\w:/.test(filepath) ? "@fs/" : ""}`;
|
|
186
|
+
const query = `${test ? "browserv" : "v"}=${hash}`;
|
|
187
|
+
const importpath = `${prefix}${filepath}?${query}`.replace(/\/+/g, "/");
|
|
188
|
+
await __vitePreload(() => import(importpath), true ? __vite__mapDeps([]) : void 0);
|
|
189
|
+
});
|
|
190
|
+
this.config = options.config;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
let cachedRunner = null;
|
|
195
|
+
async function initiateRunner() {
|
|
196
|
+
if (cachedRunner)
|
|
197
|
+
return cachedRunner;
|
|
198
|
+
const config = getConfig();
|
|
199
|
+
const [{ VitestTestRunner }, { takeCoverageInsideWorker, loadDiffConfig, loadSnapshotSerializers }] = await Promise.all([
|
|
200
|
+
importId("vitest/runners"),
|
|
201
|
+
importId("vitest/browser")
|
|
202
|
+
]);
|
|
203
|
+
const BrowserRunner = createBrowserRunner(VitestTestRunner, {
|
|
204
|
+
takeCoverage: () => takeCoverageInsideWorker(config.coverage, { executeId: importId })
|
|
205
|
+
});
|
|
206
|
+
if (!config.snapshotOptions.snapshotEnvironment)
|
|
207
|
+
config.snapshotOptions.snapshotEnvironment = new BrowserSnapshotEnvironment();
|
|
208
|
+
const runner = new BrowserRunner({
|
|
209
|
+
config
|
|
210
|
+
});
|
|
211
|
+
const executor = { executeId: importId };
|
|
212
|
+
const [diffOptions] = await Promise.all([
|
|
213
|
+
loadDiffConfig(config, executor),
|
|
214
|
+
loadSnapshotSerializers(config, executor)
|
|
215
|
+
]);
|
|
216
|
+
runner.config.diffOptions = diffOptions;
|
|
217
|
+
cachedRunner = runner;
|
|
218
|
+
return runner;
|
|
219
|
+
}
|
|
220
|
+
function throwNotImplemented(name) {
|
|
221
|
+
throw new Error(`[vitest] ${name} is not implemented in browser environment yet.`);
|
|
222
|
+
}
|
|
223
|
+
class VitestBrowserClientMocker {
|
|
224
|
+
importActual() {
|
|
225
|
+
throwNotImplemented("importActual");
|
|
226
|
+
}
|
|
227
|
+
importMock() {
|
|
228
|
+
throwNotImplemented("importMock");
|
|
229
|
+
}
|
|
230
|
+
queueMock() {
|
|
231
|
+
throwNotImplemented("queueMock");
|
|
232
|
+
}
|
|
233
|
+
queueUnmock() {
|
|
234
|
+
throwNotImplemented("queueUnmock");
|
|
235
|
+
}
|
|
236
|
+
prepare() {
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function on(event, listener) {
|
|
240
|
+
window.addEventListener(event, listener);
|
|
241
|
+
return () => window.removeEventListener(event, listener);
|
|
242
|
+
}
|
|
243
|
+
function serializeError(unhandledError) {
|
|
244
|
+
return {
|
|
245
|
+
...unhandledError,
|
|
246
|
+
name: unhandledError.name,
|
|
247
|
+
message: unhandledError.message,
|
|
248
|
+
stack: String(unhandledError.stack)
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async function defaultErrorReport(type, unhandledError) {
|
|
252
|
+
const error = serializeError(unhandledError);
|
|
253
|
+
channel.postMessage({ type: "error", files: getBrowserState().runningFiles, error, errorType: type });
|
|
254
|
+
}
|
|
255
|
+
function catchWindowErrors(cb) {
|
|
256
|
+
let userErrorListenerCount = 0;
|
|
257
|
+
function throwUnhandlerError(e) {
|
|
258
|
+
if (userErrorListenerCount === 0 && e.error != null)
|
|
259
|
+
cb(e);
|
|
260
|
+
else
|
|
261
|
+
console.error(e.error);
|
|
262
|
+
}
|
|
263
|
+
const addEventListener = window.addEventListener.bind(window);
|
|
264
|
+
const removeEventListener = window.removeEventListener.bind(window);
|
|
265
|
+
window.addEventListener("error", throwUnhandlerError);
|
|
266
|
+
window.addEventListener = function(...args) {
|
|
267
|
+
if (args[0] === "error")
|
|
268
|
+
userErrorListenerCount++;
|
|
269
|
+
return addEventListener.apply(this, args);
|
|
270
|
+
};
|
|
271
|
+
window.removeEventListener = function(...args) {
|
|
272
|
+
if (args[0] === "error" && userErrorListenerCount)
|
|
273
|
+
userErrorListenerCount--;
|
|
274
|
+
return removeEventListener.apply(this, args);
|
|
275
|
+
};
|
|
276
|
+
return function clearErrorHandlers() {
|
|
277
|
+
window.removeEventListener("error", throwUnhandlerError);
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function registerUnhandledErrors() {
|
|
281
|
+
const stopErrorHandler2 = catchWindowErrors((e) => defaultErrorReport("Error", e.error));
|
|
282
|
+
const stopRejectionHandler = on("unhandledrejection", (e) => defaultErrorReport("Unhandled Rejection", e.reason));
|
|
283
|
+
return () => {
|
|
284
|
+
stopErrorHandler2();
|
|
285
|
+
stopRejectionHandler();
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function registerUnexpectedErrors(rpc2) {
|
|
289
|
+
catchWindowErrors((event) => reportUnexpectedError(rpc2, "Error", event.error));
|
|
290
|
+
on("unhandledrejection", (event) => reportUnexpectedError(rpc2, "Unhandled Rejection", event.reason));
|
|
291
|
+
}
|
|
292
|
+
async function reportUnexpectedError(rpc2, type, error) {
|
|
293
|
+
const { processError } = await importId("vitest/browser");
|
|
294
|
+
const processedError = processError(error);
|
|
295
|
+
await rpc2.onUnhandledError(processedError, type);
|
|
296
|
+
}
|
|
297
|
+
const stopErrorHandler = registerUnhandledErrors();
|
|
298
|
+
const url = new URL(location.href);
|
|
299
|
+
const reloadStart = url.searchParams.get("__reloadStart");
|
|
300
|
+
function debug(...args) {
|
|
301
|
+
const debug2 = getConfig().env.VITEST_BROWSER_DEBUG;
|
|
302
|
+
if (debug2 && debug2 !== "false")
|
|
303
|
+
client.rpc.debug(...args.map(String));
|
|
304
|
+
}
|
|
305
|
+
async function tryCall(fn) {
|
|
306
|
+
try {
|
|
307
|
+
return await fn();
|
|
308
|
+
} catch (err) {
|
|
309
|
+
const now = Date.now();
|
|
310
|
+
const canTry = !reloadStart || now - Number(reloadStart) < 3e4;
|
|
311
|
+
debug("failed to resolve runner", err == null ? void 0 : err.message, "trying again:", canTry, "time is", now, "reloadStart is", reloadStart);
|
|
312
|
+
if (!canTry) {
|
|
313
|
+
const error = serializeError(new Error("Vitest failed to load its runner after 30 seconds."));
|
|
314
|
+
error.cause = serializeError(err);
|
|
315
|
+
await client.rpc.onUnhandledError(error, "Preload Error");
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
if (!reloadStart) {
|
|
319
|
+
const newUrl = new URL(location.href);
|
|
320
|
+
newUrl.searchParams.set("__reloadStart", now.toString());
|
|
321
|
+
debug("set the new url because reload start is not set to", newUrl);
|
|
322
|
+
location.href = newUrl.toString();
|
|
323
|
+
} else {
|
|
324
|
+
debug("reload the iframe because reload start is set", location.href);
|
|
325
|
+
location.reload();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
async function prepareTestEnvironment(files) {
|
|
330
|
+
debug("trying to resolve runner", `${reloadStart}`);
|
|
331
|
+
const config = getConfig();
|
|
332
|
+
const viteClientPath = `${config.base || "/"}@vite/client`;
|
|
333
|
+
await __vitePreload(() => import(viteClientPath), true ? __vite__mapDeps([]) : void 0);
|
|
334
|
+
const rpc2 = await loadSafeRpc(client);
|
|
335
|
+
stopErrorHandler();
|
|
336
|
+
registerUnexpectedErrors(rpc2);
|
|
337
|
+
const providedContext = await client.rpc.getProvidedContext();
|
|
338
|
+
const state = {
|
|
339
|
+
ctx: {
|
|
340
|
+
pool: "browser",
|
|
341
|
+
worker: "./browser.js",
|
|
342
|
+
workerId: 1,
|
|
343
|
+
config,
|
|
344
|
+
projectName: config.name,
|
|
345
|
+
files,
|
|
346
|
+
environment: {
|
|
347
|
+
name: "browser",
|
|
348
|
+
options: null
|
|
349
|
+
},
|
|
350
|
+
providedContext,
|
|
351
|
+
invalidates: []
|
|
352
|
+
},
|
|
353
|
+
onCancel,
|
|
354
|
+
mockMap: /* @__PURE__ */ new Map(),
|
|
355
|
+
config,
|
|
356
|
+
environment: {
|
|
357
|
+
name: "browser",
|
|
358
|
+
transformMode: "web",
|
|
359
|
+
setup() {
|
|
360
|
+
throw new Error("Not called in the browser");
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
moduleCache: getBrowserState().moduleCache,
|
|
364
|
+
rpc: rpc2,
|
|
365
|
+
durations: {
|
|
366
|
+
environment: 0,
|
|
367
|
+
prepare: 0
|
|
368
|
+
},
|
|
369
|
+
providedContext
|
|
370
|
+
};
|
|
371
|
+
globalThis.__vitest_browser__ = true;
|
|
372
|
+
globalThis.__vitest_worker__ = state;
|
|
373
|
+
globalThis.__vitest_mocker__ = new VitestBrowserClientMocker();
|
|
374
|
+
await setupConsoleLogSpy();
|
|
375
|
+
setupDialogsSpy();
|
|
376
|
+
const { startTests, setupCommonEnv } = await importId("vitest/browser");
|
|
377
|
+
const version = url.searchParams.get("browserv") || "0";
|
|
378
|
+
files.forEach((filename) => {
|
|
379
|
+
const currentVersion = browserHashMap.get(filename);
|
|
380
|
+
if (!currentVersion || currentVersion[1] !== version)
|
|
381
|
+
browserHashMap.set(filename, [true, version]);
|
|
382
|
+
});
|
|
383
|
+
const runner = await initiateRunner();
|
|
384
|
+
onCancel.then((reason) => {
|
|
385
|
+
var _a;
|
|
386
|
+
(_a = runner.onCancel) == null ? void 0 : _a.call(runner, reason);
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
runner,
|
|
390
|
+
config,
|
|
391
|
+
state,
|
|
392
|
+
setupCommonEnv,
|
|
393
|
+
startTests
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function done(files) {
|
|
397
|
+
channel.postMessage({ type: "done", filenames: files });
|
|
398
|
+
}
|
|
399
|
+
async function runTests(files) {
|
|
400
|
+
await client.waitForConnection();
|
|
401
|
+
debug("client is connected to ws server");
|
|
402
|
+
let preparedData;
|
|
403
|
+
try {
|
|
404
|
+
preparedData = await tryCall(() => prepareTestEnvironment(files));
|
|
405
|
+
} catch (error) {
|
|
406
|
+
debug("data cannot be loaded becuase it threw an error");
|
|
407
|
+
await client.rpc.onUnhandledError(serializeError(error), "Preload Error");
|
|
408
|
+
done(files);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (preparedData === false) {
|
|
412
|
+
debug("data cannot be loaded, finishing the test");
|
|
413
|
+
done(files);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (!preparedData) {
|
|
417
|
+
debug("page is reloading, waiting for the next run");
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
debug("runner resolved successfully");
|
|
421
|
+
const { config, runner, state, setupCommonEnv, startTests } = preparedData;
|
|
422
|
+
try {
|
|
423
|
+
await setupCommonEnv(config);
|
|
424
|
+
for (const file of files)
|
|
425
|
+
await startTests([file], runner);
|
|
426
|
+
} finally {
|
|
427
|
+
state.environmentTeardownRun = true;
|
|
428
|
+
debug("finished running tests");
|
|
429
|
+
done(files);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
window.__vitest_browser_runner__.runTests = runTests;
|
|
433
|
+
function __vite__mapDeps(indexes) {
|
|
434
|
+
if (!__vite__mapDeps.viteFileDeps) {
|
|
435
|
+
__vite__mapDeps.viteFileDeps = []
|
|
436
|
+
}
|
|
437
|
+
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
438
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const moduleCache = new Map()
|
|
2
|
+
|
|
3
|
+
function wrapModule(module) {
|
|
4
|
+
if (module instanceof Promise) {
|
|
5
|
+
moduleCache.set(module, { promise: module, evaluated: false })
|
|
6
|
+
return module
|
|
7
|
+
.then(m => '__vi_inject__' in m ? m.__vi_inject__ : m)
|
|
8
|
+
.finally(() => moduleCache.delete(module))
|
|
9
|
+
}
|
|
10
|
+
return '__vi_inject__' in module ? module.__vi_inject__ : module
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function exportAll(exports, sourceModule) {
|
|
14
|
+
if (exports === sourceModule)
|
|
15
|
+
return
|
|
16
|
+
|
|
17
|
+
if (Object(sourceModule) !== sourceModule || Array.isArray(sourceModule))
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
for (const key in sourceModule) {
|
|
21
|
+
if (key !== 'default') {
|
|
22
|
+
try {
|
|
23
|
+
Object.defineProperty(exports, key, {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
get: () => sourceModule[key],
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
catch (_err) { }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
window.__vitest_browser_runner__ = {
|
|
35
|
+
exportAll,
|
|
36
|
+
wrapModule,
|
|
37
|
+
moduleCache,
|
|
38
|
+
config: { __VITEST_CONFIG__ },
|
|
39
|
+
files: { __VITEST_FILES__ },
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const config = __vitest_browser_runner__.config
|
|
43
|
+
|
|
44
|
+
if (config.testNamePattern)
|
|
45
|
+
config.testNamePattern = parseRegexp(config.testNamePattern)
|
|
46
|
+
|
|
47
|
+
function parseRegexp(input) {
|
|
48
|
+
// Parse input
|
|
49
|
+
const m = input.match(/(\/?)(.+)\1([a-z]*)/i)
|
|
50
|
+
|
|
51
|
+
// match nothing
|
|
52
|
+
if (!m)
|
|
53
|
+
return /$^/
|
|
54
|
+
|
|
55
|
+
// Invalid flags
|
|
56
|
+
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3]))
|
|
57
|
+
return RegExp(input)
|
|
58
|
+
|
|
59
|
+
// Create the regular expression
|
|
60
|
+
return new RegExp(m[2], m[3])
|
|
61
|
+
}
|
package/dist/client/index.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" href="
|
|
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 Runner</title>
|
|
8
8
|
<style>
|
|
@@ -21,59 +21,12 @@
|
|
|
21
21
|
border: none;
|
|
22
22
|
}
|
|
23
23
|
</style>
|
|
24
|
-
<script
|
|
24
|
+
<script>{__VITEST_INJECTOR__}</script>
|
|
25
|
+
<script type="module" crossorigin src="/__vitest_browser__/main-zbvBuTsR.js"></script>
|
|
26
|
+
<link rel="modulepreload" crossorigin href="/__vitest_browser__/rpc-aQLc-7Wy.js">
|
|
25
27
|
</head>
|
|
26
28
|
<body>
|
|
27
29
|
<iframe id="vitest-ui" src=""></iframe>
|
|
28
|
-
<
|
|
29
|
-
const moduleCache = new Map()
|
|
30
|
-
|
|
31
|
-
// this method receives a module object or "import" promise that it resolves and keeps track of
|
|
32
|
-
// and returns a hijacked module object that can be used to mock module exports
|
|
33
|
-
function wrapModule(module) {
|
|
34
|
-
if (module instanceof Promise) {
|
|
35
|
-
moduleCache.set(module, { promise: module, evaluated: false })
|
|
36
|
-
return module
|
|
37
|
-
// TODO: add a test
|
|
38
|
-
.then(m => '__vi_inject__' in m ? m.__vi_inject__ : m)
|
|
39
|
-
.finally(() => moduleCache.delete(module))
|
|
40
|
-
}
|
|
41
|
-
return '__vi_inject__' in module ? module.__vi_inject__ : module
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function exportAll(exports, sourceModule) {
|
|
45
|
-
// #1120 when a module exports itself it causes
|
|
46
|
-
// call stack error
|
|
47
|
-
if (exports === sourceModule)
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
if (Object(sourceModule) !== sourceModule || Array.isArray(sourceModule))
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
for (const key in sourceModule) {
|
|
54
|
-
if (key !== 'default') {
|
|
55
|
-
try {
|
|
56
|
-
Object.defineProperty(exports, key, {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
get: () => sourceModule[key],
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
catch (_err) { }
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
window.__vi_export_all__ = exportAll
|
|
68
|
-
|
|
69
|
-
// TODO: allow easier rewriting of import.meta.env
|
|
70
|
-
window.__vi_import_meta__ = {
|
|
71
|
-
env: {},
|
|
72
|
-
url: location.href,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
window.__vi_module_cache__ = moduleCache
|
|
76
|
-
window.__vi_wrap_module__ = wrapModule
|
|
77
|
-
</script>
|
|
30
|
+
<div id="vitest-tester"></div>
|
|
78
31
|
</body>
|
|
79
32
|
</html>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" href="{__VITEST_FAVICON__}" type="image/svg+xml">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>{__VITEST_TITLE__}</title>
|
|
8
|
+
<style>
|
|
9
|
+
html {
|
|
10
|
+
padding: 0;
|
|
11
|
+
margin: 0;
|
|
12
|
+
}
|
|
13
|
+
body {
|
|
14
|
+
padding: 0;
|
|
15
|
+
margin: 0;
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
<script>{__VITEST_INJECTOR__}</script>
|
|
19
|
+
<script type="module" crossorigin src="/__vitest_browser__/tester-W7irZcd1.js"></script>
|
|
20
|
+
<link rel="modulepreload" crossorigin href="/__vitest_browser__/rpc-aQLc-7Wy.js">
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
{__VITEST_APPEND__}
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|