@rstest/core 0.3.4 → 0.4.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,3 +1,4 @@
1
+ import type { ReportOptions } from 'istanbul-reports';
1
2
  import type { RsbuildConfig } from '@rsbuild/core';
2
3
 
3
4
  /**
@@ -317,6 +318,56 @@ declare class CounterMap<K> extends DefaultMap<K, number> {
317
318
  total(): number;
318
319
  }
319
320
 
321
+ declare type CoverageOptions = {
322
+ /**
323
+ * Enable coverage collection.
324
+ * @default false
325
+ */
326
+ enabled?: boolean;
327
+ /**
328
+ * A list of glob patterns that should be excluded from coverage collection.
329
+ *
330
+ * This option accepts an array of wax(https://crates.io/crates/wax)-compatible glob patterns
331
+ *
332
+ * @default ['**\/node_modules/**',
333
+ * '**\/dist/**',
334
+ * '**\/test/**',
335
+ * '**\/__tests__/**',
336
+ * '**\/*.{test,spec}.?(c|m)[jt]s?(x)',
337
+ * '**\/__mocks__/**'
338
+ * ]
339
+ */
340
+ exclude?: string[];
341
+ /**
342
+ * The provider to use for coverage collection.
343
+ * @default 'istanbul'
344
+ */
345
+ provider?: 'istanbul';
346
+ /**
347
+ * The reporters to use for coverage collection.
348
+ * @default ['text', 'html', 'clover', 'json']
349
+ */
350
+ reporters?: (keyof ReportOptions | ReportWithOptions)[];
351
+ /**
352
+ * The directory to store coverage reports.
353
+ * @default './coverage'
354
+ */
355
+ reportsDirectory?: string;
356
+ /**
357
+ * Whether to clean the coverage directory before running tests.
358
+ * @default true
359
+ */
360
+ clean?: boolean;
361
+ /**
362
+ * Coverage thresholds
363
+ *
364
+ * @default undefined
365
+ */
366
+ thresholds?: CoverageThresholds;
367
+ };
368
+
369
+ declare type CoverageThresholds = Thresholds;
370
+
320
371
  declare interface CustomMatcher {
321
372
  /**
322
373
  * Checks that a value satisfies a custom matcher function.
@@ -1363,10 +1414,15 @@ declare interface NewPlugin {
1363
1414
  test: Test;
1364
1415
  }
1365
1416
 
1366
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects'>> & {
1417
+ declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage'>> & {
1367
1418
  [key in OptionalKeys]?: RstestConfig[key];
1368
1419
  } & {
1369
1420
  pool: RstestPoolOptions;
1421
+ coverage: NormalizedCoverageOptions;
1422
+ };
1423
+
1424
+ declare type NormalizedCoverageOptions = Required<Omit<CoverageOptions, 'thresholds'>> & {
1425
+ thresholds?: CoverageThresholds;
1370
1426
  };
1371
1427
 
1372
1428
  declare type NormalizedFixture = {
@@ -1380,8 +1436,8 @@ declare type NormalizedFixtures = Record<string, NormalizedFixture>;
1380
1436
 
1381
1437
  declare type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
1382
1438
 
1383
- declare type NormalizedProjectConfig = Required<Omit<RstestConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
1384
- [key in OptionalKeys]?: RstestConfig[key];
1439
+ declare type NormalizedProjectConfig = Required<Omit<NormalizedConfig, OptionalKeys | 'projects' | 'reporters' | 'pool'>> & {
1440
+ [key in OptionalKeys]?: NormalizedConfig[key];
1385
1441
  };
1386
1442
 
1387
1443
  declare interface OldPlugin {
@@ -1451,11 +1507,12 @@ declare function printWithType<T>(name: string, value: T, print: (value: T) => s
1451
1507
 
1452
1508
  declare type Procedure = (...args: any[]) => any;
1453
1509
 
1454
- declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate'>;
1510
+ declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate' | 'coverage'>;
1455
1511
 
1456
1512
  declare type ProjectContext = {
1457
1513
  name: string;
1458
1514
  environmentName: string;
1515
+ /** The root path of current project. */
1459
1516
  rootPath: string;
1460
1517
  configFilePath?: string;
1461
1518
  normalizedConfig: NormalizedProjectConfig;
@@ -1529,6 +1586,8 @@ declare const reportersMap: {
1529
1586
 
1530
1587
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
1531
1588
 
1589
+ declare type ReportWithOptions<Name extends keyof ReportOptions = keyof ReportOptions> = Name extends keyof ReportOptions ? [Name, Partial<ReportOptions[Name]>] : [Name, Record<string, unknown>];
1590
+
1532
1591
  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;
1533
1592
 
1534
1593
  declare type RoArray<T> = Ro<T>[];
@@ -1687,6 +1746,10 @@ declare interface RstestConfig {
1687
1746
  * Custom handler for console log in tests
1688
1747
  */
1689
1748
  onConsoleLog?: (content: string) => boolean | void;
1749
+ /**
1750
+ * Coverage options
1751
+ */
1752
+ coverage?: CoverageOptions;
1690
1753
  plugins?: RsbuildConfig['plugins'];
1691
1754
  source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
1692
1755
  performance?: Pick<NonNullable<RsbuildConfig['performance']>, 'bundleAnalyze'>;
@@ -1699,7 +1762,7 @@ declare interface RstestConfig {
1699
1762
  declare type RstestContext = {
1700
1763
  /** The Rstest core version. */
1701
1764
  version: string;
1702
- /** The root path of current project. */
1765
+ /** The root path of rstest. */
1703
1766
  rootPath: string;
1704
1767
  /** The original Rstest config passed from the createRstest method. */
1705
1768
  originalConfig: Readonly<RstestConfig>;
@@ -1716,8 +1779,9 @@ declare type RstestContext = {
1716
1779
  /**
1717
1780
  * The command type.
1718
1781
  *
1719
- * - dev: `rstest dev`
1720
- * - run: `rstest run`
1782
+ * - run: `rstest`
1783
+ * - dev: `rstest dev` or watch mode
1784
+ * - list: `rstest list`
1721
1785
  */
1722
1786
  command: RstestCommand;
1723
1787
  reporters: Reporter[];
@@ -1728,7 +1792,7 @@ declare type RstestExpect = ExpectStatic;
1728
1792
 
1729
1793
  declare type RstestPoolOptions = {
1730
1794
  /** Pool used to run tests in. */
1731
- type: RstestPoolType;
1795
+ type?: RstestPoolType;
1732
1796
  /** Maximum number or percentage of workers to run tests in. */
1733
1797
  maxWorkers?: number | string;
1734
1798
  /** Minimum number or percentage of workers to run tests in. */
@@ -1757,7 +1821,7 @@ declare type RunnerAPI = {
1757
1821
  onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
1758
1822
  };
1759
1823
 
1760
- declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout'>;
1824
+ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage'>;
1761
1825
 
1762
1826
  /** Runtime to Server */
1763
1827
  declare type RuntimeRPC = {
@@ -2122,6 +2186,17 @@ declare type TestSuite = {
2122
2186
  beforeEachListeners?: BeforeEachListener[];
2123
2187
  };
2124
2188
 
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
+ };
2199
+
2125
2200
  declare class TraceMap implements SourceMap {
2126
2201
  version: SourceMapV3['version'];
2127
2202
  file: SourceMapV3['file'];
@@ -2167,6 +2242,7 @@ declare type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
2167
2242
 
2168
2243
  declare type WorkerContext = {
2169
2244
  rootPath: RstestContext['rootPath'];
2245
+ projectRoot: ProjectContext['rootPath'];
2170
2246
  project: string;
2171
2247
  runtimeConfig: RuntimeConfig;
2172
2248
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -56,26 +56,28 @@
56
56
  "@vitest/expect": "^3.2.4",
57
57
  "@vitest/snapshot": "^3.2.4",
58
58
  "@babel/code-frame": "^7.27.1",
59
- "@jridgewell/trace-mapping": "0.3.30",
60
- "@microsoft/api-extractor": "^7.52.11",
61
- "@rslib/core": "0.12.2",
59
+ "@jridgewell/trace-mapping": "0.3.31",
60
+ "@microsoft/api-extractor": "^7.52.13",
61
+ "@rslib/core": "0.13.3",
62
62
  "@sinonjs/fake-timers": "^14.0.0",
63
63
  "@types/babel__code-frame": "^7.0.6",
64
+ "@types/istanbul-reports": "^3.0.4",
65
+ "@types/istanbul-lib-coverage": "^2.0.6",
64
66
  "@types/jsdom": "^21.1.7",
65
67
  "@types/sinonjs__fake-timers": "^8.1.5",
66
68
  "@types/source-map-support": "^0.5.10",
67
69
  "cac": "^6.7.14",
68
70
  "chokidar": "^4.0.3",
69
71
  "happy-dom": "^18.0.1",
70
- "jest-diff": "^30.0.5",
72
+ "jest-diff": "^30.1.2",
71
73
  "jsdom": "^26.1.0",
72
74
  "license-webpack-plugin": "^4.0.2",
73
75
  "picocolors": "^1.1.1",
74
76
  "rslog": "^1.2.11",
75
77
  "source-map-support": "^0.5.21",
76
78
  "stacktrace-parser": "0.1.11",
77
- "strip-ansi": "^7.1.0",
78
- "tinyglobby": "^0.2.14",
79
+ "strip-ansi": "^7.1.2",
80
+ "tinyglobby": "^0.2.15",
79
81
  "tinyspy": "^4.0.3",
80
82
  "@rstest/tsconfig": "0.0.1"
81
83
  },
File without changes
File without changes
File without changes