@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,4 +1,3 @@
1
- import type { ReportOptions } from 'istanbul-reports';
2
1
  import type { RsbuildConfig } from '@rsbuild/core';
3
2
 
4
3
  /**
@@ -247,12 +246,23 @@ declare type BeforeAllListener = (ctx: SuiteContext) => MaybePromise<void | Afte
247
246
 
248
247
  declare type BeforeEachListener = () => MaybePromise<void | AfterEachListener>;
249
248
 
249
+ declare interface BranchMapping {
250
+ loc: Range_2;
251
+ type: string;
252
+ locations: Range_2[];
253
+ line: number;
254
+ }
255
+
250
256
  declare type BuiltInReporterNames = keyof typeof reportersMap;
251
257
 
252
258
  declare type BuiltinReporterOptions = {
253
259
  default: DefaultReporterOptions;
254
260
  };
255
261
 
262
+ declare interface CloverOptions extends FileOptions, ProjectOptions {}
263
+
264
+ declare interface CoberturaOptions extends FileOptions, ProjectOptions {}
265
+
256
266
  /**
257
267
  * Copyright (c) Meta Platforms, Inc. and affiliates.
258
268
  *
@@ -318,12 +328,29 @@ declare class CounterMap<K> extends DefaultMap<K, number> {
318
328
  total(): number;
319
329
  }
320
330
 
331
+ declare interface Coverage {
332
+ covered: number;
333
+ total: number;
334
+ coverage: number;
335
+ }
336
+
337
+ declare interface CoverageMapData {
338
+ [key: string]: FileCoverage | FileCoverageData;
339
+ }
340
+
321
341
  declare type CoverageOptions = {
322
342
  /**
323
343
  * Enable coverage collection.
324
344
  * @default false
325
345
  */
326
346
  enabled?: boolean;
347
+ /**
348
+ * A list of glob patterns that should be included for coverage collection.
349
+ * Only collect coverage for tested files by default.
350
+ *
351
+ * @default undefined
352
+ */
353
+ include?: string[];
327
354
  /**
328
355
  * A list of glob patterns that should be excluded from coverage collection.
329
356
  *
@@ -364,9 +391,53 @@ declare type CoverageOptions = {
364
391
  * @default undefined
365
392
  */
366
393
  thresholds?: CoverageThresholds;
394
+ /**
395
+ * Whether to report coverage when tests fail.
396
+ * @default false
397
+ */
398
+ reportOnFailure?: boolean;
367
399
  };
368
400
 
369
- declare type CoverageThresholds = Thresholds;
401
+ declare class CoverageSummary {
402
+ constructor(data: CoverageSummary | CoverageSummaryData);
403
+ merge(obj: CoverageSummary): CoverageSummary;
404
+ toJSON(): CoverageSummaryData;
405
+ isEmpty(): boolean;
406
+ data: CoverageSummaryData;
407
+ lines: Totals;
408
+ statements: Totals;
409
+ branches: Totals;
410
+ functions: Totals;
411
+ }
412
+
413
+ declare interface CoverageSummaryData {
414
+ lines: Totals;
415
+ statements: Totals;
416
+ branches: Totals;
417
+ functions: Totals;
418
+ }
419
+
420
+ declare type CoverageThreshold = {
421
+ /** Threshold for statements */
422
+ statements?: number;
423
+ /** Threshold for functions */
424
+ functions?: number;
425
+ /** Threshold for branches */
426
+ branches?: number;
427
+ /** Threshold for lines */
428
+ lines?: number;
429
+ };
430
+
431
+ declare type CoverageThresholds = CoverageThreshold | (CoverageThreshold & {
432
+ /** check thresholds for matched files */
433
+ [glob: string]: CoverageThreshold & {
434
+ /**
435
+ * check thresholds per file
436
+ * @default false
437
+ */
438
+ perFile?: boolean;
439
+ };
440
+ });
370
441
 
371
442
  declare interface CustomMatcher {
372
443
  /**
@@ -571,6 +642,42 @@ declare interface ExpectStatic_2 extends Chai.ExpectStatic, Matchers, Asymmetric
571
642
  not: AsymmetricMatchersContaining;
572
643
  }
573
644
 
645
+ declare class FileCoverage implements FileCoverageData {
646
+ constructor(data: string | FileCoverage | FileCoverageData);
647
+ merge(other: FileCoverageData): void;
648
+ getBranchCoverageByLine(): { [line: number]: Coverage };
649
+ getLineCoverage(): { [line: number]: number };
650
+ getUncoveredLines(): number[];
651
+ resetHits(): void;
652
+ computeBranchTotals(): Totals;
653
+ computeSimpleTotals(): Totals;
654
+ toSummary(): CoverageSummary;
655
+ toJSON(): object;
656
+
657
+ data: FileCoverageData;
658
+ path: string;
659
+ statementMap: { [key: string]: Range_2 };
660
+ fnMap: { [key: string]: FunctionMapping };
661
+ branchMap: { [key: string]: BranchMapping };
662
+ s: { [key: string]: number };
663
+ f: { [key: string]: number };
664
+ b: { [key: string]: number[] };
665
+ }
666
+
667
+ declare interface FileCoverageData {
668
+ path: string;
669
+ statementMap: { [key: string]: Range_2 };
670
+ fnMap: { [key: string]: FunctionMapping };
671
+ branchMap: { [key: string]: BranchMapping };
672
+ s: { [key: string]: number };
673
+ f: { [key: string]: number };
674
+ b: { [key: string]: number[] };
675
+ }
676
+
677
+ declare interface FileOptions {
678
+ file: string;
679
+ }
680
+
574
681
  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);
575
682
 
576
683
  declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
@@ -600,6 +707,13 @@ declare interface Formatter {
600
707
  close: string;
601
708
  }
602
709
 
710
+ declare interface FunctionMapping {
711
+ name: string;
712
+ decl: Range_2;
713
+ loc: Range_2;
714
+ line: number;
715
+ }
716
+
603
717
  declare type GeneratedColumn = number;
604
718
 
605
719
  declare function getMatcherUtils(): {
@@ -638,6 +752,17 @@ declare class GithubActionsReporter {
638
752
  }): Promise<void>;
639
753
  }
640
754
 
755
+ declare interface HtmlOptions {
756
+ verbose: boolean;
757
+ skipEmpty: boolean;
758
+ subdir: string;
759
+ linkMapper: LinkMapper;
760
+ }
761
+
762
+ declare interface HtmlSpaOptions extends HtmlOptions {
763
+ metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
764
+ }
765
+
641
766
  declare type Indent = (arg0: string) => string;
642
767
 
643
768
  declare interface InlineSnapshotMatcher<T> {
@@ -1036,6 +1161,10 @@ declare interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomM
1036
1161
  nthReturnedWith: <E>(nthCall: number, value: E) => void;
1037
1162
  }
1038
1163
 
1164
+ declare type JsonOptions = FileOptions;
1165
+
1166
+ declare type JsonSummaryOptions = FileOptions;
1167
+
1039
1168
  declare class JUnitReporter implements Reporter {
1040
1169
  private rootPath;
1041
1170
  private outputPath?;
@@ -1058,6 +1187,21 @@ declare class JUnitReporter implements Reporter {
1058
1187
  }): Promise<void>;
1059
1188
  }
1060
1189
 
1190
+ declare interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
1191
+
1192
+ declare interface LcovOptions extends FileOptions, ProjectOptions {}
1193
+
1194
+ declare interface LinkMapper {
1195
+ getPath(node: string | Node_2): string;
1196
+ relativePath(source: string | Node_2, target: string | Node_2): string;
1197
+ assetPath(node: Node_2, name: string): string;
1198
+ }
1199
+
1200
+ declare interface Location_2 {
1201
+ line: number;
1202
+ column: number;
1203
+ }
1204
+
1061
1205
  declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
1062
1206
 
1063
1207
  declare interface MatcherHintOptions {
@@ -1414,15 +1558,26 @@ declare interface NewPlugin {
1414
1558
  test: Test;
1415
1559
  }
1416
1560
 
1417
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage'>> & {
1561
+ declare interface Node_2 {
1562
+ isRoot(): boolean;
1563
+ visit(visitor: Visitor, state: any): void;
1564
+ }
1565
+
1566
+ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'exclude'>> & {
1418
1567
  [key in OptionalKeys]?: RstestConfig[key];
1419
1568
  } & {
1420
1569
  pool: RstestPoolOptions;
1421
1570
  coverage: NormalizedCoverageOptions;
1571
+ setupFiles: string[];
1572
+ exclude: {
1573
+ patterns: string[];
1574
+ override?: boolean;
1575
+ };
1422
1576
  };
1423
1577
 
1424
- declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds'>> & {
1578
+ declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds' | 'include'>> & {
1425
1579
  thresholds?: CoverageThresholds;
1580
+ include?: string[];
1426
1581
  };
1427
1582
 
1428
1583
  declare type NormalizedFixture = {
@@ -1436,8 +1591,10 @@ declare type NormalizedFixtures = Record<string, NormalizedFixture>;
1436
1591
 
1437
1592
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1438
1593
 
1439
- declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
1594
+ declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool' | 'setupFiles'>> & {
1440
1595
  [key in OptionalKeys]?: NormalizedConfig[key];
1596
+ } & {
1597
+ setupFiles: string[];
1441
1598
  };
1442
1599
 
1443
1600
  declare interface OldPlugin {
@@ -1457,7 +1614,7 @@ declare type OnTestFinishedHandler = (params: {
1457
1614
  };
1458
1615
  }) => MaybePromise<void>;
1459
1616
 
1460
- declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1617
+ declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1461
1618
 
1462
1619
  declare type OptionsReceived = PrettyFormatOptions;
1463
1620
 
@@ -1518,6 +1675,10 @@ declare type ProjectContext = {
1518
1675
  normalizedConfig: NormalizedProjectConfig;
1519
1676
  };
1520
1677
 
1678
+ declare interface ProjectOptions {
1679
+ projectRoot: string;
1680
+ }
1681
+
1521
1682
  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] };
1522
1683
 
1523
1684
  declare type Promisify_2<O> = {
@@ -1528,6 +1689,11 @@ declare type PromisifyAssertion<T> = Promisify<Assertion<T>>;
1528
1689
 
1529
1690
  declare type PromisifyAssertion_2<T> = Promisify_2<Assertion_2<T>>;
1530
1691
 
1692
+ declare interface Range_2 {
1693
+ start: Location_2;
1694
+ end: Location_2;
1695
+ }
1696
+
1531
1697
  declare interface RawMatcherFn<
1532
1698
  T extends MatcherState = MatcherState,
1533
1699
  E extends Array<any> = Array<any>
@@ -1586,6 +1752,22 @@ declare const reportersMap: {
1586
1752
 
1587
1753
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
1588
1754
 
1755
+ declare interface ReportOptions {
1756
+ clover: CloverOptions;
1757
+ cobertura: CoberturaOptions;
1758
+ "html-spa": HtmlSpaOptions;
1759
+ html: HtmlOptions;
1760
+ json: JsonOptions;
1761
+ "json-summary": JsonSummaryOptions;
1762
+ lcov: LcovOptions;
1763
+ lcovonly: LcovOnlyOptions;
1764
+ none: never;
1765
+ teamcity: TeamcityOptions;
1766
+ text: TextOptions;
1767
+ "text-lcov": TextLcovOptions;
1768
+ "text-summary": TextSummaryOptions;
1769
+ }
1770
+
1589
1771
  declare type ReportWithOptions<Name extends keyof ReportOptions = keyof ReportOptions> = Name extends keyof ReportOptions ? [Name, Partial<ReportOptions[Name]>] : [Name, Record<string, unknown>];
1590
1772
 
1591
1773
  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;
@@ -1626,7 +1808,14 @@ declare interface RstestConfig {
1626
1808
  *
1627
1809
  * @default ['**\/node_modules/**', '**\/dist/**']
1628
1810
  */
1629
- exclude?: string[];
1811
+ exclude?: string[] | {
1812
+ patterns: string[];
1813
+ /**
1814
+ * override default exclude patterns
1815
+ * @default false
1816
+ */
1817
+ override?: boolean;
1818
+ };
1630
1819
  /**
1631
1820
  * A list of glob patterns that match your in-source test files
1632
1821
  *
@@ -1746,6 +1935,8 @@ declare interface RstestConfig {
1746
1935
  * Custom handler for console log in tests
1747
1936
  */
1748
1937
  onConsoleLog?: (content: string) => boolean | void;
1938
+ /** Format snapshot output */
1939
+ snapshotFormat?: SnapshotFormat;
1749
1940
  /**
1750
1941
  * Coverage options
1751
1942
  */
@@ -1821,7 +2012,7 @@ declare type RunnerAPI = {
1821
2012
  onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
1822
2013
  };
1823
2014
 
1824
- declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage'>;
2015
+ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat'>;
1825
2016
 
1826
2017
  /** Runtime to Server */
1827
2018
  declare type RuntimeRPC = {
@@ -1860,6 +2051,8 @@ declare interface SnapshotEnvironment {
1860
2051
  processStackTrace?: (stack: ParsedStack) => ParsedStack;
1861
2052
  }
1862
2053
 
2054
+ declare type SnapshotFormat = Omit<NonNullable<SnapshotStateOptions['snapshotFormat']>, 'plugins' | 'compareKeys'>;
2055
+
1863
2056
  declare class SnapshotManager {
1864
2057
  options: Omit<SnapshotStateOptions, "snapshotEnvironment">;
1865
2058
  summary: SnapshotSummary;
@@ -2057,6 +2250,10 @@ declare interface TaskResult {
2057
2250
 
2058
2251
  declare type TaskState = 'pass' | 'fail';
2059
2252
 
2253
+ declare interface TeamcityOptions extends FileOptions {
2254
+ blockName: string;
2255
+ }
2256
+
2060
2257
  declare type Test = (arg0: any) => boolean;
2061
2258
 
2062
2259
  declare type Test_2 = TestSuite | TestCase;
@@ -2136,6 +2333,7 @@ declare type TestFileInfo = {
2136
2333
  declare type TestFileResult = TestResult & {
2137
2334
  results: TestResult[];
2138
2335
  snapshotResult?: SnapshotResult;
2336
+ coverage?: CoverageMapData;
2139
2337
  };
2140
2338
 
2141
2339
  declare type TestFn<ExtraContext = object> = (description: string, fn?: TestCallbackFn<ExtraContext>, timeout?: number) => void;
@@ -2186,16 +2384,22 @@ declare type TestSuite = {
2186
2384
  beforeEachListeners?: BeforeEachListener[];
2187
2385
  };
2188
2386
 
2189
- declare type Thresholds = {
2190
- /** Thresholds for statements */
2191
- statements?: number;
2192
- /** Thresholds for functions */
2193
- functions?: number;
2194
- /** Thresholds for branches */
2195
- branches?: number;
2196
- /** Thresholds for lines */
2197
- lines?: number;
2198
- };
2387
+ declare type TextLcovOptions = ProjectOptions;
2388
+
2389
+ declare interface TextOptions extends FileOptions {
2390
+ maxCols: number;
2391
+ skipEmpty: boolean;
2392
+ skipFull: boolean;
2393
+ }
2394
+
2395
+ declare type TextSummaryOptions = FileOptions;
2396
+
2397
+ declare interface Totals {
2398
+ total: number;
2399
+ covered: number;
2400
+ skipped: number;
2401
+ pct: number;
2402
+ }
2199
2403
 
2200
2404
  declare class TraceMap implements SourceMap {
2201
2405
  version: SourceMapV3['version'];
@@ -2233,6 +2437,14 @@ declare class VerboseReporter extends DefaultReporter {
2233
2437
  onTestFileResult(test: TestFileResult): void;
2234
2438
  }
2235
2439
 
2440
+ declare interface Visitor<N extends Node_2 = Node_2> {
2441
+ onStart(root: N, state: any): void;
2442
+ onSummary(root: N, state: any): void;
2443
+ onDetail(root: N, state: any): void;
2444
+ onSummaryEnd(root: N, state: any): void;
2445
+ onEnd(root: N, state: any): void;
2446
+ }
2447
+
2236
2448
  declare type VitestAssertion<
2237
2449
  A,
2238
2450
  T
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -44,15 +44,14 @@
44
44
  "importMeta.d.ts"
45
45
  ],
46
46
  "dependencies": {
47
- "chai": "^5.3.3",
48
47
  "@types/chai": "^5.2.2",
49
48
  "@rsbuild/core": "1.5.0",
50
- "birpc": "2.5.0",
51
- "pathe": "^2.0.3",
52
- "std-env": "^3.9.0",
53
49
  "tinypool": "^1.1.1"
54
50
  },
55
51
  "devDependencies": {
52
+ "chai": "^5.3.3",
53
+ "pathe": "^2.0.3",
54
+ "birpc": "2.5.0",
56
55
  "@vitest/expect": "^3.2.4",
57
56
  "@vitest/snapshot": "^3.2.4",
58
57
  "@babel/code-frame": "^7.27.1",
@@ -66,6 +65,7 @@
66
65
  "@types/jsdom": "^21.1.7",
67
66
  "@types/sinonjs__fake-timers": "^8.1.5",
68
67
  "@types/source-map-support": "^0.5.10",
68
+ "@types/picomatch": "^4.0.2",
69
69
  "cac": "^6.7.14",
70
70
  "chokidar": "^4.0.3",
71
71
  "happy-dom": "^18.0.1",
@@ -75,10 +75,12 @@
75
75
  "picocolors": "^1.1.1",
76
76
  "rslog": "^1.2.11",
77
77
  "source-map-support": "^0.5.21",
78
+ "std-env": "^3.9.0",
78
79
  "stacktrace-parser": "0.1.11",
79
80
  "strip-ansi": "^7.1.2",
80
81
  "tinyglobby": "^0.2.15",
81
82
  "tinyspy": "^4.0.3",
83
+ "picomatch": "^4.0.3",
82
84
  "@rstest/tsconfig": "0.0.1"
83
85
  },
84
86
  "peerDependencies": {