@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,8 +1,4 @@
1
- import type { BrowserClientMessage, BrowserHostConfig } from '../protocol';
2
1
  declare global {
3
- interface Window {
4
- __RSTEST_BROWSER_OPTIONS__?: BrowserHostConfig;
5
- __rstest_dispatch__?: (message: BrowserClientMessage) => void;
6
- }
7
2
  var __coverage__: Record<string, unknown> | undefined;
8
3
  }
4
+ export {};
@@ -0,0 +1,125 @@
1
+ import type { BrowserLocatorIR, BrowserLocatorText } from '../rpcProtocol';
2
+ export declare const serializeText: (value: string | RegExp) => BrowserLocatorText;
3
+ export type LocatorGetByRoleOptions = {
4
+ name?: string | RegExp;
5
+ exact?: boolean;
6
+ checked?: boolean;
7
+ disabled?: boolean;
8
+ expanded?: boolean;
9
+ selected?: boolean;
10
+ pressed?: boolean;
11
+ includeHidden?: boolean;
12
+ level?: number;
13
+ };
14
+ export type LocatorTextOptions = {
15
+ exact?: boolean;
16
+ };
17
+ export type LocatorKeyboardModifier = 'Alt' | 'Control' | 'ControlOrMeta' | 'Meta' | 'Shift';
18
+ export type LocatorMouseButton = 'left' | 'right' | 'middle';
19
+ export type LocatorPosition = {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ export type LocatorClickOptions = {
24
+ button?: LocatorMouseButton;
25
+ clickCount?: number;
26
+ delay?: number;
27
+ force?: boolean;
28
+ modifiers?: LocatorKeyboardModifier[];
29
+ position?: LocatorPosition;
30
+ timeout?: number;
31
+ trial?: boolean;
32
+ };
33
+ export type LocatorDblclickOptions = Omit<LocatorClickOptions, 'clickCount'>;
34
+ export type LocatorHoverOptions = Pick<LocatorClickOptions, 'force' | 'modifiers' | 'position' | 'timeout' | 'trial'>;
35
+ export type LocatorPressOptions = {
36
+ delay?: number;
37
+ timeout?: number;
38
+ };
39
+ export type LocatorFillOptions = {
40
+ force?: boolean;
41
+ timeout?: number;
42
+ };
43
+ export type LocatorCheckOptions = {
44
+ force?: boolean;
45
+ position?: LocatorPosition;
46
+ timeout?: number;
47
+ trial?: boolean;
48
+ };
49
+ export type LocatorFocusOptions = {
50
+ timeout?: number;
51
+ };
52
+ export type LocatorBlurOptions = {
53
+ timeout?: number;
54
+ };
55
+ export type LocatorScrollIntoViewIfNeededOptions = {
56
+ timeout?: number;
57
+ };
58
+ export type LocatorWaitForOptions = {
59
+ state?: 'attached' | 'detached' | 'visible' | 'hidden';
60
+ timeout?: number;
61
+ };
62
+ export type BrowserSerializable = null | boolean | number | string | BrowserSerializable[] | {
63
+ [key: string]: BrowserSerializable;
64
+ };
65
+ export type LocatorDispatchEventInit = BrowserSerializable;
66
+ export type LocatorSelectOptionOptions = {
67
+ force?: boolean;
68
+ timeout?: number;
69
+ };
70
+ export type LocatorSetInputFilesOptions = {
71
+ timeout?: number;
72
+ };
73
+ export type LocatorFilterOptions = {
74
+ hasText?: string | RegExp;
75
+ hasNotText?: string | RegExp;
76
+ has?: Locator;
77
+ hasNot?: Locator;
78
+ };
79
+ export declare class Locator {
80
+ readonly ir: BrowserLocatorIR;
81
+ constructor(ir: BrowserLocatorIR);
82
+ getByRole(role: string, options?: LocatorGetByRoleOptions): Locator;
83
+ locator(selector: string): Locator;
84
+ getByText(text: string | RegExp, options?: LocatorTextOptions): Locator;
85
+ getByLabel(text: string | RegExp, options?: LocatorTextOptions): Locator;
86
+ getByPlaceholder(text: string | RegExp, options?: LocatorTextOptions): Locator;
87
+ getByAltText(text: string | RegExp, options?: LocatorTextOptions): Locator;
88
+ getByTitle(text: string | RegExp, options?: LocatorTextOptions): Locator;
89
+ getByTestId(text: string | RegExp): Locator;
90
+ filter(options: LocatorFilterOptions): Locator;
91
+ and(other: Locator): Locator;
92
+ or(other: Locator): Locator;
93
+ nth(index: number): Locator;
94
+ first(): Locator;
95
+ last(): Locator;
96
+ click(options?: LocatorClickOptions): Promise<void>;
97
+ dblclick(options?: LocatorDblclickOptions): Promise<void>;
98
+ fill(value: string, options?: LocatorFillOptions): Promise<void>;
99
+ hover(options?: LocatorHoverOptions): Promise<void>;
100
+ press(key: string, options?: LocatorPressOptions): Promise<void>;
101
+ clear(): Promise<void>;
102
+ check(options?: LocatorCheckOptions): Promise<void>;
103
+ uncheck(options?: LocatorCheckOptions): Promise<void>;
104
+ focus(options?: LocatorFocusOptions): Promise<void>;
105
+ blur(options?: LocatorBlurOptions): Promise<void>;
106
+ scrollIntoViewIfNeeded(options?: LocatorScrollIntoViewIfNeededOptions): Promise<void>;
107
+ waitFor(options?: LocatorWaitForOptions): Promise<void>;
108
+ dispatchEvent(type: string, eventInit?: LocatorDispatchEventInit): Promise<void>;
109
+ selectOption(value: string | string[], options?: LocatorSelectOptionOptions): Promise<void>;
110
+ setInputFiles(files: string | string[], options?: LocatorSetInputFilesOptions): Promise<void>;
111
+ private callLocator;
112
+ }
113
+ declare const browserPageQueryMethods: readonly ["locator", "getByRole", "getByText", "getByLabel", "getByPlaceholder", "getByAltText", "getByTitle", "getByTestId"];
114
+ type BrowserPageQueryMethod = (typeof browserPageQueryMethods)[number];
115
+ export type BrowserPage = Pick<Locator, BrowserPageQueryMethod>;
116
+ export declare const page: BrowserPage;
117
+ export declare const isLocator: (value: unknown) => value is Locator;
118
+ /**
119
+ * Configure the attribute used by `getByTestId()` queries.
120
+ * Forwards to the host provider (e.g. Playwright `selectors.setTestIdAttribute()`).
121
+ *
122
+ * @default 'data-testid'
123
+ */
124
+ export declare const setTestIdAttribute: (attribute: string) => Promise<void>;
125
+ export {};
@@ -1,9 +1,3 @@
1
- import type { BrowserHostConfig } from '../protocol';
2
- declare global {
3
- interface Window {
4
- __RSTEST_BROWSER_OPTIONS__?: BrowserHostConfig;
5
- }
6
- }
7
1
  /**
8
2
  * Browser snapshot environment that proxies file operations to the host
9
3
  * via postMessage RPC through the container.
@@ -0,0 +1,12 @@
1
+ import type { Rstest } from '@rstest/core/browser';
2
+ export type HeadlessConcurrencyContext = Pick<Rstest, 'command'> & {
3
+ normalizedConfig: {
4
+ pool: {
5
+ maxWorkers?: string | number;
6
+ };
7
+ };
8
+ };
9
+ export declare const getNumCpus: () => number;
10
+ export declare const parseWorkers: (maxWorkers: string | number, numCpus?: number) => number;
11
+ export declare const resolveDefaultHeadlessWorkers: (command: HeadlessConcurrencyContext["command"], numCpus?: number) => number;
12
+ export declare const getHeadlessConcurrency: (context: HeadlessConcurrencyContext, totalTests: number) => number;
@@ -0,0 +1,34 @@
1
+ import type { Reporter } from '@rstest/core/browser';
2
+ import { HostDispatchRouter } from './dispatchRouter';
3
+ import type { BrowserClientMessage, BrowserDispatchHandler, SnapshotRpcRequest } from './protocol';
4
+ export type HostDispatchRouterOptions = ConstructorParameters<typeof HostDispatchRouter>[0];
5
+ type RunnerPayload<TType extends BrowserClientMessage['type']> = Extract<BrowserClientMessage, {
6
+ type: TType;
7
+ }> extends {
8
+ payload: infer TPayload;
9
+ } ? TPayload : never;
10
+ type ReporterHookArg<THook extends keyof Reporter> = Parameters<NonNullable<Reporter[THook]>>[0];
11
+ type RunnerDispatchFileReadyPayload = ReporterHookArg<'onTestFileReady'>;
12
+ type RunnerDispatchSuiteStartPayload = ReporterHookArg<'onTestSuiteStart'>;
13
+ type RunnerDispatchSuiteResultPayload = ReporterHookArg<'onTestSuiteResult'>;
14
+ type RunnerDispatchCaseStartPayload = ReporterHookArg<'onTestCaseStart'>;
15
+ export type RunnerDispatchCallbacks = {
16
+ onTestFileStart: (payload: RunnerPayload<'file-start'>) => Promise<void>;
17
+ onTestFileReady: (payload: RunnerDispatchFileReadyPayload) => Promise<void>;
18
+ onTestSuiteStart: (payload: RunnerDispatchSuiteStartPayload) => Promise<void>;
19
+ onTestSuiteResult: (payload: RunnerDispatchSuiteResultPayload) => Promise<void>;
20
+ onTestCaseStart: (payload: RunnerDispatchCaseStartPayload) => Promise<void>;
21
+ onTestCaseResult: (payload: RunnerPayload<'case-result'>) => Promise<void>;
22
+ onTestFileComplete: (payload: RunnerPayload<'file-complete'>) => Promise<void>;
23
+ onLog: (payload: RunnerPayload<'log'>) => Promise<void>;
24
+ onFatal: (payload: RunnerPayload<'fatal'>) => Promise<void>;
25
+ };
26
+ type CreateHostDispatchRouterOptions = {
27
+ routerOptions?: HostDispatchRouterOptions;
28
+ runnerCallbacks: RunnerDispatchCallbacks;
29
+ runSnapshotRpc: (request: SnapshotRpcRequest) => Promise<unknown>;
30
+ extensionHandlers?: Map<string, BrowserDispatchHandler>;
31
+ onDuplicateNamespace?: (namespace: string) => void;
32
+ };
33
+ export declare const createHostDispatchRouter: ({ routerOptions, runnerCallbacks, runSnapshotRpc, extensionHandlers, onDuplicateNamespace, }: CreateHostDispatchRouterOptions) => HostDispatchRouter;
34
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { BrowserDispatchRequest, BrowserDispatchResponse } from './protocol';
2
+ type DispatchHandler = (request: BrowserDispatchRequest) => Promise<unknown>;
3
+ type HostDispatchRouterOptions = {
4
+ isRunTokenStale?: (runToken: number) => boolean;
5
+ onStale?: (request: BrowserDispatchRequest) => void;
6
+ };
7
+ /**
8
+ * Host-side routing layer for dispatch envelopes.
9
+ * Capabilities are registered by namespace, while routing stays transport-agnostic.
10
+ */
11
+ export declare class HostDispatchRouter {
12
+ private handlers;
13
+ private options;
14
+ constructor(options?: HostDispatchRouterOptions);
15
+ register(namespace: string, handler: DispatchHandler): void;
16
+ unregister(namespace: string): void;
17
+ has(namespace: string): boolean;
18
+ dispatch(request: BrowserDispatchRequest): Promise<BrowserDispatchResponse>;
19
+ }
20
+ export {};
@@ -0,0 +1,19 @@
1
+ export type HeadlessLatestRerunScheduler<TFile> = {
2
+ enqueueLatest: (files: TFile[]) => Promise<void>;
3
+ whenIdle: () => Promise<void>;
4
+ };
5
+ type HeadlessLatestRerunSchedulerOptions<TFile, TRun> = {
6
+ getActiveRun: () => TRun | null;
7
+ isRunCancelled: (run: TRun) => boolean;
8
+ invalidateActiveRun: () => void;
9
+ interruptActiveRun: (run: TRun) => Promise<void>;
10
+ runFiles: (files: TFile[]) => Promise<void>;
11
+ onError?: (error: unknown) => Promise<void> | void;
12
+ onInterrupt?: (run: TRun) => void;
13
+ };
14
+ /**
15
+ * Latest-only rerun scheduler for headless watch mode.
16
+ * Keeps only the newest pending payload and interrupts active run generations.
17
+ */
18
+ export declare const createHeadlessLatestRerunScheduler: <TFile, TRun>(options: HeadlessLatestRerunSchedulerOptions<TFile, TRun>) => HeadlessLatestRerunScheduler<TFile>;
19
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { BrowserClientMessage, BrowserDispatchRequest, BrowserDispatchResponse } from './protocol';
2
+ import type { BrowserProviderPage } from './providers';
3
+ type HeadlessRunnerTransportHandlers = {
4
+ onDispatchMessage: (message: BrowserClientMessage) => Promise<void>;
5
+ onDispatchRpc: (request: BrowserDispatchRequest) => Promise<BrowserDispatchResponse>;
6
+ };
7
+ /**
8
+ * Headless transport adapter.
9
+ * This only binds page bridge functions and delegates all scheduling decisions upstream.
10
+ */
11
+ export declare const attachHeadlessRunnerTransport: (page: BrowserProviderPage, handlers: HeadlessRunnerTransportHandlers) => Promise<void>;
12
+ export {};