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