@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,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
  *
@@ -366,7 +393,46 @@ declare type CoverageOptions = {
366
393
  thresholds?: CoverageThresholds;
367
394
  };
368
395
 
369
- declare type CoverageThresholds = Thresholds;
396
+ declare class CoverageSummary {
397
+ constructor(data: CoverageSummary | CoverageSummaryData);
398
+ merge(obj: CoverageSummary): CoverageSummary;
399
+ toJSON(): CoverageSummaryData;
400
+ isEmpty(): boolean;
401
+ data: CoverageSummaryData;
402
+ lines: Totals;
403
+ statements: Totals;
404
+ branches: Totals;
405
+ functions: Totals;
406
+ }
407
+
408
+ declare interface CoverageSummaryData {
409
+ lines: Totals;
410
+ statements: Totals;
411
+ branches: Totals;
412
+ functions: Totals;
413
+ }
414
+
415
+ declare type CoverageThreshold = {
416
+ /** Threshold for statements */
417
+ statements?: number;
418
+ /** Threshold for functions */
419
+ functions?: number;
420
+ /** Threshold for branches */
421
+ branches?: number;
422
+ /** Threshold for lines */
423
+ lines?: number;
424
+ };
425
+
426
+ declare type CoverageThresholds = CoverageThreshold | (CoverageThreshold & {
427
+ /** check thresholds for matched files */
428
+ [glob: string]: CoverageThreshold & {
429
+ /**
430
+ * check thresholds per file
431
+ * @default false
432
+ */
433
+ perFile?: boolean;
434
+ };
435
+ });
370
436
 
371
437
  declare interface CustomMatcher {
372
438
  /**
@@ -571,6 +637,42 @@ declare interface ExpectStatic_2 extends Chai.ExpectStatic, Matchers, Asymmetric
571
637
  not: AsymmetricMatchersContaining;
572
638
  }
573
639
 
640
+ declare class FileCoverage implements FileCoverageData {
641
+ constructor(data: string | FileCoverage | FileCoverageData);
642
+ merge(other: FileCoverageData): void;
643
+ getBranchCoverageByLine(): { [line: number]: Coverage };
644
+ getLineCoverage(): { [line: number]: number };
645
+ getUncoveredLines(): number[];
646
+ resetHits(): void;
647
+ computeBranchTotals(): Totals;
648
+ computeSimpleTotals(): Totals;
649
+ toSummary(): CoverageSummary;
650
+ toJSON(): object;
651
+
652
+ data: FileCoverageData;
653
+ path: string;
654
+ statementMap: { [key: string]: Range_2 };
655
+ fnMap: { [key: string]: FunctionMapping };
656
+ branchMap: { [key: string]: BranchMapping };
657
+ s: { [key: string]: number };
658
+ f: { [key: string]: number };
659
+ b: { [key: string]: number[] };
660
+ }
661
+
662
+ declare interface FileCoverageData {
663
+ path: string;
664
+ statementMap: { [key: string]: Range_2 };
665
+ fnMap: { [key: string]: FunctionMapping };
666
+ branchMap: { [key: string]: BranchMapping };
667
+ s: { [key: string]: number };
668
+ f: { [key: string]: number };
669
+ b: { [key: string]: number[] };
670
+ }
671
+
672
+ declare interface FileOptions {
673
+ file: string;
674
+ }
675
+
574
676
  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
677
 
576
678
  declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
@@ -600,6 +702,13 @@ declare interface Formatter {
600
702
  close: string;
601
703
  }
602
704
 
705
+ declare interface FunctionMapping {
706
+ name: string;
707
+ decl: Range_2;
708
+ loc: Range_2;
709
+ line: number;
710
+ }
711
+
603
712
  declare type GeneratedColumn = number;
604
713
 
605
714
  declare function getMatcherUtils(): {
@@ -638,6 +747,17 @@ declare class GithubActionsReporter {
638
747
  }): Promise<void>;
639
748
  }
640
749
 
750
+ declare interface HtmlOptions {
751
+ verbose: boolean;
752
+ skipEmpty: boolean;
753
+ subdir: string;
754
+ linkMapper: LinkMapper;
755
+ }
756
+
757
+ declare interface HtmlSpaOptions extends HtmlOptions {
758
+ metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
759
+ }
760
+
641
761
  declare type Indent = (arg0: string) => string;
642
762
 
643
763
  declare interface InlineSnapshotMatcher<T> {
@@ -1036,6 +1156,10 @@ declare interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomM
1036
1156
  nthReturnedWith: <E>(nthCall: number, value: E) => void;
1037
1157
  }
1038
1158
 
1159
+ declare type JsonOptions = FileOptions;
1160
+
1161
+ declare type JsonSummaryOptions = FileOptions;
1162
+
1039
1163
  declare class JUnitReporter implements Reporter {
1040
1164
  private rootPath;
1041
1165
  private outputPath?;
@@ -1058,6 +1182,21 @@ declare class JUnitReporter implements Reporter {
1058
1182
  }): Promise<void>;
1059
1183
  }
1060
1184
 
1185
+ declare interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
1186
+
1187
+ declare interface LcovOptions extends FileOptions, ProjectOptions {}
1188
+
1189
+ declare interface LinkMapper {
1190
+ getPath(node: string | Node_2): string;
1191
+ relativePath(source: string | Node_2, target: string | Node_2): string;
1192
+ assetPath(node: Node_2, name: string): string;
1193
+ }
1194
+
1195
+ declare interface Location_2 {
1196
+ line: number;
1197
+ column: number;
1198
+ }
1199
+
1061
1200
  declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
1062
1201
 
1063
1202
  declare interface MatcherHintOptions {
@@ -1414,15 +1553,26 @@ declare interface NewPlugin {
1414
1553
  test: Test;
1415
1554
  }
1416
1555
 
1417
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage'>> & {
1556
+ declare interface Node_2 {
1557
+ isRoot(): boolean;
1558
+ visit(visitor: Visitor, state: any): void;
1559
+ }
1560
+
1561
+ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'exclude'>> & {
1418
1562
  [key in OptionalKeys]?: RstestConfig[key];
1419
1563
  } & {
1420
1564
  pool: RstestPoolOptions;
1421
1565
  coverage: NormalizedCoverageOptions;
1566
+ setupFiles: string[];
1567
+ exclude: {
1568
+ patterns: string[];
1569
+ override?: boolean;
1570
+ };
1422
1571
  };
1423
1572
 
1424
- declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds'>> & {
1573
+ declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds' | 'include'>> & {
1425
1574
  thresholds?: CoverageThresholds;
1575
+ include?: string[];
1426
1576
  };
1427
1577
 
1428
1578
  declare type NormalizedFixture = {
@@ -1436,8 +1586,10 @@ declare type NormalizedFixtures = Record<string, NormalizedFixture>;
1436
1586
 
1437
1587
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1438
1588
 
1439
- declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
1589
+ declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool' | 'setupFiles'>> & {
1440
1590
  [key in OptionalKeys]?: NormalizedConfig[key];
1591
+ } & {
1592
+ setupFiles: string[];
1441
1593
  };
1442
1594
 
1443
1595
  declare interface OldPlugin {
@@ -1457,7 +1609,7 @@ declare type OnTestFinishedHandler = (params: {
1457
1609
  };
1458
1610
  }) => MaybePromise<void>;
1459
1611
 
1460
- declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1612
+ declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1461
1613
 
1462
1614
  declare type OptionsReceived = PrettyFormatOptions;
1463
1615
 
@@ -1518,6 +1670,10 @@ declare type ProjectContext = {
1518
1670
  normalizedConfig: NormalizedProjectConfig;
1519
1671
  };
1520
1672
 
1673
+ declare interface ProjectOptions {
1674
+ projectRoot: string;
1675
+ }
1676
+
1521
1677
  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
1678
 
1523
1679
  declare type Promisify_2<O> = {
@@ -1528,6 +1684,11 @@ declare type PromisifyAssertion<T> = Promisify<Assertion<T>>;
1528
1684
 
1529
1685
  declare type PromisifyAssertion_2<T> = Promisify_2<Assertion_2<T>>;
1530
1686
 
1687
+ declare interface Range_2 {
1688
+ start: Location_2;
1689
+ end: Location_2;
1690
+ }
1691
+
1531
1692
  declare interface RawMatcherFn<
1532
1693
  T extends MatcherState = MatcherState,
1533
1694
  E extends Array<any> = Array<any>
@@ -1586,6 +1747,22 @@ declare const reportersMap: {
1586
1747
 
1587
1748
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
1588
1749
 
1750
+ declare interface ReportOptions {
1751
+ clover: CloverOptions;
1752
+ cobertura: CoberturaOptions;
1753
+ "html-spa": HtmlSpaOptions;
1754
+ html: HtmlOptions;
1755
+ json: JsonOptions;
1756
+ "json-summary": JsonSummaryOptions;
1757
+ lcov: LcovOptions;
1758
+ lcovonly: LcovOnlyOptions;
1759
+ none: never;
1760
+ teamcity: TeamcityOptions;
1761
+ text: TextOptions;
1762
+ "text-lcov": TextLcovOptions;
1763
+ "text-summary": TextSummaryOptions;
1764
+ }
1765
+
1589
1766
  declare type ReportWithOptions<Name extends keyof ReportOptions = keyof ReportOptions> = Name extends keyof ReportOptions ? [Name, Partial<ReportOptions[Name]>] : [Name, Record<string, unknown>];
1590
1767
 
1591
1768
  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 +1803,14 @@ declare interface RstestConfig {
1626
1803
  *
1627
1804
  * @default ['**\/node_modules/**', '**\/dist/**']
1628
1805
  */
1629
- exclude?: string[];
1806
+ exclude?: string[] | {
1807
+ patterns: string[];
1808
+ /**
1809
+ * override default exclude patterns
1810
+ * @default false
1811
+ */
1812
+ override?: boolean;
1813
+ };
1630
1814
  /**
1631
1815
  * A list of glob patterns that match your in-source test files
1632
1816
  *
@@ -2057,6 +2241,10 @@ declare interface TaskResult {
2057
2241
 
2058
2242
  declare type TaskState = 'pass' | 'fail';
2059
2243
 
2244
+ declare interface TeamcityOptions extends FileOptions {
2245
+ blockName: string;
2246
+ }
2247
+
2060
2248
  declare type Test = (arg0: any) => boolean;
2061
2249
 
2062
2250
  declare type Test_2 = TestSuite | TestCase;
@@ -2136,6 +2324,7 @@ declare type TestFileInfo = {
2136
2324
  declare type TestFileResult = TestResult & {
2137
2325
  results: TestResult[];
2138
2326
  snapshotResult?: SnapshotResult;
2327
+ coverage?: CoverageMapData;
2139
2328
  };
2140
2329
 
2141
2330
  declare type TestFn<ExtraContext = object> = (description: string, fn?: TestCallbackFn<ExtraContext>, timeout?: number) => void;
@@ -2186,16 +2375,22 @@ declare type TestSuite = {
2186
2375
  beforeEachListeners?: BeforeEachListener[];
2187
2376
  };
2188
2377
 
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
- };
2378
+ declare type TextLcovOptions = ProjectOptions;
2379
+
2380
+ declare interface TextOptions extends FileOptions {
2381
+ maxCols: number;
2382
+ skipEmpty: boolean;
2383
+ skipFull: boolean;
2384
+ }
2385
+
2386
+ declare type TextSummaryOptions = FileOptions;
2387
+
2388
+ declare interface Totals {
2389
+ total: number;
2390
+ covered: number;
2391
+ skipped: number;
2392
+ pct: number;
2393
+ }
2199
2394
 
2200
2395
  declare class TraceMap implements SourceMap {
2201
2396
  version: SourceMapV3['version'];
@@ -2233,6 +2428,14 @@ declare class VerboseReporter extends DefaultReporter {
2233
2428
  onTestFileResult(test: TestFileResult): void;
2234
2429
  }
2235
2430
 
2431
+ declare interface Visitor<N extends Node_2 = Node_2> {
2432
+ onStart(root: N, state: any): void;
2433
+ onSummary(root: N, state: any): void;
2434
+ onDetail(root: N, state: any): void;
2435
+ onSummaryEnd(root: N, state: any): void;
2436
+ onEnd(root: N, state: any): void;
2437
+ }
2438
+
2236
2439
  declare type VitestAssertion<
2237
2440
  A,
2238
2441
  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.0",
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": {