@vitest/browser 3.0.9 → 3.1.0-beta.2
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/context.d.ts +22 -0
- package/dist/client/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/{index-CsZqQx26.js → index-C3wX9Cb1.js} +1 -1
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{tester-lo_P6U-u.js → tester-DRF-LncV.js} +1112 -324
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +91 -105
- package/dist/context.js +374 -390
- package/dist/index-VvsEiykv.js +327 -0
- package/dist/index.js +1914 -1885
- package/dist/locators/index.d.ts +3 -0
- package/dist/locators/index.js +2 -2
- package/dist/locators/playwright.js +99 -108
- package/dist/locators/preview.js +71 -78
- package/dist/locators/webdriverio.js +135 -138
- package/dist/providers.js +34 -37
- package/dist/{public-utils-J4vwTaki.js → public-utils-4WiYB3_6.js} +38 -40
- package/dist/state.js +170 -1
- package/dist/utils.js +1 -1
- package/dist/webdriver-BP2w_ajA.js +271 -0
- package/package.json +8 -8
- package/dist/index-DrTP5i7N.js +0 -195
- package/dist/utils-VCysLhWp.js +0 -115
- package/dist/webdriver-C5-VI7VH.js +0 -275
|
@@ -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-DRF-LncV.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-CNTxSNQV.js">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/dist/client.js
CHANGED
|
@@ -230,27 +230,21 @@ const stringify = (value, replacer, space) => {
|
|
|
230
230
|
}
|
|
231
231
|
};
|
|
232
232
|
|
|
233
|
-
|
|
233
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
234
234
|
function getBrowserState() {
|
|
235
|
-
|
|
235
|
+
return window.__vitest_browser_runner__;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
const channel = new BroadcastChannel(
|
|
239
|
-
`vitest:${getBrowserState().sessionId}`
|
|
240
|
-
);
|
|
238
|
+
const channel = new BroadcastChannel(`vitest:${getBrowserState().sessionId}`);
|
|
241
239
|
const globalChannel = new BroadcastChannel("vitest:global");
|
|
242
240
|
function waitForChannel(event) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
{ once: true }
|
|
252
|
-
);
|
|
253
|
-
});
|
|
241
|
+
return new Promise((resolve) => {
|
|
242
|
+
channel.addEventListener("message", (e) => {
|
|
243
|
+
if (e.data?.type === event) {
|
|
244
|
+
resolve();
|
|
245
|
+
}
|
|
246
|
+
}, { once: true });
|
|
247
|
+
});
|
|
254
248
|
}
|
|
255
249
|
|
|
256
250
|
const PAGE_TYPE = getBrowserState().type;
|
|
@@ -259,98 +253,90 @@ const HOST = [location.hostname, PORT].filter(Boolean).join(":");
|
|
|
259
253
|
const RPC_ID = PAGE_TYPE === "orchestrator" ? getBrowserState().sessionId : getBrowserState().testerId;
|
|
260
254
|
const METHOD = getBrowserState().method;
|
|
261
255
|
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}`;
|
|
262
|
-
let setCancel = (_) => {
|
|
263
|
-
};
|
|
256
|
+
let setCancel = (_) => {};
|
|
264
257
|
const onCancel = new Promise((resolve) => {
|
|
265
|
-
|
|
258
|
+
setCancel = resolve;
|
|
266
259
|
});
|
|
267
260
|
function createClient() {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
registerWS();
|
|
350
|
-
function waitForConnection() {
|
|
351
|
-
return openPromise;
|
|
352
|
-
}
|
|
353
|
-
return ctx;
|
|
261
|
+
const reconnectInterval = 2e3;
|
|
262
|
+
const reconnectTries = 10;
|
|
263
|
+
const connectTimeout = 6e4;
|
|
264
|
+
let tries = reconnectTries;
|
|
265
|
+
const ctx = {
|
|
266
|
+
ws: new WebSocket(ENTRY_URL),
|
|
267
|
+
waitForConnection
|
|
268
|
+
};
|
|
269
|
+
let onMessage;
|
|
270
|
+
ctx.rpc = createBirpc({
|
|
271
|
+
onCancel: setCancel,
|
|
272
|
+
async createTesters(files) {
|
|
273
|
+
if (PAGE_TYPE !== "orchestrator") {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
getBrowserState().createTesters?.(files);
|
|
277
|
+
},
|
|
278
|
+
cdpEvent(event, payload) {
|
|
279
|
+
const cdp = getBrowserState().cdp;
|
|
280
|
+
if (!cdp) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
cdp.emit(event, payload);
|
|
284
|
+
}
|
|
285
|
+
}, {
|
|
286
|
+
post: (msg) => ctx.ws.send(msg),
|
|
287
|
+
on: (fn) => onMessage = fn,
|
|
288
|
+
serialize: (e) => stringify(e, (_, v) => {
|
|
289
|
+
if (v instanceof Error) {
|
|
290
|
+
return {
|
|
291
|
+
name: v.name,
|
|
292
|
+
message: v.message,
|
|
293
|
+
stack: v.stack
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
return v;
|
|
297
|
+
}),
|
|
298
|
+
deserialize: parse,
|
|
299
|
+
onTimeoutError(functionName) {
|
|
300
|
+
throw new Error(`[vitest-browser]: Timeout calling "${functionName}"`);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
let openPromise;
|
|
304
|
+
function reconnect(reset = false) {
|
|
305
|
+
if (reset) {
|
|
306
|
+
tries = reconnectTries;
|
|
307
|
+
}
|
|
308
|
+
ctx.ws = new WebSocket(ENTRY_URL);
|
|
309
|
+
registerWS();
|
|
310
|
+
}
|
|
311
|
+
function registerWS() {
|
|
312
|
+
openPromise = new Promise((resolve, reject) => {
|
|
313
|
+
const timeout = setTimeout(() => {
|
|
314
|
+
reject(new Error(`Cannot connect to the server in ${connectTimeout / 1e3} seconds`));
|
|
315
|
+
}, connectTimeout)?.unref?.();
|
|
316
|
+
if (ctx.ws.OPEN === ctx.ws.readyState) {
|
|
317
|
+
resolve();
|
|
318
|
+
}
|
|
319
|
+
ctx.ws.addEventListener("open", () => {
|
|
320
|
+
tries = reconnectTries;
|
|
321
|
+
resolve();
|
|
322
|
+
clearTimeout(timeout);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
ctx.ws.addEventListener("message", (v) => {
|
|
326
|
+
onMessage(v.data);
|
|
327
|
+
});
|
|
328
|
+
ctx.ws.addEventListener("close", () => {
|
|
329
|
+
tries -= 1;
|
|
330
|
+
if (tries > 0) {
|
|
331
|
+
setTimeout(reconnect, reconnectInterval);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
registerWS();
|
|
336
|
+
function waitForConnection() {
|
|
337
|
+
return openPromise;
|
|
338
|
+
}
|
|
339
|
+
return ctx;
|
|
354
340
|
}
|
|
355
341
|
const client = createClient();
|
|
356
342
|
|