@rstest/browser 0.7.9

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/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { Rstest } from '@rstest/core/browser';
2
+ import {
3
+ type ListBrowserTestsResult,
4
+ listBrowserTests as listBrowserTestsImpl,
5
+ runBrowserController,
6
+ } from './hostController';
7
+
8
+ export async function runBrowserTests(context: Rstest): Promise<void> {
9
+ await runBrowserController(context);
10
+ }
11
+
12
+ export async function listBrowserTests(
13
+ context: Rstest,
14
+ ): Promise<ListBrowserTestsResult> {
15
+ return listBrowserTestsImpl(context);
16
+ }
17
+
18
+ export type { ListBrowserTestsResult };
@@ -0,0 +1,41 @@
1
+ declare module '@rstest/browser-manifest' {
2
+ /** Project configuration from manifest */
3
+ export type ManifestProjectConfig = {
4
+ name: string;
5
+ environmentName: string;
6
+ projectRoot: string;
7
+ };
8
+
9
+ /** Test context for a project */
10
+ export type ManifestTestContext = {
11
+ getTestKeys: () => string[];
12
+ loadTest: (key: string) => Promise<unknown>;
13
+ projectRoot: string;
14
+ };
15
+
16
+ /** All projects configuration (multi-project support) */
17
+ export const projects: ManifestProjectConfig[];
18
+
19
+ /** Setup loaders for each project, keyed by project name */
20
+ export const projectSetupLoaders: Record<
21
+ string,
22
+ Array<() => Promise<unknown>>
23
+ >;
24
+
25
+ /** Test contexts for each project, keyed by project name */
26
+ export const projectTestContexts: Record<string, ManifestTestContext>;
27
+
28
+ // Backward compatibility exports (use first project as default)
29
+
30
+ /** @deprecated Use `projects[0]` instead */
31
+ export const projectConfig: ManifestProjectConfig;
32
+
33
+ /** @deprecated Use `projectSetupLoaders[projectName]` instead */
34
+ export const setupLoaders: Array<() => Promise<unknown>>;
35
+
36
+ /** @deprecated Use `projectTestContexts[projectName].getTestKeys()` instead */
37
+ export function getTestKeys(): string[];
38
+
39
+ /** @deprecated Use `projectTestContexts[projectName].loadTest(key)` instead */
40
+ export function loadTest(key: string): Promise<unknown>;
41
+ }
@@ -0,0 +1,132 @@
1
+ import type {
2
+ RuntimeConfig,
3
+ Test,
4
+ TestFileResult,
5
+ TestResult,
6
+ } from '@rstest/core/browser-runtime';
7
+ import type { SnapshotUpdateState } from '@vitest/snapshot';
8
+
9
+ export type SerializedRuntimeConfig = RuntimeConfig;
10
+
11
+ export type BrowserProjectRuntime = {
12
+ name: string;
13
+ environmentName: string;
14
+ projectRoot: string;
15
+ runtimeConfig: SerializedRuntimeConfig;
16
+ };
17
+
18
+ /**
19
+ * Test file info with associated project name.
20
+ * Used to track which project a test file belongs to.
21
+ */
22
+ export type TestFileInfo = {
23
+ testPath: string;
24
+ projectName: string;
25
+ };
26
+
27
+ /**
28
+ * Execution mode for browser tests.
29
+ * - 'run': Execute tests and report results (default)
30
+ * - 'collect': Only collect test metadata without running
31
+ */
32
+ export type BrowserExecutionMode = 'run' | 'collect';
33
+
34
+ export type BrowserHostConfig = {
35
+ rootPath: string;
36
+ projects: BrowserProjectRuntime[];
37
+ snapshot: {
38
+ updateSnapshot: SnapshotUpdateState;
39
+ };
40
+ testFile?: string; // Optional: if provided, only run this specific test file
41
+ /**
42
+ * Base URL for runner (iframe) pages.
43
+ */
44
+ runnerUrl?: string;
45
+ /**
46
+ * WebSocket port for container RPC.
47
+ */
48
+ wsPort?: number;
49
+ /**
50
+ * Execution mode. Defaults to 'run'.
51
+ */
52
+ mode?: BrowserExecutionMode;
53
+ /**
54
+ * Debug mode. When true, enables verbose logging in browser.
55
+ */
56
+ debug?: boolean;
57
+ /**
58
+ * Timeout for RPC operations in milliseconds (e.g., snapshot file operations).
59
+ * Derived from testTimeout config.
60
+ */
61
+ rpcTimeout?: number;
62
+ };
63
+
64
+ export type BrowserClientMessage =
65
+ | { type: 'ready' }
66
+ | {
67
+ type: 'file-start';
68
+ payload: { testPath: string; projectName: string };
69
+ }
70
+ | { type: 'case-result'; payload: TestResult }
71
+ | { type: 'file-complete'; payload: TestFileResult }
72
+ | {
73
+ type: 'log';
74
+ payload: {
75
+ level: 'log' | 'warn' | 'error' | 'info' | 'debug';
76
+ content: string;
77
+ testPath: string;
78
+ type: 'stdout' | 'stderr';
79
+ trace?: string;
80
+ };
81
+ }
82
+ | {
83
+ type: 'fatal';
84
+ payload: { message: string; stack?: string };
85
+ }
86
+ | { type: 'complete' }
87
+ // Collect mode messages
88
+ | {
89
+ type: 'collect-result';
90
+ payload: { testPath: string; project: string; tests: Test[] };
91
+ }
92
+ | { type: 'collect-complete' }
93
+ // Snapshot RPC requests (from runner iframe to container)
94
+ | {
95
+ type: 'snapshot-rpc-request';
96
+ payload: SnapshotRpcRequest;
97
+ };
98
+
99
+ /**
100
+ * Snapshot RPC request from runner iframe.
101
+ * The container will forward these to the host via WebSocket RPC.
102
+ */
103
+ export type SnapshotRpcRequest =
104
+ | {
105
+ id: string;
106
+ method: 'resolveSnapshotPath';
107
+ args: { testPath: string };
108
+ }
109
+ | {
110
+ id: string;
111
+ method: 'readSnapshotFile';
112
+ args: { filepath: string };
113
+ }
114
+ | {
115
+ id: string;
116
+ method: 'saveSnapshotFile';
117
+ args: { filepath: string; content: string };
118
+ }
119
+ | {
120
+ id: string;
121
+ method: 'removeSnapshotFile';
122
+ args: { filepath: string };
123
+ };
124
+
125
+ /**
126
+ * Snapshot RPC response from container to runner iframe.
127
+ */
128
+ export type SnapshotRpcResponse = {
129
+ id: string;
130
+ result?: unknown;
131
+ error?: string;
132
+ };