vitest 0.0.105 → 0.0.109

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.
@@ -0,0 +1,11 @@
1
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ function commonjsRequire (path) {
8
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
9
+ }
10
+
11
+ export { commonjsRequire as a, commonjsGlobal as c, getDefaultExportFromCjs as g };
package/dist/cli.js CHANGED
@@ -1,23 +1,22 @@
1
1
  import require$$0 from 'readline';
2
2
  import { EventEmitter } from 'events';
3
- import { e as ensurePackageInstalled } from './utils-5307e690.js';
4
- import { c as createVitest } from './index-1da01554.js';
3
+ import { e as ensurePackageInstalled } from './utils-d97bd6d9.js';
4
+ import { c as createVitest } from './index-a727b58c.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
- import 'chai';
9
- import 'tinyspy';
10
8
  import 'vite';
11
9
  import 'process';
12
10
  import 'fs';
13
11
  import 'os';
14
12
  import 'util';
15
13
  import 'stream';
16
- import './constants-9320a46c.js';
14
+ import './constants-e762cbc5.js';
17
15
  import 'url';
18
16
  import 'perf_hooks';
19
- import './error-4e165107.js';
20
- import './index-4cf13e25.js';
17
+ import './diff-46ee5d7d.js';
18
+ import './index-61c8686f.js';
19
+ import './_commonjsHelpers-c9e3b764.js';
21
20
  import 'assert';
22
21
  import 'worker_threads';
23
22
  import 'tinypool';
@@ -635,10 +634,10 @@ class CAC extends EventEmitter {
635
634
 
636
635
  const cac = (name = "") => new CAC(name);
637
636
 
638
- var version = "0.0.105";
637
+ var version = "0.0.109";
639
638
 
640
639
  const cli = cac("vitest");
641
- 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("--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();
640
+ 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("--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
641
  cli.command("run [...filters]").action(run);
643
642
  cli.command("watch [...filters]").action(dev);
644
643
  cli.command("dev [...filters]").action(dev);
@@ -1,9 +1,9 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { m as resolve } from './utils-5307e690.js';
2
+ import { h as resolve } from './utils-d97bd6d9.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"];
6
+ const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/.{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 { format } from 'util';
3
- import { p as notNullish, c, r as relative } from './utils-5307e690.js';
2
+ import { k as notNullish, c, r as relative } from './utils-d97bd6d9.js';
4
3
 
5
4
  function Diff() {}
6
5
  Diff.prototype = {
@@ -4564,7 +4563,7 @@ async function getSourcePos(ctx, nearest) {
4564
4563
  return pos;
4565
4564
  }
4566
4565
  function displayDiff(actual, expected) {
4567
- console.error(c.gray(unifiedDiff(stringify(actual), stringify(expected))));
4566
+ console.error(c.gray(unifiedDiff(actual, expected)) + "\n");
4568
4567
  }
4569
4568
  function printErrorMessage(error) {
4570
4569
  const errorName = error.name || error.nameStr || "Unknown Error";
@@ -4648,9 +4647,6 @@ function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
4648
4647
  res = res.map((line) => " ".repeat(indent) + line);
4649
4648
  return res.join("\n");
4650
4649
  }
4651
- function stringify(obj) {
4652
- return format(obj);
4653
- }
4654
4650
  const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
4655
4651
  const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/;
4656
4652
  function parseStack(stack) {
@@ -4675,64 +4671,66 @@ function parseStack(stack) {
4675
4671
  function unifiedDiff(actual, expected) {
4676
4672
  if (actual === expected)
4677
4673
  return "";
4678
- const diffLimit = 10;
4679
4674
  const indent = " ";
4680
- let expectedLinesCount = 0;
4681
- let actualLinesCount = 0;
4675
+ const diffLimit = 15;
4676
+ const counts = {
4677
+ "+": 0,
4678
+ "-": 0
4679
+ };
4680
+ const expectedLinesCount = 0;
4681
+ const actualLinesCount = 0;
4682
+ let previousState = null;
4683
+ let previousCount = 0;
4682
4684
  function preprocess(line) {
4683
- if (line[0] === "+") {
4684
- if (expectedLinesCount >= diffLimit)
4685
+ if (!line || line.match(/\\ No newline/))
4686
+ return;
4687
+ const char = line[0];
4688
+ if ("-+".includes(char)) {
4689
+ if (previousState !== char) {
4690
+ previousState = char;
4691
+ previousCount = 0;
4692
+ }
4693
+ previousCount++;
4694
+ counts[char]++;
4695
+ if (previousCount === diffLimit)
4696
+ return c.dim(char + " ...");
4697
+ else if (previousCount > diffLimit)
4685
4698
  return;
4686
- expectedLinesCount++;
4687
- return (compact) => {
4688
- if (compact)
4689
- return c.red(formatLine(line.slice(1)));
4690
- line = line[0] + " " + line.slice(1);
4691
- const isLastLine = expectedLinesCount === diffLimit;
4692
- return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
4693
- };
4694
4699
  }
4700
+ return line;
4701
+ }
4702
+ const msg = createPatch("string", expected, actual);
4703
+ const lines = msg.split("\n").slice(5).map(preprocess).filter(Boolean);
4704
+ const isCompact = counts["+"] === 1 && counts["-"] === 1 && lines.length === 2;
4705
+ let formatted = lines.map((line) => {
4695
4706
  if (line[0] === "-") {
4696
- if (actualLinesCount >= diffLimit)
4697
- return;
4698
- actualLinesCount++;
4699
- return (compact) => {
4700
- if (compact)
4701
- return c.green(formatLine(line.slice(1)));
4702
- line = line[0] + " " + line.slice(1);
4703
- const isLastLine = actualLinesCount === diffLimit;
4704
- return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
4705
- };
4707
+ line = formatLine(line.slice(1));
4708
+ if (isCompact)
4709
+ return c.green(line);
4710
+ return c.green(`- ${formatLine(line)}`);
4711
+ }
4712
+ if (line[0] === "+") {
4713
+ line = formatLine(line.slice(1));
4714
+ if (isCompact)
4715
+ return c.red(line);
4716
+ return c.red(`+ ${formatLine(line)}`);
4706
4717
  }
4707
4718
  if (line.match(/@@/))
4708
- return () => "--";
4709
- if (line.match(/\\ No newline/))
4710
- return null;
4711
- return () => indent + " " + line;
4712
- }
4713
- const msg = createPatch("string", actual, expected);
4714
- const lines = msg.split("\n").splice(5);
4715
- const cleanLines = lines.map(preprocess).filter(notBlank);
4716
- if (expectedLinesCount === 1 && actualLinesCount === 1) {
4717
- return `
4718
- ${indent}${c.green("- expected")} ${cleanLines[0](true)}
4719
- ${indent}${c.red("+ actual")} ${cleanLines[1](true)}`;
4719
+ return "--";
4720
+ return " " + line;
4721
+ });
4722
+ if (isCompact) {
4723
+ formatted = [
4724
+ `${c.green("- Expected")} ${formatted[0]}`,
4725
+ `${c.red("+ Received")} ${formatted[1]}`
4726
+ ];
4727
+ } else {
4728
+ formatted.unshift(c.green("- Expected -" + expectedLinesCount), c.red("+ Received +" + actualLinesCount), "");
4720
4729
  }
4721
- return `
4722
- ${indent}${c.green("- expected")}
4723
- ${indent}${c.red("+ actual")}
4724
-
4725
- ${cleanLines.map((l) => l()).join("\n")}`;
4730
+ return formatted.map((i) => indent + i).join("\n");
4726
4731
  }
4727
4732
  function formatLine(line) {
4728
- return cliTruncate(line, (process.stdout.columns || 80) - 1);
4729
- }
4730
- function renderTruncateMessage(indent) {
4731
- return `
4732
- ${indent}${c.dim("[...truncated]")}`;
4733
- }
4734
- function notBlank(line) {
4735
- return typeof line !== "undefined" && line !== null;
4733
+ return cliTruncate(line, (process.stdout.columns || 80) - 4);
4736
4734
  }
4737
4735
 
4738
4736
  export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, F_DOWN as d, F_LONG_DASH as e, F_DOWN_RIGHT as f, F_DOT as g, F_CHECK as h, F_CROSS as i, cliTruncate as j, F_RIGHT as k, printError as p, stringWidth as s, unifiedDiff as u };
package/dist/entry.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import fs, { promises } from 'fs';
2
- import { w as commonjsRequire, q as commonjsGlobal, x as index, g as getNames, c as c$1, t as toArray, k as basename, y as interpretOnlyMode, z as partitionSuiteChildren, A as hasTests, o as hasFailed, B as clearModuleMocks, b as vi } from './utils-5307e690.js';
2
+ import { c as clearContext, e as defaultSuite, f as setHooks, h as getHooks, j as context, k as getFn, b as vi } from './vi-9754296d.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
+ import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
8
+ import { l as index, g as getNames, c as c$1, t as toArray, b as basename, o as interpretOnlyMode, p as partitionSuiteChildren, q as hasTests, j as hasFailed } from './utils-d97bd6d9.js';
7
9
  import { r as rpc, s as send } from './rpc-7de86f29.js';
8
- import { u as unifiedDiff } from './error-4e165107.js';
10
+ import { u as unifiedDiff } from './diff-46ee5d7d.js';
9
11
  import { performance } from 'perf_hooks';
10
- import { c as clearContext, b as defaultSuite, e as setHooks, f as getHooks, h as context, j as getFn } from './suite-101bab76.js';
11
- import { n as nanoid } from './index-9e71c815.js';
12
+ import { n as nanoid } from './jest-mock-8498c46d.js';
12
13
  import { format as format$1 } from 'util';
13
14
  import 'tty';
14
15
  import 'path';
@@ -3168,14 +3169,12 @@ const stringify = (object, maxDepth = 10) => {
3168
3169
  try {
3169
3170
  result = format_1(object, {
3170
3171
  maxDepth,
3171
- min: true,
3172
3172
  plugins: PLUGINS
3173
3173
  });
3174
3174
  } catch {
3175
3175
  result = format_1(object, {
3176
3176
  callToJSON: false,
3177
3177
  maxDepth,
3178
- min: true,
3179
3178
  plugins: PLUGINS
3180
3179
  });
3181
3180
  }
@@ -3907,7 +3906,7 @@ async function setupGlobalEnv(config) {
3907
3906
  setupConsoleLogSpy();
3908
3907
  await setupChai();
3909
3908
  if (config.global)
3910
- (await import('./global-a3634033.js')).registerApiGlobally();
3909
+ (await import('./global-e0d00047.js')).registerApiGlobally();
3911
3910
  }
3912
3911
  function setupConsoleLogSpy() {
3913
3912
  const stdout = new Writable({
@@ -3932,13 +3931,12 @@ function setupConsoleLogSpy() {
3932
3931
  callback();
3933
3932
  }
3934
3933
  });
3935
- const newConsole = new Console({
3934
+ globalThis.console = new Console({
3936
3935
  stdout,
3937
3936
  stderr,
3938
3937
  colorMode: true,
3939
3938
  groupIndentation: 2
3940
3939
  });
3941
- globalThis.console = newConsole;
3942
3940
  }
3943
3941
  async function withEnv(name, fn) {
3944
3942
  const env = await environments[name].setup(globalThis);
@@ -3957,7 +3955,7 @@ async function runSetupFiles(config) {
3957
3955
  }
3958
3956
 
3959
3957
  function serializeError(val) {
3960
- if (!val)
3958
+ if (!val || typeof val === "string")
3961
3959
  return val;
3962
3960
  if (typeof val === "function")
3963
3961
  return `Function<${val.name}>`;
@@ -3981,6 +3979,10 @@ function processError(err) {
3981
3979
  err.stackStr = String(err.stack);
3982
3980
  if (err.name)
3983
3981
  err.nameStr = String(err.name);
3982
+ if (typeof err.expected !== "string")
3983
+ err.expected = stringify(err.expected);
3984
+ if (typeof err.actual !== "string")
3985
+ err.actual = stringify(err.actual);
3984
3986
  return serializeError(err);
3985
3987
  }
3986
3988
 
@@ -4135,6 +4137,15 @@ async function startTests(paths, config) {
4135
4137
  await runSuites(files);
4136
4138
  await getSnapshotClient().saveSnap();
4137
4139
  }
4140
+ function clearModuleMocks() {
4141
+ const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config;
4142
+ if (restoreMocks)
4143
+ vi.restoreAllMocks();
4144
+ else if (mockReset)
4145
+ vi.resetAllMocks();
4146
+ else if (clearMocks)
4147
+ vi.clearAllMocks();
4148
+ }
4138
4149
 
4139
4150
  async function run(files, config) {
4140
4151
  var _a;
@@ -0,0 +1,20 @@
1
+ import { g as globalApis } from './constants-e762cbc5.js';
2
+ import { i as index } from './index-0961cf69.js';
3
+ import 'url';
4
+ import './utils-d97bd6d9.js';
5
+ import 'tty';
6
+ import 'local-pkg';
7
+ import 'path';
8
+ import './vi-9754296d.js';
9
+ import './jest-mock-8498c46d.js';
10
+ import 'chai';
11
+ import 'tinyspy';
12
+ import './_commonjsHelpers-c9e3b764.js';
13
+
14
+ function registerApiGlobally() {
15
+ globalApis.forEach((api) => {
16
+ globalThis[api] = index[api];
17
+ });
18
+ }
19
+
20
+ export { registerApiGlobally };
@@ -1,6 +1,6 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-101bab76.js';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, v as vitest, b as vi } from './vi-9754296d.js';
2
2
  import chai, { assert, should, expect } from 'chai';
3
- import { s as spies, a as spyOn, f as fn, v as vitest, b as vi } from './utils-5307e690.js';
3
+ import { s as spies, a as spyOn, f as fn } from './jest-mock-8498c46d.js';
4
4
 
5
5
  const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
6
6
  const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
@@ -1,4 +1,4 @@
1
- import { q as commonjsGlobal } from './utils-5307e690.js';
1
+ import { c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
2
2
  import assert$1 from 'assert';
3
3
  import require$$2 from 'events';
4
4
 
@@ -2,15 +2,11 @@ import path$5 from 'path';
2
2
  import fs$5 from 'fs';
3
3
  import require$$0 from 'util';
4
4
  import require$$0$1 from 'child_process';
5
- import { q as commonjsGlobal } from './utils-5307e690.js';
6
- import { a as signalExit, b as onetime$1 } from './index-4cf13e25.js';
5
+ import { c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
6
+ import { a as signalExit, b as onetime$1 } from './index-61c8686f.js';
7
7
  import require$$0$2 from 'os';
8
8
  import require$$0$4 from 'buffer';
9
9
  import require$$0$3 from 'stream';
10
- import 'tty';
11
- import 'local-pkg';
12
- import 'chai';
13
- import 'tinyspy';
14
10
  import 'assert';
15
11
  import 'events';
16
12
 
@@ -1,4 +1,4 @@
1
- import { c, g as getNames, d as slash$1, h as getTests, i as isAbsolute, r as relative, j as dirname, k as basename, l as getSuites, m as resolve, n as noop$1, t as toArray, o as hasFailed } from './utils-5307e690.js';
1
+ import { c, g as getNames, s as slash$1, a as getTests, i as isAbsolute, r as relative, d as dirname, b as basename, f as getSuites, h as resolve, n as noop$1, t as toArray, j as hasFailed } from './utils-d97bd6d9.js';
2
2
  import { createServer, mergeConfig } from 'vite';
3
3
  import path$a from 'path';
4
4
  import process$1 from 'process';
@@ -7,10 +7,10 @@ import require$$0 from 'os';
7
7
  import require$$0$1 from 'util';
8
8
  import require$$0$2 from 'stream';
9
9
  import require$$2 from 'events';
10
- import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-9320a46c.js';
10
+ import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-e762cbc5.js';
11
11
  import { performance } from 'perf_hooks';
12
- import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, F as F_POINTER, d as F_DOWN, e as F_LONG_DASH, f as F_DOWN_RIGHT, g as F_DOT, h as F_CHECK, i as F_CROSS, j as cliTruncate, k as F_RIGHT, p as printError } from './error-4e165107.js';
13
- import { o as onetime, s as signalExit } from './index-4cf13e25.js';
12
+ import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, F as F_POINTER, d as F_DOWN, e as F_LONG_DASH, f as F_DOWN_RIGHT, g as F_DOT, h as F_CHECK, i as F_CROSS, j as cliTruncate, k as F_RIGHT, p as printError } from './diff-46ee5d7d.js';
13
+ import { o as onetime, s as signalExit } from './index-61c8686f.js';
14
14
  import { MessageChannel } from 'worker_threads';
15
15
  import { pathToFileURL } from 'url';
16
16
  import { Tinypool } from 'tinypool';
@@ -7483,8 +7483,9 @@ ${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
7483
7483
  this.ctx.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
7484
7484
  this.ctx.error();
7485
7485
  for (const suite of failedSuites) {
7486
+ const filepath = (suite == null ? void 0 : suite.filepath) || "";
7486
7487
  this.ctx.error(c.red(`
7487
- - ${getFullName(suite)}`));
7488
+ - ${getFullName(suite)} ${c.dim(`[ ${this.relative(filepath)} ]`)}`));
7488
7489
  await printError((_a = suite.result) == null ? void 0 : _a.error, this.ctx);
7489
7490
  errorDivider();
7490
7491
  }
@@ -9113,7 +9114,7 @@ async function createVitest(options, viteOverrides = {}) {
9113
9114
  ctx.setServer(options, server2);
9114
9115
  haveStarted = true;
9115
9116
  if (options.api)
9116
- server2.middlewares.use((await import('./middleware-c66abe08.js')).default(ctx));
9117
+ server2.middlewares.use((await import('./middleware-093a3bde.js')).default(ctx));
9117
9118
  }
9118
9119
  },
9119
9120
  MocksPlugin()
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Formatter } from 'picocolors/types';
2
2
  import { OptionsReceived } from 'pretty-format';
3
3
  import { MessagePort } from 'worker_threads';
4
4
  export { assert, default as chai, expect, should } from 'chai';
5
+ export { Spy, SpyFn } from 'tinyspy';
5
6
 
6
7
  declare const EXPECTED_COLOR: Formatter;
7
8
  declare const RECEIVED_COLOR: Formatter;
@@ -605,7 +606,7 @@ declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...ar
605
606
 
606
607
  declare class VitestUtils {
607
608
  private _timers;
608
- private _systemDate;
609
+ private _mockedDate;
609
610
  constructor();
610
611
  useFakeTimers(): void;
611
612
  useRealTimers(): void;
@@ -614,9 +615,9 @@ declare class VitestUtils {
614
615
  advanceTimersByTime(ms: number): void | Promise<void>;
615
616
  advanceTimersToNextTimer(): void | Promise<void>;
616
617
  getTimerCount(): number;
617
- setSystemDate(date: string | number | Date): void;
618
- resetSystemDate(): void;
619
- getSystemDate(): string | number | Date;
618
+ mockCurrentDate(date: string | number | Date): void;
619
+ restoreCurrentDate(): void;
620
+ getMockedDate(): string | number | Date | null;
620
621
  spyOn: typeof spyOn;
621
622
  fn: typeof fn;
622
623
  mock(path: string): void;
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
- export { d as describe, i as it, s as suite, t as test } from './suite-101bab76.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './index-a76b4291.js';
1
+ export { d as describe, i as it, s as suite, t as test, b as vi, v as vitest } from './vi-9754296d.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './index-0961cf69.js';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
- export { f as fn, s as spies, a as spyOn, b as vi, v as vitest } from './utils-5307e690.js';
5
- import './index-9e71c815.js';
4
+ export { f as fn, s as spies, a as spyOn } from './jest-mock-8498c46d.js';
5
+ import './utils-d97bd6d9.js';
6
6
  import 'tty';
7
7
  import 'local-pkg';
8
8
  import 'path';
9
+ import './_commonjsHelpers-c9e3b764.js';
9
10
  import 'tinyspy';
@@ -0,0 +1,104 @@
1
+ import { util } from 'chai';
2
+ import * as tinyspy from 'tinyspy';
3
+
4
+ let urlAlphabet =
5
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
6
+ let nanoid = (size = 21) => {
7
+ let id = '';
8
+ let i = size;
9
+ while (i--) {
10
+ id += urlAlphabet[(Math.random() * 64) | 0];
11
+ }
12
+ return id
13
+ };
14
+
15
+ const spies = /* @__PURE__ */ new Set();
16
+ function spyOn(obj, method, accessType) {
17
+ const dictionary = {
18
+ get: "getter",
19
+ set: "setter"
20
+ };
21
+ const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
22
+ const stub = tinyspy.spyOn(obj, objMethod);
23
+ return enhanceSpy(stub);
24
+ }
25
+ function enhanceSpy(spy) {
26
+ const stub = spy;
27
+ let implementation;
28
+ const instances = [];
29
+ const mockContext = {
30
+ get calls() {
31
+ return stub.calls;
32
+ },
33
+ get instances() {
34
+ return instances;
35
+ },
36
+ get invocationCallOrder() {
37
+ return [];
38
+ },
39
+ get results() {
40
+ return stub.results.map(([callType, value]) => {
41
+ const type = callType === "error" ? "throw" : "return";
42
+ return { type, value };
43
+ });
44
+ }
45
+ };
46
+ let onceImplementations = [];
47
+ let name = "";
48
+ Object.defineProperty(stub, "name", {
49
+ get: () => name
50
+ });
51
+ stub.getMockName = () => name || "vi.fn()";
52
+ stub.mockName = (n) => {
53
+ name = n;
54
+ return stub;
55
+ };
56
+ stub.mockClear = () => {
57
+ stub.reset();
58
+ return stub;
59
+ };
60
+ stub.mockReset = () => {
61
+ stub.reset();
62
+ implementation = () => void 0;
63
+ onceImplementations = [];
64
+ return stub;
65
+ };
66
+ stub.mockRestore = () => {
67
+ stub.mockReset();
68
+ implementation = void 0;
69
+ return stub;
70
+ };
71
+ stub.getMockImplementation = () => implementation;
72
+ stub.mockImplementation = (fn2) => {
73
+ implementation = fn2;
74
+ return stub;
75
+ };
76
+ stub.mockImplementationOnce = (fn2) => {
77
+ onceImplementations.push(fn2);
78
+ return stub;
79
+ };
80
+ stub.mockReturnThis = () => stub.mockImplementation(function() {
81
+ return this;
82
+ });
83
+ stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
84
+ stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
85
+ stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
86
+ stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
87
+ stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
88
+ stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
89
+ util.addProperty(stub, "mock", () => mockContext);
90
+ stub.willCall(function(...args) {
91
+ instances.push(this);
92
+ const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
93
+ });
94
+ return impl.apply(this, args);
95
+ });
96
+ spies.add(stub);
97
+ return stub;
98
+ }
99
+ function fn(implementation) {
100
+ return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
101
+ }) }, "fn"));
102
+ }
103
+
104
+ export { spyOn as a, fn as f, nanoid as n, spies as s };
@@ -1,11 +1,9 @@
1
- import { A as API_PATH } from './constants-9320a46c.js';
1
+ import { A as API_PATH } from './constants-e762cbc5.js';
2
2
  import 'url';
3
- import './utils-5307e690.js';
3
+ import './utils-d97bd6d9.js';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
7
- import 'chai';
8
- import 'tinyspy';
9
7
 
10
8
  /*! (c) 2020 Andrea Giammarchi */
11
9
 
package/dist/node.js CHANGED
@@ -1,10 +1,8 @@
1
- export { c as createVitest } from './index-1da01554.js';
2
- import './utils-5307e690.js';
1
+ export { c as createVitest } from './index-a727b58c.js';
2
+ import './utils-d97bd6d9.js';
3
3
  import 'tty';
4
4
  import 'local-pkg';
5
5
  import 'path';
6
- import 'chai';
7
- import 'tinyspy';
8
6
  import 'vite';
9
7
  import 'process';
10
8
  import 'fs';
@@ -12,11 +10,12 @@ import 'os';
12
10
  import 'util';
13
11
  import 'stream';
14
12
  import 'events';
15
- import './constants-9320a46c.js';
13
+ import './constants-e762cbc5.js';
16
14
  import 'url';
17
15
  import 'perf_hooks';
18
- import './error-4e165107.js';
19
- import './index-4cf13e25.js';
16
+ import './diff-46ee5d7d.js';
17
+ import './index-61c8686f.js';
18
+ import './_commonjsHelpers-c9e3b764.js';
20
19
  import 'assert';
21
20
  import 'worker_threads';
22
21
  import 'tinypool';