vitest 0.0.113 → 0.0.114

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.
package/LICENSE.md CHANGED
@@ -193,6 +193,35 @@ Repository: chalk/ansi-styles
193
193
 
194
194
  ---------------------------------------
195
195
 
196
+ ## birpc
197
+ License: MIT
198
+ By: Anthony Fu
199
+ Repository: git+https://github.com/antfu/birpc.git
200
+
201
+ > MIT License
202
+ >
203
+ > Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
204
+ >
205
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
206
+ > of this software and associated documentation files (the "Software"), to deal
207
+ > in the Software without restriction, including without limitation the rights
208
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
209
+ > copies of the Software, and to permit persons to whom the Software is
210
+ > furnished to do so, subject to the following conditions:
211
+ >
212
+ > The above copyright notice and this permission notice shall be included in all
213
+ > copies or substantial portions of the Software.
214
+ >
215
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
216
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
217
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
218
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
219
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
220
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
221
+ > SOFTWARE.
222
+
223
+ ---------------------------------------
224
+
196
225
  ## braces
197
226
  License: MIT
198
227
  By: Jon Schlinkert, Brian Woodward, Elan Shanker, Eugene Sharygin, hemanth.hm
package/dist/cli.js CHANGED
@@ -1,27 +1,27 @@
1
1
  import require$$0 from 'readline';
2
2
  import { EventEmitter } from 'events';
3
- import { e as ensurePackageInstalled } from './index-041e627e.js';
4
- import { c as createVitest } from './index-c3f2f9fe.js';
3
+ import { e as ensurePackageInstalled } from './index-ea5153a0.js';
4
+ import { c as createVitest } from './index-36694964.js';
5
+ import 'url';
5
6
  import 'tty';
6
7
  import 'local-pkg';
7
- import './index-1488b423.js';
8
8
  import 'path';
9
+ import 'fs';
9
10
  import 'vite';
10
11
  import 'process';
11
- import 'fs';
12
12
  import 'os';
13
13
  import 'util';
14
14
  import 'stream';
15
- import './constants-900abe4a.js';
16
- import 'url';
15
+ import './constants-9c7f06df.js';
17
16
  import './magic-string.es-94000aea.js';
18
17
  import 'perf_hooks';
19
- import './diff-9c43ab50.js';
18
+ import './diff-3cfdad26.js';
20
19
  import './index-61c8686f.js';
21
20
  import './_commonjsHelpers-c9e3b764.js';
22
21
  import 'assert';
23
22
  import 'worker_threads';
24
23
  import 'tinypool';
24
+ import './index-7889832e.js';
25
25
 
26
26
  function toArr(any) {
27
27
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -636,10 +636,10 @@ class CAC extends EventEmitter {
636
636
 
637
637
  const cac = (name = "") => new CAC(name);
638
638
 
639
- var version = "0.0.113";
639
+ var version = "0.0.114";
640
640
 
641
641
  const cli = cac("vitest");
642
- 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", "watch mode").option("-o, --open", "open Vitest UI").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
642
+ 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", "watch mode").option("-o, --open", "open Vitest UI").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console.log output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
643
643
  cli.command("run [...filters]").action(run);
644
644
  cli.command("watch [...filters]").action(dev);
645
645
  cli.command("dev [...filters]").action(dev);
@@ -647,7 +647,7 @@ cli.command("[...filters]").action(dev);
647
647
  cli.parse();
648
648
  async function dev(cliFilters, argv) {
649
649
  if (argv.watch == null)
650
- argv.watch = !process.env.CI && !process.env.NODE_V8_COVERAGE && !argv.silent && !argv.run;
650
+ argv.watch = !process.env.CI && !process.env.NODE_V8_COVERAGE && !argv.run;
651
651
  await run(cliFilters, argv);
652
652
  }
653
653
  async function run(cliFilters, options) {
@@ -1,9 +1,9 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { a as resolve } from './index-1488b423.js';
2
+ import { j as resolve } from './index-ea5153a0.js';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
5
  const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
6
- const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/.{idea,git,cache,output,temp}/**"];
6
+ const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
7
7
  const defaultPort = 51204;
8
8
  const API_PATH = "/__vitest_api__";
9
9
  const configFiles = [
@@ -1,6 +1,5 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { r as relative } from './index-1488b423.js';
3
- import { d as notNullish, c } from './index-041e627e.js';
2
+ import { m as notNullish, c, r as relative } from './index-ea5153a0.js';
4
3
 
5
4
  function Diff() {}
6
5
  Diff.prototype = {
package/dist/entry.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import fs, { promises } from 'fs';
2
- import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, b as getState, e as vi } from './vi-51946984.js';
2
+ import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, n as nanoid, l as clearContext, m as defaultSuite, o as setHooks, p as getHooks, q as context, s as setState, r as getFn, b as getState, e as vi } from './vi-67e478ef.js';
3
3
  import { Console } from 'console';
4
4
  import { Writable } from 'stream';
5
5
  import { importModule } from 'local-pkg';
6
6
  import chai$1, { expect, util } from 'chai';
7
7
  import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
8
- import { c as index, r as relative } from './index-1488b423.js';
9
- import { r as rpc, s as send } from './rpc-7de86f29.js';
10
- import { s as slash, f as getNames, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, j as hasTests, h as hasFailed } from './index-041e627e.js';
11
- import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-9c43ab50.js';
8
+ import { p as index, s as slash, q as getNames, c as c$1, k as toArray, r as relative, u as interpretOnlyMode, v as partitionSuiteChildren, w as hasTests, h as hasFailed } from './index-ea5153a0.js';
9
+ import { r as rpc, s as send } from './rpc-85fe6402.js';
10
+ import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-3cfdad26.js';
12
11
  import { performance } from 'perf_hooks';
13
- import { n as nanoid } from './jest-mock-a57b745c.js';
14
12
  import { format as format$1 } from 'util';
15
- import 'path';
16
- import 'tty';
13
+ import './jest-mock-4a754991.js';
17
14
  import 'tinyspy';
15
+ import 'url';
16
+ import 'tty';
17
+ import 'path';
18
18
 
19
19
  var node = {
20
20
  name: "node",
@@ -387,7 +387,7 @@ async function saveInlineSnapshots(snapshots) {
387
387
  const MagicString = (await import('./magic-string.es-94000aea.js')).default;
388
388
  const files = new Set(snapshots.map((i) => i.file));
389
389
  await Promise.all(Array.from(files).map(async (file) => {
390
- const map = await rpc("getSourceMap", file, true);
390
+ const map = await rpc("getSourceMap", file);
391
391
  const snaps = snapshots.filter((i) => i.file === file);
392
392
  const code = await promises.readFile(file, "utf8");
393
393
  const s = new MagicString(code);
@@ -396,7 +396,9 @@ async function saveInlineSnapshots(snapshots) {
396
396
  const index = posToNumber(code, pos);
397
397
  replaceInlineSnap(code, s, index, snap.snapshot);
398
398
  }
399
- await promises.writeFile(file, s.toString(), "utf-8");
399
+ const transformed = s.toString();
400
+ if (transformed !== code)
401
+ await promises.writeFile(file, transformed, "utf-8");
400
402
  }));
401
403
  }
402
404
  const startRegex = /toMatchInlineSnapshot\s*\(\s*(['"`\)])/m;
@@ -3528,7 +3530,7 @@ async function setupGlobalEnv(config) {
3528
3530
  setupConsoleLogSpy();
3529
3531
  await setupChai();
3530
3532
  if (config.global)
3531
- (await import('./global-75208c77.js')).registerApiGlobally();
3533
+ (await import('./global-12653c72.js')).registerApiGlobally();
3532
3534
  }
3533
3535
  function setupConsoleLogSpy() {
3534
3536
  const stdout = new Writable({
@@ -3583,7 +3585,7 @@ function serializeError(val) {
3583
3585
  return `Function<${val.name}>`;
3584
3586
  if (typeof val !== "object")
3585
3587
  return val;
3586
- if (val instanceof Promise || "then" in val)
3588
+ if (val instanceof Promise || "then" in val || val.constructor && val.constructor.prototype === "AsyncFunction")
3587
3589
  return "Promise";
3588
3590
  if (typeof Element !== "undefined" && val instanceof Element)
3589
3591
  return val.tagName;
@@ -1,16 +1,15 @@
1
- import { g as globalApis } from './constants-900abe4a.js';
2
- import { i as index } from './index-09437c50.js';
1
+ import { g as globalApis } from './constants-9c7f06df.js';
2
+ import { i as index } from './index-ebf35a56.js';
3
3
  import 'url';
4
- import './index-1488b423.js';
5
- import 'path';
6
- import './vi-51946984.js';
7
- import './jest-mock-a57b745c.js';
8
- import 'chai';
9
- import 'tinyspy';
10
- import './index-041e627e.js';
4
+ import './index-ea5153a0.js';
11
5
  import 'tty';
12
6
  import 'local-pkg';
7
+ import 'path';
8
+ import './vi-67e478ef.js';
13
9
  import './_commonjsHelpers-c9e3b764.js';
10
+ import './jest-mock-4a754991.js';
11
+ import 'chai';
12
+ import 'tinyspy';
14
13
 
15
14
  function registerApiGlobally() {
16
15
  globalApis.forEach((api) => {
@@ -1,21 +1,21 @@
1
- import { i as isAbsolute, r as relative, d as dirname, b as basename, a as resolve } from './index-1488b423.js';
1
+ import fs$8, { promises, existsSync } from 'fs';
2
+ import { pathToFileURL } from 'url';
3
+ import { c, s as slash$1, i as isAbsolute, r as relative, d as dirname, b as basename, g as getFullName, h as hasFailed, a as getSuites, f as getTests, j as resolve, t as toFilePath, n as noop$1, k as toArray, l as join } from './index-ea5153a0.js';
2
4
  import { createServer, mergeConfig } from 'vite';
3
5
  import path$a from 'path';
4
6
  import process$1 from 'process';
5
- import fs$8, { promises } from 'fs';
6
7
  import require$$0 from 'os';
7
8
  import require$$0$1 from 'util';
8
9
  import require$$0$2 from 'stream';
9
10
  import require$$2 from 'events';
10
- import { c, s as slash$1, g as getFullName, h as hasFailed, a as getSuites, b as getTests, n as noop$1, t as toArray } from './index-041e627e.js';
11
- import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-900abe4a.js';
11
+ import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-9c7f06df.js';
12
12
  import MagicString from './magic-string.es-94000aea.js';
13
- import { performance } from 'perf_hooks';
14
- import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-9c43ab50.js';
13
+ import { performance as performance$1 } from 'perf_hooks';
14
+ import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-3cfdad26.js';
15
15
  import { o as onetime, s as signalExit } from './index-61c8686f.js';
16
16
  import { MessageChannel } from 'worker_threads';
17
- import { pathToFileURL } from 'url';
18
17
  import { Tinypool } from 'tinypool';
18
+ import { c as createBirpc } from './index-7889832e.js';
19
19
 
20
20
  /*
21
21
  How it works:
@@ -6975,13 +6975,13 @@ class BaseReporter {
6975
6975
  this.ctx.log(`
6976
6976
  ${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
6977
6977
  `);
6978
- this.start = performance.now();
6978
+ this.start = performance$1.now();
6979
6979
  }
6980
6980
  relative(path) {
6981
6981
  return relative(this.ctx.config.root, path);
6982
6982
  }
6983
6983
  async onFinished(files = this.ctx.state.getFiles()) {
6984
- this.end = performance.now();
6984
+ this.end = performance$1.now();
6985
6985
  await this.reportSummary(files);
6986
6986
  }
6987
6987
  onTaskUpdate(pack) {
@@ -7010,13 +7010,13 @@ ${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")
7010
7010
  }
7011
7011
  async onWatcherRerun(files, trigger) {
7012
7012
  this.watchFilters = files;
7013
- if (!this.ctx.config.silent) {
7014
- this.ctx.console.clear();
7015
- this.ctx.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
7013
+ this.ctx.console.clear();
7014
+ this.ctx.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
7016
7015
  `));
7017
- }
7018
7016
  }
7019
7017
  onUserConsoleLog(log) {
7018
+ if (this.ctx.config.silent)
7019
+ return;
7020
7020
  const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
7021
7021
  this.ctx.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
7022
7022
  process[log.type].write(`${log.content}
@@ -7855,30 +7855,30 @@ class StateManager {
7855
7855
  }
7856
7856
  }
7857
7857
 
7858
- var __defProp = Object.defineProperty;
7859
- var __defProps = Object.defineProperties;
7860
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7861
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7862
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7863
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7864
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7865
- var __spreadValues = (a, b) => {
7858
+ var __defProp$1 = Object.defineProperty;
7859
+ var __defProps$1 = Object.defineProperties;
7860
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
7861
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
7862
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
7863
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
7864
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7865
+ var __spreadValues$1 = (a, b) => {
7866
7866
  for (var prop in b || (b = {}))
7867
- if (__hasOwnProp.call(b, prop))
7868
- __defNormalProp(a, prop, b[prop]);
7869
- if (__getOwnPropSymbols)
7870
- for (var prop of __getOwnPropSymbols(b)) {
7871
- if (__propIsEnum.call(b, prop))
7872
- __defNormalProp(a, prop, b[prop]);
7867
+ if (__hasOwnProp$1.call(b, prop))
7868
+ __defNormalProp$1(a, prop, b[prop]);
7869
+ if (__getOwnPropSymbols$1)
7870
+ for (var prop of __getOwnPropSymbols$1(b)) {
7871
+ if (__propIsEnum$1.call(b, prop))
7872
+ __defNormalProp$1(a, prop, b[prop]);
7873
7873
  }
7874
7874
  return a;
7875
7875
  };
7876
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7876
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
7877
7877
  function resolveConfig(options, viteConfig) {
7878
7878
  var _a, _b;
7879
7879
  if (options.dom)
7880
7880
  options.environment = "happy-dom";
7881
- const resolved = __spreadProps(__spreadValues(__spreadValues({}, options), viteConfig.test), {
7881
+ const resolved = __spreadProps$1(__spreadValues$1(__spreadValues$1({}, options), viteConfig.test), {
7882
7882
  root: viteConfig.root
7883
7883
  });
7884
7884
  resolved.depsInline = [...((_a = resolved.deps) == null ? void 0 : _a.inline) || []];
@@ -7893,6 +7893,7 @@ function resolveConfig(options, viteConfig) {
7893
7893
  resolved.exclude = resolved.exclude ?? defaultExclude;
7894
7894
  resolved.testTimeout = resolved.testTimeout ?? 5e3;
7895
7895
  resolved.hookTimeout = resolved.hookTimeout ?? 1e4;
7896
+ resolved.isolate = resolved.isolate ?? true;
7896
7897
  resolved.watchIgnore = resolved.watchIgnore ?? [/\/node_modules\//, /\/dist\//];
7897
7898
  const CI = !!process.env.CI;
7898
7899
  const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT;
@@ -7928,8 +7929,11 @@ async function _transformRequest(ctx, id) {
7928
7929
  if (result)
7929
7930
  result = await ctx.server.ssrTransform(result.code, result.map, id);
7930
7931
  }
7931
- if (result && process.env.NODE_V8_COVERAGE)
7932
+ if (result && process.env.NODE_V8_COVERAGE) {
7932
7933
  withInlineSourcemap(result);
7934
+ if (result.map)
7935
+ ctx.visitedFilesMap.set(toFilePath(id, ctx.config.root), result.map);
7936
+ }
7933
7937
  return result;
7934
7938
  }
7935
7939
  let SOURCEMAPPING_URL = "sourceMa";
@@ -7978,14 +7982,16 @@ function createFakePool(ctx) {
7978
7982
  function createWorkerPool(ctx) {
7979
7983
  const options = {
7980
7984
  filename: workerPath,
7981
- isolateWorkers: true,
7982
- concurrentTasksPerWorker: 1,
7983
7985
  useAtomics: false
7984
7986
  };
7985
7987
  if (ctx.config.maxThreads != null)
7986
7988
  options.maxThreads = ctx.config.maxThreads;
7987
7989
  if (ctx.config.minThreads != null)
7988
7990
  options.minThreads = ctx.config.minThreads;
7991
+ if (ctx.config.isolate) {
7992
+ options.isolateWorkers = true;
7993
+ options.concurrentTasksPerWorker = 1;
7994
+ }
7989
7995
  const pool = new Tinypool(options);
7990
7996
  const runWithFiles = (name) => {
7991
7997
  return async (files, invalidates) => {
@@ -8013,58 +8019,66 @@ function createChannel(ctx) {
8013
8019
  const channel = new MessageChannel();
8014
8020
  const port = channel.port2;
8015
8021
  const workerPort = channel.port1;
8016
- port.on("message", async ({ id, method, args = [] }) => {
8017
- async function send(fn) {
8018
- try {
8019
- port.postMessage({ id, result: await fn() });
8020
- } catch (e) {
8021
- port.postMessage({ id, error: e });
8022
+ createBirpc({
8023
+ functions: {
8024
+ processExit(code) {
8025
+ process.exit(code || 1);
8026
+ },
8027
+ snapshotSaved(snapshot) {
8028
+ ctx.snapshot.add(snapshot);
8029
+ },
8030
+ getSourceMap(id, force) {
8031
+ if (force) {
8032
+ const mod = ctx.server.moduleGraph.getModuleById(id);
8033
+ if (mod)
8034
+ ctx.server.moduleGraph.invalidateModule(mod);
8035
+ }
8036
+ return transformRequest(ctx, id).then((r) => r == null ? void 0 : r.map);
8037
+ },
8038
+ fetch(id) {
8039
+ return transformRequest(ctx, id).then((r) => r == null ? void 0 : r.code);
8040
+ },
8041
+ onCollected(files) {
8042
+ ctx.state.collectFiles(files);
8043
+ ctx.report("onStart", files.map((i) => i.filepath));
8044
+ },
8045
+ onTaskUpdate(pack) {
8046
+ ctx.state.updateTasks([pack]);
8047
+ ctx.report("onTaskUpdate", pack);
8048
+ },
8049
+ log(msg) {
8050
+ ctx.report("onUserConsoleLog", msg);
8022
8051
  }
8052
+ },
8053
+ post(v) {
8054
+ port.postMessage(v);
8055
+ },
8056
+ on(fn) {
8057
+ port.on("message", fn);
8023
8058
  }
8024
- switch (method) {
8025
- case "processExit":
8026
- process.exit(args[0] || 1);
8027
- return;
8028
- case "snapshotSaved":
8029
- return send(() => ctx.snapshot.add(args[0]));
8030
- case "getSourceMap":
8031
- return send(() => {
8032
- const [id2, force] = args;
8033
- if (force) {
8034
- const mod = ctx.server.moduleGraph.getModuleById(id2);
8035
- if (mod)
8036
- ctx.server.moduleGraph.invalidateModule(mod);
8037
- }
8038
- return transformRequest(ctx, id2).then((r) => r == null ? void 0 : r.map);
8039
- });
8040
- case "fetch":
8041
- return send(() => transformRequest(ctx, ...args).then((r) => r == null ? void 0 : r.code));
8042
- case "onCollected":
8043
- ctx.state.collectFiles(args[0]);
8044
- ctx.reporters.forEach((r) => {
8045
- var _a;
8046
- return (_a = r.onStart) == null ? void 0 : _a.call(r, args[0].map((i) => i.filepath));
8047
- });
8048
- return;
8049
- case "onTaskUpdate":
8050
- ctx.state.updateTasks([args[0]]);
8051
- ctx.reporters.forEach((r) => {
8052
- var _a;
8053
- return (_a = r.onTaskUpdate) == null ? void 0 : _a.call(r, args[0]);
8054
- });
8055
- return;
8056
- case "log":
8057
- ctx.reporters.forEach((r) => {
8058
- var _a;
8059
- return (_a = r.onUserConsoleLog) == null ? void 0 : _a.call(r, args[0]);
8060
- });
8061
- return;
8062
- }
8063
- console.error("Unhandled message", method, args);
8064
8059
  });
8065
8060
  return { workerPort, port };
8066
8061
  }
8067
8062
 
8063
+ var __defProp = Object.defineProperty;
8064
+ var __defProps = Object.defineProperties;
8065
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8066
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8067
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8068
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8069
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8070
+ var __spreadValues = (a, b) => {
8071
+ for (var prop in b || (b = {}))
8072
+ if (__hasOwnProp.call(b, prop))
8073
+ __defNormalProp(a, prop, b[prop]);
8074
+ if (__getOwnPropSymbols)
8075
+ for (var prop of __getOwnPropSymbols(b)) {
8076
+ if (__propIsEnum.call(b, prop))
8077
+ __defNormalProp(a, prop, b[prop]);
8078
+ }
8079
+ return a;
8080
+ };
8081
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8068
8082
  const WATCHER_DEBOUNCE = 100;
8069
8083
  class Vitest {
8070
8084
  constructor() {
@@ -8075,6 +8089,7 @@ class Vitest {
8075
8089
  this.reporters = void 0;
8076
8090
  this.invalidates = /* @__PURE__ */ new Set();
8077
8091
  this.changedTests = /* @__PURE__ */ new Set();
8092
+ this.visitedFilesMap = /* @__PURE__ */ new Map();
8078
8093
  this.isFirstRun = true;
8079
8094
  this.restartsCount = 0;
8080
8095
  this._onRestartListeners = [];
@@ -8102,7 +8117,7 @@ class Vitest {
8102
8117
  }
8103
8118
  return i;
8104
8119
  });
8105
- if (!this.reporters.length && !this.config.silent)
8120
+ if (!this.reporters.length)
8106
8121
  this.reporters.push(new DefaultReporter(this));
8107
8122
  if (this.config.watch)
8108
8123
  this.registerWatcher();
@@ -8121,6 +8136,7 @@ class Vitest {
8121
8136
  await this.runFiles(files);
8122
8137
  if (this.config.watch)
8123
8138
  await this.report("onWatcherStart");
8139
+ await this.writeC8Sourcemap();
8124
8140
  }
8125
8141
  async runFiles(files) {
8126
8142
  await this.runningPromise;
@@ -8139,13 +8155,9 @@ class Vitest {
8139
8155
  return await this.runningPromise;
8140
8156
  }
8141
8157
  log(...args) {
8142
- if (this.config.silent)
8143
- return;
8144
8158
  this.console.log(...args);
8145
8159
  }
8146
8160
  error(...args) {
8147
- if (this.config.silent)
8148
- return;
8149
8161
  this.console.error(...args);
8150
8162
  }
8151
8163
  async scheduleRerun(triggerId) {
@@ -8241,6 +8253,28 @@ class Vitest {
8241
8253
  files = files.filter((i) => filters.some((f) => i.includes(f)));
8242
8254
  return files;
8243
8255
  }
8256
+ async writeC8Sourcemap() {
8257
+ const coverageDir = process.env.NODE_V8_COVERAGE;
8258
+ if (!coverageDir)
8259
+ return;
8260
+ const cache = {};
8261
+ const files = Array.from(this.visitedFilesMap.entries()).filter((i) => !i[0].includes("/node_modules/"));
8262
+ files.forEach(([file, map]) => {
8263
+ if (!existsSync(file))
8264
+ return;
8265
+ const url = pathToFileURL(file).href;
8266
+ cache[url] = {
8267
+ data: __spreadProps(__spreadValues({}, map), {
8268
+ sources: map.sources.map((i) => pathToFileURL(i).href) || [url]
8269
+ })
8270
+ };
8271
+ });
8272
+ await promises.writeFile(join(coverageDir, "vitest-source-map.json"), JSON.stringify({
8273
+ "result": [],
8274
+ "timestamp": performance.now(),
8275
+ "source-map-cache": cache
8276
+ }), "utf-8");
8277
+ }
8244
8278
  isTargetFile(id) {
8245
8279
  if (micromatch_1.isMatch(id, this.config.exclude))
8246
8280
  return false;
@@ -8269,7 +8303,7 @@ async function createVitest(options, viteOverrides = {}) {
8269
8303
  ctx.setServer(options, server2);
8270
8304
  haveStarted = true;
8271
8305
  if (options.api)
8272
- server2.middlewares.use((await import('./middleware-0ebc5238.js')).default(ctx));
8306
+ server2.middlewares.use((await import('./middleware-85ff8fbf.js')).default(ctx));
8273
8307
  }
8274
8308
  },
8275
8309
  MocksPlugin()
@@ -0,0 +1,53 @@
1
+ function createBirpc({
2
+ functions,
3
+ post,
4
+ on,
5
+ serialize = (i) => i,
6
+ deserialize = (i) => i
7
+ }) {
8
+ const rpcPromiseMap = /* @__PURE__ */ new Map();
9
+ on(async (data) => {
10
+ const msg = deserialize(data);
11
+ if (msg.type === "req") {
12
+ const { method, args, ack } = msg;
13
+ let result, error;
14
+ try {
15
+ result = await functions[method](...args);
16
+ } catch (e) {
17
+ error = e;
18
+ }
19
+ if (ack)
20
+ await post(serialize({ type: "res", ack, result, error }));
21
+ } else {
22
+ const { ack, result, error } = msg;
23
+ const promise = rpcPromiseMap.get(ack);
24
+ if (error)
25
+ promise?.reject(error);
26
+ else
27
+ promise?.resolve(result);
28
+ rpcPromiseMap.delete(ack);
29
+ }
30
+ });
31
+ return {
32
+ call(method, ...args) {
33
+ return new Promise((resolve, reject) => {
34
+ const ack = nanoid();
35
+ rpcPromiseMap.set(ack, { resolve, reject });
36
+ post(serialize({ method, args, ack, type: "req" }));
37
+ });
38
+ },
39
+ send(method, ...args) {
40
+ post(serialize({ method, args, type: "req" }));
41
+ }
42
+ };
43
+ }
44
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
45
+ function nanoid(size = 21) {
46
+ let id = "";
47
+ let i = size;
48
+ while (i--)
49
+ id += urlAlphabet[Math.random() * 64 | 0];
50
+ return id;
51
+ }
52
+
53
+ export { createBirpc as c };