@rstest/core 0.7.9 → 0.8.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.
@@ -299,20 +299,14 @@ declare type BrowserModeConfig = {
299
299
  * Browser provider to use for running tests.
300
300
  *
301
301
  * Currently only 'playwright' is supported.
302
- *
303
- * @default 'playwright'
304
302
  */
305
- provider?: 'playwright';
303
+ provider: 'playwright';
306
304
  /**
307
305
  * Which browser to use for testing.
308
306
  *
309
- * - `chromium` - Google Chrome, Microsoft Edge
310
- * - `firefox` - Mozilla Firefox
311
- * - `webkit` - Safari
312
- *
313
307
  * @default 'chromium'
314
308
  */
315
- browser?: 'chromium' | 'firefox' | 'webkit';
309
+ browser?: BrowserName;
316
310
  /**
317
311
  * Run browser in headless mode.
318
312
  *
@@ -325,12 +319,28 @@ declare type BrowserModeConfig = {
325
319
  * If not specified, a random available port will be used.
326
320
  */
327
321
  port?: number;
322
+ /**
323
+ * Whether to exit if the specified port is already in use.
324
+ *
325
+ * @default false
326
+ */
327
+ strictPort?: boolean;
328
328
  };
329
329
 
330
+ /**
331
+ * Supported browser types for browser mode testing.
332
+ *
333
+ * - `chromium` - Google Chrome, Microsoft Edge
334
+ * - `firefox` - Mozilla Firefox
335
+ * - `webkit` - Safari
336
+ */
337
+ declare type BrowserName = 'chromium' | 'firefox' | 'webkit';
338
+
330
339
  declare type BuiltInReporterNames = keyof typeof reportersMap;
331
340
 
332
341
  declare type BuiltinReporterOptions = {
333
342
  default: DefaultReporterOptions;
343
+ verbose: VerboseReporterOptions;
334
344
  };
335
345
 
336
346
  declare type ChaiConfig = Partial<Omit<typeof config, 'useProxy' | 'proxyExcludedKeys' | 'deepEqual'>>;
@@ -339,6 +349,8 @@ declare interface CloverOptions extends FileOptions, ProjectOptions {}
339
349
 
340
350
  declare interface CoberturaOptions extends FileOptions, ProjectOptions {}
341
351
 
352
+ declare type Constructor<T = any> = new (...args: any[]) => T;
353
+
342
354
  /**
343
355
  * Base class for writing content
344
356
  */
@@ -588,6 +600,12 @@ declare class DefaultReporter implements Reporter {
588
600
  options: DefaultReporterOptions;
589
601
  testState: RstestTestState;
590
602
  });
603
+ /**
604
+ * Lazily create StatusRenderer on first test file start.
605
+ * This avoids intercepting stdout/stderr before tests actually begin,
606
+ * ensuring early errors (like missing Playwright browsers) remain visible.
607
+ */
608
+ private ensureStatusRenderer;
591
609
  onTestFileStart(): void;
592
610
  onTestFileResult(test: TestFileResult): void;
593
611
  onTestCaseResult(): void;
@@ -615,6 +633,11 @@ declare type DefaultReporterOptions = {
615
633
  * @default process.stdout/process.stderr
616
634
  */
617
635
  logger?: Options['logger'];
636
+ /**
637
+ * prints out project name in test file title
638
+ * show project name by default when running multiple projects
639
+ */
640
+ showProjectName?: boolean;
618
641
  };
619
642
 
620
643
  export declare const describe: Rstest['describe'];
@@ -702,9 +725,9 @@ declare interface ExpectStatic_2 extends Chai.ExpectStatic, Matchers, Asymmetric
702
725
  not: AsymmetricMatchersContaining;
703
726
  }
704
727
 
705
- declare type ExtendConfig = Omit<RstestConfig, 'projects'>;
728
+ declare type ExtendConfig = Omit<LooseRstestConfig, 'projects'>;
706
729
 
707
- declare type ExtendConfigFn = (userConfig: Readonly<RstestConfig>) => MaybePromise<ExtendConfig>;
730
+ declare type ExtendConfigFn = (userConfig: Readonly<LooseRstestConfig>) => MaybePromise<ExtendConfig>;
708
731
 
709
732
  /**
710
733
  * Names of clock methods that may be faked by install.
@@ -1362,6 +1385,10 @@ declare interface Location_3 {
1362
1385
  column: number;
1363
1386
  }
1364
1387
 
1388
+ declare type LooseRstestConfig = Omit<RstestConfig, 'reporters'> & {
1389
+ reporters?: any;
1390
+ };
1391
+
1365
1392
  declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
1366
1393
 
1367
1394
  declare interface MatcherHintOptions {
@@ -1412,8 +1439,18 @@ declare interface MatcherState_2 extends MatcherState {
1412
1439
  snapshotState: SnapshotState;
1413
1440
  }
1414
1441
 
1442
+ declare type MaybeMockedDeep<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
1443
+
1444
+ declare type MaybePartiallyMocked<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
1445
+
1446
+ declare type MaybePartiallyMockedDeep<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
1447
+
1415
1448
  declare type MaybePromise<T> = T | Promise<T>;
1416
1449
 
1450
+ declare type Methods<T> = {
1451
+ [K in keyof T]: T[K] extends MockProcedure ? K : never;
1452
+ }[keyof T];
1453
+
1417
1454
  export declare interface Mock<T extends FunctionLike = FunctionLike> extends MockInstance_2<T> {
1418
1455
  new (...args: Parameters<T>): ReturnType<T>;
1419
1456
  (...args: Parameters<T>): ReturnType<T>;
@@ -1453,6 +1490,31 @@ declare type MockContext<T extends FunctionLike = FunctionLike> = {
1453
1490
  settledResults: MockSettledResult<Awaited<ReturnType<T>>>[];
1454
1491
  };
1455
1492
 
1493
+ export declare type Mocked<T> = T extends Constructor ? MockedClass<T> : T extends MockProcedure ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
1494
+
1495
+ declare type MockedClass<T extends Constructor> = Mock<(...args: ConstructorParameters<T>) => InstanceType<T>> & {
1496
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
1497
+ prototype: InstanceType<T>;
1498
+ };
1499
+
1500
+ declare type MockedFunction<T extends MockProcedure> = Mock<T> & {
1501
+ [K in keyof T]: T[K];
1502
+ };
1503
+
1504
+ declare type MockedFunctionDeep<T extends MockProcedure> = Mock<T> & MockedObjectDeep<T>;
1505
+
1506
+ declare type MockedObject<T> = {
1507
+ [K in Methods<T>]: T[K] extends MockProcedure ? MockedFunction<T[K]> : T[K];
1508
+ } & {
1509
+ [K in Properties<T>]: T[K];
1510
+ };
1511
+
1512
+ declare type MockedObjectDeep<T> = {
1513
+ [K in Methods<T>]: T[K] extends MockProcedure ? MockedFunctionDeep<T[K]> : T[K];
1514
+ } & {
1515
+ [K in Properties<T>]: MaybeMockedDeep<T[K]>;
1516
+ };
1517
+
1456
1518
  declare type MockFactory<T = unknown> = () => MaybePromise<Partial<T>>;
1457
1519
 
1458
1520
  declare type MockFn = <T extends FunctionLike = FunctionLike>(fn?: T) => Mock<T>;
@@ -1526,6 +1588,37 @@ declare interface MockInstance_2<T extends FunctionLike = FunctionLike> {
1526
1588
  mockRejectedValueOnce(error: unknown): this;
1527
1589
  }
1528
1590
 
1591
+ /**
1592
+ * Options for rs.mock module mocking.
1593
+ * Supports `{ spy: true }` or `{ mock: true }`.
1594
+ */
1595
+ declare type MockModuleOptions = {
1596
+ /**
1597
+ * If `true`, the module will be auto-mocked but the original implementations
1598
+ * will be preserved - all exports will be wrapped in spy functions that track calls.
1599
+ */
1600
+ spy: true;
1601
+ } | {
1602
+ /**
1603
+ * If `true`, the module will be auto-mocked with all exports replaced by mock functions.
1604
+ * Original implementations will NOT be preserved.
1605
+ */
1606
+ mock: true;
1607
+ };
1608
+
1609
+ /**
1610
+ * Options for mockObject
1611
+ */
1612
+ declare interface MockOptions {
1613
+ /**
1614
+ * If `true`, the original implementation will be kept.
1615
+ * All methods will call the original implementation, but you can still track the calls.
1616
+ */
1617
+ spy?: boolean;
1618
+ }
1619
+
1620
+ declare type MockProcedure = (...args: any[]) => any;
1621
+
1529
1622
  declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
1530
1623
 
1531
1624
  declare interface MockResultIncomplete {
@@ -1571,9 +1664,10 @@ declare interface Node_2 {
1571
1664
  declare type NormalizedBrowserModeConfig = {
1572
1665
  enabled: boolean;
1573
1666
  provider: 'playwright';
1574
- browser: 'chromium' | 'firefox' | 'webkit';
1667
+ browser: BrowserName;
1575
1668
  headless: boolean;
1576
1669
  port?: number;
1670
+ strictPort: boolean;
1577
1671
  };
1578
1672
 
1579
1673
  declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'globalSetup' | 'exclude' | 'testEnvironment' | 'browser'>> & Partial<Pick<RstestConfig, OptionalKeys>> & {
@@ -1618,7 +1712,7 @@ export declare const onTestFinished: Rstest['onTestFinished'];
1618
1712
 
1619
1713
  declare type OnTestFinishedHandler = (ctx: TestContext) => MaybePromise<void>;
1620
1714
 
1621
- declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'chaiConfig' | 'resolveSnapshotPath' | 'extends';
1715
+ declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'chaiConfig' | 'hideSkippedTestFiles' | 'resolveSnapshotPath' | 'extends';
1622
1716
 
1623
1717
  declare interface Options {
1624
1718
  logger: {
@@ -1645,7 +1739,7 @@ declare function printWithType<T>(name: string, value: T, print: (value: T) => s
1645
1739
 
1646
1740
  declare type Procedure = (...args: any[]) => any;
1647
1741
 
1648
- declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate' | 'coverage' | 'resolveSnapshotPath' | 'onConsoleLog' | 'hideSkippedTests' | 'bail'>;
1742
+ declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate' | 'coverage' | 'resolveSnapshotPath' | 'onConsoleLog' | 'hideSkippedTests' | 'hideSkippedTestFiles' | 'bail'>;
1649
1743
 
1650
1744
  declare type ProjectContext = {
1651
1745
  name: string;
@@ -1673,6 +1767,10 @@ declare type PromisifyAssertion<T> = Promisify<Assertion_2<T>>;
1673
1767
 
1674
1768
  declare type PromisifyAssertion_2<T> = Promisify_2<Assertion<T>>;
1675
1769
 
1770
+ declare type Properties<T> = {
1771
+ [K in keyof T]: T[K] extends MockProcedure ? never : K;
1772
+ }[keyof T];
1773
+
1676
1774
  declare interface Range_2 {
1677
1775
  start: Location_3;
1678
1776
  end: Location_3;
@@ -1930,6 +2028,12 @@ declare interface RstestConfig {
1930
2028
  * @default false
1931
2029
  */
1932
2030
  hideSkippedTests?: boolean;
2031
+ /**
2032
+ * Hide skipped test files logs.
2033
+ *
2034
+ * @default false
2035
+ */
2036
+ hideSkippedTestFiles?: boolean;
1933
2037
  /**
1934
2038
  * Run only tests with a name that matches the regex.
1935
2039
  */
@@ -2092,6 +2196,74 @@ declare interface RstestUtilities {
2092
2196
  * Determines if the given function is a mocked function.
2093
2197
  */
2094
2198
  isMockFunction: (fn: any) => fn is MockInstance_2;
2199
+ /**
2200
+ * Deeply mocks properties and methods of a given object
2201
+ * in the same way as `rstest.mock()` mocks module exports.
2202
+ *
2203
+ * @example
2204
+ * ```ts
2205
+ * const original = {
2206
+ * simple: () => 'value',
2207
+ * nested: {
2208
+ * method: () => 'real'
2209
+ * },
2210
+ * prop: 'foo',
2211
+ * }
2212
+ *
2213
+ * const mocked = rstest.mockObject(original)
2214
+ * expect(mocked.simple()).toBe(undefined)
2215
+ * expect(mocked.nested.method()).toBe(undefined)
2216
+ * expect(mocked.prop).toBe('foo')
2217
+ *
2218
+ * mocked.simple.mockReturnValue('mocked')
2219
+ * expect(mocked.simple()).toBe('mocked')
2220
+ *
2221
+ * // With spy option to keep original implementations
2222
+ * const spied = rstest.mockObject(original, { spy: true })
2223
+ * expect(spied.simple()).toBe('value')
2224
+ * expect(spied.simple).toHaveBeenCalled()
2225
+ * ```
2226
+ *
2227
+ * @param value - The object to be mocked
2228
+ * @param options - Mock options
2229
+ * @returns A deeply mocked version of the input object
2230
+ */
2231
+ mockObject: <T>(value: T, options?: MockOptions) => MaybeMockedDeep<T>;
2232
+ /**
2233
+ * Type helper for TypeScript. Just returns the object that was passed.
2234
+ *
2235
+ * When `partial` is `true` it will expect a `Partial<T>` as a return value.
2236
+ * By default, this will only make TypeScript believe that the first level values are mocked.
2237
+ * You can pass down `{ deep: true }` as a second argument to tell TypeScript
2238
+ * that the whole object is mocked, if it actually is.
2239
+ *
2240
+ * @example
2241
+ * ```ts
2242
+ * import example from './example.js'
2243
+ *
2244
+ * rstest.mock('./example.js')
2245
+ *
2246
+ * test('1 + 1 equals 10', async () => {
2247
+ * rstest.mocked(example.calc).mockReturnValue(10)
2248
+ * expect(example.calc(1, '+', 1)).toBe(10)
2249
+ * })
2250
+ * ```
2251
+ * @param item - Anything that can be mocked
2252
+ * @returns The same item with mocked type
2253
+ */
2254
+ mocked: (<T>(item: T, deep?: false) => Mocked<T>) & (<T>(item: T, deep: true) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
2255
+ partial?: false;
2256
+ deep?: false;
2257
+ }) => Mocked<T>) & (<T>(item: T, options: {
2258
+ partial?: false;
2259
+ deep: true;
2260
+ }) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
2261
+ partial: true;
2262
+ deep?: false;
2263
+ }) => MaybePartiallyMocked<T>) & (<T>(item: T, options: {
2264
+ partial: true;
2265
+ deep: true;
2266
+ }) => MaybePartiallyMockedDeep<T>);
2095
2267
  /**
2096
2268
  * Calls `.mockClear()` on all spies.
2097
2269
  */
@@ -2105,21 +2277,37 @@ declare interface RstestUtilities {
2105
2277
  */
2106
2278
  restoreAllMocks: () => RstestUtilities;
2107
2279
  /**
2108
- * Mock a module
2280
+ * Mock a module.
2281
+ *
2282
+ * When called with a factory function, the module will be replaced with the return value of the factory.
2283
+ * When called with `{ spy: true }`, the module will be auto-mocked but the original implementations
2284
+ * will be preserved - all exports will be wrapped in spy functions that track calls.
2285
+ *
2286
+ * @example
2287
+ * ```ts
2288
+ * // Replace module with factory
2289
+ * rs.mock('./module', () => ({ fn: rs.fn() }))
2290
+ *
2291
+ * // Auto-mock with spy mode - keeps original implementations
2292
+ * rs.mock('./module', { spy: true })
2293
+ * ```
2109
2294
  */
2110
- mock<T = unknown>(moduleName: string | Promise<T>, moduleFactory?: MockFactory<T>): void;
2295
+ mock<T = unknown>(moduleName: string | Promise<T>, factoryOrOptions?: MockFactory<T> | MockModuleOptions): void;
2111
2296
  /**
2112
- * Mock a module
2297
+ * Mock a module (CommonJS require)
2113
2298
  */
2114
- mockRequire: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
2299
+ mockRequire: <T = unknown>(moduleName: string, factoryOrOptions?: (() => T) | MockModuleOptions) => void;
2115
2300
  /**
2116
2301
  * Mock a module, not hoisted.
2302
+ *
2303
+ * When called with `{ spy: true }`, the module will be auto-mocked but the original implementations
2304
+ * will be preserved - all exports will be wrapped in spy functions that track calls.
2117
2305
  */
2118
- doMock<T = unknown>(moduleName: string | Promise<T>, moduleFactory?: MockFactory<T>): void;
2306
+ doMock<T = unknown>(moduleName: string | Promise<T>, factoryOrOptions?: MockFactory<T> | MockModuleOptions): void;
2119
2307
  /**
2120
- * Mock a module, not hoisted.
2308
+ * Mock a module, not hoisted (CommonJS require).
2121
2309
  */
2122
- doMockRequire: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
2310
+ doMockRequire: <T = unknown>(moduleName: string, factoryOrOptions?: (() => T) | MockModuleOptions) => void;
2123
2311
  /**
2124
2312
  * Hoisted mock function.
2125
2313
  */
@@ -2731,9 +2919,18 @@ declare interface UserConsoleLog {
2731
2919
  }
2732
2920
 
2733
2921
  declare class VerboseReporter extends DefaultReporter {
2922
+ private verboseOptions;
2923
+ constructor({ rootPath, options, config, testState, }: {
2924
+ rootPath: string;
2925
+ config: NormalizedConfig;
2926
+ options: VerboseReporterOptions;
2927
+ testState: RstestTestState;
2928
+ });
2734
2929
  onTestFileResult(test: TestFileResult): void;
2735
2930
  }
2736
2931
 
2932
+ declare type VerboseReporterOptions = Omit<DefaultReporterOptions, 'summary'>;
2933
+
2737
2934
  declare interface Visitor<N extends Node_2 = Node_2> {
2738
2935
  onStart(root: N, state: any): void;
2739
2936
  onSummary(root: N, state: any): void;