@rstest/core 0.0.1 → 0.0.2

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.
@@ -187,10 +187,9 @@ export declare interface RstestConfig {
187
187
  /**
188
188
  * The environment that will be used for testing
189
189
  *
190
- * TODO: support more test environments
191
190
  * @default 'node'
192
191
  */
193
- testEnvironment?: 'node';
192
+ testEnvironment?: 'node' | 'jsdom';
194
193
  /**
195
194
  * print console traces when calling any console method.
196
195
  *
@@ -197,6 +197,62 @@ declare interface ExpectStatic extends ExpectStatic_2 {
197
197
  setState: (state: Partial<MatcherState>) => void;
198
198
  }
199
199
 
200
+ /**
201
+ * Names of clock methods that may be faked by install.
202
+ */
203
+ declare type FakeMethod =
204
+ | "setTimeout"
205
+ | "clearTimeout"
206
+ | "setImmediate"
207
+ | "clearImmediate"
208
+ | "setInterval"
209
+ | "clearInterval"
210
+ | "Date"
211
+ | "nextTick"
212
+ | "hrtime"
213
+ | "requestAnimationFrame"
214
+ | "cancelAnimationFrame"
215
+ | "requestIdleCallback"
216
+ | "cancelIdleCallback"
217
+ | "performance"
218
+ | "queueMicrotask";
219
+
220
+ declare interface FakeTimerInstallOpts {
221
+ /**
222
+ * Installs fake timers with the specified unix epoch (default: 0)
223
+ */
224
+ now?: number | Date | undefined;
225
+
226
+ /**
227
+ * An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
228
+ * For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
229
+ */
230
+ toFake?: FakeMethod[] | undefined;
231
+
232
+ /**
233
+ * The maximum number of timers that will be run when calling runAll() (default: 1000)
234
+ */
235
+ loopLimit?: number | undefined;
236
+
237
+ /**
238
+ * Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
239
+ * 20ms for every 20ms change in the real system time) (default: false)
240
+ */
241
+ shouldAdvanceTime?: boolean | undefined;
242
+
243
+ /**
244
+ * Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
245
+ * in the real system time (default: 20)
246
+ */
247
+ advanceTimeDelta?: number | undefined;
248
+
249
+ /**
250
+ * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
251
+ * default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
252
+ */
253
+ shouldClearNativeTimers?: boolean | undefined;
254
+ }
255
+
200
256
  declare type Fixture<T, K extends keyof T, ExtraContext = object> = ((...args: any) => any) extends T[K] ? T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
201
257
 
202
258
  declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
@@ -451,10 +507,13 @@ declare const reportersMap: {
451
507
 
452
508
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
453
509
 
510
+ export declare const rs: RstestUtilities;
511
+
454
512
  declare type Rstest = RunnerAPI & {
455
513
  expect: RstestExpect;
456
514
  assert: typeof assert_2;
457
515
  rstest: RstestUtilities;
516
+ rs: RstestUtilities;
458
517
  };
459
518
 
460
519
  export declare const rstest: RstestUtilities;
@@ -524,10 +583,9 @@ export declare interface RstestConfig {
524
583
  /**
525
584
  * The environment that will be used for testing
526
585
  *
527
- * TODO: support more test environments
528
586
  * @default 'node'
529
587
  */
530
- testEnvironment?: 'node';
588
+ testEnvironment?: 'node' | 'jsdom';
531
589
  /**
532
590
  * print console traces when calling any console method.
533
591
  *
@@ -679,9 +737,14 @@ declare type RstestUtilities = {
679
737
  importMock: <T = Record<string, unknown>>(path: string) => Promise<T>;
680
738
  /**
681
739
  * @todo
682
- * Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
740
+ * Import and return the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
683
741
  */
684
742
  importActual: <T = Record<string, unknown>>(path: string) => Promise<T>;
743
+ /**
744
+ * @todo
745
+ * 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
+ */
747
+ requireActual: <T = Record<string, unknown>>(path: string) => T;
685
748
  /**
686
749
  * @todo
687
750
  * Resets modules registry by clearing the cache of all modules.
@@ -703,6 +766,35 @@ declare type RstestUtilities = {
703
766
  * Restores all global variables that were changed with `rstest.stubGlobal`.
704
767
  */
705
768
  unstubAllGlobals: () => RstestUtilities;
769
+ /**
770
+ * Mocks timers using `@sinonjs/fake-timers`.
771
+ */
772
+ useFakeTimers: (config?: FakeTimerInstallOpts) => RstestUtilities;
773
+ useRealTimers: () => RstestUtilities;
774
+ isFakeTimers: () => boolean;
775
+ /**
776
+ * Set the current system time used by fake timers.
777
+ */
778
+ setSystemTime: (now?: number | Date) => RstestUtilities;
779
+ getRealSystemTime: () => number;
780
+ runAllTicks: () => RstestUtilities;
781
+ runAllTimers: () => RstestUtilities;
782
+ runAllTimersAsync: () => Promise<RstestUtilities>;
783
+ runOnlyPendingTimers: () => RstestUtilities;
784
+ runOnlyPendingTimersAsync: () => Promise<RstestUtilities>;
785
+ advanceTimersByTime: (ms: number) => RstestUtilities;
786
+ advanceTimersByTimeAsync: (ms: number) => Promise<RstestUtilities>;
787
+ advanceTimersToNextTimer: (steps?: number) => RstestUtilities;
788
+ advanceTimersToNextTimerAsync: (steps?: number) => Promise<RstestUtilities>;
789
+ advanceTimersToNextFrame: () => RstestUtilities;
790
+ /**
791
+ * Returns the number of fake timers still left to run.
792
+ */
793
+ getTimerCount: () => number;
794
+ /**
795
+ * Removes all timers that are scheduled to run.
796
+ */
797
+ clearAllTimers: () => RstestUtilities;
706
798
  };
707
799
 
708
800
  declare type RunnerAPI = {
@@ -325,10 +325,9 @@ declare interface RstestConfig {
325
325
  /**
326
326
  * The environment that will be used for testing
327
327
  *
328
- * TODO: support more test environments
329
328
  * @default 'node'
330
329
  */
331
- testEnvironment?: 'node';
330
+ testEnvironment?: 'node' | 'jsdom';
332
331
  /**
333
332
  * print console traces when calling any console method.
334
333
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -10,10 +10,16 @@
10
10
  "url": "https://github.com/web-infra-dev/rstest",
11
11
  "directory": "packages/core"
12
12
  },
13
+ "keywords": [
14
+ "rstest",
15
+ "test",
16
+ "rstack",
17
+ "rspack"
18
+ ],
13
19
  "license": "MIT",
14
20
  "type": "module",
15
- "main": "./dist/index.js",
16
- "types": "./dist-types/index.d.ts",
21
+ "main": "./dist/public.js",
22
+ "types": "./dist-types/public.d.ts",
17
23
  "bin": {
18
24
  "rstest": "./bin/rstest.js"
19
25
  },
@@ -42,33 +48,46 @@
42
48
  "importMeta.d.ts"
43
49
  ],
44
50
  "dependencies": {
45
- "@rsbuild/core": "^1.4.0-beta.2",
46
- "@vitest/expect": "^3.2.3",
47
- "@vitest/snapshot": "^3.2.3",
51
+ "@rsbuild/core": "^1.4.0-beta.5",
48
52
  "@types/chai": "^5.2.2",
49
- "birpc": "2.3.0",
53
+ "@vitest/expect": "^3.2.4",
54
+ "@vitest/snapshot": "^3.2.4",
55
+ "birpc": "2.4.0",
50
56
  "chai": "^5.2.0",
51
57
  "pathe": "^2.0.3",
52
58
  "std-env": "^3.9.0",
53
- "tinypool": "^1.1.0"
59
+ "tinypool": "^1.1.1"
54
60
  },
55
61
  "devDependencies": {
62
+ "@sinonjs/fake-timers": "^14.0.0",
56
63
  "@babel/code-frame": "^7.27.1",
57
64
  "@jridgewell/trace-mapping": "0.3.25",
58
65
  "@microsoft/api-extractor": "^7.52.8",
59
- "@rslib/core": "0.9.2",
66
+ "@rslib/core": "0.10.2",
60
67
  "@types/babel__code-frame": "^7.0.6",
68
+ "@types/sinonjs__fake-timers": "^8.1.5",
69
+ "@types/jsdom": "^21.1.7",
70
+ "jsdom": "^26.1.0",
61
71
  "@types/source-map-support": "^0.5.10",
62
72
  "cac": "^6.7.14",
63
- "jest-diff": "^30.0.0",
73
+ "jest-diff": "^30.0.2",
74
+ "license-webpack-plugin": "^4.0.2",
64
75
  "picocolors": "^1.1.1",
65
- "rslog": "^1.2.3",
76
+ "rslog": "^1.2.7",
66
77
  "source-map-support": "^0.5.21",
67
78
  "stacktrace-parser": "0.1.11",
68
79
  "tinyglobby": "^0.2.14",
69
80
  "tinyspy": "^4.0.3",
70
81
  "@rstest/tsconfig": "0.0.1"
71
82
  },
83
+ "peerDependencies": {
84
+ "jsdom": "*"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "jsdom": {
88
+ "optional": true
89
+ }
90
+ },
72
91
  "engines": {
73
92
  "node": ">=18.0.0"
74
93
  },