@rstest/core 0.4.1 → 0.5.0

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.
@@ -1,8 +1,6 @@
1
1
  import type { assert as assert_2 } from 'chai';
2
- import type { CoverageMap } from 'istanbul-lib-coverage';
3
- import type { ReportOptions } from 'istanbul-reports';
4
2
  import type { RsbuildConfig } from '@rsbuild/core';
5
- import { RsbuildPlugin } from '@rsbuild/core';
3
+ import type { RsbuildPlugin } from '@rsbuild/core';
6
4
 
7
5
  /**
8
6
  * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
@@ -260,12 +258,23 @@ export declare const beforeEach: Rstest['beforeEach'];
260
258
 
261
259
  declare type BeforeEachListener = () => MaybePromise<void | AfterEachListener>;
262
260
 
261
+ declare interface BranchMapping {
262
+ loc: Range_2;
263
+ type: string;
264
+ locations: Range_2[];
265
+ line: number;
266
+ }
267
+
263
268
  declare type BuiltInReporterNames = keyof typeof reportersMap;
264
269
 
265
270
  declare type BuiltinReporterOptions = {
266
271
  default: DefaultReporterOptions;
267
272
  };
268
273
 
274
+ declare interface CloverOptions extends FileOptions, ProjectOptions {}
275
+
276
+ declare interface CoberturaOptions extends FileOptions, ProjectOptions {}
277
+
269
278
  /**
270
279
  * Copyright (c) Meta Platforms, Inc. and affiliates.
271
280
  *
@@ -331,12 +340,41 @@ declare class CounterMap<K> extends DefaultMap<K, number> {
331
340
  total(): number;
332
341
  }
333
342
 
343
+ declare interface Coverage {
344
+ covered: number;
345
+ total: number;
346
+ coverage: number;
347
+ }
348
+
349
+ declare class CoverageMap {
350
+ constructor(data: CoverageMapData | CoverageMap);
351
+ addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
352
+ files(): string[];
353
+ fileCoverageFor(filename: string): FileCoverage;
354
+ filter(callback: (key: string) => boolean): void;
355
+ getCoverageSummary(): CoverageSummary;
356
+ merge(data: CoverageMapData | CoverageMap): void;
357
+ toJSON(): CoverageMapData;
358
+ data: CoverageMapData;
359
+ }
360
+
361
+ declare interface CoverageMapData {
362
+ [key: string]: FileCoverage | FileCoverageData;
363
+ }
364
+
334
365
  export declare type CoverageOptions = {
335
366
  /**
336
367
  * Enable coverage collection.
337
368
  * @default false
338
369
  */
339
370
  enabled?: boolean;
371
+ /**
372
+ * A list of glob patterns that should be included for coverage collection.
373
+ * Only collect coverage for tested files by default.
374
+ *
375
+ * @default undefined
376
+ */
377
+ include?: string[];
340
378
  /**
341
379
  * A list of glob patterns that should be excluded from coverage collection.
342
380
  *
@@ -393,6 +431,13 @@ export declare class CoverageProvider {
393
431
  * Create a new coverage map
394
432
  */
395
433
  createCoverageMap(): CoverageMap;
434
+ /**
435
+ * Generate coverage for untested files
436
+ */
437
+ generateCoverageForUntestedFiles(params: {
438
+ environmentName: string;
439
+ files: string[];
440
+ }): Promise<FileCoverageData[]>;
396
441
  /**
397
442
  * Generate coverage reports
398
443
  */
@@ -403,7 +448,46 @@ export declare class CoverageProvider {
403
448
  cleanup(): void;
404
449
  }
405
450
 
406
- declare type CoverageThresholds = Thresholds;
451
+ declare class CoverageSummary {
452
+ constructor(data: CoverageSummary | CoverageSummaryData);
453
+ merge(obj: CoverageSummary): CoverageSummary;
454
+ toJSON(): CoverageSummaryData;
455
+ isEmpty(): boolean;
456
+ data: CoverageSummaryData;
457
+ lines: Totals;
458
+ statements: Totals;
459
+ branches: Totals;
460
+ functions: Totals;
461
+ }
462
+
463
+ declare interface CoverageSummaryData {
464
+ lines: Totals;
465
+ statements: Totals;
466
+ branches: Totals;
467
+ functions: Totals;
468
+ }
469
+
470
+ declare type CoverageThreshold = {
471
+ /** Threshold for statements */
472
+ statements?: number;
473
+ /** Threshold for functions */
474
+ functions?: number;
475
+ /** Threshold for branches */
476
+ branches?: number;
477
+ /** Threshold for lines */
478
+ lines?: number;
479
+ };
480
+
481
+ declare type CoverageThresholds = CoverageThreshold | (CoverageThreshold & {
482
+ /** check thresholds for matched files */
483
+ [glob: string]: CoverageThreshold & {
484
+ /**
485
+ * check thresholds per file
486
+ * @default false
487
+ */
488
+ perFile?: boolean;
489
+ };
490
+ });
407
491
 
408
492
  declare interface CustomMatcher {
409
493
  /**
@@ -670,6 +754,42 @@ declare interface FakeTimerInstallOpts {
670
754
  shouldClearNativeTimers?: boolean | undefined;
671
755
  }
672
756
 
757
+ declare class FileCoverage implements FileCoverageData {
758
+ constructor(data: string | FileCoverage | FileCoverageData);
759
+ merge(other: FileCoverageData): void;
760
+ getBranchCoverageByLine(): { [line: number]: Coverage };
761
+ getLineCoverage(): { [line: number]: number };
762
+ getUncoveredLines(): number[];
763
+ resetHits(): void;
764
+ computeBranchTotals(): Totals;
765
+ computeSimpleTotals(): Totals;
766
+ toSummary(): CoverageSummary;
767
+ toJSON(): object;
768
+
769
+ data: FileCoverageData;
770
+ path: string;
771
+ statementMap: { [key: string]: Range_2 };
772
+ fnMap: { [key: string]: FunctionMapping };
773
+ branchMap: { [key: string]: BranchMapping };
774
+ s: { [key: string]: number };
775
+ f: { [key: string]: number };
776
+ b: { [key: string]: number[] };
777
+ }
778
+
779
+ declare interface FileCoverageData {
780
+ path: string;
781
+ statementMap: { [key: string]: Range_2 };
782
+ fnMap: { [key: string]: FunctionMapping };
783
+ branchMap: { [key: string]: BranchMapping };
784
+ s: { [key: string]: number };
785
+ f: { [key: string]: number };
786
+ b: { [key: string]: number[] };
787
+ }
788
+
789
+ declare interface FileOptions {
790
+ file: string;
791
+ }
792
+
673
793
  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);
674
794
 
675
795
  declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
@@ -701,6 +821,13 @@ declare interface Formatter {
701
821
 
702
822
  declare type FunctionLike = (...args: any) => any;
703
823
 
824
+ declare interface FunctionMapping {
825
+ name: string;
826
+ decl: Range_2;
827
+ loc: Range_2;
828
+ line: number;
829
+ }
830
+
704
831
  declare type GeneratedColumn = number;
705
832
 
706
833
  declare function getMatcherUtils(): {
@@ -739,6 +866,17 @@ declare class GithubActionsReporter {
739
866
  }): Promise<void>;
740
867
  }
741
868
 
869
+ declare interface HtmlOptions {
870
+ verbose: boolean;
871
+ skipEmpty: boolean;
872
+ subdir: string;
873
+ linkMapper: LinkMapper;
874
+ }
875
+
876
+ declare interface HtmlSpaOptions extends HtmlOptions {
877
+ metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
878
+ }
879
+
742
880
  declare type Indent = (arg0: string) => string;
743
881
 
744
882
  declare interface InlineSnapshotMatcher<T> {
@@ -1139,6 +1277,10 @@ declare interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomM
1139
1277
  nthReturnedWith: <E>(nthCall: number, value: E) => void;
1140
1278
  }
1141
1279
 
1280
+ declare type JsonOptions = FileOptions;
1281
+
1282
+ declare type JsonSummaryOptions = FileOptions;
1283
+
1142
1284
  declare class JUnitReporter implements Reporter {
1143
1285
  private rootPath;
1144
1286
  private outputPath?;
@@ -1161,6 +1303,21 @@ declare class JUnitReporter implements Reporter {
1161
1303
  }): Promise<void>;
1162
1304
  }
1163
1305
 
1306
+ declare interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
1307
+
1308
+ declare interface LcovOptions extends FileOptions, ProjectOptions {}
1309
+
1310
+ declare interface LinkMapper {
1311
+ getPath(node: string | Node_2): string;
1312
+ relativePath(source: string | Node_2, target: string | Node_2): string;
1313
+ assetPath(node: Node_2, name: string): string;
1314
+ }
1315
+
1316
+ declare interface Location_2 {
1317
+ line: number;
1318
+ column: number;
1319
+ }
1320
+
1164
1321
  declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
1165
1322
 
1166
1323
  declare interface MatcherHintOptions {
@@ -1666,23 +1823,36 @@ declare interface NewPlugin {
1666
1823
  test: Test;
1667
1824
  }
1668
1825
 
1669
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage'>> & {
1826
+ declare interface Node_2 {
1827
+ isRoot(): boolean;
1828
+ visit(visitor: Visitor, state: any): void;
1829
+ }
1830
+
1831
+ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'exclude'>> & {
1670
1832
  [key in OptionalKeys]?: RstestConfig[key];
1671
1833
  } & {
1672
1834
  pool: RstestPoolOptions;
1673
1835
  coverage: NormalizedCoverageOptions;
1836
+ setupFiles: string[];
1837
+ exclude: {
1838
+ patterns: string[];
1839
+ override?: boolean;
1840
+ };
1674
1841
  };
1675
1842
 
1676
- export declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds'>> & {
1843
+ export declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds' | 'include'>> & {
1677
1844
  thresholds?: CoverageThresholds;
1845
+ include?: string[];
1678
1846
  };
1679
1847
 
1680
1848
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1681
1849
 
1682
1850
  declare type NormalizedProcedure_2<T extends Procedure_2> = (...args: Parameters<T>) => ReturnType<T>;
1683
1851
 
1684
- declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
1852
+ declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool' | 'setupFiles'>> & {
1685
1853
  [key in OptionalKeys]?: NormalizedConfig[key];
1854
+ } & {
1855
+ setupFiles: string[];
1686
1856
  };
1687
1857
 
1688
1858
  declare interface OldPlugin {
@@ -1706,7 +1876,7 @@ declare type OnTestFinishedHandler = (params: {
1706
1876
  };
1707
1877
  }) => MaybePromise<void>;
1708
1878
 
1709
- declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1879
+ declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1710
1880
 
1711
1881
  declare type OptionsReceived = PrettyFormatOptions;
1712
1882
 
@@ -1769,6 +1939,10 @@ declare type ProjectContext = {
1769
1939
  normalizedConfig: NormalizedProjectConfig;
1770
1940
  };
1771
1941
 
1942
+ declare interface ProjectOptions {
1943
+ projectRoot: string;
1944
+ }
1945
+
1772
1946
  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] };
1773
1947
 
1774
1948
  declare type Promisify_2<O> = {
@@ -1779,6 +1953,11 @@ declare type PromisifyAssertion<T> = Promisify<Assertion_2<T>>;
1779
1953
 
1780
1954
  declare type PromisifyAssertion_2<T> = Promisify_2<Assertion<T>>;
1781
1955
 
1956
+ declare interface Range_2 {
1957
+ start: Location_2;
1958
+ end: Location_2;
1959
+ }
1960
+
1782
1961
  declare interface RawMatcherFn<
1783
1962
  T extends MatcherState = MatcherState,
1784
1963
  E extends Array<any> = Array<any>
@@ -1837,6 +2016,22 @@ declare const reportersMap: {
1837
2016
 
1838
2017
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
1839
2018
 
2019
+ declare interface ReportOptions {
2020
+ clover: CloverOptions;
2021
+ cobertura: CoberturaOptions;
2022
+ "html-spa": HtmlSpaOptions;
2023
+ html: HtmlOptions;
2024
+ json: JsonOptions;
2025
+ "json-summary": JsonSummaryOptions;
2026
+ lcov: LcovOptions;
2027
+ lcovonly: LcovOnlyOptions;
2028
+ none: never;
2029
+ teamcity: TeamcityOptions;
2030
+ text: TextOptions;
2031
+ "text-lcov": TextLcovOptions;
2032
+ "text-summary": TextSummaryOptions;
2033
+ }
2034
+
1840
2035
  declare type ReportWithOptions<Name extends keyof ReportOptions = keyof ReportOptions> = Name extends keyof ReportOptions ? [Name, Partial<ReportOptions[Name]>] : [Name, Record<string, unknown>];
1841
2036
 
1842
2037
  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;
@@ -1890,7 +2085,14 @@ export declare interface RstestConfig {
1890
2085
  *
1891
2086
  * @default ['**\/node_modules/**', '**\/dist/**']
1892
2087
  */
1893
- exclude?: string[];
2088
+ exclude?: string[] | {
2089
+ patterns: string[];
2090
+ /**
2091
+ * override default exclude patterns
2092
+ * @default false
2093
+ */
2094
+ override?: boolean;
2095
+ };
1894
2096
  /**
1895
2097
  * A list of glob patterns that match your in-source test files
1896
2098
  *
@@ -2411,6 +2613,10 @@ declare interface SyncExpectationResult {
2411
2613
  expected?: any;
2412
2614
  }
2413
2615
 
2616
+ declare interface TeamcityOptions extends FileOptions {
2617
+ blockName: string;
2618
+ }
2619
+
2414
2620
  declare type Test = (arg0: any) => boolean;
2415
2621
 
2416
2622
  export declare const test: Rstest['test'];
@@ -2460,6 +2666,7 @@ export declare type TestFileInfo = {
2460
2666
  export declare type TestFileResult = TestResult & {
2461
2667
  results: TestResult[];
2462
2668
  snapshotResult?: SnapshotResult;
2669
+ coverage?: CoverageMapData;
2463
2670
  };
2464
2671
 
2465
2672
  declare type TestFn<ExtraContext = object> = (description: string, fn?: TestCallbackFn<ExtraContext>, timeout?: number) => void;
@@ -2489,16 +2696,22 @@ export declare type TestResult = {
2489
2696
 
2490
2697
  declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
2491
2698
 
2492
- declare type Thresholds = {
2493
- /** Thresholds for statements */
2494
- statements?: number;
2495
- /** Thresholds for functions */
2496
- functions?: number;
2497
- /** Thresholds for branches */
2498
- branches?: number;
2499
- /** Thresholds for lines */
2500
- lines?: number;
2501
- };
2699
+ declare type TextLcovOptions = ProjectOptions;
2700
+
2701
+ declare interface TextOptions extends FileOptions {
2702
+ maxCols: number;
2703
+ skipEmpty: boolean;
2704
+ skipFull: boolean;
2705
+ }
2706
+
2707
+ declare type TextSummaryOptions = FileOptions;
2708
+
2709
+ declare interface Totals {
2710
+ total: number;
2711
+ covered: number;
2712
+ skipped: number;
2713
+ pct: number;
2714
+ }
2502
2715
 
2503
2716
  declare class TraceMap implements SourceMap {
2504
2717
  version: SourceMapV3['version'];
@@ -2536,6 +2749,14 @@ declare class VerboseReporter extends DefaultReporter {
2536
2749
  onTestFileResult(test: TestFileResult): void;
2537
2750
  }
2538
2751
 
2752
+ declare interface Visitor<N extends Node_2 = Node_2> {
2753
+ onStart(root: N, state: any): void;
2754
+ onSummary(root: N, state: any): void;
2755
+ onDetail(root: N, state: any): void;
2756
+ onSummaryEnd(root: N, state: any): void;
2757
+ onEnd(root: N, state: any): void;
2758
+ }
2759
+
2539
2760
  declare type VitestAssertion<
2540
2761
  A,
2541
2762
  T