@rstest/core 0.7.2 → 0.7.4

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/dist/worker.d.ts CHANGED
@@ -13,11 +13,7 @@ declare function addSerializer(plugin: Plugin_2): void;
13
13
 
14
14
  declare type AfterAllListener = (ctx: SuiteContext) => MaybePromise<void>;
15
15
 
16
- declare type AfterEachListener = (params: {
17
- task: {
18
- result: Readonly<TestResult>;
19
- };
20
- }) => MaybePromise<void>;
16
+ declare type AfterEachListener = (ctx: TestContext) => MaybePromise<void>;
21
17
 
22
18
  declare interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, Matchers<T> {
23
19
  /**
@@ -246,7 +242,7 @@ declare type AsyncExpectationResult = Promise<SyncExpectationResult>;
246
242
 
247
243
  declare type BeforeAllListener = (ctx: SuiteContext) => MaybePromise<void | AfterAllListener>;
248
244
 
249
- declare type BeforeEachListener = () => MaybePromise<void | AfterEachListener>;
245
+ declare type BeforeEachListener = (ctx: TestContext) => MaybePromise<void | AfterEachListener>;
250
246
 
251
247
  declare interface BranchMapping {
252
248
  loc: Range_2;
@@ -319,6 +315,59 @@ declare interface Constructable {
319
315
  new (...args: any[]): any;
320
316
  }
321
317
 
318
+ /**
319
+ * Base class for writing content
320
+ */
321
+ declare class ContentWriter {
322
+ /**
323
+ * returns the colorized version of a string. Typically,
324
+ * content writers that write to files will return the
325
+ * same string and ones writing to a tty will wrap it in
326
+ * appropriate escape sequences.
327
+ */
328
+ colorize(str: string, clazz?: string): string;
329
+ /**
330
+ * writes a string appended with a newline to the destination
331
+ */
332
+ println(str: string): void;
333
+ /**
334
+ * closes this content writer. Should be called after all writes are complete.
335
+ */
336
+ close(): void;
337
+ }
338
+
339
+ declare interface Context {
340
+ data: any;
341
+ dir: string;
342
+ sourceFinder(filepath: string): string;
343
+ watermarks: Watermarks;
344
+ writer: FileWriter;
345
+ /**
346
+ * returns the coverage class given a coverage
347
+ * types and a percentage value.
348
+ */
349
+ classForPercent(type: keyof Watermarks, value: number): string;
350
+ /**
351
+ * returns the source code for the specified file path or throws if
352
+ * the source could not be found.
353
+ */
354
+ getSource(filepath: string): string;
355
+ getTree(summarizer?: Summarizers): Tree;
356
+ /**
357
+ * returns a full visitor given a partial one.
358
+ */
359
+ getVisitor<N extends Node_2 = Node_2>(visitor: Partial<Visitor<N>>): Visitor<N>;
360
+ /**
361
+ * returns a FileWriter implementation for reporting use. Also available
362
+ * as the `writer` property on the context.
363
+ */
364
+ getWriter(): FileWriter;
365
+ /**
366
+ * returns an XML writer for the supplied content writer
367
+ */
368
+ getXmlWriter(contentWriter: ContentWriter): XmlWriter;
369
+ }
370
+
322
371
  declare class CounterMap<K> extends DefaultMap<K, number> {
323
372
  constructor();
324
373
  // compat for jest-image-snapshot https://github.com/vitest-dev/vitest/issues/7322
@@ -378,7 +427,7 @@ declare type CoverageOptions = {
378
427
  * The reporters to use for coverage collection.
379
428
  * @default ['text', 'html', 'clover', 'json']
380
429
  */
381
- reporters?: (keyof ReportOptions | ReportWithOptions)[];
430
+ reporters?: (keyof ReportOptions | ReportWithOptions | ReportBase)[];
382
431
  /**
383
432
  * The directory to store coverage reports.
384
433
  * @default './coverage'
@@ -497,12 +546,13 @@ declare class DefaultReporter implements Reporter {
497
546
  onTestCaseResult(): void;
498
547
  onUserConsoleLog(log: UserConsoleLog): void;
499
548
  onExit(): Promise<void>;
500
- onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths, }: {
549
+ onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths, unhandledErrors, }: {
501
550
  results: TestFileResult[];
502
551
  testResults: TestResult[];
503
552
  duration: Duration;
504
553
  snapshotSummary: SnapshotSummary;
505
554
  getSourcemap: GetSourcemap;
555
+ unhandledErrors?: Error[];
506
556
  filterRerunTestPaths?: string[];
507
557
  }): Promise<void>;
508
558
  }
@@ -680,6 +730,29 @@ declare interface FileOptions {
680
730
  file: string;
681
731
  }
682
732
 
733
+ /**
734
+ * utility for writing files under a specific directory
735
+ */
736
+ declare class FileWriter {
737
+ constructor(baseDir: string);
738
+ static startCapture(): void;
739
+ static stopCapture(): void;
740
+ static getOutput(): string;
741
+ static resetOutput(): void;
742
+ /**
743
+ * returns a FileWriter that is rooted at the supplied subdirectory
744
+ */
745
+ writeForDir(subdir: string): FileWriter;
746
+ /**
747
+ * copies a file from a source directory to a destination name
748
+ */
749
+ copyFile(source: string, dest: string, header?: string): void;
750
+ /**
751
+ * returns a content writer for writing content to the supplied file.
752
+ */
753
+ writeFile(file: string | null): ContentWriter;
754
+ }
755
+
683
756
  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);
684
757
 
685
758
  declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
@@ -1213,7 +1286,12 @@ declare interface LinkMapper {
1213
1286
  assetPath(node: Node_2, name: string): string;
1214
1287
  }
1215
1288
 
1216
- declare interface Location_2 {
1289
+ declare type Location_2 = {
1290
+ line: number;
1291
+ column: number;
1292
+ };
1293
+
1294
+ declare interface Location_3 {
1217
1295
  line: number;
1218
1296
  column: number;
1219
1297
  }
@@ -1579,10 +1657,11 @@ declare interface Node_2 {
1579
1657
  visit(visitor: Visitor, state: any): void;
1580
1658
  }
1581
1659
 
1582
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'exclude'>> & Partial<Pick<RstestConfig, OptionalKeys>> & {
1660
+ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'globalSetup' | 'exclude'>> & Partial<Pick<RstestConfig, OptionalKeys>> & {
1583
1661
  pool: RstestPoolOptions;
1584
1662
  coverage: NormalizedCoverageOptions;
1585
1663
  setupFiles: string[];
1664
+ globalSetup: string[];
1586
1665
  exclude: {
1587
1666
  patterns: string[];
1588
1667
  override?: boolean;
@@ -1605,8 +1684,9 @@ declare type NormalizedFixtures = Record<string, NormalizedFixture>;
1605
1684
 
1606
1685
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1607
1686
 
1608
- declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool' | 'setupFiles'>> & Pick<NormalizedConfig, OptionalKeys> & {
1687
+ declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool' | 'setupFiles' | 'globalSetup'>> & Pick<NormalizedConfig, OptionalKeys> & {
1609
1688
  setupFiles: string[];
1689
+ globalSetup: string[];
1610
1690
  };
1611
1691
 
1612
1692
  declare interface OldPlugin {
@@ -1614,17 +1694,9 @@ declare interface OldPlugin {
1614
1694
  test: Test;
1615
1695
  }
1616
1696
 
1617
- declare type OnTestFailedHandler = (params: {
1618
- task: {
1619
- result: Readonly<TestResult>;
1620
- };
1621
- }) => MaybePromise<void>;
1697
+ declare type OnTestFailedHandler = (ctx: TestContext) => MaybePromise<void>;
1622
1698
 
1623
- declare type OnTestFinishedHandler = (params: {
1624
- task: {
1625
- result: Readonly<TestResult>;
1626
- };
1627
- }) => MaybePromise<void>;
1699
+ declare type OnTestFinishedHandler = (ctx: TestContext) => MaybePromise<void>;
1628
1700
 
1629
1701
  declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'chaiConfig' | 'resolveSnapshotPath';
1630
1702
 
@@ -1697,6 +1769,7 @@ declare type ProjectContext = {
1697
1769
  outputModule: boolean;
1698
1770
  configFilePath?: string;
1699
1771
  normalizedConfig: NormalizedProjectConfig;
1772
+ _globalSetups: boolean;
1700
1773
  };
1701
1774
 
1702
1775
  declare interface ProjectOptions {
@@ -1714,8 +1787,8 @@ declare type PromisifyAssertion<T> = Promisify<Assertion<T>>;
1714
1787
  declare type PromisifyAssertion_2<T> = Promisify_2<Assertion_2<T>>;
1715
1788
 
1716
1789
  declare interface Range_2 {
1717
- start: Location_2;
1718
- end: Location_2;
1790
+ start: Location_3;
1791
+ end: Location_3;
1719
1792
  }
1720
1793
 
1721
1794
  declare interface RawMatcherFn<
@@ -1733,11 +1806,24 @@ declare interface RawSnapshotInfo {
1733
1806
 
1734
1807
  declare type Refs = Array<unknown>;
1735
1808
 
1809
+ declare class ReportBase {
1810
+ constructor(options?: Partial<ReportBaseOptions>);
1811
+ execute(context: Context): void;
1812
+ }
1813
+
1814
+ declare interface ReportBaseOptions {
1815
+ summarizer: Summarizers;
1816
+ }
1817
+
1736
1818
  declare interface Reporter {
1737
1819
  /**
1738
1820
  * Called before test file run.
1739
1821
  */
1740
1822
  onTestFileStart?: (test: TestFileInfo) => void;
1823
+ /**
1824
+ * Called after tests in file collected.
1825
+ */
1826
+ onTestFileReady?: (test: TestFileInfo) => void;
1741
1827
  /**
1742
1828
  * Called when the test file has finished running.
1743
1829
  */
@@ -1763,11 +1849,12 @@ declare interface Reporter {
1763
1849
  /**
1764
1850
  * Called after all tests have finished running.
1765
1851
  */
1766
- onTestRunEnd?: ({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
1852
+ onTestRunEnd?: ({ results, testResults, duration, getSourcemap, snapshotSummary, unhandledErrors, }: {
1767
1853
  results: TestFileResult[];
1768
1854
  testResults: TestResult[];
1769
1855
  duration: Duration;
1770
1856
  getSourcemap: GetSourcemap;
1857
+ unhandledErrors?: Error[];
1771
1858
  snapshotSummary: SnapshotSummary;
1772
1859
  filterRerunTestPaths?: string[];
1773
1860
  }) => MaybePromise<void>;
@@ -1864,6 +1951,12 @@ declare interface RstestConfig {
1864
1951
  * Path to setup files. They will be run before each test file.
1865
1952
  */
1866
1953
  setupFiles?: string[] | string;
1954
+ /**
1955
+ * Path to global setup files, relative to project root.
1956
+ * A global setup file can either export named functions `setup` and `teardown`
1957
+ * or a `default` function that returns a teardown function.
1958
+ */
1959
+ globalSetup?: string[] | string;
1867
1960
  /**
1868
1961
  * Retry the test specific number of times if it fails.
1869
1962
  * @default 0
@@ -2009,6 +2102,10 @@ declare interface RstestConfig {
2009
2102
  * chai configuration options
2010
2103
  */
2011
2104
  chaiConfig?: ChaiConfig;
2105
+ /**
2106
+ * Include `location` property in `TestInfo` received by reporters
2107
+ */
2108
+ includeTaskLocation?: boolean;
2012
2109
  plugins?: RsbuildConfig['plugins'];
2013
2110
  source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
2014
2111
  performance?: Pick<NonNullable<RsbuildConfig['performance']>, 'bundleAnalyze'>;
@@ -2095,11 +2192,12 @@ declare type RunningModules = Map<string, {
2095
2192
  results: TestResult[];
2096
2193
  }>;
2097
2194
 
2098
- declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat' | 'env' | 'logHeapUsage' | 'bail' | 'chaiConfig'>;
2195
+ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat' | 'env' | 'logHeapUsage' | 'bail' | 'chaiConfig' | 'includeTaskLocation'>;
2099
2196
 
2100
2197
  /** Runtime to Server */
2101
2198
  declare type RuntimeRPC = {
2102
2199
  onTestFileStart: (test: TestFileInfo) => Promise<void>;
2200
+ onTestFileReady: (test: TestFileInfo) => Promise<void>;
2103
2201
  getAssetsByEntry: () => Promise<{
2104
2202
  assetFiles: Record<string, string>;
2105
2203
  sourceMaps: Record<string, string>;
@@ -2322,6 +2420,8 @@ declare type SuiteContext = {
2322
2420
  filepath: TestPath;
2323
2421
  };
2324
2422
 
2423
+ declare type Summarizers = "flat" | "nested" | "pkg" | "defaultSummarizer";
2424
+
2325
2425
  declare interface SyncExpectationResult {
2326
2426
  pass: boolean;
2327
2427
  message: () => string;
@@ -2389,11 +2489,14 @@ declare type TestCase = TestCaseInfo & {
2389
2489
  only?: boolean;
2390
2490
  onFinished: OnTestFinishedHandler[];
2391
2491
  onFailed: OnTestFailedHandler[];
2392
- type: 'case';
2393
2492
  /**
2394
2493
  * Store promises (from async expects) to wait for them before finishing the test
2395
2494
  */
2396
2495
  promises?: Promise<any>[];
2496
+ /**
2497
+ * Store stack trace error created when test is registered, used for trace original position
2498
+ */
2499
+ stackTraceError: Error;
2397
2500
  /**
2398
2501
  * Result of the task. if `expect.soft()` failed multiple times or `retry` was triggered.
2399
2502
  */
@@ -2408,9 +2511,21 @@ declare type TestCaseInfo = {
2408
2511
  parentNames?: string[];
2409
2512
  project: string;
2410
2513
  startTime?: number;
2514
+ /** Only included when `includeTaskLocation` config is enabled */
2515
+ location?: Location_2;
2516
+ type: 'case';
2411
2517
  };
2412
2518
 
2413
2519
  declare type TestContext = {
2520
+ /**
2521
+ * Metadata of the current test
2522
+ */
2523
+ task: {
2524
+ /** Test name provided by user */
2525
+ name: string;
2526
+ /** Result of the current test, undefined if the test is not run yet */
2527
+ result?: TestResult;
2528
+ };
2414
2529
  expect: RstestExpect;
2415
2530
  onTestFinished: RunnerAPI['onTestFinished'];
2416
2531
  onTestFailed: RunnerAPI['onTestFailed'];
@@ -2430,6 +2545,7 @@ declare interface TesterContext {
2430
2545
 
2431
2546
  declare type TestFileInfo = {
2432
2547
  testPath: TestPath;
2548
+ tests: TestInfo[];
2433
2549
  };
2434
2550
 
2435
2551
  declare type TestFileResult = TestResult & {
@@ -2442,6 +2558,10 @@ declare type TestFn<ExtraContext = object> = (description: string, fn?: TestCall
2442
2558
 
2443
2559
  declare type TestForFn<ExtraContext = object> = <T>(cases: readonly T[]) => (description: string, fn?: (param: T, context: TestContext & ExtraContext) => MaybePromise<void>, timeout?: number) => void;
2444
2560
 
2561
+ declare type TestInfo = TestCaseInfo | (TestSuiteInfo & {
2562
+ tests: TestInfo[];
2563
+ });
2564
+
2445
2565
  /** The test file original path */
2446
2566
  declare type TestPath = string;
2447
2567
 
@@ -2485,8 +2605,7 @@ declare type TestSuite = TestSuiteInfo & {
2485
2605
  concurrent?: boolean;
2486
2606
  sequential?: boolean;
2487
2607
  /** nested cases and suite could in a suite */
2488
- tests: (TestSuite | TestCase)[];
2489
- type: 'suite';
2608
+ tests: Test_2[];
2490
2609
  afterAllListeners?: AfterAllListener[];
2491
2610
  beforeAllListeners?: BeforeAllListener[];
2492
2611
  afterEachListeners?: AfterEachListener[];
@@ -2499,6 +2618,9 @@ declare type TestSuiteInfo = {
2499
2618
  parentNames?: string[];
2500
2619
  testPath: TestPath;
2501
2620
  project: string;
2621
+ type: 'suite';
2622
+ /** Only included when `includeTaskLocation` config is enabled */
2623
+ location?: Location_2;
2502
2624
  };
2503
2625
 
2504
2626
  declare type TextLcovOptions = ProjectOptions;
@@ -2544,6 +2666,11 @@ declare class TraceMap implements SourceMap {
2544
2666
  constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
2545
2667
  }
2546
2668
 
2669
+ declare interface Tree<N extends Node_2 = Node_2> {
2670
+ getRoot(): N;
2671
+ visit(visitor: Partial<Visitor<N>>, state: any): void;
2672
+ }
2673
+
2547
2674
  declare interface UncheckedSnapshot {
2548
2675
  filePath: string;
2549
2676
  keys: Array<string>;
@@ -2576,6 +2703,15 @@ declare type VitestAssertion<
2576
2703
  T
2577
2704
  > = { [K in keyof A] : A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T> } & ((type: string, message?: string) => Assertion);
2578
2705
 
2706
+ declare type Watermark = [number, number];
2707
+
2708
+ declare interface Watermarks {
2709
+ statements: Watermark;
2710
+ functions: Watermark;
2711
+ branches: Watermark;
2712
+ lines: Watermark;
2713
+ }
2714
+
2579
2715
  declare type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
2580
2716
 
2581
2717
  declare type WorkerContext = {
@@ -2591,4 +2727,24 @@ declare type XInput = {
2591
2727
  x_google_ignoreList?: SourceMapV3['ignoreList'];
2592
2728
  };
2593
2729
 
2730
+ declare interface XmlWriter {
2731
+ indent(str: string): string;
2732
+ /**
2733
+ * writes the opening XML tag with the supplied attributes
2734
+ */
2735
+ openTag(name: string, attrs?: any): void;
2736
+ /**
2737
+ * closes an open XML tag.
2738
+ */
2739
+ closeTag(name: string): void;
2740
+ /**
2741
+ * writes a tag and its value opening and closing it at the same time
2742
+ */
2743
+ inlineTag(name: string, attrs?: any, content?: string): void;
2744
+ /**
2745
+ * closes all open tags and ends the document
2746
+ */
2747
+ closeAll(): void;
2748
+ }
2749
+
2594
2750
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -60,10 +60,11 @@
60
60
  "@jridgewell/trace-mapping": "0.3.31",
61
61
  "@microsoft/api-extractor": "^7.53.3",
62
62
  "@rslib/core": "0.18.3",
63
- "@sinonjs/fake-timers": "^14.0.0",
63
+ "@sinonjs/fake-timers": "^15.0.0",
64
64
  "@types/babel__code-frame": "^7.0.6",
65
65
  "@types/istanbul-reports": "^3.0.4",
66
66
  "@types/istanbul-lib-coverage": "^2.0.6",
67
+ "@types/istanbul-lib-report": "^3.0.3",
67
68
  "@types/jsdom": "^21.1.7",
68
69
  "@types/sinonjs__fake-timers": "^8.1.5",
69
70
  "@types/source-map-support": "^0.5.10",
File without changes