vitest 0.28.5 → 0.29.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.
Files changed (44) hide show
  1. package/LICENSE.md +1 -1
  2. package/coverage.d.ts +1 -0
  3. package/dist/browser.d.ts +2 -1
  4. package/dist/browser.js +3 -3
  5. package/dist/child.js +89 -0
  6. package/dist/{chunk-api-setup.d88afda6.js → chunk-api-setup.d9eccaeb.js} +3 -3
  7. package/dist/{chunk-env-node.ffd1183b.js → chunk-env-node.affdd278.js} +1 -2
  8. package/dist/{chunk-install-pkg.e1e08354.js → chunk-install-pkg.ea1a5ef4.js} +9 -8
  9. package/dist/chunk-integrations-coverage.e0a6acd2.js +51 -0
  10. package/dist/{chunk-integrations-globals.59432f4f.js → chunk-integrations-globals.b56fcb06.js} +7 -7
  11. package/dist/{chunk-integrations-run-once.38756e30.js → chunk-integrations-run-once.9012f759.js} +1 -1
  12. package/dist/{chunk-integrations-utils.9717ad89.js → chunk-integrations-utils.233d6a3b.js} +2 -2
  13. package/dist/{chunk-node-git.d9ad64ab.js → chunk-node-git.ed5bded8.js} +1 -2
  14. package/dist/{chunk-node-pkg.9a107dfb.js → chunk-node-pkg.88e7e848.js} +4403 -246
  15. package/dist/{chunk-runtime-mocker.dafe0f77.js → chunk-runtime-mocker.a048e92d.js} +63 -13
  16. package/dist/chunk-runtime-rpc.971b3848.js +61 -0
  17. package/dist/{chunk-runtime-setup.30ab0a4b.js → chunk-runtime-setup.992bb661.js} +2 -2
  18. package/dist/{chunk-utils-base.904102a8.js → chunk-utils-base.81f83dbd.js} +15 -1
  19. package/dist/{chunk-utils-global.442d1d33.js → chunk-utils-global.727b6d25.js} +1 -7
  20. package/dist/{chunk-utils-import.847b4a2d.js → chunk-utils-import.ec15dcad.js} +5 -5
  21. package/dist/{chunk-utils-tasks.d07dcea9.js → chunk-utils-tasks.b41c8284.js} +1 -1
  22. package/dist/cli-wrapper.js +1 -2
  23. package/dist/cli.js +12 -11
  24. package/dist/config.cjs +1 -1
  25. package/dist/config.d.ts +8 -7
  26. package/dist/config.js +1 -1
  27. package/dist/coverage.d.ts +142 -0
  28. package/dist/coverage.js +49 -0
  29. package/dist/entry.js +30 -73
  30. package/dist/environments.d.ts +2 -1
  31. package/dist/environments.js +1 -1
  32. package/dist/index.d.ts +3 -2
  33. package/dist/index.js +8 -8
  34. package/dist/loader.js +2 -2
  35. package/dist/node.d.ts +5 -3
  36. package/dist/node.js +13 -12
  37. package/dist/runners.d.ts +2 -1
  38. package/dist/runners.js +5 -5
  39. package/dist/{types-0373403c.d.ts → types-7cd96283.d.ts} +162 -37
  40. package/dist/{vendor-index.618ca5a1.js → vendor-index.2cbcdd1e.js} +18 -13
  41. package/dist/worker.js +12 -53
  42. package/package.json +16 -10
  43. package/dist/chunk-integrations-coverage.48e6286b.js +0 -3993
  44. package/dist/chunk-runtime-rpc.9c0386cc.js +0 -31
@@ -1,15 +1,16 @@
1
1
  import { MatchersObject, MatcherState } from '@vitest/expect';
2
- import { UserConfig as UserConfig$1, ViteDevServer, CommonServerOptions, AliasOptions } from 'vite';
2
+ import { UserConfig as UserConfig$1, ViteDevServer, CommonServerOptions, DepOptimizationConfig, AliasOptions } from 'vite';
3
3
  import { File, Test as Test$1, Suite, TaskResultPack, Task } from '@vitest/runner/types';
4
4
  import * as _vitest_runner from '@vitest/runner';
5
- import { Task as Task$1, File as File$1, TaskResultPack as TaskResultPack$1, Test as Test$2, TaskCustom } from '@vitest/runner';
5
+ import { Task as Task$1, Test as Test$2, TaskCustom } from '@vitest/runner';
6
6
  import { ParsedStack, ErrorWithDiff, ChainableFunction } from '@vitest/runner/utils';
7
7
  import { Arrayable as Arrayable$1 } from '@vitest/utils';
8
8
  import { Task as Task$2, TaskResult, Bench, Options } from 'tinybench';
9
9
  import { ViteNodeRunner } from 'vite-node/client';
10
10
  import { ViteNodeServer } from 'vite-node/server';
11
11
  import { MessagePort } from 'node:worker_threads';
12
- import { RawSourceMap, ViteNodeResolveId, FetchFunction, ModuleCacheMap } from 'vite-node';
12
+ import { RawSourceMap, FetchResult, ViteNodeResolveId, ModuleCacheMap } from 'vite-node';
13
+ import { RawSourceMap as RawSourceMap$1 } from 'source-map';
13
14
  import { Stats } from 'node:fs';
14
15
 
15
16
  /**
@@ -252,7 +253,7 @@ declare class Typechecker {
252
253
  }
253
254
 
254
255
  type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
255
- interface WorkerPool {
256
+ interface ProcessPool {
256
257
  runTests: RunWithFiles;
257
258
  close: () => Promise<void>;
258
259
  }
@@ -375,7 +376,7 @@ declare class Vitest {
375
376
  reporters: Reporter[];
376
377
  coverageProvider: CoverageProvider | null | undefined;
377
378
  logger: Logger;
378
- pool: WorkerPool | undefined;
379
+ pool: ProcessPool | undefined;
379
380
  typechecker: Typechecker | undefined;
380
381
  vitenode: ViteNodeServer;
381
382
  invalidates: Set<string>;
@@ -417,7 +418,10 @@ declare class Vitest {
417
418
  */
418
419
  exit(force?: boolean): Promise<void>;
419
420
  report<T extends keyof Reporter>(name: T, ...args: ArgumentsType$1<Reporter[T]>): Promise<void>;
420
- globFiles(filters: string[], include: string[], exclude: string[]): Promise<string[]>;
421
+ globFiles(include: string[], exclude: string[], cwd: string): Promise<string[]>;
422
+ private _allTestsCache;
423
+ globAllTestFiles(config: ResolvedConfig, cwd: string): Promise<string[]>;
424
+ filterFiles(testFiles: string[], filters?: string[]): string[];
421
425
  globTestFiles(filters?: string[]): Promise<string[]>;
422
426
  isTargetFile(id: string, source?: string): Promise<boolean>;
423
427
  isInSourceTestFile(code: string): boolean;
@@ -890,6 +894,87 @@ interface AcornNode {
890
894
  type: string;
891
895
  }
892
896
 
897
+ // Type definitions for istanbul-lib-report 3.0
898
+
899
+
900
+ interface Node {
901
+ isRoot(): boolean;
902
+ visit(visitor: Visitor, state: any): void;
903
+ }
904
+
905
+ interface Visitor<N extends Node = Node> {
906
+ onStart(root: N, state: any): void;
907
+ onSummary(root: N, state: any): void;
908
+ onDetail(root: N, state: any): void;
909
+ onSummaryEnd(root: N, state: any): void;
910
+ onEnd(root: N, state: any): void;
911
+ }
912
+
913
+ // Type definitions for istanbul-reports 3.0
914
+
915
+
916
+ interface FileOptions {
917
+ file: string;
918
+ }
919
+
920
+ interface ProjectOptions {
921
+ projectRoot: string;
922
+ }
923
+
924
+ interface ReportOptions {
925
+ clover: CloverOptions;
926
+ cobertura: CoberturaOptions;
927
+ 'html-spa': HtmlSpaOptions;
928
+ html: HtmlOptions;
929
+ json: JsonOptions;
930
+ 'json-summary': JsonSummaryOptions;
931
+ lcov: LcovOptions;
932
+ lcovonly: LcovOnlyOptions;
933
+ none: never;
934
+ teamcity: TeamcityOptions;
935
+ text: TextOptions;
936
+ 'text-lcov': TextLcovOptions;
937
+ 'text-summary': TextSummaryOptions;
938
+ }
939
+
940
+ interface CloverOptions extends FileOptions, ProjectOptions {}
941
+
942
+ interface CoberturaOptions extends FileOptions, ProjectOptions {}
943
+
944
+ interface HtmlSpaOptions extends HtmlOptions {
945
+ metricsToShow: Array<'lines' | 'branches' | 'functions' | 'statements'>;
946
+ }
947
+ interface HtmlOptions {
948
+ verbose: boolean;
949
+ skipEmpty: boolean;
950
+ subdir: string;
951
+ linkMapper: LinkMapper;
952
+ }
953
+
954
+ type JsonOptions = FileOptions;
955
+ type JsonSummaryOptions = FileOptions;
956
+
957
+ interface LcovOptions extends FileOptions, ProjectOptions {}
958
+ interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
959
+
960
+ interface TeamcityOptions extends FileOptions {
961
+ blockName: string;
962
+ }
963
+
964
+ interface TextOptions extends FileOptions {
965
+ maxCols: number;
966
+ skipEmpty: boolean;
967
+ skipFull: boolean;
968
+ }
969
+ type TextLcovOptions = ProjectOptions;
970
+ type TextSummaryOptions = FileOptions;
971
+
972
+ interface LinkMapper {
973
+ getPath(node: string | Node): string;
974
+ relativePath(source: string | Node, target: string | Node): string;
975
+ assetPath(node: Node, name: string): string;
976
+ }
977
+
893
978
  declare type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
894
979
  declare type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
895
980
  declare type PromisifyFn<T> = ReturnType$1<T> extends Promise<any> ? T : (...args: ArgumentsType<T>) => Promise<Awaited<ReturnType$1<T>>>;
@@ -950,36 +1035,44 @@ interface SnapshotSummary {
950
1035
  updated: number;
951
1036
  }
952
1037
 
953
- interface WorkerContext {
954
- workerId: number;
955
- port: MessagePort;
956
- config: ResolvedConfig;
957
- files: string[];
958
- invalidates?: string[];
959
- }
960
- type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
961
- interface AfterSuiteRunMeta {
962
- coverage?: unknown;
963
- }
964
- interface WorkerRPC {
965
- fetch: FetchFunction;
966
- resolveId: ResolveIdFunction;
967
- getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
968
- onFinished: (files: File$1[], errors?: unknown[]) => void;
1038
+ interface RuntimeRPC {
1039
+ fetch: (id: string, environment: VitestEnvironment) => Promise<FetchResult>;
1040
+ resolveId: (id: string, importer: string | undefined, environment: VitestEnvironment) => Promise<ViteNodeResolveId | null>;
1041
+ getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap$1 | undefined>;
1042
+ onFinished: (files: File[], errors?: unknown[]) => void;
969
1043
  onWorkerExit: (error: unknown, code?: number) => void;
970
1044
  onPathsCollected: (paths: string[]) => void;
971
1045
  onUserConsoleLog: (log: UserConsoleLog) => void;
972
1046
  onUnhandledError: (err: unknown, type: string) => void;
973
- onCollected: (files: File$1[]) => void;
1047
+ onCollected: (files: File[]) => void;
974
1048
  onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
975
- onTaskUpdate: (pack: TaskResultPack$1[]) => void;
1049
+ onTaskUpdate: (pack: TaskResultPack[]) => void;
976
1050
  snapshotSaved: (snapshot: SnapshotResult) => void;
977
1051
  resolveSnapshotPath: (testPath: string) => string;
978
1052
  }
1053
+ interface ContextTestEnvironment {
1054
+ name: VitestEnvironment;
1055
+ options: EnvironmentOptions | null;
1056
+ }
1057
+ interface ContextRPC {
1058
+ config: ResolvedConfig;
1059
+ files: string[];
1060
+ invalidates?: string[];
1061
+ environment: ContextTestEnvironment;
1062
+ }
1063
+
1064
+ interface WorkerContext extends ContextRPC {
1065
+ workerId: number;
1066
+ port: MessagePort;
1067
+ }
1068
+ type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
1069
+ interface AfterSuiteRunMeta {
1070
+ coverage?: unknown;
1071
+ }
979
1072
  interface WorkerGlobalState {
980
1073
  ctx: WorkerContext;
981
1074
  config: ResolvedConfig;
982
- rpc: BirpcReturn<WorkerRPC>;
1075
+ rpc: BirpcReturn<RuntimeRPC>;
983
1076
  current?: Test$2;
984
1077
  filepath?: string;
985
1078
  moduleCache: ModuleCacheMap;
@@ -991,7 +1084,6 @@ interface CoverageProvider {
991
1084
  initialize(ctx: Vitest): Promise<void> | void;
992
1085
  resolveOptions(): ResolvedCoverageOptions;
993
1086
  clean(clean?: boolean): void | Promise<void>;
994
- onBeforeFilesRun?(): void | Promise<void>;
995
1087
  onAfterSuiteRun(meta: AfterSuiteRunMeta): void | Promise<void>;
996
1088
  reportCoverage(reportContext?: ReportContext): void | Promise<void>;
997
1089
  onFileTransform?(sourceCode: string, id: string, pluginCtx: TransformPluginContext): TransformResult | Promise<TransformResult>;
@@ -1005,24 +1097,35 @@ interface CoverageProviderModule {
1005
1097
  * Factory for creating a new coverage provider
1006
1098
  */
1007
1099
  getProvider(): CoverageProvider | Promise<CoverageProvider>;
1100
+ /**
1101
+ * Executed before tests are run in the worker thread.
1102
+ */
1103
+ startCoverage?(): unknown | Promise<unknown>;
1008
1104
  /**
1009
1105
  * Executed on after each run in the worker thread. Possible to return a payload passed to the provider
1010
1106
  */
1011
1107
  takeCoverage?(): unknown | Promise<unknown>;
1108
+ /**
1109
+ * Executed after all tests have been run in the worker thread.
1110
+ */
1111
+ stopCoverage?(): unknown | Promise<unknown>;
1012
1112
  }
1013
- type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
1014
- type Provider = 'c8' | 'istanbul' | CoverageProviderModule | undefined;
1015
- type CoverageOptions<T extends Provider = Provider> = T extends CoverageProviderModule ? ({
1113
+ type CoverageReporter = keyof ReportOptions;
1114
+ type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends CoverageReporter ? ReportOptions[ReporterName] extends never ? [ReporterName, {}] : [ReporterName, Partial<ReportOptions[ReporterName]>] : never;
1115
+ type Provider = 'c8' | 'istanbul' | 'custom' | undefined;
1116
+ type CoverageOptions<T extends Provider = Provider> = T extends 'istanbul' ? ({
1016
1117
  provider: T;
1017
- } & BaseCoverageOptions) : T extends 'istanbul' ? ({
1118
+ } & CoverageIstanbulOptions) : T extends 'c8' ? ({
1018
1119
  provider: T;
1019
- } & CoverageIstanbulOptions) : ({
1120
+ } & CoverageC8Options) : T extends 'custom' ? ({
1121
+ provider: T;
1122
+ } & CustomProviderOptions) : ({
1020
1123
  provider?: T;
1021
- } & CoverageC8Options);
1124
+ } & (CoverageC8Options));
1022
1125
  /** Fields that have default values. Internally these will always be defined. */
1023
- type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension' | 'reporter';
1126
+ type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension';
1024
1127
  type ResolvedCoverageOptions<T extends Provider = Provider> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
1025
- reporter: CoverageReporter[];
1128
+ reporter: CoverageReporterWithOptions[];
1026
1129
  };
1027
1130
  interface BaseCoverageOptions {
1028
1131
  /**
@@ -1075,7 +1178,7 @@ interface BaseCoverageOptions {
1075
1178
  *
1076
1179
  * @default ['text', 'html', 'clover', 'json']
1077
1180
  */
1078
- reporter?: Arrayable<CoverageReporter>;
1181
+ reporter?: Arrayable<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
1079
1182
  /**
1080
1183
  * Do not show files with 100% statement, branch, and function coverage
1081
1184
  *
@@ -1113,6 +1216,12 @@ interface BaseCoverageOptions {
1113
1216
  * @default undefined
1114
1217
  */
1115
1218
  statements?: number;
1219
+ /**
1220
+ * Update threshold values automatically when current coverage is higher than earlier thresholds
1221
+ *
1222
+ * @default false
1223
+ */
1224
+ thresholdAutoUpdate?: boolean;
1116
1225
  }
1117
1226
  interface CoverageIstanbulOptions extends BaseCoverageOptions {
1118
1227
  /**
@@ -1159,6 +1268,10 @@ interface CoverageC8Options extends BaseCoverageOptions {
1159
1268
  */
1160
1269
  100?: boolean;
1161
1270
  }
1271
+ interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
1272
+ /** Name of the module or path to a file to load the custom provider from */
1273
+ customProviderModule: string;
1274
+ }
1162
1275
 
1163
1276
  interface JSDOMOptions {
1164
1277
  /**
@@ -1336,6 +1449,12 @@ interface InlineConfig {
1336
1449
  * Handling for dependencies inlining or externalizing
1337
1450
  */
1338
1451
  deps?: {
1452
+ /**
1453
+ * Enable dependency optimization. This can improve the performance of your tests.
1454
+ */
1455
+ experimentalOptimizer?: Omit<DepOptimizationConfig, 'disabled'> & {
1456
+ enabled: boolean;
1457
+ };
1339
1458
  /**
1340
1459
  * Externalize means that Vite will bypass the package to native Node.
1341
1460
  *
@@ -1541,6 +1660,12 @@ interface InlineConfig {
1541
1660
  * @default true
1542
1661
  */
1543
1662
  isolate?: boolean;
1663
+ /**
1664
+ * Run tests inside a single thread.
1665
+ *
1666
+ * @default false
1667
+ */
1668
+ singleThread?: boolean;
1544
1669
  /**
1545
1670
  * Coverage options
1546
1671
  */
@@ -1828,7 +1953,7 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
1828
1953
  sequencer: TestSequencerConstructor;
1829
1954
  hooks: SequenceHooks;
1830
1955
  shuffle?: boolean;
1831
- seed?: number;
1956
+ seed: number;
1832
1957
  };
1833
1958
  typecheck: TypecheckConfig;
1834
1959
  runner?: string;
@@ -2041,4 +2166,4 @@ type Context = RootAndTarget & {
2041
2166
  lastActivePath?: string;
2042
2167
  };
2043
2168
 
2044
- export { CoverageReporter as $, ApiConfig as A, BenchmarkAPI as B, CollectLineNumbers as C, MergeInsertions as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, DeepMerge as G, MutableArray as H, InlineConfig as I, JSDOMOptions as J, Constructable as K, ModuleCache as L, MockFactoryWithHelper as M, Nullable as N, EnvironmentReturn as O, Environment as P, UserConsoleLog as Q, RuntimeConfig as R, SnapshotResult as S, TscErrorInfo as T, UserConfig as U, VitestEnvironment as V, WorkerContext as W, OnServerRestartHandler as X, CoverageProvider as Y, ReportContext as Z, CoverageProviderModule as _, ResolvedConfig as a, CoverageOptions as a0, ResolvedCoverageOptions as a1, BaseCoverageOptions as a2, CoverageIstanbulOptions as a3, CoverageC8Options as a4, BenchmarkUserOptions as a5, Benchmark as a6, BenchmarkResult as a7, BenchFunction as a8, MockFactory as a9, MockMap as aa, TestSequencer as ab, startVitest as ac, TestSequencerConstructor as ad, ModuleGraphData as b, Reporter as c, RawErrsMap as d, CollectLines as e, RootAndTarget as f, Context as g, BuiltinEnvironment as h, CSSModuleScopeStrategy as i, SequenceHooks as j, VitestRunMode as k, TypecheckConfig as l, Vitest as m, SnapshotData as n, SnapshotUpdateState as o, SnapshotStateOptions as p, SnapshotMatchOptions as q, UncheckedSnapshot as r, SnapshotSummary as s, ResolveIdFunction as t, AfterSuiteRunMeta as u, WorkerRPC as v, WorkerGlobalState as w, Awaitable as x, Arrayable as y, ArgumentsType$1 as z };
2169
+ export { ReportContext as $, ApiConfig as A, BenchmarkAPI as B, CollectLineNumbers as C, Arrayable as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, ArgumentsType$1 as G, MergeInsertions as H, InlineConfig as I, JSDOMOptions as J, DeepMerge as K, MutableArray as L, MockFactoryWithHelper as M, Nullable as N, Constructable as O, ModuleCache as P, EnvironmentReturn as Q, RuntimeConfig as R, SnapshotResult as S, TscErrorInfo as T, UserConfig as U, VitestEnvironment as V, WorkerContext as W, Environment as X, UserConsoleLog as Y, OnServerRestartHandler as Z, CoverageProvider as _, ResolvedConfig as a, CoverageProviderModule as a0, CoverageReporter as a1, CoverageOptions as a2, ResolvedCoverageOptions as a3, BaseCoverageOptions as a4, CoverageIstanbulOptions as a5, CoverageC8Options as a6, CustomProviderOptions as a7, BenchmarkUserOptions as a8, Benchmark as a9, BenchmarkResult as aa, BenchFunction as ab, MockFactory as ac, MockMap as ad, TestSequencer as ae, startVitest as af, TestSequencerConstructor as ag, HtmlOptions as ah, FileOptions as ai, CloverOptions as aj, CoberturaOptions as ak, HtmlSpaOptions as al, LcovOptions as am, LcovOnlyOptions as an, TeamcityOptions as ao, TextOptions as ap, ProjectOptions as aq, ModuleGraphData as b, Reporter as c, RawErrsMap as d, CollectLines as e, RootAndTarget as f, Context as g, BuiltinEnvironment as h, CSSModuleScopeStrategy as i, SequenceHooks as j, VitestRunMode as k, TypecheckConfig as l, RuntimeRPC as m, ContextTestEnvironment as n, ContextRPC as o, Vitest as p, SnapshotData as q, SnapshotUpdateState as r, SnapshotStateOptions as s, SnapshotMatchOptions as t, UncheckedSnapshot as u, SnapshotSummary as v, ResolveIdFunction as w, AfterSuiteRunMeta as x, WorkerGlobalState as y, Awaitable as z };
@@ -7,8 +7,7 @@ import k from 'path';
7
7
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
8
8
  import require$$0 from 'fs';
9
9
  import url from 'node:url';
10
- import { constants } from 'os';
11
- import os from 'node:os';
10
+ import os, { constants } from 'node:os';
12
11
  import require$$0$2 from 'assert';
13
12
  import require$$2 from 'events';
14
13
  import require$$0$5 from 'buffer';
@@ -1135,16 +1134,21 @@ return {name,number,description,supported,action,forced,standard};
1135
1134
 
1136
1135
  const getSignalsByName=function(){
1137
1136
  const signals=getSignals();
1138
- return signals.reduce(getSignalByName,{});
1137
+ return Object.fromEntries(signals.map(getSignalByName));
1139
1138
  };
1140
1139
 
1141
- const getSignalByName=function(
1142
- signalByNameMemo,
1143
- {name,number,description,supported,action,forced,standard})
1140
+ const getSignalByName=function({
1141
+ name,
1142
+ number,
1143
+ description,
1144
+ supported,
1145
+ action,
1146
+ forced,
1147
+ standard})
1144
1148
  {
1145
- return {
1146
- ...signalByNameMemo,
1147
- [name]:{name,number,description,supported,action,forced,standard}};
1149
+ return [
1150
+ name,
1151
+ {name,number,description,supported,action,forced,standard}];
1148
1152
 
1149
1153
  };
1150
1154
 
@@ -1845,9 +1849,7 @@ var mergeStream = function (/*streams...*/) {
1845
1849
 
1846
1850
  // `input` option
1847
1851
  const handleInput = (spawned, input) => {
1848
- // Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
1849
- // @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
1850
- if (input === undefined || spawned.stdin === undefined) {
1852
+ if (input === undefined) {
1851
1853
  return;
1852
1854
  }
1853
1855
 
@@ -1879,7 +1881,8 @@ const makeAllStream = (spawned, {all}) => {
1879
1881
 
1880
1882
  // On failure, `result.stdout|stderr|all` should contain the currently buffered stream
1881
1883
  const getBufferedData = async (stream, streamPromise) => {
1882
- if (!stream) {
1884
+ // When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve
1885
+ if (!stream || streamPromise === undefined) {
1883
1886
  return;
1884
1887
  }
1885
1888
 
@@ -1922,7 +1925,9 @@ const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuf
1922
1925
  }
1923
1926
  };
1924
1927
 
1928
+ // eslint-disable-next-line unicorn/prefer-top-level-await
1925
1929
  const nativePromisePrototype = (async () => {})().constructor.prototype;
1930
+
1926
1931
  const descriptors = ['then', 'catch', 'finally'].map(property => [
1927
1932
  property,
1928
1933
  Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),
package/dist/worker.js CHANGED
@@ -1,17 +1,16 @@
1
- import { pathToFileURL } from 'node:url';
2
- import { resolve, relative } from 'pathe';
3
1
  import { c as createBirpc } from './vendor-index.783e7f3e.js';
4
2
  import { workerId } from 'tinypool';
5
- import { processError } from '@vitest/runner/utils';
6
- import { ModuleCacheMap } from 'vite-node/client';
7
- import { isPrimitive } from 'vite-node/utils';
8
- import { d as distDir } from './chunk-constants.797d3ebf.js';
9
- import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
10
- import { c as createVitestExecutor } from './chunk-runtime-mocker.dafe0f77.js';
11
- import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
3
+ import { g as getWorkerState } from './chunk-utils-global.727b6d25.js';
4
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './chunk-runtime-mocker.a048e92d.js';
5
+ import { a as rpcDone } from './chunk-runtime-rpc.971b3848.js';
6
+ import 'pathe';
12
7
  import './chunk-utils-env.860d90c2.js';
13
8
  import 'std-env';
9
+ import '@vitest/runner/utils';
14
10
  import '@vitest/utils';
11
+ import 'node:url';
12
+ import 'vite-node/client';
13
+ import 'vite-node/utils';
15
14
  import './vendor-index.bdee400f.js';
16
15
  import 'acorn';
17
16
  import 'node:module';
@@ -21,51 +20,10 @@ import 'node:process';
21
20
  import 'node:path';
22
21
  import 'node:v8';
23
22
  import 'node:util';
24
- import './chunk-utils-base.904102a8.js';
23
+ import './chunk-constants.797d3ebf.js';
24
+ import './chunk-utils-base.81f83dbd.js';
25
25
  import '@vitest/spy';
26
26
 
27
- let _viteNode;
28
- const moduleCache = new ModuleCacheMap();
29
- const mockMap = /* @__PURE__ */ new Map();
30
- async function startViteNode(ctx) {
31
- if (_viteNode)
32
- return _viteNode;
33
- const { config } = ctx;
34
- const processExit = process.exit;
35
- process.exit = (code = process.exitCode || 0) => {
36
- const error = new Error(`process.exit called with "${code}"`);
37
- rpc().onWorkerExit(error, code);
38
- return processExit(code);
39
- };
40
- function catchError(err, type) {
41
- var _a;
42
- const worker = getWorkerState();
43
- const error = processError(err);
44
- if (worker.filepath && !isPrimitive(error)) {
45
- error.VITEST_TEST_NAME = (_a = worker.current) == null ? void 0 : _a.name;
46
- error.VITEST_TEST_PATH = relative(config.root, worker.filepath);
47
- }
48
- rpc().onUnhandledError(error, type);
49
- }
50
- process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
51
- process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
52
- const executor = await createVitestExecutor({
53
- fetchModule(id) {
54
- return rpc().fetch(id);
55
- },
56
- resolveId(id, importer) {
57
- return rpc().resolveId(id, importer);
58
- },
59
- moduleCache,
60
- mockMap,
61
- interopDefault: config.deps.interopDefault,
62
- root: config.root,
63
- base: config.base
64
- });
65
- const { run: run2 } = await import(pathToFileURL(resolve(distDir, "entry.js")).href);
66
- _viteNode = { run: run2, executor };
67
- return _viteNode;
68
- }
69
27
  function init(ctx) {
70
28
  if (typeof __vitest_worker__ !== "undefined" && ctx.config.threads && ctx.config.isolate)
71
29
  throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${getWorkerState().ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
@@ -102,7 +60,8 @@ function init(ctx) {
102
60
  async function run(ctx) {
103
61
  init(ctx);
104
62
  const { run: run2, executor } = await startViteNode(ctx);
105
- return run2(ctx.files, ctx.config, executor);
63
+ await run2(ctx.files, ctx.config, ctx.environment, executor);
64
+ await rpcDone();
106
65
  }
107
66
 
108
67
  export { run };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.28.5",
4
+ "version": "0.29.0",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -65,6 +65,10 @@
65
65
  "types": "./config.d.ts",
66
66
  "require": "./dist/config.cjs",
67
67
  "import": "./dist/config.js"
68
+ },
69
+ "./coverage": {
70
+ "types": "./coverage.d.ts",
71
+ "import": "./dist/coverage.js"
68
72
  }
69
73
  },
70
74
  "main": "./dist/index.js",
@@ -128,18 +132,20 @@
128
132
  "tinyspy": "^1.0.2",
129
133
  "vite": "^3.0.0 || ^4.0.0",
130
134
  "why-is-node-running": "^2.2.2",
131
- "vite-node": "0.28.5",
132
- "@vitest/expect": "0.28.5",
133
- "@vitest/runner": "0.28.5",
134
- "@vitest/utils": "0.28.5",
135
- "@vitest/spy": "0.28.5"
135
+ "@vitest/expect": "0.29.0",
136
+ "@vitest/runner": "0.29.0",
137
+ "@vitest/spy": "0.29.0",
138
+ "vite-node": "0.29.0",
139
+ "@vitest/utils": "0.29.0"
136
140
  },
137
141
  "devDependencies": {
138
142
  "@antfu/install-pkg": "^0.1.1",
139
143
  "@edge-runtime/vm": "2.0.2",
140
144
  "@sinonjs/fake-timers": "^10.0.2",
141
145
  "@types/diff": "^5.0.2",
142
- "@types/jsdom": "^20.0.1",
146
+ "@types/istanbul-lib-coverage": "^2.0.4",
147
+ "@types/istanbul-reports": "^3.0.1",
148
+ "@types/jsdom": "^21.1.0",
143
149
  "@types/micromatch": "^4.0.2",
144
150
  "@types/natural-compare": "^1.4.1",
145
151
  "@types/prompts": "^2.4.2",
@@ -149,14 +155,14 @@
149
155
  "cli-truncate": "^3.1.0",
150
156
  "diff": "^5.1.0",
151
157
  "event-target-polyfill": "^0.0.3",
152
- "execa": "^6.1.0",
158
+ "execa": "^7.0.0",
153
159
  "expect-type": "^0.15.0",
154
160
  "fast-glob": "^3.2.12",
155
161
  "find-up": "^6.3.0",
156
162
  "flatted": "^3.2.7",
157
163
  "get-tsconfig": "^4.3.0",
158
- "happy-dom": "^7.8.1",
159
- "jsdom": "^20.0.3",
164
+ "happy-dom": "^8.3.2",
165
+ "jsdom": "^21.1.0",
160
166
  "log-update": "^5.0.1",
161
167
  "magic-string": "^0.27.0",
162
168
  "micromatch": "^4.0.5",