@rstest/browser 0.11.1 → 0.11.3

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 CHANGED
@@ -2,8 +2,10 @@ import type {
2
2
  BrowserHostModule,
3
3
  BrowserTestRunOptions,
4
4
  BrowserTestRunResult,
5
+ ListBrowserTestsOptions,
5
6
  RstestContext,
6
7
  } from '@rstest/core/internal/browser';
8
+ import { createBrowserExecutor } from './browserExecutor';
7
9
  import { validateBrowserConfig } from './configValidation';
8
10
  import {
9
11
  type ListBrowserTestsResult,
@@ -11,7 +13,7 @@ import {
11
13
  runBrowserController,
12
14
  } from './hostController';
13
15
 
14
- export { validateBrowserConfig };
16
+ export { createBrowserExecutor, validateBrowserConfig };
15
17
 
16
18
  export async function runBrowserTests(
17
19
  context: RstestContext,
@@ -22,7 +24,7 @@ export async function runBrowserTests(
22
24
 
23
25
  export async function listBrowserTests(
24
26
  context: RstestContext,
25
- options?: Pick<BrowserTestRunOptions, 'shardedEntries'>,
27
+ options?: ListBrowserTestsOptions,
26
28
  ): Promise<ListBrowserTestsResult> {
27
29
  // Forward `options` (e.g. `shardedEntries`) so `rstest list --shard` lists
28
30
  // only the current shard's browser test files, matching the run path.
@@ -31,13 +33,15 @@ export async function listBrowserTests(
31
33
 
32
34
  /**
33
35
  * Compile-time guard: ensure the public host exports satisfy the core-owned
34
- * {@link BrowserHostModule} contract. This catches drift such as a dropped
35
- * `options` argument at the load boundary. No runtime side effect.
36
+ * {@link BrowserHostModule} contract (`listBrowserTests` stays a plain public
37
+ * export core lists through `createBrowserExecutor(...).collect()`). This
38
+ * catches drift such as a dropped `options` argument at the load boundary.
39
+ * No runtime side effect.
36
40
  */
37
41
  void ({
38
42
  validateBrowserConfig,
43
+ createBrowserExecutor,
39
44
  runBrowserTests,
40
- listBrowserTests,
41
45
  } satisfies BrowserHostModule);
42
46
 
43
47
  export type {
package/src/protocol.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { BrowserViewport } from '@rstest/core/internal/browser';
2
2
  import type {
3
- RuntimeConfig,
3
+ BrowserRuntimeConfig,
4
4
  TestFileResult,
5
5
  TestInfo,
6
6
  TestResult,
@@ -28,7 +28,7 @@ export const DISPATCH_NAMESPACE_BROWSER = 'browser';
28
28
  export const DISPATCH_NAMESPACE_SNAPSHOT = 'snapshot';
29
29
  export const DISPATCH_METHOD_RPC = 'rpc';
30
30
 
31
- export type SerializedRuntimeConfig = RuntimeConfig;
31
+ export type SerializedRuntimeConfig = BrowserRuntimeConfig;
32
32
 
33
33
  // `BrowserViewport` is a core config type (`@rstest/core` owns the canonical
34
34
  // definition used by `NormalizedBrowserModeConfig`). Re-export it so the host
@@ -1 +0,0 @@
1
- /*! LICENSE: 328.37af068e21.js.LICENSE.txt */
@@ -1,77 +0,0 @@
1
- /** Stringify a single console argument for terminal forwarding. */
2
- export const formatArg = (arg: unknown): string => {
3
- if (arg === null) return 'null';
4
- if (arg === undefined) return 'undefined';
5
- if (typeof arg === 'string') return arg;
6
- if (typeof arg === 'number' || typeof arg === 'boolean') return String(arg);
7
- // `JSON.stringify(symbol)` is `undefined`, so a symbol must be handled before
8
- // the JSON path or it would forward as an empty/`undefined` log.
9
- if (typeof arg === 'symbol') return arg.toString();
10
- if (arg instanceof Error) {
11
- return arg.stack || `${arg.name}: ${arg.message}`;
12
- }
13
- try {
14
- return JSON.stringify(arg, null, 2);
15
- } catch {
16
- return String(arg);
17
- }
18
- };
19
-
20
- // Format specifiers understood by the browser console. `%c` applies CSS in a
21
- // real console; forwarded to a terminal there is no styling, so it is consumed
22
- // and dropped (matching how Node's `util.format` handles it). `%%` is a literal
23
- // percent sign. Kept aligned with the browser console spec (no Node-only `%j`,
24
- // since these logs originate in the browser).
25
- // cspell:ignore sdifo WHATWG
26
- const HAS_SPECIFIER = /%[sdifoOc%]/;
27
- const SPECIFIER = /%[sdifoOc%]/g;
28
-
29
- /**
30
- * Join console arguments the way a console does. When the first argument is a
31
- * string carrying `printf`-style specifiers, substitute the following arguments
32
- * into it (consuming `%c` styles without emitting them), then append any
33
- * leftover arguments. Otherwise fall back to a plain space-join.
34
- *
35
- * Without this, `console.info('%cText', 'font-weight:bold')` (e.g. React's
36
- * DevTools notice) leaks the raw `%c` directive and its CSS argument into the
37
- * forwarded terminal output.
38
- */
39
- export const formatConsoleArgs = (args: unknown[]): string => {
40
- const first = args[0];
41
- if (typeof first !== 'string' || !HAS_SPECIFIER.test(first)) {
42
- return args.map(formatArg).join(' ');
43
- }
44
-
45
- let next = 1;
46
- const substituted = first.replace(SPECIFIER, (spec) => {
47
- if (spec === '%%') return '%';
48
- if (next >= args.length) return spec;
49
- const arg = args[next++];
50
- switch (spec) {
51
- case '%c':
52
- return ''; // CSS directive: swallow the style argument
53
- case '%s':
54
- return formatArg(arg);
55
- case '%d':
56
- case '%i': {
57
- // Match the browser console formatter (WHATWG): parseInt on the value,
58
- // so unit-suffixed strings like '42px' format as 42 (not NaN).
59
- // `String()` first keeps Symbol safe — a bare `parseInt(symbol)` throws
60
- // via ToString, whereas the spec maps a Symbol to NaN.
61
- const num = Number.parseInt(String(arg), 10);
62
- return Number.isNaN(num) ? 'NaN' : String(num);
63
- }
64
- case '%f': {
65
- const num = Number.parseFloat(String(arg));
66
- return Number.isNaN(num) ? 'NaN' : String(num);
67
- }
68
- default: // %o, %O
69
- return formatArg(arg);
70
- }
71
- });
72
-
73
- if (next >= args.length) {
74
- return substituted;
75
- }
76
- return [substituted, ...args.slice(next).map(formatArg)].join(' ');
77
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * Re-export runtime API from @rstest/core/internal/browser-runtime for browser use.
3
- * This file is used as an alias target for '@rstest/core' in browser mode.
4
- *
5
- * Uses @rstest/core/internal/browser-runtime which only exports the test APIs
6
- * (describe, it, expect, etc.) without any Node.js dependencies.
7
- */
8
-
9
- // Re-export types from @rstest/core (these are compile-time only)
10
- export type { Assertion, Mock } from '@rstest/core';
11
- // Re-export all public test APIs
12
- export * from '@rstest/core/internal/browser-runtime';