vitest 0.30.0 → 0.31.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 (32) hide show
  1. package/LICENSE.md +331 -594
  2. package/dist/browser.d.ts +3 -4
  3. package/dist/browser.js +2 -2
  4. package/dist/child.js +12 -4
  5. package/dist/{chunk-api-setup.6662587e.js → chunk-api-setup.df3106cd.js} +14 -5
  6. package/dist/{chunk-install-pkg.6450b372.js → chunk-install-pkg.e0e70dba.js} +4 -5
  7. package/dist/{chunk-integrations-globals.d419838f.js → chunk-integrations-globals.88c8a0cf.js} +2 -2
  8. package/dist/cli.js +6 -7
  9. package/dist/config.cjs +1 -0
  10. package/dist/config.d.ts +11 -8
  11. package/dist/config.js +1 -0
  12. package/dist/coverage.d.ts +5 -5
  13. package/dist/coverage.js +6 -6
  14. package/dist/entry.js +22 -5
  15. package/dist/environments.d.ts +3 -4
  16. package/dist/index.d.ts +14 -6
  17. package/dist/index.js +3 -3
  18. package/dist/node.d.ts +4 -5
  19. package/dist/node.js +6 -7
  20. package/dist/runners.d.ts +7 -5
  21. package/dist/runners.js +12 -1
  22. package/dist/{types-f03c83c4.d.ts → types-b7007192.d.ts} +84 -328
  23. package/dist/{vendor-cli-api.c04eaa34.js → vendor-cli-api.de0530cb.js} +2061 -2353
  24. package/dist/{vendor-coverage.a585b712.js → vendor-coverage.c8fd34c3.js} +2 -0
  25. package/dist/{vendor-execute.8eaab47b.js → vendor-execute.a08cff9c.js} +2 -2
  26. package/dist/{vendor-index.4f82d248.js → vendor-index.7dcbfa46.js} +7 -1
  27. package/dist/{vendor-index.81b9e499.js → vendor-index.b0b501c8.js} +1 -1
  28. package/dist/{vendor-setup.common.cef38f4e.js → vendor-setup.common.266b69fb.js} +1 -1
  29. package/dist/{vendor-vi.a3ff54b1.js → vendor-vi.458e47b1.js} +9 -1
  30. package/dist/worker.js +13 -4
  31. package/package.json +11 -10
  32. package/suppress-warnings.cjs +1 -0
package/dist/browser.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { startTests } from '@vitest/runner';
2
- import { a as ResolvedConfig, _ as CoverageOptions, S as CoverageProvider, Y as CoverageProviderModule } from './types-f03c83c4.js';
3
- import '@vitest/expect';
2
+ import { a as ResolvedConfig, $ as CoverageOptions, X as CoverageProvider, Z as CoverageProviderModule } from './types-b7007192.js';
4
3
  import '@vitest/snapshot';
4
+ import '@vitest/expect';
5
5
  import 'vite';
6
6
  import '@vitest/runner/types';
7
7
  import '@vitest/runner/utils';
@@ -9,10 +9,9 @@ import '@vitest/utils';
9
9
  import 'tinybench';
10
10
  import 'vite-node/client';
11
11
  import '@vitest/snapshot/manager';
12
+ import 'vite-node/server';
12
13
  import 'node:worker_threads';
13
14
  import 'vite-node';
14
- import 'source-map';
15
- import 'vite-node/server';
16
15
  import 'node:fs';
17
16
  import 'chai';
18
17
 
package/dist/browser.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { startTests } from '@vitest/runner';
2
- export { s as setupCommonEnv } from './vendor-setup.common.cef38f4e.js';
3
- export { g as getCoverageProvider, a as startCoverageInsideWorker, s as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './vendor-coverage.a585b712.js';
2
+ export { s as setupCommonEnv } from './vendor-setup.common.266b69fb.js';
3
+ export { g as getCoverageProvider, a as startCoverageInsideWorker, s as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './vendor-coverage.c8fd34c3.js';
4
4
  import '@vitest/utils';
5
5
  import './vendor-run-once.69ce7172.js';
6
6
  import './vendor-index.fad2598b.js';
package/dist/child.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import v8 from 'node:v8';
2
- import { c as createBirpc } from './vendor-index.4f82d248.js';
2
+ import { c as createBirpc } from './vendor-index.7dcbfa46.js';
3
3
  import { parseRegexp } from '@vitest/utils';
4
- import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.8eaab47b.js';
4
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.a08cff9c.js';
5
5
  import { a as rpcDone } from './vendor-rpc.4d3d7a54.js';
6
6
  import { s as setupInspect } from './vendor-inspector.47fc8cbb.js';
7
7
  import 'node:url';
@@ -19,20 +19,28 @@ function init(ctx) {
19
19
  const { config } = ctx;
20
20
  process.env.VITEST_WORKER_ID = "1";
21
21
  process.env.VITEST_POOL_ID = "1";
22
+ let setCancel = (_reason) => {
23
+ };
24
+ const onCancel = new Promise((resolve) => {
25
+ setCancel = resolve;
26
+ });
22
27
  globalThis.__vitest_environment__ = config.environment;
23
28
  globalThis.__vitest_worker__ = {
24
29
  ctx,
25
30
  moduleCache,
26
31
  config,
27
32
  mockMap,
33
+ onCancel,
28
34
  durations: {
29
35
  environment: 0,
30
36
  prepare: performance.now()
31
37
  },
32
38
  rpc: createBirpc(
33
- {},
34
39
  {
35
- eventNames: ["onUserConsoleLog", "onFinished", "onCollected", "onWorkerExit"],
40
+ onCancel: setCancel
41
+ },
42
+ {
43
+ eventNames: ["onUserConsoleLog", "onFinished", "onCollected", "onWorkerExit", "onCancel"],
36
44
  serialize: v8.serialize,
37
45
  deserialize: (v) => v8.deserialize(Buffer.from(v)),
38
46
  post(v) {
@@ -1,5 +1,6 @@
1
1
  import { promises, existsSync } from 'node:fs';
2
- import { c as createBirpc, i as isPrimitive } from './vendor-index.4f82d248.js';
2
+ import { dirname } from 'pathe';
3
+ import { c as createBirpc, i as isPrimitive } from './vendor-index.7dcbfa46.js';
3
4
  import require$$0$2 from 'stream';
4
5
  import require$$0 from 'zlib';
5
6
  import require$$0$1 from 'buffer';
@@ -13,7 +14,6 @@ import require$$7 from 'url';
13
14
  import { A as API_PATH } from './vendor-constants.538d9b49.js';
14
15
  import './vendor-index.fad2598b.js';
15
16
  import { parseErrorStacktrace } from '@vitest/utils';
16
- import 'pathe';
17
17
  import 'std-env';
18
18
  import '@vitest/runner/utils';
19
19
  import './vendor-global.6795f91f.js';
@@ -4548,8 +4548,10 @@ function setup(vitestOrWorkspace, server) {
4548
4548
  snapshotSaved(snapshot) {
4549
4549
  ctx.snapshot.add(snapshot);
4550
4550
  },
4551
- writeFile(id, content) {
4552
- return promises.writeFile(id, content, "utf-8");
4551
+ async writeFile(id, content, ensureDir) {
4552
+ if (ensureDir)
4553
+ await promises.mkdir(dirname(id), { recursive: true });
4554
+ return await promises.writeFile(id, content, "utf-8");
4553
4555
  },
4554
4556
  async rerun(files) {
4555
4557
  await ctx.rerunFiles(files);
@@ -4574,16 +4576,23 @@ function setup(vitestOrWorkspace, server) {
4574
4576
  if (!file)
4575
4577
  return ctx.updateSnapshot();
4576
4578
  return ctx.updateSnapshot([file.filepath]);
4579
+ },
4580
+ onCancel(reason) {
4581
+ ctx.cancelCurrentRun(reason);
4582
+ },
4583
+ getCountOfFailedTests() {
4584
+ return ctx.state.getCountOfFailedTests();
4577
4585
  }
4578
4586
  },
4579
4587
  {
4580
4588
  post: (msg) => ws.send(msg),
4581
4589
  on: (fn) => ws.on("message", fn),
4582
- eventNames: ["onUserConsoleLog", "onFinished", "onCollected"],
4590
+ eventNames: ["onUserConsoleLog", "onFinished", "onCollected", "onCancel"],
4583
4591
  serialize: stringify,
4584
4592
  deserialize: parse$3
4585
4593
  }
4586
4594
  );
4595
+ ctx.onCancel((reason) => rpc.onCancel(reason));
4587
4596
  clients.set(ws, rpc);
4588
4597
  ws.on("close", () => {
4589
4598
  clients.delete(ws);
@@ -3,7 +3,7 @@ import p from 'path';
3
3
  import require$$0$1 from 'util';
4
4
  import require$$0$3 from 'child_process';
5
5
  import { p as pathKey, s as signalExit, m as mergeStream$1, g as getStream$1, c as crossSpawn$1 } from './vendor-index.c1e09929.js';
6
- import { o as onetime$1 } from './vendor-cli-api.c04eaa34.js';
6
+ import { o as onetime$1 } from './vendor-cli-api.de0530cb.js';
7
7
  import require$$0$2 from 'os';
8
8
  import 'node:buffer';
9
9
  import 'node:path';
@@ -20,7 +20,7 @@ import 'stream';
20
20
  import 'node:util';
21
21
  import 'pathe';
22
22
  import './vendor-constants.538d9b49.js';
23
- import './vendor-coverage.a585b712.js';
23
+ import './vendor-coverage.c8fd34c3.js';
24
24
  import './vendor-index.75f2b63d.js';
25
25
  import 'node:console';
26
26
  import 'local-pkg';
@@ -34,9 +34,10 @@ import 'vite';
34
34
  import 'vite-node/utils';
35
35
  import 'vite-node/client';
36
36
  import '@vitest/snapshot/manager';
37
+ import 'vite-node/server';
37
38
  import './vendor-paths.84fc7a99.js';
38
39
  import 'node:v8';
39
- import './vendor-index.4f82d248.js';
40
+ import './vendor-index.7dcbfa46.js';
40
41
  import 'node:worker_threads';
41
42
  import 'tinypool';
42
43
  import 'node:perf_hooks';
@@ -44,13 +45,11 @@ import './vendor-tasks.042d6084.js';
44
45
  import 'node:module';
45
46
  import 'node:crypto';
46
47
  import 'node:fs/promises';
47
- import 'source-map';
48
48
  import 'module';
49
49
  import 'acorn';
50
50
  import 'acorn-walk';
51
51
  import 'magic-string';
52
52
  import 'strip-literal';
53
- import 'vite-node/server';
54
53
  import 'node:readline';
55
54
  import 'readline';
56
55
 
@@ -1,7 +1,7 @@
1
1
  import { g as globalApis } from './vendor-constants.538d9b49.js';
2
- import { i as index } from './vendor-index.81b9e499.js';
2
+ import { i as index } from './vendor-index.b0b501c8.js';
3
3
  import '@vitest/runner';
4
- import './vendor-vi.a3ff54b1.js';
4
+ import './vendor-vi.458e47b1.js';
5
5
  import '@vitest/runner/utils';
6
6
  import '@vitest/utils';
7
7
  import './vendor-index.fad2598b.js';
package/dist/cli.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { normalize } from 'pathe';
2
2
  import cac from 'cac';
3
3
  import c from 'picocolors';
4
- import { v as version, s as startVitest, d as divider } from './vendor-cli-api.c04eaa34.js';
4
+ import { v as version, s as startVitest, d as divider } from './vendor-cli-api.de0530cb.js';
5
5
  import './vendor-constants.538d9b49.js';
6
- import './vendor-coverage.a585b712.js';
6
+ import './vendor-coverage.c8fd34c3.js';
7
7
  import './vendor-index.75f2b63d.js';
8
8
  import 'node:console';
9
9
  import 'local-pkg';
10
+ import 'node:url';
10
11
  import './vendor-index.fad2598b.js';
11
12
  import 'std-env';
12
13
  import '@vitest/runner/utils';
@@ -14,7 +15,6 @@ import '@vitest/utils';
14
15
  import './vendor-global.6795f91f.js';
15
16
  import 'vite';
16
17
  import 'node:path';
17
- import 'node:url';
18
18
  import 'node:process';
19
19
  import 'node:fs';
20
20
  import 'path';
@@ -27,10 +27,11 @@ import './vendor-_commonjsHelpers.76cdd49e.js';
27
27
  import 'vite-node/utils';
28
28
  import 'vite-node/client';
29
29
  import '@vitest/snapshot/manager';
30
+ import 'vite-node/server';
30
31
  import './vendor-paths.84fc7a99.js';
31
32
  import 'node:v8';
32
33
  import 'node:child_process';
33
- import './vendor-index.4f82d248.js';
34
+ import './vendor-index.7dcbfa46.js';
34
35
  import 'node:worker_threads';
35
36
  import 'node:os';
36
37
  import 'tinypool';
@@ -45,18 +46,16 @@ import 'assert';
45
46
  import 'buffer';
46
47
  import 'node:util';
47
48
  import 'node:fs/promises';
48
- import 'source-map';
49
49
  import 'module';
50
50
  import 'acorn';
51
51
  import 'acorn-walk';
52
52
  import 'magic-string';
53
53
  import 'strip-literal';
54
- import 'vite-node/server';
55
54
  import 'node:readline';
56
55
  import 'readline';
57
56
 
58
57
  const cli = cac("vitest");
59
- cli.version(version).option("-r, --root <path>", "Root path").option("-c, --config <path>", "Path to config file").option("-u, --update", "Update snapshot").option("-w, --watch", "Enable watch mode").option("-t, --testNamePattern <pattern>", "Run tests with full names matching the specified regexp pattern").option("--dir <path>", "Base directory to scan for the test files").option("--ui", "Enable UI").option("--open", "Open UI automatically (default: !process.env.CI))").option("--api [api]", "Serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "Enabled threads (default: true)").option("--single-thread", "Run tests inside a single thread, requires --threads (default: false)").option("--silent", "Silent console output from tests").option("--isolate", "Isolate environment for each test file (default: true)").option("--reporter <name>", "Specify reporters").option("--outputFile <filename/-s>", "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "Enable coverage report").option("--run", "Disable watch mode").option("--mode <name>", "Override Vite mode (default: test)").option("--globals", "Inject apis globally").option("--dom", "Mock browser api with happy-dom").option("--browser [options]", "Run tests in the browser (default: false)").option("--environment <env>", "Specify runner environment, if not running in the browser (default: node)").option("--passWithNoTests", "Pass when no tests found").option("--logHeapUsage", "Show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--segfaultRetry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--no-color", "Removes colors from the console output").option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").option("--test-timeout <time>", "Default timeout of a test in milliseconds (default: 5000)").help();
58
+ cli.version(version).option("-r, --root <path>", "Root path").option("-c, --config <path>", "Path to config file").option("-u, --update", "Update snapshot").option("-w, --watch", "Enable watch mode").option("-t, --testNamePattern <pattern>", "Run tests with full names matching the specified regexp pattern").option("--dir <path>", "Base directory to scan for the test files").option("--ui", "Enable UI").option("--open", "Open UI automatically (default: !process.env.CI))").option("--api [api]", "Serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "Enabled threads (default: true)").option("--single-thread", "Run tests inside a single thread, requires --threads (default: false)").option("--silent", "Silent console output from tests").option("--hideSkippedTests", "Hide logs for skipped tests").option("--isolate", "Isolate environment for each test file (default: true)").option("--reporter <name>", "Specify reporters").option("--outputFile <filename/-s>", "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "Enable coverage report").option("--run", "Disable watch mode").option("--mode <name>", "Override Vite mode (default: test)").option("--globals", "Inject apis globally").option("--dom", "Mock browser api with happy-dom").option("--browser [options]", "Run tests in the browser (default: false)").option("--environment <env>", "Specify runner environment, if not running in the browser (default: node)").option("--passWithNoTests", "Pass when no tests found").option("--logHeapUsage", "Show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--segfaultRetry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--no-color", "Removes colors from the console output").option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").option("--test-timeout <time>", "Default timeout of a test in milliseconds (default: 5000)").option("--bail <number>", "Stop test execution when given number of tests have failed", { default: 0 }).help();
60
59
  cli.command("run [...filters]").action(run);
61
60
  cli.command("related [...filters]").action(runRelated);
62
61
  cli.command("watch [...filters]").action(watch);
package/dist/config.cjs CHANGED
@@ -70,6 +70,7 @@ const config = {
70
70
  update: false,
71
71
  reporters: [],
72
72
  silent: false,
73
+ hideSkippedTests: false,
73
74
  api: false,
74
75
  ui: false,
75
76
  uiBase: "/__vitest__/",
package/dist/config.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { UserConfig as UserConfig$2, ConfigEnv } from 'vite';
2
2
  export { ConfigEnv, mergeConfig } from 'vite';
3
- import { $ as ResolvedCoverageOptions, q as UserConfig$1, a2 as CoverageC8Options, a3 as CustomProviderOptions, a1 as CoverageIstanbulOptions, af as HtmlOptions, ag as FileOptions, ah as CloverOptions, ai as CoberturaOptions, aj as HtmlSpaOptions, ak as LcovOptions, al as LcovOnlyOptions, am as TeamcityOptions, an as TextOptions, ao as ProjectOptions, F as FakeTimerInstallOpts, P as ProjectConfig } from './types-f03c83c4.js';
4
- import '@vitest/expect';
3
+ import { a0 as ResolvedCoverageOptions, q as UserConfig$1, a3 as CoverageC8Options, a4 as CustomProviderOptions, a2 as CoverageIstanbulOptions, ag as HtmlOptions, ah as FileOptions, ai as CloverOptions, aj as CoberturaOptions, ak as HtmlSpaOptions, al as LcovOptions, am as LcovOnlyOptions, an as TeamcityOptions, ao as TextOptions, ap as ProjectOptions, F as FakeTimerInstallOpts, P as ProjectConfig } from './types-b7007192.js';
5
4
  import '@vitest/snapshot';
5
+ import '@vitest/expect';
6
6
  import '@vitest/runner';
7
7
  import '@vitest/runner/types';
8
8
  import '@vitest/runner/utils';
@@ -10,10 +10,9 @@ import '@vitest/utils';
10
10
  import 'tinybench';
11
11
  import 'vite-node/client';
12
12
  import '@vitest/snapshot/manager';
13
+ import 'vite-node/server';
13
14
  import 'node:worker_threads';
14
15
  import 'vite-node';
15
- import 'source-map';
16
- import 'vite-node/server';
17
16
  import 'node:fs';
18
17
  import 'chai';
19
18
 
@@ -40,6 +39,7 @@ declare const config: {
40
39
  update: boolean;
41
40
  reporters: never[];
42
41
  silent: boolean;
42
+ hideSkippedTests: boolean;
43
43
  api: boolean;
44
44
  ui: boolean;
45
45
  uiBase: string;
@@ -73,11 +73,10 @@ declare const config: {
73
73
  declare const configDefaults: Required<Pick<UserConfig$1, keyof typeof config>>;
74
74
 
75
75
  interface UserConfig extends UserConfig$2 {
76
- test?: UserConfig$2['test'];
76
+ test?: UserConfig$2['test'] | undefined;
77
77
  }
78
78
  interface UserWorkspaceConfig extends UserConfig$2 {
79
- extends?: string;
80
- test?: ProjectConfig;
79
+ test?: ProjectConfig | undefined;
81
80
  }
82
81
 
83
82
  type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>;
@@ -86,6 +85,10 @@ type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<Use
86
85
  type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
87
86
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
88
87
  declare function defineProject(config: UserProjectConfigExport): UserProjectConfigExport;
89
- declare function defineWorkspace(config: (string | UserProjectConfigExport)[]): (string | UserProjectConfigExport)[];
88
+ declare function defineWorkspace(config: (string | (UserProjectConfigExport & {
89
+ extends?: string;
90
+ }))[]): (string | (UserProjectConfigExport & {
91
+ extends?: string | undefined;
92
+ }))[];
90
93
 
91
94
  export { UserConfig, UserConfigExport, UserConfigFn, UserProjectConfigExport, UserProjectConfigFn, UserWorkspaceConfig, configDefaults, coverageConfigDefaults, defaultExclude, defaultInclude, defineConfig, defineProject, defineWorkspace };
package/dist/config.js CHANGED
@@ -68,6 +68,7 @@ const config = {
68
68
  update: false,
69
69
  reporters: [],
70
70
  silent: false,
71
+ hideSkippedTests: false,
71
72
  api: false,
72
73
  ui: false,
73
74
  uiBase: "/__vitest__/",
@@ -1,6 +1,6 @@
1
- import { a0 as BaseCoverageOptions, $ as ResolvedCoverageOptions } from './types-f03c83c4.js';
2
- import '@vitest/expect';
1
+ import { a1 as BaseCoverageOptions, a0 as ResolvedCoverageOptions } from './types-b7007192.js';
3
2
  import '@vitest/snapshot';
3
+ import '@vitest/expect';
4
4
  import 'vite';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/types';
@@ -9,10 +9,9 @@ import '@vitest/utils';
9
9
  import 'tinybench';
10
10
  import 'vite-node/client';
11
11
  import '@vitest/snapshot/manager';
12
+ import 'vite-node/server';
12
13
  import 'node:worker_threads';
13
14
  import 'vite-node';
14
- import 'source-map';
15
- import 'vite-node/server';
16
15
  import 'node:fs';
17
16
  import 'chai';
18
17
 
@@ -131,9 +130,10 @@ declare class BaseCoverageProvider {
131
130
  /**
132
131
  * Check if current coverage is above configured thresholds and bump the thresholds if needed
133
132
  */
134
- updateThresholds({ configurationFile, coverageMap, thresholds }: {
133
+ updateThresholds({ configurationFile, coverageMap, thresholds, perFile }: {
135
134
  coverageMap: CoverageMap;
136
135
  thresholds: Record<Threshold, number | undefined>;
136
+ perFile?: boolean;
137
137
  configurationFile?: string;
138
138
  }): void;
139
139
  /**
package/dist/coverage.js CHANGED
@@ -5,27 +5,27 @@ class BaseCoverageProvider {
5
5
  /**
6
6
  * Check if current coverage is above configured thresholds and bump the thresholds if needed
7
7
  */
8
- updateThresholds({ configurationFile, coverageMap, thresholds }) {
8
+ updateThresholds({ configurationFile, coverageMap, thresholds, perFile }) {
9
9
  if (!configurationFile)
10
10
  throw new Error('Missing configurationFile. The "coverage.thresholdAutoUpdate" can only be enabled when configuration file is used.');
11
- const summary = coverageMap.getCoverageSummary();
11
+ const summaries = perFile ? coverageMap.files().map((file) => coverageMap.fileCoverageFor(file).toSummary()) : [coverageMap.getCoverageSummary()];
12
12
  const thresholdsToUpdate = [];
13
13
  for (const key of THRESHOLD_KEYS) {
14
14
  const threshold = thresholds[key] || 100;
15
- const actual = summary[key].pct;
15
+ const actual = Math.min(...summaries.map((summary) => summary[key].pct));
16
16
  if (actual > threshold)
17
- thresholdsToUpdate.push(key);
17
+ thresholdsToUpdate.push([key, actual]);
18
18
  }
19
19
  if (thresholdsToUpdate.length === 0)
20
20
  return;
21
21
  const originalConfig = readFileSync(configurationFile, "utf8");
22
22
  let updatedConfig = originalConfig;
23
- for (const threshold of thresholdsToUpdate) {
23
+ for (const [threshold, newValue] of thresholdsToUpdate) {
24
24
  const previousThreshold = (thresholds[threshold] || 100).toString();
25
25
  const pattern = new RegExp(`(${threshold}\\s*:\\s*)${previousThreshold.replace(".", "\\.")}`);
26
26
  const matches = originalConfig.match(pattern);
27
27
  if (matches)
28
- updatedConfig = updatedConfig.replace(matches[0], matches[1] + summary[threshold].pct);
28
+ updatedConfig = updatedConfig.replace(matches[0], matches[1] + newValue);
29
29
  else
30
30
  console.error(`Unable to update coverage threshold ${threshold}. No threshold found using pattern ${pattern}`);
31
31
  }
package/dist/entry.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { performance } from 'node:perf_hooks';
1
2
  import { startTests } from '@vitest/runner';
2
3
  import { resolve } from 'pathe';
3
4
  import { c as resetModules } from './vendor-index.fad2598b.js';
4
- import { R as RealDate, d as globalExpect, s as setupChaiConfig, v as vi } from './vendor-vi.a3ff54b1.js';
5
+ import { R as RealDate, d as globalExpect, s as setupChaiConfig, v as vi } from './vendor-vi.458e47b1.js';
5
6
  import { d as distDir } from './vendor-paths.84fc7a99.js';
6
- import { a as startCoverageInsideWorker, t as takeCoverageInsideWorker, s as stopCoverageInsideWorker } from './vendor-coverage.a585b712.js';
7
+ import { a as startCoverageInsideWorker, t as takeCoverageInsideWorker, s as stopCoverageInsideWorker } from './vendor-coverage.c8fd34c3.js';
7
8
  import { createRequire } from 'node:module';
8
9
  import { isatty } from 'node:tty';
9
10
  import { installSourcemapsSupport } from 'vite-node/source-map';
@@ -11,8 +12,8 @@ import { setupColors, createColors, getSafeTimers } from '@vitest/utils';
11
12
  import { e as environments } from './vendor-index.75f2b63d.js';
12
13
  import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
13
14
  import { r as rpc } from './vendor-rpc.4d3d7a54.js';
14
- import { i as index } from './vendor-index.81b9e499.js';
15
- import { s as setupCommonEnv } from './vendor-setup.common.cef38f4e.js';
15
+ import { i as index } from './vendor-index.b0b501c8.js';
16
+ import { s as setupCommonEnv } from './vendor-setup.common.266b69fb.js';
16
17
  import { g as getWorkerState } from './vendor-global.6795f91f.js';
17
18
  import 'std-env';
18
19
  import '@vitest/runner/utils';
@@ -235,6 +236,19 @@ async function getTestRunner(config, executor) {
235
236
  rpc().onAfterSuiteRun({ coverage });
236
237
  await (originalOnAfterRun == null ? void 0 : originalOnAfterRun.call(testRunner, files));
237
238
  };
239
+ const originalOnAfterRunTest = testRunner.onAfterRunTest;
240
+ testRunner.onAfterRunTest = async (test) => {
241
+ var _a, _b;
242
+ if (config.bail && ((_a = test.result) == null ? void 0 : _a.state) === "fail") {
243
+ const previousFailures = await rpc().getCountOfFailedTests();
244
+ const currentFailures = 1 + previousFailures;
245
+ if (currentFailures >= config.bail) {
246
+ rpc().onCancel("test-failure");
247
+ (_b = testRunner.onCancel) == null ? void 0 : _b.call(testRunner, "test-failure");
248
+ }
249
+ }
250
+ await (originalOnAfterRunTest == null ? void 0 : originalOnAfterRunTest.call(testRunner, test));
251
+ };
238
252
  return testRunner;
239
253
  }
240
254
  async function run(files, config, environment, executor) {
@@ -244,6 +258,10 @@ async function run(files, config, environment, executor) {
244
258
  if (config.chaiConfig)
245
259
  setupChaiConfig(config.chaiConfig);
246
260
  const runner = await getTestRunner(config, executor);
261
+ workerState.onCancel.then((reason) => {
262
+ var _a;
263
+ return (_a = runner.onCancel) == null ? void 0 : _a.call(runner, reason);
264
+ });
247
265
  workerState.durations.prepare = performance.now() - workerState.durations.prepare;
248
266
  globalThis.__vitest_environment__ = environment;
249
267
  workerState.durations.environment = performance.now();
@@ -256,7 +274,6 @@ async function run(files, config, environment, executor) {
256
274
  }
257
275
  workerState.filepath = file;
258
276
  await startTests([file], runner);
259
- workerState.filepath = void 0;
260
277
  vi.resetConfig();
261
278
  vi.restoreAllMocks();
262
279
  }
@@ -1,6 +1,6 @@
1
- import { O as Environment } from './types-f03c83c4.js';
2
- import '@vitest/expect';
1
+ import { Q as Environment } from './types-b7007192.js';
3
2
  import '@vitest/snapshot';
3
+ import '@vitest/expect';
4
4
  import 'vite';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/types';
@@ -9,10 +9,9 @@ import '@vitest/utils';
9
9
  import 'tinybench';
10
10
  import 'vite-node/client';
11
11
  import '@vitest/snapshot/manager';
12
+ import 'vite-node/server';
12
13
  import 'node:worker_threads';
13
14
  import 'vite-node';
14
- import 'source-map';
15
- import 'vite-node/server';
16
15
  import 'node:fs';
17
16
  import 'chai';
18
17
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { CancelReason } from '@vitest/runner';
1
2
  export { SequenceHooks, SequenceSetupFiles, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
- import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, A as AfterSuiteRunMeta, U as UserConsoleLog, a as ResolvedConfig, b as ModuleGraphData, c as Reporter } from './types-f03c83c4.js';
3
- export { n as ApiConfig, D as ArgumentsType, z as Arrayable, y as Awaitable, a0 as BaseCoverageOptions, a7 as BenchFunction, a5 as Benchmark, a6 as BenchmarkResult, a4 as BenchmarkUserOptions, k as BuiltinEnvironment, m as CSSModuleScopeStrategy, C as ChaiConfig, f as CollectLineNumbers, h as CollectLines, H as Constructable, j as Context, u as ContextRPC, t as ContextTestEnvironment, a2 as CoverageC8Options, a1 as CoverageIstanbulOptions, _ as CoverageOptions, S as CoverageProvider, Y as CoverageProviderModule, Z as CoverageReporter, a3 as CustomProviderOptions, O as Environment, E as EnvironmentOptions, L as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, K as ModuleCache, G as MutableArray, N as Nullable, Q as OnServerRestartHandler, P as ProjectConfig, e as RawErrsMap, X as ReportContext, w as ResolveIdFunction, $ as ResolvedCoverageOptions, i as RootAndTarget, r as RuntimeRPC, T as TscErrorInfo, p as TypecheckConfig, q as UserConfig, v as Vitest, V as VitestEnvironment, l as VitestPool, o as VitestRunMode, W as WorkerContext, x as WorkerGlobalState, d as createExpect, g as expect, s as setupChaiConfig } from './types-f03c83c4.js';
3
+ import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, A as AfterSuiteRunMeta, U as UserConsoleLog, a as ResolvedConfig, b as ModuleGraphData, c as Reporter } from './types-b7007192.js';
4
+ export { n as ApiConfig, G as ArgumentsType, D as Arrayable, z as Awaitable, a1 as BaseCoverageOptions, a8 as BenchFunction, a6 as Benchmark, a7 as BenchmarkResult, a5 as BenchmarkUserOptions, k as BuiltinEnvironment, m as CSSModuleScopeStrategy, C as ChaiConfig, f as CollectLineNumbers, h as CollectLines, K as Constructable, j as Context, v as ContextRPC, u as ContextTestEnvironment, a3 as CoverageC8Options, a2 as CoverageIstanbulOptions, $ as CoverageOptions, X as CoverageProvider, Z as CoverageProviderModule, _ as CoverageReporter, a4 as CustomProviderOptions, Q as Environment, E as EnvironmentOptions, O as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, L as ModuleCache, H as MutableArray, N as Nullable, S as OnServerRestartHandler, P as ProjectConfig, e as RawErrsMap, Y as ReportContext, x as ResolveIdFunction, a0 as ResolvedCoverageOptions, i as RootAndTarget, t as RunnerRPC, r as RuntimeRPC, T as TscErrorInfo, p as TypecheckConfig, q as UserConfig, w as Vitest, V as VitestEnvironment, l as VitestPool, o as VitestRunMode, W as WorkerContext, y as WorkerGlobalState, d as createExpect, g as expect, s as setupChaiConfig } from './types-b7007192.js';
4
5
  import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, EnhancedSpy } from '@vitest/spy';
5
6
  export { EnhancedSpy, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, SpyInstance } from '@vitest/spy';
6
7
  export { SnapshotEnvironment } from '@vitest/snapshot/environment';
@@ -8,6 +9,7 @@ import { File, TaskResultPack } from '@vitest/runner/types';
8
9
  export { DoneCallback, File, HookCleanupCallback, HookListener, OnTestFailedHandler, RunMode, RuntimeContext, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TestOptions } from '@vitest/runner/types';
9
10
  import { SnapshotResult } from '@vitest/snapshot';
10
11
  export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot';
12
+ export { Assertion, AsymmetricMatchersContaining, ExpectStatic, JestAssertion } from '@vitest/expect';
11
13
  import { TransformResult } from 'vite';
12
14
  import * as chai from 'chai';
13
15
  export { chai };
@@ -15,14 +17,12 @@ export { assert, should } from 'chai';
15
17
  export { UserWorkspaceConfig } from './config.js';
16
18
  export { ErrorWithDiff, ParsedStack } from '@vitest/runner/utils';
17
19
  export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
18
- import '@vitest/expect';
19
20
  import '@vitest/utils';
20
21
  import 'vite-node/client';
21
22
  import '@vitest/snapshot/manager';
23
+ import 'vite-node/server';
22
24
  import 'node:worker_threads';
23
25
  import 'vite-node';
24
- import 'source-map';
25
- import 'vite-node/server';
26
26
  import 'node:fs';
27
27
 
28
28
  declare type Not<T extends boolean> = T extends true ? false : true;
@@ -203,6 +203,11 @@ interface VitestUtils {
203
203
  clearAllTimers(): this;
204
204
  spyOn: typeof spyOn;
205
205
  fn: typeof fn;
206
+ /**
207
+ * Run the factory before imports are evaluated. You can return a value from the factory
208
+ * to reuse it inside your `vi.mock` factory and tests.
209
+ */
210
+ hoisted<T>(factory: () => T): T;
206
211
  /**
207
212
  * Makes all `imports` to passed module to be mocked.
208
213
  * - If there is a factory, will return it's result. The call to `vi.mock` is hoisted to the top of the file,
@@ -334,6 +339,8 @@ interface WebSocketHandlers {
334
339
  onTaskUpdate(packs: TaskResultPack[]): void;
335
340
  onAfterSuiteRun(meta: AfterSuiteRunMeta): void;
336
341
  onDone(name: string): void;
342
+ onCancel(reason: CancelReason): void;
343
+ getCountOfFailedTests(): number;
337
344
  sendLog(log: UserConsoleLog): void;
338
345
  getFiles(): File[];
339
346
  getPaths(): string[];
@@ -343,7 +350,7 @@ interface WebSocketHandlers {
343
350
  getModuleGraph(id: string): Promise<ModuleGraphData>;
344
351
  getTransformResult(id: string): Promise<TransformResultWithSource | undefined>;
345
352
  readFile(id: string): Promise<string | null>;
346
- writeFile(id: string, content: string): Promise<void>;
353
+ writeFile(id: string, content: string, ensureDir?: boolean): Promise<void>;
347
354
  removeFile(id: string): Promise<void>;
348
355
  createDirectory(id: string): Promise<string | undefined>;
349
356
  snapshotSaved(snapshot: SnapshotResult): void;
@@ -351,6 +358,7 @@ interface WebSocketHandlers {
351
358
  updateSnapshot(file?: File): Promise<void>;
352
359
  }
353
360
  interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' | 'onTaskUpdate' | 'onUserConsoleLog' | 'onPathsCollected'> {
361
+ onCancel(reason: CancelReason): void;
354
362
  }
355
363
 
356
364
  export { AfterSuiteRunMeta, AssertType, BenchmarkAPI, ExpectTypeOf, ModuleGraphData, Reporter, ResolvedConfig, RuntimeConfig, TransformResultWithSource, UserConsoleLog, WebSocketEvents, WebSocketHandlers, assertType, bench, expectTypeOf, getRunningMode, isFirstRun, isWatchMode, runOnce, vi, vitest };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
- export { e as bench, c as createExpect, d as expect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.a3ff54b1.js';
2
+ export { e as bench, c as createExpect, d as expect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.458e47b1.js';
3
3
  export { i as isFirstRun, a as runOnce } from './vendor-run-once.69ce7172.js';
4
- import { d as dist } from './vendor-index.81b9e499.js';
5
- export { b as assertType, g as getRunningMode, a as isWatchMode } from './vendor-index.81b9e499.js';
4
+ import { d as dist } from './vendor-index.b0b501c8.js';
5
+ export { b as assertType, g as getRunningMode, a as isWatchMode } from './vendor-index.b0b501c8.js';
6
6
  import * as chai from 'chai';
7
7
  export { chai };
8
8
  export { assert, should } from 'chai';
package/dist/node.d.ts CHANGED
@@ -1,19 +1,18 @@
1
- import { o as VitestRunMode, q as UserConfig, v as Vitest, a8 as MockFactory, a9 as MockMap, aa as TestSequencer, ab as WorkspaceSpec } from './types-f03c83c4.js';
2
- export { ae as TestSequencerConstructor, ac as VitestWorkspace, ad as startVitest } from './types-f03c83c4.js';
1
+ import { o as VitestRunMode, q as UserConfig, w as Vitest, a9 as MockFactory, aa as MockMap, ab as TestSequencer, ac as WorkspaceSpec } from './types-b7007192.js';
2
+ export { af as TestSequencerConstructor, ad as VitestWorkspace, ae as startVitest } from './types-b7007192.js';
3
3
  import { UserConfig as UserConfig$1, Plugin } from 'vite';
4
4
  import { ViteNodeRunner } from 'vite-node/client';
5
5
  import { ViteNodeRunnerOptions } from 'vite-node';
6
- import '@vitest/expect';
7
6
  import '@vitest/snapshot';
7
+ import '@vitest/expect';
8
8
  import '@vitest/runner';
9
9
  import '@vitest/runner/types';
10
10
  import '@vitest/runner/utils';
11
11
  import '@vitest/utils';
12
12
  import 'tinybench';
13
13
  import '@vitest/snapshot/manager';
14
- import 'node:worker_threads';
15
- import 'source-map';
16
14
  import 'vite-node/server';
15
+ import 'node:worker_threads';
17
16
  import 'node:fs';
18
17
  import 'chai';
19
18
 
package/dist/node.js CHANGED
@@ -1,11 +1,12 @@
1
- export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './vendor-cli-api.c04eaa34.js';
2
- export { V as VitestExecutor } from './vendor-execute.8eaab47b.js';
1
+ export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './vendor-cli-api.de0530cb.js';
2
+ export { V as VitestExecutor } from './vendor-execute.a08cff9c.js';
3
3
  import 'pathe';
4
4
  import './vendor-constants.538d9b49.js';
5
- import './vendor-coverage.a585b712.js';
5
+ import './vendor-coverage.c8fd34c3.js';
6
6
  import './vendor-index.75f2b63d.js';
7
7
  import 'node:console';
8
8
  import 'local-pkg';
9
+ import 'node:url';
9
10
  import 'picocolors';
10
11
  import './vendor-index.fad2598b.js';
11
12
  import 'std-env';
@@ -14,7 +15,6 @@ import '@vitest/utils';
14
15
  import './vendor-global.6795f91f.js';
15
16
  import 'vite';
16
17
  import 'node:path';
17
- import 'node:url';
18
18
  import 'node:process';
19
19
  import 'node:fs';
20
20
  import 'path';
@@ -27,10 +27,11 @@ import './vendor-_commonjsHelpers.76cdd49e.js';
27
27
  import 'vite-node/utils';
28
28
  import 'vite-node/client';
29
29
  import '@vitest/snapshot/manager';
30
+ import 'vite-node/server';
30
31
  import './vendor-paths.84fc7a99.js';
31
32
  import 'node:v8';
32
33
  import 'node:child_process';
33
- import './vendor-index.4f82d248.js';
34
+ import './vendor-index.7dcbfa46.js';
34
35
  import 'node:worker_threads';
35
36
  import 'node:os';
36
37
  import 'tinypool';
@@ -45,13 +46,11 @@ import 'assert';
45
46
  import 'buffer';
46
47
  import 'node:util';
47
48
  import 'node:fs/promises';
48
- import 'source-map';
49
49
  import 'module';
50
50
  import 'acorn';
51
51
  import 'acorn-walk';
52
52
  import 'magic-string';
53
53
  import 'strip-literal';
54
- import 'vite-node/server';
55
54
  import 'node:readline';
56
55
  import 'readline';
57
56
  import '@vitest/spy';