@rstest/core 0.4.1 → 0.5.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.
@@ -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
  *
@@ -377,6 +415,11 @@ export declare type CoverageOptions = {
377
415
  * @default undefined
378
416
  */
379
417
  thresholds?: CoverageThresholds;
418
+ /**
419
+ * Whether to report coverage when tests fail.
420
+ * @default false
421
+ */
422
+ reportOnFailure?: boolean;
380
423
  };
381
424
 
382
425
  export declare class CoverageProvider {
@@ -393,6 +436,13 @@ export declare class CoverageProvider {
393
436
  * Create a new coverage map
394
437
  */
395
438
  createCoverageMap(): CoverageMap;
439
+ /**
440
+ * Generate coverage for untested files
441
+ */
442
+ generateCoverageForUntestedFiles(params: {
443
+ environmentName: string;
444
+ files: string[];
445
+ }): Promise<FileCoverageData[]>;
396
446
  /**
397
447
  * Generate coverage reports
398
448
  */
@@ -403,7 +453,46 @@ export declare class CoverageProvider {
403
453
  cleanup(): void;
404
454
  }
405
455
 
406
- declare type CoverageThresholds = Thresholds;
456
+ declare class CoverageSummary {
457
+ constructor(data: CoverageSummary | CoverageSummaryData);
458
+ merge(obj: CoverageSummary): CoverageSummary;
459
+ toJSON(): CoverageSummaryData;
460
+ isEmpty(): boolean;
461
+ data: CoverageSummaryData;
462
+ lines: Totals;
463
+ statements: Totals;
464
+ branches: Totals;
465
+ functions: Totals;
466
+ }
467
+
468
+ declare interface CoverageSummaryData {
469
+ lines: Totals;
470
+ statements: Totals;
471
+ branches: Totals;
472
+ functions: Totals;
473
+ }
474
+
475
+ declare type CoverageThreshold = {
476
+ /** Threshold for statements */
477
+ statements?: number;
478
+ /** Threshold for functions */
479
+ functions?: number;
480
+ /** Threshold for branches */
481
+ branches?: number;
482
+ /** Threshold for lines */
483
+ lines?: number;
484
+ };
485
+
486
+ declare type CoverageThresholds = CoverageThreshold | (CoverageThreshold & {
487
+ /** check thresholds for matched files */
488
+ [glob: string]: CoverageThreshold & {
489
+ /**
490
+ * check thresholds per file
491
+ * @default false
492
+ */
493
+ perFile?: boolean;
494
+ };
495
+ });
407
496
 
408
497
  declare interface CustomMatcher {
409
498
  /**
@@ -670,6 +759,42 @@ declare interface FakeTimerInstallOpts {
670
759
  shouldClearNativeTimers?: boolean | undefined;
671
760
  }
672
761
 
762
+ declare class FileCoverage implements FileCoverageData {
763
+ constructor(data: string | FileCoverage | FileCoverageData);
764
+ merge(other: FileCoverageData): void;
765
+ getBranchCoverageByLine(): { [line: number]: Coverage };
766
+ getLineCoverage(): { [line: number]: number };
767
+ getUncoveredLines(): number[];
768
+ resetHits(): void;
769
+ computeBranchTotals(): Totals;
770
+ computeSimpleTotals(): Totals;
771
+ toSummary(): CoverageSummary;
772
+ toJSON(): object;
773
+
774
+ data: FileCoverageData;
775
+ path: string;
776
+ statementMap: { [key: string]: Range_2 };
777
+ fnMap: { [key: string]: FunctionMapping };
778
+ branchMap: { [key: string]: BranchMapping };
779
+ s: { [key: string]: number };
780
+ f: { [key: string]: number };
781
+ b: { [key: string]: number[] };
782
+ }
783
+
784
+ declare interface FileCoverageData {
785
+ path: string;
786
+ statementMap: { [key: string]: Range_2 };
787
+ fnMap: { [key: string]: FunctionMapping };
788
+ branchMap: { [key: string]: BranchMapping };
789
+ s: { [key: string]: number };
790
+ f: { [key: string]: number };
791
+ b: { [key: string]: number[] };
792
+ }
793
+
794
+ declare interface FileOptions {
795
+ file: string;
796
+ }
797
+
673
798
  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
799
 
675
800
  declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
@@ -701,6 +826,13 @@ declare interface Formatter {
701
826
 
702
827
  declare type FunctionLike = (...args: any) => any;
703
828
 
829
+ declare interface FunctionMapping {
830
+ name: string;
831
+ decl: Range_2;
832
+ loc: Range_2;
833
+ line: number;
834
+ }
835
+
704
836
  declare type GeneratedColumn = number;
705
837
 
706
838
  declare function getMatcherUtils(): {
@@ -739,6 +871,17 @@ declare class GithubActionsReporter {
739
871
  }): Promise<void>;
740
872
  }
741
873
 
874
+ declare interface HtmlOptions {
875
+ verbose: boolean;
876
+ skipEmpty: boolean;
877
+ subdir: string;
878
+ linkMapper: LinkMapper;
879
+ }
880
+
881
+ declare interface HtmlSpaOptions extends HtmlOptions {
882
+ metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
883
+ }
884
+
742
885
  declare type Indent = (arg0: string) => string;
743
886
 
744
887
  declare interface InlineSnapshotMatcher<T> {
@@ -1139,6 +1282,10 @@ declare interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomM
1139
1282
  nthReturnedWith: <E>(nthCall: number, value: E) => void;
1140
1283
  }
1141
1284
 
1285
+ declare type JsonOptions = FileOptions;
1286
+
1287
+ declare type JsonSummaryOptions = FileOptions;
1288
+
1142
1289
  declare class JUnitReporter implements Reporter {
1143
1290
  private rootPath;
1144
1291
  private outputPath?;
@@ -1161,6 +1308,21 @@ declare class JUnitReporter implements Reporter {
1161
1308
  }): Promise<void>;
1162
1309
  }
1163
1310
 
1311
+ declare interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
1312
+
1313
+ declare interface LcovOptions extends FileOptions, ProjectOptions {}
1314
+
1315
+ declare interface LinkMapper {
1316
+ getPath(node: string | Node_2): string;
1317
+ relativePath(source: string | Node_2, target: string | Node_2): string;
1318
+ assetPath(node: Node_2, name: string): string;
1319
+ }
1320
+
1321
+ declare interface Location_2 {
1322
+ line: number;
1323
+ column: number;
1324
+ }
1325
+
1164
1326
  declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
1165
1327
 
1166
1328
  declare interface MatcherHintOptions {
@@ -1666,23 +1828,36 @@ declare interface NewPlugin {
1666
1828
  test: Test;
1667
1829
  }
1668
1830
 
1669
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage'>> & {
1831
+ declare interface Node_2 {
1832
+ isRoot(): boolean;
1833
+ visit(visitor: Visitor, state: any): void;
1834
+ }
1835
+
1836
+ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'exclude'>> & {
1670
1837
  [key in OptionalKeys]?: RstestConfig[key];
1671
1838
  } & {
1672
1839
  pool: RstestPoolOptions;
1673
1840
  coverage: NormalizedCoverageOptions;
1841
+ setupFiles: string[];
1842
+ exclude: {
1843
+ patterns: string[];
1844
+ override?: boolean;
1845
+ };
1674
1846
  };
1675
1847
 
1676
- export declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds'>> & {
1848
+ export declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds' | 'include'>> & {
1677
1849
  thresholds?: CoverageThresholds;
1850
+ include?: string[];
1678
1851
  };
1679
1852
 
1680
1853
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1681
1854
 
1682
1855
  declare type NormalizedProcedure_2<T extends Procedure_2> = (...args: Parameters<T>) => ReturnType<T>;
1683
1856
 
1684
- declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
1857
+ declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool' | 'setupFiles'>> & {
1685
1858
  [key in OptionalKeys]?: NormalizedConfig[key];
1859
+ } & {
1860
+ setupFiles: string[];
1686
1861
  };
1687
1862
 
1688
1863
  declare interface OldPlugin {
@@ -1706,7 +1881,7 @@ declare type OnTestFinishedHandler = (params: {
1706
1881
  };
1707
1882
  }) => MaybePromise<void>;
1708
1883
 
1709
- declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1884
+ declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1710
1885
 
1711
1886
  declare type OptionsReceived = PrettyFormatOptions;
1712
1887
 
@@ -1769,6 +1944,10 @@ declare type ProjectContext = {
1769
1944
  normalizedConfig: NormalizedProjectConfig;
1770
1945
  };
1771
1946
 
1947
+ declare interface ProjectOptions {
1948
+ projectRoot: string;
1949
+ }
1950
+
1772
1951
  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
1952
 
1774
1953
  declare type Promisify_2<O> = {
@@ -1779,6 +1958,11 @@ declare type PromisifyAssertion<T> = Promisify<Assertion_2<T>>;
1779
1958
 
1780
1959
  declare type PromisifyAssertion_2<T> = Promisify_2<Assertion<T>>;
1781
1960
 
1961
+ declare interface Range_2 {
1962
+ start: Location_2;
1963
+ end: Location_2;
1964
+ }
1965
+
1782
1966
  declare interface RawMatcherFn<
1783
1967
  T extends MatcherState = MatcherState,
1784
1968
  E extends Array<any> = Array<any>
@@ -1837,6 +2021,22 @@ declare const reportersMap: {
1837
2021
 
1838
2022
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
1839
2023
 
2024
+ declare interface ReportOptions {
2025
+ clover: CloverOptions;
2026
+ cobertura: CoberturaOptions;
2027
+ "html-spa": HtmlSpaOptions;
2028
+ html: HtmlOptions;
2029
+ json: JsonOptions;
2030
+ "json-summary": JsonSummaryOptions;
2031
+ lcov: LcovOptions;
2032
+ lcovonly: LcovOnlyOptions;
2033
+ none: never;
2034
+ teamcity: TeamcityOptions;
2035
+ text: TextOptions;
2036
+ "text-lcov": TextLcovOptions;
2037
+ "text-summary": TextSummaryOptions;
2038
+ }
2039
+
1840
2040
  declare type ReportWithOptions<Name extends keyof ReportOptions = keyof ReportOptions> = Name extends keyof ReportOptions ? [Name, Partial<ReportOptions[Name]>] : [Name, Record<string, unknown>];
1841
2041
 
1842
2042
  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 +2090,14 @@ export declare interface RstestConfig {
1890
2090
  *
1891
2091
  * @default ['**\/node_modules/**', '**\/dist/**']
1892
2092
  */
1893
- exclude?: string[];
2093
+ exclude?: string[] | {
2094
+ patterns: string[];
2095
+ /**
2096
+ * override default exclude patterns
2097
+ * @default false
2098
+ */
2099
+ override?: boolean;
2100
+ };
1894
2101
  /**
1895
2102
  * A list of glob patterns that match your in-source test files
1896
2103
  *
@@ -2010,6 +2217,8 @@ export declare interface RstestConfig {
2010
2217
  * Custom handler for console log in tests
2011
2218
  */
2012
2219
  onConsoleLog?: (content: string) => boolean | void;
2220
+ /** Format snapshot output */
2221
+ snapshotFormat?: SnapshotFormat;
2013
2222
  /**
2014
2223
  * Coverage options
2015
2224
  */
@@ -2211,7 +2420,7 @@ declare type RunnerAPI = {
2211
2420
  onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
2212
2421
  };
2213
2422
 
2214
- declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage'>;
2423
+ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat'>;
2215
2424
 
2216
2425
  declare type RuntimeOptions = Partial<Pick<RuntimeConfig, 'testTimeout' | 'hookTimeout' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'maxConcurrency' | 'retry'>>;
2217
2426
 
@@ -2231,6 +2440,8 @@ declare interface SnapshotEnvironment {
2231
2440
  processStackTrace?: (stack: ParsedStack) => ParsedStack;
2232
2441
  }
2233
2442
 
2443
+ declare type SnapshotFormat = Omit<NonNullable<SnapshotStateOptions['snapshotFormat']>, 'plugins' | 'compareKeys'>;
2444
+
2234
2445
  declare class SnapshotManager {
2235
2446
  options: Omit<SnapshotStateOptions, "snapshotEnvironment">;
2236
2447
  summary: SnapshotSummary;
@@ -2411,6 +2622,10 @@ declare interface SyncExpectationResult {
2411
2622
  expected?: any;
2412
2623
  }
2413
2624
 
2625
+ declare interface TeamcityOptions extends FileOptions {
2626
+ blockName: string;
2627
+ }
2628
+
2414
2629
  declare type Test = (arg0: any) => boolean;
2415
2630
 
2416
2631
  export declare const test: Rstest['test'];
@@ -2460,6 +2675,7 @@ export declare type TestFileInfo = {
2460
2675
  export declare type TestFileResult = TestResult & {
2461
2676
  results: TestResult[];
2462
2677
  snapshotResult?: SnapshotResult;
2678
+ coverage?: CoverageMapData;
2463
2679
  };
2464
2680
 
2465
2681
  declare type TestFn<ExtraContext = object> = (description: string, fn?: TestCallbackFn<ExtraContext>, timeout?: number) => void;
@@ -2489,16 +2705,22 @@ export declare type TestResult = {
2489
2705
 
2490
2706
  declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
2491
2707
 
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
- };
2708
+ declare type TextLcovOptions = ProjectOptions;
2709
+
2710
+ declare interface TextOptions extends FileOptions {
2711
+ maxCols: number;
2712
+ skipEmpty: boolean;
2713
+ skipFull: boolean;
2714
+ }
2715
+
2716
+ declare type TextSummaryOptions = FileOptions;
2717
+
2718
+ declare interface Totals {
2719
+ total: number;
2720
+ covered: number;
2721
+ skipped: number;
2722
+ pct: number;
2723
+ }
2502
2724
 
2503
2725
  declare class TraceMap implements SourceMap {
2504
2726
  version: SourceMapV3['version'];
@@ -2536,6 +2758,14 @@ declare class VerboseReporter extends DefaultReporter {
2536
2758
  onTestFileResult(test: TestFileResult): void;
2537
2759
  }
2538
2760
 
2761
+ declare interface Visitor<N extends Node_2 = Node_2> {
2762
+ onStart(root: N, state: any): void;
2763
+ onSummary(root: N, state: any): void;
2764
+ onDetail(root: N, state: any): void;
2765
+ onSummaryEnd(root: N, state: any): void;
2766
+ onEnd(root: N, state: any): void;
2767
+ }
2768
+
2539
2769
  declare type VitestAssertion<
2540
2770
  A,
2541
2771
  T