@rstest/browser 0.8.5 → 0.9.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.
Files changed (79) hide show
  1. package/LICENSE-APACHE-2.0 +202 -0
  2. package/NOTICE +11 -0
  3. package/dist/361.js +8 -0
  4. package/dist/augmentExpect.d.ts +73 -0
  5. package/dist/browser-container/container-static/css/index.5c72297783.css +1 -0
  6. package/dist/browser-container/container-static/js/{565.226c9ef5.js → 101.36a8ccdf84.js} +4024 -3856
  7. package/dist/browser-container/container-static/js/101.36a8ccdf84.js.LICENSE.txt +1 -0
  8. package/dist/browser-container/container-static/js/{index.c1d17467.js → index.0687a8142a.js} +742 -692
  9. package/dist/browser-container/container-static/js/{lib-react.97ee79b0.js → lib-react.dcf2a5e57a.js} +10 -10
  10. package/dist/browser-container/container-static/js/lib-react.dcf2a5e57a.js.LICENSE.txt +1 -0
  11. package/dist/browser-container/index.html +1 -1
  12. package/dist/browser.d.ts +2 -0
  13. package/dist/browser.js +583 -0
  14. package/dist/browserRpcRegistry.d.ts +18 -0
  15. package/dist/client/api.d.ts +3 -0
  16. package/dist/client/browserRpc.d.ts +2 -0
  17. package/dist/client/dispatchTransport.d.ts +11 -0
  18. package/dist/client/entry.d.ts +1 -5
  19. package/dist/client/locator.d.ts +125 -0
  20. package/dist/client/snapshot.d.ts +0 -6
  21. package/dist/concurrency.d.ts +12 -0
  22. package/dist/dispatchCapabilities.d.ts +34 -0
  23. package/dist/dispatchRouter.d.ts +20 -0
  24. package/dist/headlessLatestRerunScheduler.d.ts +19 -0
  25. package/dist/headlessTransport.d.ts +12 -0
  26. package/dist/index.js +1580 -258
  27. package/dist/protocol.d.ts +44 -33
  28. package/dist/providers/index.d.ts +79 -0
  29. package/dist/providers/playwright/compileLocator.d.ts +3 -0
  30. package/dist/providers/playwright/dispatchBrowserRpc.d.ts +13 -0
  31. package/dist/providers/playwright/expectUtils.d.ts +24 -0
  32. package/dist/providers/playwright/implementation.d.ts +2 -0
  33. package/dist/providers/playwright/index.d.ts +1 -0
  34. package/dist/providers/playwright/runtime.d.ts +5 -0
  35. package/dist/providers/playwright/textMatcher.d.ts +8 -0
  36. package/dist/rpcProtocol.d.ts +145 -0
  37. package/dist/runSession.d.ts +33 -0
  38. package/dist/sessionRegistry.d.ts +34 -0
  39. package/dist/sourceMap/sourceMapLoader.d.ts +14 -0
  40. package/dist/watchRerunPlanner.d.ts +21 -0
  41. package/package.json +15 -10
  42. package/src/AGENTS.md +128 -0
  43. package/src/augmentExpect.ts +62 -0
  44. package/src/browser.ts +3 -0
  45. package/src/browserRpcRegistry.ts +57 -0
  46. package/src/client/AGENTS.md +82 -0
  47. package/src/client/api.ts +213 -0
  48. package/src/client/browserRpc.ts +86 -0
  49. package/src/client/dispatchTransport.ts +178 -0
  50. package/src/client/entry.ts +96 -33
  51. package/src/client/locator.ts +452 -0
  52. package/src/client/snapshot.ts +32 -97
  53. package/src/client/sourceMapSupport.ts +26 -37
  54. package/src/concurrency.ts +62 -0
  55. package/src/dispatchCapabilities.ts +162 -0
  56. package/src/dispatchRouter.ts +82 -0
  57. package/src/env.d.ts +8 -1
  58. package/src/headlessLatestRerunScheduler.ts +76 -0
  59. package/src/headlessTransport.ts +28 -0
  60. package/src/hostController.ts +1292 -367
  61. package/src/protocol.ts +66 -31
  62. package/src/providers/index.ts +103 -0
  63. package/src/providers/playwright/compileLocator.ts +130 -0
  64. package/src/providers/playwright/dispatchBrowserRpc.ts +372 -0
  65. package/src/providers/playwright/expectUtils.ts +57 -0
  66. package/src/providers/playwright/implementation.ts +33 -0
  67. package/src/providers/playwright/index.ts +1 -0
  68. package/src/providers/playwright/runtime.ts +32 -0
  69. package/src/providers/playwright/textMatcher.ts +10 -0
  70. package/src/rpcProtocol.ts +220 -0
  71. package/src/runSession.ts +110 -0
  72. package/src/sessionRegistry.ts +89 -0
  73. package/src/sourceMap/sourceMapLoader.ts +96 -0
  74. package/src/watchRerunPlanner.ts +77 -0
  75. package/dist/browser-container/container-static/css/index.5a71c757.css +0 -1
  76. package/dist/browser-container/container-static/js/565.226c9ef5.js.LICENSE.txt +0 -1
  77. package/dist/browser-container/container-static/js/lib-react.97ee79b0.js.LICENSE.txt +0 -1
  78. package/dist/browser-container/container-static/js/scheduler.5accca0c.js +0 -407
  79. package/dist/browser-container/scheduler.html +0 -19
@@ -1,407 +0,0 @@
1
- (()=>{
2
- "use strict";
3
- let e = Math.random.bind(Math), t = (e)=>e, { clearTimeout: a, setTimeout: r } = globalThis, i = async (e, t, a)=>{
4
- if (!e || null === a || "function" != typeof a.postMessage) return;
5
- let r = (e)=>{
6
- a.postMessage({
7
- type: "__rstest_snapshot_response__",
8
- payload: e
9
- }, "*");
10
- };
11
- try {
12
- let a;
13
- switch(t.method){
14
- case "resolveSnapshotPath":
15
- a = await e.resolveSnapshotPath(t.args.testPath);
16
- break;
17
- case "readSnapshotFile":
18
- a = await e.readSnapshotFile(t.args.filepath);
19
- break;
20
- case "saveSnapshotFile":
21
- a = await e.saveSnapshotFile(t.args.filepath, t.args.content);
22
- break;
23
- case "removeSnapshotFile":
24
- a = await e.removeSnapshotFile(t.args.filepath);
25
- break;
26
- default:
27
- a = void 0;
28
- }
29
- r({
30
- id: t.id,
31
- result: a
32
- });
33
- } catch (e) {
34
- r({
35
- id: t.id,
36
- error: e instanceof Error ? e.message : String(e)
37
- });
38
- }
39
- }, l = [
40
- 1e3,
41
- 2e3,
42
- 4e3,
43
- 8e3,
44
- 16e3,
45
- 3e4
46
- ], o = function(e, t, a) {
47
- let r = arguments.length > 3 && void 0 !== arguments[3] && arguments[3], i = new URL("/runner.html", t || window.location.origin);
48
- return i.searchParams.set("testFile", e), a && i.searchParams.set("testNamePattern", a), r && i.searchParams.set("t", Date.now().toString()), i.toString();
49
- }, n = [
50
- {
51
- id: "iPhoneSE",
52
- label: "iPhone SE",
53
- width: 375,
54
- height: 667
55
- },
56
- {
57
- id: "iPhoneXR",
58
- label: "iPhone XR",
59
- width: 414,
60
- height: 896
61
- },
62
- {
63
- id: "iPhone12Pro",
64
- label: "iPhone 12 Pro",
65
- width: 390,
66
- height: 844
67
- },
68
- {
69
- id: "iPhone14ProMax",
70
- label: "iPhone 14 Pro Max",
71
- width: 430,
72
- height: 932
73
- },
74
- {
75
- id: "Pixel7",
76
- label: "Pixel 7",
77
- width: 412,
78
- height: 915
79
- },
80
- {
81
- id: "SamsungGalaxyS8Plus",
82
- label: "Samsung Galaxy S8+",
83
- width: 360,
84
- height: 740
85
- },
86
- {
87
- id: "SamsungGalaxyS20Ultra",
88
- label: "Samsung Galaxy S20 Ultra",
89
- width: 412,
90
- height: 915
91
- },
92
- {
93
- id: "iPadMini",
94
- label: "iPad Mini",
95
- width: 768,
96
- height: 1024
97
- },
98
- {
99
- id: "iPadAir",
100
- label: "iPad Air",
101
- width: 820,
102
- height: 1180
103
- },
104
- {
105
- id: "iPadPro",
106
- label: "iPad Pro",
107
- width: 1024,
108
- height: 1366
109
- },
110
- {
111
- id: "SurfacePro7",
112
- label: "Surface Pro 7",
113
- width: 912,
114
- height: 1368
115
- },
116
- {
117
- id: "SurfaceDuo",
118
- label: "Surface Duo",
119
- width: 540,
120
- height: 720
121
- },
122
- {
123
- id: "GalaxyZFold5",
124
- label: "Galaxy Z Fold 5",
125
- width: 344,
126
- height: 882
127
- },
128
- {
129
- id: "AsusZenbookFold",
130
- label: "Asus Zenbook Fold",
131
- width: 853,
132
- height: 1280
133
- },
134
- {
135
- id: "SamsungGalaxyA51A71",
136
- label: "Samsung Galaxy A51/71",
137
- width: 412,
138
- height: 914
139
- },
140
- {
141
- id: "NestHub",
142
- label: "Nest Hub",
143
- width: 1024,
144
- height: 600
145
- },
146
- {
147
- id: "NestHubMax",
148
- label: "Nest Hub Max",
149
- width: 1280,
150
- height: 800
151
- }
152
- ], s = new Set(n.map((e)=>e.id)), h = window.__RSTEST_BROWSER_OPTIONS__, d = (null == h ? void 0 : h.debug) === !0, c = (null == h ? void 0 : h.rpcTimeout) ?? 3e4, u = null, w = 0, p = null, f = new Map, g = new Map, y = function() {
153
- for(var e = arguments.length, t = Array(e), a = 0; a < e; a++)t[a] = arguments[a];
154
- d && console.log("[Scheduler]", ...t);
155
- }, m = (e, t)=>{
156
- let a = f.get(e);
157
- a || ((a = document.createElement("iframe")).style.position = "fixed", a.style.left = "0", a.style.top = "0", a.style.opacity = "0", a.style.pointerEvents = "none", a.style.border = "0", a.title = `Scheduler runner for ${e}`, a.dataset.testFile = e, a.addEventListener("load", ()=>{
158
- var t, r;
159
- let i;
160
- t = a, i = g.get(e) || "", null == (r = t.contentWindow) || r.postMessage({
161
- type: "RSTEST_CONFIG",
162
- payload: {
163
- ...h,
164
- testFile: e,
165
- projectName: i
166
- }
167
- }, "*");
168
- }), document.body.appendChild(a), f.set(e, a));
169
- let r = ((e)=>{
170
- let t = g.get(e);
171
- if (!t) return null;
172
- let a = null == h ? void 0 : h.projects.find((e)=>e.name === t), r = null == a ? void 0 : a.viewport;
173
- if (!r) return null;
174
- if ("string" == typeof r && "string" == typeof r && s.has(r)) {
175
- let e = ((e)=>{
176
- let t = n.find((t)=>t.id === e);
177
- if (!t) throw Error(`Unknown device preset: ${e}`);
178
- return t;
179
- })(r);
180
- return {
181
- width: e.width,
182
- height: e.height
183
- };
184
- }
185
- return "object" == typeof r && null !== r && "number" == typeof r.width && "number" == typeof r.height ? {
186
- width: r.width,
187
- height: r.height
188
- } : null;
189
- })(e);
190
- r ? (a.style.width = `${r.width}px`, a.style.height = `${r.height}px`) : (a.style.width = "100vw", a.style.height = "100vh"), a.src = o(e, null == h ? void 0 : h.runnerUrl, t, !0);
191
- }, b = (e)=>{
192
- let t = new Set(g.keys()), a = new Set(e.map((e)=>e.testPath));
193
- for (let [e, t] of f.entries())a.has(e) || (t.remove(), f.delete(e), g.delete(e));
194
- for (let t of e)g.set(t.testPath, t.projectName);
195
- for (let a of e.filter((e)=>!t.has(e.testPath)))m(a.testPath);
196
- }, S = async (e)=>{
197
- if (u) try {
198
- switch(e.type){
199
- case "file-start":
200
- await u.onTestFileStart(e.payload);
201
- break;
202
- case "case-result":
203
- await u.onTestCaseResult(e.payload);
204
- break;
205
- case "file-complete":
206
- await u.onTestFileComplete(e.payload);
207
- break;
208
- case "log":
209
- await u.onLog(e.payload);
210
- break;
211
- case "fatal":
212
- await u.onFatal(e.payload);
213
- }
214
- } catch (e) {
215
- y("failed to forward client message", e);
216
- }
217
- }, P = ()=>{
218
- let e = l[Math.min(w, l.length - 1)];
219
- w++, y(`reconnecting in ${e}ms`), p = setTimeout(()=>{
220
- v().catch((e)=>{
221
- y("reconnect attempt failed", e instanceof Error ? e.message : String(e)), P();
222
- });
223
- }, e);
224
- }, v = async ()=>{
225
- var i;
226
- let l;
227
- if (!(null == h ? void 0 : h.wsPort)) throw Error("Scheduler requires wsPort in browser options.");
228
- p && (clearTimeout(p), p = null);
229
- let o = new WebSocket((i = h.wsPort, l = "https:" === window.location.protocol ? "wss:" : "ws:", `${l}//${window.location.hostname}:${i}`));
230
- await new Promise((e, t)=>{
231
- let a = setTimeout(()=>{
232
- t(Error(`Scheduler websocket timeout after ${c}ms`));
233
- }, c);
234
- o.addEventListener("open", ()=>{
235
- clearTimeout(a), e();
236
- }), o.addEventListener("error", ()=>{
237
- clearTimeout(a), t(Error("Scheduler websocket failed to connect."));
238
- });
239
- }), w = 0, u = function(i, l) {
240
- let o, n, { post: s, on: h, off: d = ()=>{}, eventNames: c = [], serialize: u = t, deserialize: w = t, resolver: p, bind: f = "rpc", timeout: g = 6e4, proxify: y = !0 } = l, m = !1, b = new Map;
241
- async function S(t, i, h, d) {
242
- let c, w, p;
243
- if (m) throw Error(`[birpc] rpc is closed, cannot call "${t}"`);
244
- let f = {
245
- m: t,
246
- a: i,
247
- t: "q"
248
- };
249
- d && (f.o = !0);
250
- let y = async (e)=>s(u(e));
251
- if (h) return void await y(f);
252
- if (o) try {
253
- await o;
254
- } finally{
255
- o = void 0;
256
- }
257
- let { promise: S, resolve: P, reject: v } = {
258
- promise: new Promise((e, t)=>{
259
- w = e, p = t;
260
- }),
261
- resolve: w,
262
- reject: p
263
- }, E = function(t = 21) {
264
- let a = "", r = t;
265
- for(; r--;)a += "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[64 * e() | 0];
266
- return a;
267
- }();
268
- async function F(e = f) {
269
- return g >= 0 && "object" == typeof (c = r(()=>{
270
- try {
271
- if (l.onTimeoutError?.call(n, t, i) !== !0) throw Error(`[birpc] timeout on calling "${t}"`);
272
- } catch (e) {
273
- v(e);
274
- }
275
- b.delete(E);
276
- }, g)) && (c = c.unref?.()), b.set(E, {
277
- resolve: P,
278
- reject: v,
279
- timeoutId: c,
280
- method: t
281
- }), await y(e), S;
282
- }
283
- f.i = E;
284
- try {
285
- l.onRequest ? await l.onRequest.call(n, f, F, P) : await F();
286
- } catch (e) {
287
- if (l.onGeneralError?.call(n, e) !== !0) throw e;
288
- return;
289
- } finally{
290
- a(c), b.delete(E);
291
- }
292
- return S;
293
- }
294
- let P = {
295
- $call: (e, ...t)=>S(e, t, !1),
296
- $callOptional: (e, ...t)=>S(e, t, !1, !0),
297
- $callEvent: (e, ...t)=>S(e, t, !0),
298
- $callRaw: (e)=>S(e.method, e.args, e.event, e.optional),
299
- $rejectPendingCalls: function(e) {
300
- let t = Array.from(b.values()).map(({ method: t, reject: a })=>e ? e({
301
- method: t,
302
- reject: a
303
- }) : a(Error(`[birpc]: rejected pending call "${t}".`)));
304
- return b.clear(), t;
305
- },
306
- get $closed () {
307
- return m;
308
- },
309
- get $meta () {
310
- return l.meta;
311
- },
312
- $close: function(e) {
313
- m = !0, b.forEach(({ reject: t, method: a })=>{
314
- let r = Error(`[birpc] rpc is closed, cannot call "${a}"`);
315
- if (e) return e.cause ??= r, t(e);
316
- t(r);
317
- }), b.clear(), d(v);
318
- },
319
- $functions: i
320
- };
321
- async function v(e, ...t) {
322
- let r;
323
- try {
324
- r = w(e);
325
- } catch (e) {
326
- if (l.onGeneralError?.call(n, e) !== !0) throw e;
327
- return;
328
- }
329
- if ("q" === r.t) {
330
- let e, a, { m: o, a: h, o: d } = r, c = await (p ? p.call(n, o, i[o]) : i[o]);
331
- if (d && (c ||= ()=>void 0), c) try {
332
- e = await c.apply("rpc" === f ? n : i, h);
333
- } catch (e) {
334
- a = e;
335
- }
336
- else a = Error(`[birpc] function "${o}" not found`);
337
- if (r.i) {
338
- if (a && l.onFunctionError && !0 === l.onFunctionError.call(n, a, o, h)) return;
339
- if (!a) try {
340
- await s(u({
341
- t: "s",
342
- i: r.i,
343
- r: e
344
- }), ...t);
345
- return;
346
- } catch (e) {
347
- if (a = e, l.onGeneralError?.call(n, e, o, h) !== !0) throw e;
348
- }
349
- try {
350
- await s(u({
351
- t: "s",
352
- i: r.i,
353
- e: a
354
- }), ...t);
355
- } catch (e) {
356
- if (l.onGeneralError?.call(n, e, o, h) !== !0) throw e;
357
- }
358
- }
359
- } else {
360
- let { i: e, r: t, e: i } = r, l = b.get(e);
361
- l && (a(l.timeoutId), i ? l.reject(i) : l.resolve(t)), b.delete(e);
362
- }
363
- }
364
- return n = y ? new Proxy({}, {
365
- get (e, t) {
366
- if (Object.prototype.hasOwnProperty.call(P, t)) return P[t];
367
- if ("then" === t && !c.includes("then") && !("then" in i)) return;
368
- let a = (...e)=>S(t, e, !0);
369
- if (c.includes(t)) return a.asEvent = a, a;
370
- let r = (...e)=>S(t, e, !1);
371
- return r.asEvent = a, r;
372
- }
373
- }) : P, o = h(v), n;
374
- }({
375
- onTestFileUpdate (e) {
376
- y("onTestFileUpdate", e.length), b(e);
377
- },
378
- reloadTestFile (e, t) {
379
- y("reloadTestFile", e, t), m(e, t);
380
- }
381
- }, {
382
- timeout: c,
383
- post (e) {
384
- o.readyState === WebSocket.OPEN && o.send(JSON.stringify(e));
385
- },
386
- on (e) {
387
- o.addEventListener("message", (t)=>{
388
- try {
389
- e(JSON.parse(String(t.data)));
390
- } catch {}
391
- });
392
- }
393
- }), o.addEventListener("close", ()=>{
394
- y("websocket closed"), u = null, P();
395
- }), b(await u.getTestFiles());
396
- };
397
- window.addEventListener("message", (e)=>{
398
- var t;
399
- let a = (null == (t = e.data) ? void 0 : t.type) !== "__rstest_dispatch__" ? null : e.data.payload;
400
- if (a) {
401
- if ("snapshot-rpc-request" === a.type) return void i(u, a.payload, e.source);
402
- S(a);
403
- }
404
- }), v().catch((e)=>{
405
- console.error("[Scheduler] Failed to initialize:", e instanceof Error ? e.message : String(e)), P();
406
- });
407
- })();
@@ -1,19 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <link
7
- rel="icon"
8
- type="image/svg+xml"
9
- href="https://assets.rspack.rs/rstest/rstest-logo.svg"
10
- />
11
- <title>Rstest Browser Test Runner</title>
12
- <script>
13
- window.__RSTEST_BROWSER_OPTIONS__ = __RSTEST_OPTIONS_PLACEHOLDER__;
14
- </script>
15
- <script defer src="/container-static/js/scheduler.5accca0c.js"></script></head>
16
- <body>
17
- <div id="root"></div>
18
- </body>
19
- </html>