@rstest/browser 0.10.6 → 0.11.1

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/src/protocol.ts CHANGED
@@ -91,9 +91,16 @@ export type BrowserHostConfig = {
91
91
  */
92
92
  runId?: string;
93
93
  /**
94
- * Base URL for runner (iframe) pages.
94
+ * Base URL for runner (iframe) pages. Container origin; used as a fallback
95
+ * when a project has no entry in `projectRunnerUrls`.
95
96
  */
96
97
  runnerUrl?: string;
98
+ /**
99
+ * Per-project runner origin base URLs, keyed by project name. Each browser
100
+ * project runs on its own dev server, so the container must load each test
101
+ * file's iframe from that project's own origin.
102
+ */
103
+ projectRunnerUrls?: Record<string, string>;
97
104
  /**
98
105
  * WebSocket port for container RPC.
99
106
  */
@@ -149,10 +156,7 @@ export type BrowserClientMessage =
149
156
  * host router.
150
157
  */
151
158
  export type RunnerLifecycleMethod =
152
- | 'file-ready'
153
- | 'suite-start'
154
- | 'suite-result'
155
- | 'case-start';
159
+ 'file-ready' | 'suite-start' | 'suite-result' | 'case-start';
156
160
 
157
161
  /**
158
162
  * {@link BrowserClientMessage} types that are forwarded to the `runner`
@@ -49,6 +49,9 @@ export type BrowserProviderPage = {
49
49
  event: 'console',
50
50
  listener: (message: BrowserConsoleMessage) => void,
51
51
  ): void;
52
+ // Page died: renderer crash or unexpected close. Headless scheduling wires
53
+ // these to fail the file immediately. Listeners take no payload.
54
+ (event: 'crash' | 'close', listener: () => void): void;
52
55
  };
53
56
  close: () => Promise<void>;
54
57
  [Symbol.asyncDispose]: () => Promise<void>;
@@ -15,6 +15,7 @@ type PlaywrightPageLike = Omit<
15
15
  event: 'console',
16
16
  listener: (message: BrowserConsoleMessage) => void,
17
17
  ): void;
18
+ (event: 'crash' | 'close', listener: () => void): void;
18
19
  };
19
20
  };
20
21
  type PlaywrightContextLike = Omit<
@@ -63,10 +64,11 @@ const wrapPage = (page: PlaywrightPageLike): BrowserProviderPage => {
63
64
  patchedPages.add(page);
64
65
  const originalOn = page.on.bind(page);
65
66
  page.on = ((
66
- event: 'popup' | 'console',
67
+ event: 'popup' | 'console' | 'crash' | 'close',
67
68
  listener:
68
69
  | ((page: BrowserProviderPage) => void)
69
- | ((message: BrowserConsoleMessage) => void),
70
+ | ((message: BrowserConsoleMessage) => void)
71
+ | (() => void),
70
72
  ) => {
71
73
  if (event === 'popup') {
72
74
  originalOn(event, (popup) => {
@@ -75,6 +77,11 @@ const wrapPage = (page: PlaywrightPageLike): BrowserProviderPage => {
75
77
  return;
76
78
  }
77
79
 
80
+ if (event === 'crash' || event === 'close') {
81
+ originalOn(event, listener as () => void);
82
+ return;
83
+ }
84
+
78
85
  originalOn(event, listener as (message: BrowserConsoleMessage) => void);
79
86
  }) as PlaywrightPageLike['on'];
80
87
 
@@ -112,8 +119,7 @@ export async function launchPlaywrightBrowser({
112
119
  const playwright = await import('playwright');
113
120
  const browserType = playwright[browserName];
114
121
  const launchOptions = providerOptions.launch as
115
- | Record<string, unknown>
116
- | undefined;
122
+ Record<string, unknown> | undefined;
117
123
  const launchArgs = Array.isArray(launchOptions?.args)
118
124
  ? launchOptions.args
119
125
  : browserName === 'chromium'
@@ -137,8 +143,7 @@ export async function launchPlaywrightBrowser({
137
143
  viewport,
138
144
  }) => {
139
145
  const contextOptions = contextProviderOptions?.context as
140
- | Record<string, unknown>
141
- | undefined;
146
+ Record<string, unknown> | undefined;
142
147
  const context = await browser.newContext({
143
148
  ...contextOptions,
144
149
  viewport,
@@ -1 +0,0 @@
1
- /*! LICENSE: 854.c59f71483d.js.LICENSE.txt */
@@ -1,91 +0,0 @@
1
- export type FakeTimerInstallOpts = Record<string, unknown>;
2
-
3
- export type FakeTimerWithContext = {
4
- timers: Record<string, unknown>;
5
- };
6
-
7
- export type InstalledClock = {
8
- now: number;
9
- reset: () => void;
10
- uninstall: () => void;
11
- runAll: () => void;
12
- runAllAsync: () => Promise<void>;
13
- runToLast: () => void;
14
- runToLastAsync: () => Promise<void>;
15
- tick: (ms: number) => void;
16
- tickAsync: (ms: number) => Promise<void>;
17
- next: () => void;
18
- nextAsync: () => Promise<void>;
19
- runToFrame: () => void;
20
- runMicrotasks: () => void;
21
- setSystemTime: (now?: number | Date) => void;
22
- countTimers: () => number;
23
- };
24
-
25
- const createClock = (): InstalledClock => {
26
- const clock: InstalledClock = {
27
- now: Date.now(),
28
- reset: () => {
29
- clock.now = Date.now();
30
- },
31
- uninstall: () => {
32
- /* noop */
33
- },
34
- runAll: () => {
35
- /* noop */
36
- },
37
- runAllAsync: async () => {
38
- /* noop */
39
- },
40
- runToLast: () => {
41
- /* noop */
42
- },
43
- runToLastAsync: async () => {
44
- /* noop */
45
- },
46
- tick: (ms: number) => {
47
- clock.now += ms;
48
- },
49
- tickAsync: async (ms: number) => {
50
- clock.now += ms;
51
- },
52
- next: () => {
53
- /* noop */
54
- },
55
- nextAsync: async () => {
56
- /* noop */
57
- },
58
- runToFrame: () => {
59
- /* noop */
60
- },
61
- runMicrotasks: () => {
62
- /* noop */
63
- },
64
- setSystemTime: (value?: number | Date) => {
65
- if (typeof value === 'number') {
66
- clock.now = value;
67
- return;
68
- }
69
- if (value instanceof Date) {
70
- clock.now = value.valueOf();
71
- return;
72
- }
73
- clock.now = Date.now();
74
- },
75
- countTimers: () => 0,
76
- };
77
-
78
- return clock;
79
- };
80
-
81
- export const withGlobal = (_global: typeof globalThis) => {
82
- const clock = createClock();
83
-
84
- return {
85
- timers: {},
86
- install: (_config: FakeTimerInstallOpts = {}): InstalledClock => {
87
- clock.now = Date.now();
88
- return clock;
89
- },
90
- };
91
- };
File without changes