@rstest/core 0.7.3 → 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>;
@@ -1584,10 +1657,11 @@ declare interface Node_2 {
1584
1657
  visit(visitor: Visitor, state: any): void;
1585
1658
  }
1586
1659
 
1587
- 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>> & {
1588
1661
  pool: RstestPoolOptions;
1589
1662
  coverage: NormalizedCoverageOptions;
1590
1663
  setupFiles: string[];
1664
+ globalSetup: string[];
1591
1665
  exclude: {
1592
1666
  patterns: string[];
1593
1667
  override?: boolean;
@@ -1610,8 +1684,9 @@ declare type NormalizedFixtures = Record<string, NormalizedFixture>;
1610
1684
 
1611
1685
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1612
1686
 
1613
- 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> & {
1614
1688
  setupFiles: string[];
1689
+ globalSetup: string[];
1615
1690
  };
1616
1691
 
1617
1692
  declare interface OldPlugin {
@@ -1619,17 +1694,9 @@ declare interface OldPlugin {
1619
1694
  test: Test;
1620
1695
  }
1621
1696
 
1622
- declare type OnTestFailedHandler = (params: {
1623
- task: {
1624
- result: Readonly<TestResult>;
1625
- };
1626
- }) => MaybePromise<void>;
1697
+ declare type OnTestFailedHandler = (ctx: TestContext) => MaybePromise<void>;
1627
1698
 
1628
- declare type OnTestFinishedHandler = (params: {
1629
- task: {
1630
- result: Readonly<TestResult>;
1631
- };
1632
- }) => MaybePromise<void>;
1699
+ declare type OnTestFinishedHandler = (ctx: TestContext) => MaybePromise<void>;
1633
1700
 
1634
1701
  declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'chaiConfig' | 'resolveSnapshotPath';
1635
1702
 
@@ -1702,6 +1769,7 @@ declare type ProjectContext = {
1702
1769
  outputModule: boolean;
1703
1770
  configFilePath?: string;
1704
1771
  normalizedConfig: NormalizedProjectConfig;
1772
+ _globalSetups: boolean;
1705
1773
  };
1706
1774
 
1707
1775
  declare interface ProjectOptions {
@@ -1738,6 +1806,15 @@ declare interface RawSnapshotInfo {
1738
1806
 
1739
1807
  declare type Refs = Array<unknown>;
1740
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
+
1741
1818
  declare interface Reporter {
1742
1819
  /**
1743
1820
  * Called before test file run.
@@ -1772,11 +1849,12 @@ declare interface Reporter {
1772
1849
  /**
1773
1850
  * Called after all tests have finished running.
1774
1851
  */
1775
- onTestRunEnd?: ({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
1852
+ onTestRunEnd?: ({ results, testResults, duration, getSourcemap, snapshotSummary, unhandledErrors, }: {
1776
1853
  results: TestFileResult[];
1777
1854
  testResults: TestResult[];
1778
1855
  duration: Duration;
1779
1856
  getSourcemap: GetSourcemap;
1857
+ unhandledErrors?: Error[];
1780
1858
  snapshotSummary: SnapshotSummary;
1781
1859
  filterRerunTestPaths?: string[];
1782
1860
  }) => MaybePromise<void>;
@@ -1873,6 +1951,12 @@ declare interface RstestConfig {
1873
1951
  * Path to setup files. They will be run before each test file.
1874
1952
  */
1875
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;
1876
1960
  /**
1877
1961
  * Retry the test specific number of times if it fails.
1878
1962
  * @default 0
@@ -2336,6 +2420,8 @@ declare type SuiteContext = {
2336
2420
  filepath: TestPath;
2337
2421
  };
2338
2422
 
2423
+ declare type Summarizers = "flat" | "nested" | "pkg" | "defaultSummarizer";
2424
+
2339
2425
  declare interface SyncExpectationResult {
2340
2426
  pass: boolean;
2341
2427
  message: () => string;
@@ -2431,6 +2517,15 @@ declare type TestCaseInfo = {
2431
2517
  };
2432
2518
 
2433
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
+ };
2434
2529
  expect: RstestExpect;
2435
2530
  onTestFinished: RunnerAPI['onTestFinished'];
2436
2531
  onTestFailed: RunnerAPI['onTestFailed'];
@@ -2571,6 +2666,11 @@ declare class TraceMap implements SourceMap {
2571
2666
  constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
2572
2667
  }
2573
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
+
2574
2674
  declare interface UncheckedSnapshot {
2575
2675
  filePath: string;
2576
2676
  keys: Array<string>;
@@ -2603,6 +2703,15 @@ declare type VitestAssertion<
2603
2703
  T
2604
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);
2605
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
+
2606
2715
  declare type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
2607
2716
 
2608
2717
  declare type WorkerContext = {
@@ -2618,4 +2727,24 @@ declare type XInput = {
2618
2727
  x_google_ignoreList?: SourceMapV3['ignoreList'];
2619
2728
  };
2620
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
+
2621
2750
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.7.3",
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"
@@ -64,6 +64,7 @@
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