@rstest/core 0.0.3 → 0.0.5

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.
@@ -364,19 +364,19 @@ declare interface MockInstance<T extends FunctionLike = FunctionLike> {
364
364
  /**
365
365
  * Returns current mock implementation if there is one.
366
366
  */
367
- getMockImplementation(): T | undefined;
367
+ getMockImplementation(): NormalizedProcedure<T> | undefined;
368
368
  /**
369
369
  * Accepts a function that should be used as the implementation of the mock.
370
370
  */
371
- mockImplementation(fn: T): this;
371
+ mockImplementation(fn: NormalizedProcedure<T>): this;
372
372
  /**
373
373
  * Accepts a function that will be used as an implementation of the mock for one call to the mocked function.
374
374
  */
375
- mockImplementationOnce(fn: T): this;
375
+ mockImplementationOnce(fn: NormalizedProcedure<T>): this;
376
376
  /**
377
377
  * Accepts a function which should be temporarily used as the implementation of the mock while the callback is being executed.
378
378
  */
379
- withImplementation<T2>(fn: T, callback: () => T2): T2 extends Promise<unknown> ? Promise<void> : void;
379
+ withImplementation<T2>(fn: NormalizedProcedure<T>, callback: () => T2): T2 extends Promise<unknown> ? Promise<void> : void;
380
380
  /**
381
381
  * Return the `this` context from the method without invoking the actual implementation.
382
382
  */
@@ -437,16 +437,6 @@ declare interface MockSettledResultFulfilled<T> {
437
437
  value: T;
438
438
  }
439
439
 
440
- declare interface MockSettledResultFulfilled<T> {
441
- type: 'fulfilled';
442
- value: T;
443
- }
444
-
445
- declare interface MockSettledResultRejected {
446
- type: 'rejected';
447
- value: any;
448
- }
449
-
450
440
  declare interface MockSettledResultRejected {
451
441
  type: 'rejected';
452
442
  value: any;
@@ -460,7 +450,11 @@ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool
460
450
  pool: RstestPoolOptions;
461
451
  };
462
452
 
463
- declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'tools' | 'onConsoleLog';
453
+ declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
454
+
455
+ declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
456
+
457
+ declare type Procedure = (...args: any[]) => any;
464
458
 
465
459
  declare type Promisify<O> = {
466
460
  [K in keyof O]: O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K];
@@ -507,6 +501,14 @@ declare const reportersMap: {
507
501
 
508
502
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
509
503
 
504
+ declare type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
505
+
506
+ declare type RoArray<T> = Ro<T>[];
507
+
508
+ declare type RoObject<T> = {
509
+ [K in keyof T]: T[K] | Ro<T[K]>;
510
+ };
511
+
510
512
  export declare const rs: RstestUtilities;
511
513
 
512
514
  declare type Rstest = RunnerAPI & {
@@ -559,7 +561,7 @@ export declare interface RstestConfig {
559
561
  */
560
562
  retry?: number;
561
563
  /**
562
- * Allows the test suite to pass when no files are found.
564
+ * Pass when no tests are found.
563
565
  *
564
566
  * @default false
565
567
  */
@@ -659,7 +661,9 @@ export declare interface RstestConfig {
659
661
  onConsoleLog?: (content: string) => boolean | void;
660
662
  plugins?: RsbuildConfig['plugins'];
661
663
  source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
662
- output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules'>;
664
+ performance?: Pick<NonNullable<RsbuildConfig['performance']>, 'bundleAnalyze'>;
665
+ dev?: Pick<NonNullable<RsbuildConfig['dev']>, 'writeToDisk'>;
666
+ output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules' | 'externals' | 'cleanDistPath'>;
663
667
  resolve?: RsbuildConfig['resolve'];
664
668
  tools?: Pick<NonNullable<RsbuildConfig['tools']>, 'rspack' | 'swc' | 'bundlerChain'>;
665
669
  }
@@ -711,42 +715,46 @@ declare type RstestUtilities = {
711
715
  */
712
716
  restoreAllMocks: () => RstestUtilities;
713
717
  /**
714
- * @todo
715
718
  * Mock a module
716
719
  */
717
720
  mock: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
718
721
  /**
719
- * @todo
722
+ * Mock a module
723
+ */
724
+ mockRequire: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
725
+ /**
720
726
  * Mock a module, not hoisted.
721
727
  */
722
728
  doMock: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
723
729
  /**
724
- * @todo
730
+ * Mock a module, not hoisted.
731
+ */
732
+ doMockRequire: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
733
+ /**
725
734
  * Removes module from the mocked registry.
726
735
  */
727
- unMock: (path: string) => void;
736
+ unmock: (path: string) => void;
728
737
  /**
729
- * @todo
730
738
  * Removes module from the mocked registry, not hoisted.
731
739
  */
732
- doUnMock: (path: string) => void;
740
+ doUnmock: (path: string) => void;
733
741
  /**
734
- * @todo
735
742
  * Imports a module with all of its properties (including nested properties) mocked.
736
743
  */
737
744
  importMock: <T = Record<string, unknown>>(path: string) => Promise<T>;
738
745
  /**
739
- * @todo
746
+ * Imports a module with all of its properties (including nested properties) mocked.
747
+ */
748
+ requireMock: <T = Record<string, unknown>>(path: string) => T;
749
+ /**
740
750
  * Import and return the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
741
751
  */
742
752
  importActual: <T = Record<string, unknown>>(path: string) => Promise<T>;
743
753
  /**
744
- * @todo
745
754
  * Require and return the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
746
755
  */
747
756
  requireActual: <T = Record<string, unknown>>(path: string) => T;
748
757
  /**
749
- * @todo
750
758
  * Resets modules registry by clearing the cache of all modules.
751
759
  */
752
760
  resetModules: () => RstestUtilities;
@@ -904,6 +912,7 @@ declare type TestResult = {
904
912
  parentNames?: string[];
905
913
  duration?: number;
906
914
  errors?: FormattedError[];
915
+ retryCount?: number;
907
916
  };
908
917
 
909
918
  declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
@@ -922,7 +931,7 @@ declare class TraceMap implements SourceMap {
922
931
  private _decodedMemo;
923
932
  private _bySources;
924
933
  private _bySourceMemos;
925
- constructor(map: SourceMapInput, mapUrl?: string | null);
934
+ constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
926
935
  }
927
936
 
928
937
  declare type Use<T> = (value: T) => Promise<void>;
@@ -211,7 +211,7 @@ declare type NormalizedFixture = {
211
211
 
212
212
  declare type NormalizedFixtures = Record<string, NormalizedFixture>;
213
213
 
214
- declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'tools' | 'onConsoleLog';
214
+ declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
215
215
 
216
216
  declare type Promisify<O> = {
217
217
  [K in keyof O]: O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K];
@@ -258,6 +258,14 @@ declare const reportersMap: {
258
258
 
259
259
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
260
260
 
261
+ declare type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
262
+
263
+ declare type RoArray<T> = Ro<T>[];
264
+
265
+ declare type RoObject<T> = {
266
+ [K in keyof T]: T[K] | Ro<T[K]>;
267
+ };
268
+
261
269
  declare type RstestCommand = 'watch' | 'run' | 'list';
262
270
 
263
271
  declare interface RstestConfig {
@@ -301,7 +309,7 @@ declare interface RstestConfig {
301
309
  */
302
310
  retry?: number;
303
311
  /**
304
- * Allows the test suite to pass when no files are found.
312
+ * Pass when no tests are found.
305
313
  *
306
314
  * @default false
307
315
  */
@@ -401,7 +409,9 @@ declare interface RstestConfig {
401
409
  onConsoleLog?: (content: string) => boolean | void;
402
410
  plugins?: RsbuildConfig['plugins'];
403
411
  source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
404
- output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules'>;
412
+ performance?: Pick<NonNullable<RsbuildConfig['performance']>, 'bundleAnalyze'>;
413
+ dev?: Pick<NonNullable<RsbuildConfig['dev']>, 'writeToDisk'>;
414
+ output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules' | 'externals' | 'cleanDistPath'>;
405
415
  resolve?: RsbuildConfig['resolve'];
406
416
  tools?: Pick<NonNullable<RsbuildConfig['tools']>, 'rspack' | 'swc' | 'bundlerChain'>;
407
417
  }
@@ -447,7 +457,7 @@ declare const runInPool: (options: RunWorkerOptions["options"]) => Promise<{
447
457
  } | TestFileResult>;
448
458
  export default runInPool;
449
459
 
450
- declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment'>;
460
+ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate'>;
451
461
 
452
462
  /** Runtime to Server */
453
463
  declare type RuntimeRPC = {
@@ -582,6 +592,7 @@ declare type TestResult = {
582
592
  parentNames?: string[];
583
593
  duration?: number;
584
594
  errors?: FormattedError[];
595
+ retryCount?: number;
585
596
  };
586
597
 
587
598
  declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
@@ -620,7 +631,7 @@ declare class TraceMap implements SourceMap {
620
631
  private _decodedMemo;
621
632
  private _bySources;
622
633
  private _bySourceMemos;
623
- constructor(map: SourceMapInput, mapUrl?: string | null);
634
+ constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
624
635
  }
625
636
 
626
637
  declare type Use<T> = (value: T) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -48,7 +48,7 @@
48
48
  "importMeta.d.ts"
49
49
  ],
50
50
  "dependencies": {
51
- "@rsbuild/core": "1.4.0-rc.0",
51
+ "@rsbuild/core": "1.4.3",
52
52
  "@types/chai": "^5.2.2",
53
53
  "@vitest/expect": "^3.2.4",
54
54
  "@vitest/snapshot": "^3.2.4",
@@ -61,19 +61,19 @@
61
61
  "devDependencies": {
62
62
  "@sinonjs/fake-timers": "^14.0.0",
63
63
  "@babel/code-frame": "^7.27.1",
64
- "@jridgewell/trace-mapping": "0.3.25",
64
+ "@jridgewell/trace-mapping": "0.3.29",
65
65
  "@microsoft/api-extractor": "^7.52.8",
66
- "@rslib/core": "0.10.2",
66
+ "@rslib/core": "0.10.4",
67
67
  "@types/babel__code-frame": "^7.0.6",
68
68
  "@types/sinonjs__fake-timers": "^8.1.5",
69
69
  "@types/jsdom": "^21.1.7",
70
70
  "jsdom": "^26.1.0",
71
71
  "@types/source-map-support": "^0.5.10",
72
72
  "cac": "^6.7.14",
73
- "jest-diff": "^30.0.2",
73
+ "jest-diff": "^30.0.3",
74
74
  "license-webpack-plugin": "^4.0.2",
75
75
  "picocolors": "^1.1.1",
76
- "rslog": "^1.2.8",
76
+ "rslog": "^1.2.9",
77
77
  "source-map-support": "^0.5.21",
78
78
  "stacktrace-parser": "0.1.11",
79
79
  "tinyglobby": "^0.2.14",
@@ -98,6 +98,7 @@
98
98
  },
99
99
  "scripts": {
100
100
  "build": "rslib build",
101
+ "typecheck": "tsc --noEmit",
101
102
  "dev": "rslib build --watch",
102
103
  "test": "npx rstest run --globals"
103
104
  }