@rstest/core 0.2.2 → 0.3.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.
@@ -11,7 +11,11 @@ declare function addSerializer(plugin: Plugin_2): void;
11
11
 
12
12
  declare type AfterAllListener = (ctx: SuiteContext) => MaybePromise<void>;
13
13
 
14
- declare type AfterEachListener = () => MaybePromise<void>;
14
+ declare type AfterEachListener = (params: {
15
+ task: {
16
+ result: Readonly<TestResult>;
17
+ };
18
+ }) => MaybePromise<void>;
15
19
 
16
20
  declare interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, Matchers<T> {
17
21
  /**
@@ -375,12 +379,13 @@ declare class DefaultReporter implements Reporter {
375
379
  onTestCaseResult(_result: TestResult): void;
376
380
  onUserConsoleLog(log: UserConsoleLog): void;
377
381
  onExit(): Promise<void>;
378
- onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
382
+ onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths, }: {
379
383
  results: TestFileResult[];
380
384
  testResults: TestResult[];
381
385
  duration: Duration;
382
386
  snapshotSummary: SnapshotSummary;
383
387
  getSourcemap: GetSourcemap;
388
+ filterRerunTestPaths?: string[];
384
389
  }): Promise<void>;
385
390
  }
386
391
 
@@ -392,6 +397,27 @@ declare type DefaultReporterOptions = {
392
397
  summary?: boolean;
393
398
  };
394
399
 
400
+ declare type DescribeAPI = DescribeFn & {
401
+ each: DescribeEachFn;
402
+ for: DescribeForFn;
403
+ only: DescribeAPI;
404
+ skip: DescribeAPI;
405
+ runIf: (condition: boolean) => DescribeAPI;
406
+ skipIf: (condition: boolean) => DescribeAPI;
407
+ todo: DescribeAPI;
408
+ concurrent: DescribeAPI;
409
+ sequential: DescribeAPI;
410
+ };
411
+
412
+ declare interface DescribeEachFn {
413
+ <T extends Record<string, unknown>>(cases: readonly T[]): (description: string, fn?: (param: T) => MaybePromise<void>) => void;
414
+ <T extends readonly [unknown, ...unknown[]]>(cases: readonly T[]): (description: string, fn: (...args: [...T]) => MaybePromise<void>) => void;
415
+ }
416
+
417
+ declare type DescribeFn = (description: string, fn?: () => void) => void;
418
+
419
+ declare type DescribeForFn = <T>(cases: readonly T[]) => (description: string, fn?: (param: T) => MaybePromise<void>) => void;
420
+
395
421
  /**
396
422
  * @param a Expected value
397
423
  * @param b Received value
@@ -452,6 +478,7 @@ declare type EncodedSourceMapXInput = EncodedSourceMap & XInput;
452
478
 
453
479
  declare type EntryInfo = {
454
480
  distPath: DistPath;
481
+ chunks: (string | number)[];
455
482
  testPath: TestPath;
456
483
  files?: string[];
457
484
  };
@@ -493,6 +520,8 @@ declare interface ExpectStatic_2 extends Chai.ExpectStatic, Matchers, Asymmetric
493
520
  not: AsymmetricMatchersContaining;
494
521
  }
495
522
 
523
+ 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);
524
+
496
525
  declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
497
526
 
498
527
  declare interface FixtureOptions {
@@ -502,6 +531,10 @@ declare interface FixtureOptions {
502
531
  auto?: boolean;
503
532
  }
504
533
 
534
+ declare type Fixtures<T extends Record<string, any> = object, ExtraContext = object> = {
535
+ [K in keyof T]: Fixture<T, K, ExtraContext & TestContext> | [Fixture<T, K, ExtraContext & TestContext>, FixtureOptions?];
536
+ };
537
+
505
538
  declare type FormattedError = {
506
539
  fullStack?: boolean;
507
540
  message: string;
@@ -550,6 +583,7 @@ declare class GithubActionsReporter {
550
583
  duration: Duration;
551
584
  snapshotSummary: SnapshotSummary;
552
585
  getSourcemap: GetSourcemap;
586
+ filterRerunTestPaths?: string[];
553
587
  }): Promise<void>;
554
588
  }
555
589
 
@@ -1307,7 +1341,7 @@ declare interface NewPlugin {
1307
1341
  test: Test;
1308
1342
  }
1309
1343
 
1310
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool'>> & {
1344
+ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects'>> & {
1311
1345
  [key in OptionalKeys]?: RstestConfig[key];
1312
1346
  } & {
1313
1347
  pool: RstestPoolOptions;
@@ -1324,11 +1358,27 @@ declare type NormalizedFixtures = Record<string, NormalizedFixture>;
1324
1358
 
1325
1359
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1326
1360
 
1361
+ declare type NormalizedProjectConfig = Required<Omit<RstestConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
1362
+ [key in OptionalKeys]?: RstestConfig[key];
1363
+ };
1364
+
1327
1365
  declare interface OldPlugin {
1328
1366
  print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
1329
1367
  test: Test;
1330
1368
  }
1331
1369
 
1370
+ declare type OnTestFailedHandler = (params: {
1371
+ task: {
1372
+ result: Readonly<TestResult>;
1373
+ };
1374
+ }) => MaybePromise<void>;
1375
+
1376
+ declare type OnTestFinishedHandler = (params: {
1377
+ task: {
1378
+ result: Readonly<TestResult>;
1379
+ };
1380
+ }) => MaybePromise<void>;
1381
+
1332
1382
  declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1333
1383
 
1334
1384
  declare type OptionsReceived = PrettyFormatOptions;
@@ -1379,6 +1429,16 @@ declare function printWithType<T>(name: string, value: T, print: (value: T) => s
1379
1429
 
1380
1430
  declare type Procedure = (...args: any[]) => any;
1381
1431
 
1432
+ declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate'>;
1433
+
1434
+ declare type ProjectContext = {
1435
+ name: string;
1436
+ environmentName: string;
1437
+ rootPath: string;
1438
+ configFilePath?: string;
1439
+ normalizedConfig: NormalizedProjectConfig;
1440
+ };
1441
+
1382
1442
  declare type Promisify<O> = { [K in keyof O] : O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
1383
1443
 
1384
1444
  declare type Promisify_2<O> = {
@@ -1426,6 +1486,7 @@ declare interface Reporter {
1426
1486
  duration: Duration;
1427
1487
  getSourcemap: GetSourcemap;
1428
1488
  snapshotSummary: SnapshotSummary;
1489
+ filterRerunTestPaths?: string[];
1429
1490
  }) => MaybePromise<void>;
1430
1491
  /**
1431
1492
  * Called when console log is calling.
@@ -1462,6 +1523,10 @@ declare interface RstestConfig {
1462
1523
  * @default process.cwd()
1463
1524
  */
1464
1525
  root?: string;
1526
+ /**
1527
+ * Run tests from one or more projects.
1528
+ */
1529
+ projects?: TestProject[];
1465
1530
  /**
1466
1531
  * Project name
1467
1532
  *
@@ -1621,6 +1686,10 @@ declare type RstestContext = {
1621
1686
  fileFilters?: string[];
1622
1687
  /** The config file path. */
1623
1688
  configFilePath?: string;
1689
+ /**
1690
+ * Run tests from one or more projects.
1691
+ */
1692
+ projects: ProjectContext[];
1624
1693
  /**
1625
1694
  * The command type.
1626
1695
  *
@@ -1653,6 +1722,18 @@ declare const runInPool: (options: RunWorkerOptions["options"]) => Promise<{
1653
1722
  } | TestFileResult>;
1654
1723
  export default runInPool;
1655
1724
 
1725
+ declare type RunnerAPI = {
1726
+ describe: DescribeAPI;
1727
+ it: TestAPIs;
1728
+ test: TestAPIs;
1729
+ beforeAll: (fn: BeforeAllListener, timeout?: number) => MaybePromise<void>;
1730
+ afterAll: (fn: AfterAllListener, timeout?: number) => MaybePromise<void>;
1731
+ beforeEach: (fn: BeforeEachListener, timeout?: number) => MaybePromise<void>;
1732
+ afterEach: (fn: AfterEachListener, timeout?: number) => MaybePromise<void>;
1733
+ onTestFinished: (fn: OnTestFinishedHandler, timeout?: number) => void;
1734
+ onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
1735
+ };
1736
+
1656
1737
  declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout'>;
1657
1738
 
1658
1739
  /** Runtime to Server */
@@ -1893,6 +1974,27 @@ declare type Test = (arg0: any) => boolean;
1893
1974
 
1894
1975
  declare type Test_2 = TestSuite | TestCase;
1895
1976
 
1977
+ declare type TestAPI<ExtraContext = object> = TestFn<ExtraContext> & {
1978
+ each: TestEachFn;
1979
+ for: TestForFn<ExtraContext>;
1980
+ fails: TestAPI<ExtraContext>;
1981
+ concurrent: TestAPI<ExtraContext>;
1982
+ sequential: TestAPI<ExtraContext>;
1983
+ only: TestAPI<ExtraContext>;
1984
+ skip: TestAPI<ExtraContext>;
1985
+ todo: TestAPI<ExtraContext>;
1986
+ runIf: (condition: boolean) => TestAPI<ExtraContext>;
1987
+ skipIf: (condition: boolean) => TestAPI<ExtraContext>;
1988
+ };
1989
+
1990
+ declare type TestAPIs<ExtraContext = object> = TestAPI<ExtraContext> & {
1991
+ extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPIs<{
1992
+ [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
1993
+ }>;
1994
+ };
1995
+
1996
+ declare type TestCallbackFn<ExtraContext = object> = (context: TestContext & ExtraContext) => MaybePromise<void>;
1997
+
1896
1998
  declare type TestCase = {
1897
1999
  testPath: TestPath;
1898
2000
  name: string;
@@ -1908,7 +2010,8 @@ declare type TestCase = {
1908
2010
  inTestEach?: boolean;
1909
2011
  context: TestContext;
1910
2012
  only?: boolean;
1911
- onFinished?: any[];
2013
+ onFinished: OnTestFinishedHandler[];
2014
+ onFailed: OnTestFailedHandler[];
1912
2015
  type: 'case';
1913
2016
  parentNames?: string[];
1914
2017
  /**
@@ -1919,12 +2022,20 @@ declare type TestCase = {
1919
2022
  * Result of the task. if `expect.soft()` failed multiple times or `retry` was triggered.
1920
2023
  */
1921
2024
  result?: TaskResult;
2025
+ project: string;
1922
2026
  };
1923
2027
 
1924
2028
  declare type TestContext = {
1925
2029
  expect: RstestExpect;
2030
+ onTestFinished: RunnerAPI['onTestFinished'];
2031
+ onTestFailed: RunnerAPI['onTestFailed'];
1926
2032
  };
1927
2033
 
2034
+ declare interface TestEachFn {
2035
+ <T extends Record<string, unknown>>(cases: readonly T[]): (description: string, fn?: (param: T) => MaybePromise<void>, timeout?: number) => void;
2036
+ <T extends readonly [unknown, ...unknown[]]>(cases: readonly T[]): (description: string, fn: (...args: [...T]) => MaybePromise<void>, timeout?: number) => void;
2037
+ }
2038
+
1928
2039
  declare type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
1929
2040
 
1930
2041
  declare interface TesterContext {
@@ -1940,9 +2051,20 @@ declare type TestFileResult = TestResult & {
1940
2051
  snapshotResult?: SnapshotResult;
1941
2052
  };
1942
2053
 
2054
+ declare type TestFn<ExtraContext = object> = (description: string, fn?: TestCallbackFn<ExtraContext>, timeout?: number) => void;
2055
+
2056
+ declare type TestForFn<ExtraContext = object> = <T>(cases: readonly T[]) => (description: string, fn?: (param: T, context: TestContext & ExtraContext) => MaybePromise<void>, timeout?: number) => void;
2057
+
1943
2058
  /** The test file original path */
1944
2059
  declare type TestPath = string;
1945
2060
 
2061
+ /**
2062
+ * A list of glob patterns or files that match your test projects.
2063
+ *
2064
+ * eg. ['packages/*', 'examples/node/rstest.config.ts']
2065
+ */
2066
+ declare type TestProject = string | ProjectConfig;
2067
+
1946
2068
  declare type TestResult = {
1947
2069
  status: TestResultStatus;
1948
2070
  name: string;
@@ -1951,6 +2073,7 @@ declare type TestResult = {
1951
2073
  duration?: number;
1952
2074
  errors?: FormattedError[];
1953
2075
  retryCount?: number;
2076
+ project: string;
1954
2077
  };
1955
2078
 
1956
2079
  declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
@@ -1966,6 +2089,7 @@ declare type TestSuite = {
1966
2089
  concurrent?: boolean;
1967
2090
  sequential?: boolean;
1968
2091
  testPath: TestPath;
2092
+ project: string;
1969
2093
  /** nested cases and suite could in a suite */
1970
2094
  tests: (TestSuite | TestCase)[];
1971
2095
  type: 'suite';
@@ -2020,6 +2144,7 @@ declare type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
2020
2144
 
2021
2145
  declare type WorkerContext = {
2022
2146
  rootPath: RstestContext['rootPath'];
2147
+ project: string;
2023
2148
  runtimeConfig: RuntimeConfig;
2024
2149
  };
2025
2150
 
package/globals.d.ts CHANGED
@@ -8,6 +8,8 @@ declare global {
8
8
  const afterAll: typeof import('@rstest/core')['afterAll'];
9
9
  const beforeEach: typeof import('@rstest/core')['beforeEach'];
10
10
  const afterEach: typeof import('@rstest/core')['afterEach'];
11
+ const onTestFinished: typeof import('@rstest/core')['onTestFinished'];
12
+ const onTestFailed: typeof import('@rstest/core')['onTestFailed'];
11
13
  const rstest: typeof import('@rstest/core')['rstest'];
12
14
  }
13
15
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -44,9 +44,9 @@
44
44
  "importMeta.d.ts"
45
45
  ],
46
46
  "dependencies": {
47
- "chai": "^5.2.1",
47
+ "chai": "^5.3.3",
48
48
  "@types/chai": "^5.2.2",
49
- "@rsbuild/core": "1.5.0-beta.4",
49
+ "@rsbuild/core": "1.5.0",
50
50
  "birpc": "2.5.0",
51
51
  "pathe": "^2.0.3",
52
52
  "std-env": "^3.9.0",
@@ -57,7 +57,7 @@
57
57
  "@vitest/snapshot": "^3.2.4",
58
58
  "@babel/code-frame": "^7.27.1",
59
59
  "@jridgewell/trace-mapping": "0.3.30",
60
- "@microsoft/api-extractor": "^7.52.10",
60
+ "@microsoft/api-extractor": "^7.52.11",
61
61
  "@rslib/core": "0.12.2",
62
62
  "@sinonjs/fake-timers": "^14.0.0",
63
63
  "@types/babel__code-frame": "^7.0.6",