vitest 0.0.79 → 0.0.80

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/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import path, { isAbsolute, relative, dirname, basename, resolve } from 'path';
4
4
  import process$2 from 'process';
5
5
  import { promises } from 'fs';
6
6
  import { createServer } from 'vite';
7
- import { d as defaultIncludes, a as defaultExcludes, b as defaultPort, c as configFiles, e as distDir } from './constants-2435fa16.js';
7
+ import { d as defaultIncludes, a as defaultExcludes, b as defaultPort, c as configFiles, e as distDir } from './constants-9da0006f.js';
8
8
  import { performance } from 'perf_hooks';
9
9
  import { g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-9dcc4050.js';
10
10
  import require$$0 from 'assert';
@@ -632,7 +632,7 @@ const cac = (name = "") => new CAC(name);
632
632
 
633
633
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
634
634
 
635
- var version = "0.0.79";
635
+ var version = "0.0.80";
636
636
 
637
637
  /*
638
638
  How it works:
@@ -2182,7 +2182,7 @@ async function initVitest(options = {}) {
2182
2182
  },
2183
2183
  async configureServer(server2) {
2184
2184
  if (resolved.api)
2185
- server2.middlewares.use((await import('./middleware-37267df8.js')).default());
2185
+ server2.middlewares.use((await import('./middleware-fe2b1f7f.js')).default());
2186
2186
  }
2187
2187
  }
2188
2188
  ],
@@ -22,10 +22,9 @@ const globalApis = [
22
22
  "chai",
23
23
  "expect",
24
24
  "assert",
25
- "sinon",
26
25
  "spy",
27
- "mock",
28
- "stub",
26
+ "spyOn",
27
+ "vitest",
29
28
  "beforeAll",
30
29
  "afterAll",
31
30
  "beforeEach",
package/dist/entry.js CHANGED
@@ -2,7 +2,6 @@ import { Console } from 'console';
2
2
  import { Writable } from 'stream';
3
3
  import { importModule } from 'local-pkg';
4
4
  import chai, { expect, util } from 'chai';
5
- import SinonChai from 'sinon-chai';
6
5
  import Subset from 'chai-subset';
7
6
  import path, { basename } from 'path';
8
7
  import { r as rpc, s as send } from './rpc-7de86f29.js';
@@ -3500,31 +3499,22 @@ function JestChaiExpect() {
3500
3499
  utils.expectTypes(this, ["number"]);
3501
3500
  return this.closeTo(number, numDigits);
3502
3501
  });
3503
- function isSpy(putativeSpy) {
3504
- return typeof putativeSpy === "function" && typeof putativeSpy.getCall === "function" && typeof putativeSpy.calledWithExactly === "function";
3505
- }
3506
- function isCall(putativeCall) {
3507
- return putativeCall && isSpy(putativeCall.proxy);
3508
- }
3509
- const assertIsMock = (assertion) => {
3510
- if (!isSpy(assertion._obj) && !isCall(assertion._obj))
3511
- throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
3502
+ const getSpy = (assertion) => {
3503
+ return assertion._obj;
3512
3504
  };
3513
3505
  def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
3514
- assertIsMock(this);
3515
- return this.callCount(number);
3506
+ return this.assert(getSpy(this).callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number);
3516
3507
  });
3517
3508
  def("toHaveBeenCalledOnce", function() {
3518
- assertIsMock(this);
3519
- return this.callCount(1);
3509
+ return this.assert(getSpy(this).callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1);
3520
3510
  });
3521
3511
  def(["toHaveBeenCalled", "toBeCalled"], function() {
3522
- assertIsMock(this);
3523
- return this.called;
3512
+ return this.assert(getSpy(this).called, "expected spy to be called at least once", "expected spy to not be called at all", true);
3524
3513
  });
3525
3514
  def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
3526
- assertIsMock(this);
3527
- return this.calledWith(...args);
3515
+ const spy = getSpy(this);
3516
+ const pass = spy.calls.some((callArg) => equals(callArg, args));
3517
+ return this.assert(pass, "expected spy to be called with arguments: #{exp}", "expected spy to not be called with arguments: #{exp}", args);
3528
3518
  });
3529
3519
  const ordinalOf = (i) => {
3530
3520
  const j = i % 10;
@@ -3538,16 +3528,14 @@ function JestChaiExpect() {
3538
3528
  return `${i}th`;
3539
3529
  };
3540
3530
  def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
3541
- assertIsMock(this);
3542
- const spy = utils.flag(this, "object");
3543
- const nthCall = spy.getCall(times - 1);
3544
- this.assert(nthCall.calledWith(...args), `expected ${ordinalOf(times)} spy call to have been called with #{exp}`, `expected ${ordinalOf(times)} spy call not to have been called with #{exp}`, args, nthCall.args);
3531
+ const spy = getSpy(this);
3532
+ const nthCall = spy.calls[times - 1];
3533
+ this.assert(equals(nthCall, args), `expected ${ordinalOf(times)} spy call to have been called with #{exp}`, `expected ${ordinalOf(times)} spy call to not have been called with #{exp}`, args, nthCall);
3545
3534
  });
3546
3535
  def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
3547
- assertIsMock(this);
3548
- const spy = utils.flag(this, "object");
3549
- const lastCall = spy.getCall(spy.returnValues.length - 1);
3550
- this.assert(lastCall.calledWith(...args), "expected last spy call to have been called with #{exp}", "expected last spy call not to have been called with #{exp}", args, lastCall.args);
3536
+ const spy = getSpy(this);
3537
+ const lastCall = spy.calls.at(-1);
3538
+ this.assert(equals(lastCall, args), "expected last spy call to have been called with #{exp}", "expected last spy call to not have been called with #{exp}", args, lastCall);
3551
3539
  });
3552
3540
  def(["toThrow", "toThrowError"], function(expected) {
3553
3541
  const negate = utils.flag(this, "negate");
@@ -3557,37 +3545,35 @@ function JestChaiExpect() {
3557
3545
  this.to.throw(expected);
3558
3546
  });
3559
3547
  def(["toHaveReturned", "toReturn"], function() {
3560
- assertIsMock(this);
3561
- const spy = utils.flag(this, "object");
3562
- const calledAndNotThrew = spy.called && !spy.alwaysThrew();
3563
- this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy not to be successfully called", calledAndNotThrew, !calledAndNotThrew);
3548
+ const spy = getSpy(this);
3549
+ const calledAndNotThrew = spy.called && !spy.results.some(([type]) => type === "error");
3550
+ this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy to not be successfully called", calledAndNotThrew, !calledAndNotThrew);
3564
3551
  });
3565
3552
  def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
3566
- assertIsMock(this);
3567
- const spy = utils.flag(this, "object");
3568
- const successfullReturns = spy.getCalls().reduce((success, call) => call.threw() ? success : ++success, 0);
3569
- this.assert(successfullReturns === times, `expected spy to be successfully called ${times} times`, `expected spy not to be successfully called ${times} times`, `expected number of returns: ${times}`, `recieved number of returns: ${successfullReturns}`);
3553
+ const spy = getSpy(this);
3554
+ const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
3555
+ this.assert(successfullReturns === times, `expected spy to be successfully called ${times} times`, `expected spy to not be successfully called ${times} times`, `expected number of returns: ${times}`, `recieved number of returns: ${successfullReturns}`);
3570
3556
  });
3571
3557
  def(["toHaveReturnedWith", "toReturnWith"], function(value) {
3572
- assertIsMock(this);
3573
- return this.returned(value);
3558
+ const spy = getSpy(this);
3559
+ const pass = spy.results.some(([type, result]) => type === "ok" && equals(value, result));
3560
+ this.assert(pass, "expected spy to be successfully called with #{exp}", "expected spy to not be successfully called with #{exp}", value);
3574
3561
  });
3575
3562
  def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
3576
- assertIsMock(this);
3577
- const spy = utils.flag(this, "object");
3578
- const lastReturn = spy.lastCall.returned(value);
3579
- this.assert(lastReturn, "expected last spy call to return #{exp}", "expected last spy call not to return #{exp}", value, spy.lastCall.returnValue);
3563
+ const spy = getSpy(this);
3564
+ const lastResult = spy.returns.at(-1);
3565
+ const pass = equals(lastResult, value);
3566
+ this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
3580
3567
  });
3581
3568
  def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
3582
- assertIsMock(this);
3583
- const spy = utils.flag(this, "object");
3569
+ const spy = getSpy(this);
3584
3570
  const isNot = utils.flag(this, "negate");
3585
- const call = spy.getCall(nthCall - 1);
3571
+ const [callType, callResult] = spy.results[nthCall - 1];
3586
3572
  const ordinalCall = `${ordinalOf(nthCall)} call`;
3587
- if (!isNot && call.threw())
3573
+ if (!isNot && callType === "error")
3588
3574
  chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
3589
- const nthCallReturn = call.returned(value);
3590
- this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call not to return #{exp}`, value, call.returnValue);
3575
+ const nthCallReturn = equals(callResult, value);
3576
+ this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call to not return #{exp}`, value, callResult);
3591
3577
  });
3592
3578
  };
3593
3579
  }
@@ -3596,7 +3582,6 @@ let installed = false;
3596
3582
  async function setupChai() {
3597
3583
  if (installed)
3598
3584
  return;
3599
- chai.use(SinonChai);
3600
3585
  chai.use(JestExtend());
3601
3586
  chai.use(JestChaiExpect());
3602
3587
  chai.use(Subset);
@@ -3612,7 +3597,7 @@ async function setupGlobalEnv(config) {
3612
3597
  setupConsoleLogSpy();
3613
3598
  await setupChai();
3614
3599
  if (config.global)
3615
- (await import('./global-38c2f902.js')).registerApiGlobally();
3600
+ (await import('./global-6446cca1.js')).registerApiGlobally();
3616
3601
  }
3617
3602
  function setupConsoleLogSpy() {
3618
3603
  const stdout = new Writable({
@@ -1,11 +1,11 @@
1
- import { g as globalApis } from './constants-2435fa16.js';
2
- import { i as index } from './index-6feda5ef.js';
1
+ import { g as globalApis } from './constants-9da0006f.js';
2
+ import { i as index } from './index-16a06164.js';
3
3
  import 'path';
4
4
  import 'url';
5
5
  import './suite-95be5909.js';
6
6
  import './index-9e71c815.js';
7
7
  import 'chai';
8
- import 'sinon';
8
+ import 'tinyspy';
9
9
 
10
10
  function registerApiGlobally() {
11
11
  globalApis.forEach((api) => {
@@ -1,14 +1,16 @@
1
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-95be5909.js';
2
2
  import chai, { assert, should, expect } from 'chai';
3
- import sinon from 'sinon';
3
+ import { spyOn, spy } from 'tinyspy';
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()));
7
7
  const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
8
8
  const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
9
9
 
10
- const { mock, spy, stub } = sinon;
11
- sinon.fn = sinon.spy;
10
+ const vitest = {
11
+ spyOn,
12
+ fn: spy
13
+ };
12
14
 
13
15
  var index = /*#__PURE__*/Object.freeze({
14
16
  __proto__: null,
@@ -24,10 +26,9 @@ var index = /*#__PURE__*/Object.freeze({
24
26
  should: should,
25
27
  expect: expect,
26
28
  chai: chai,
27
- sinon: sinon,
28
- mock: mock,
29
29
  spy: spy,
30
- stub: stub
30
+ spyOn: spyOn,
31
+ vitest: vitest
31
32
  });
32
33
 
33
- export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, stub as e, index as i, mock as m, spy as s };
34
+ export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, index as i, vitest as v };
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ import { TransformResult, ViteDevServer } from 'vite';
3
3
  import { OptionsReceived } from 'pretty-format';
4
4
  import { MessagePort } from 'worker_threads';
5
5
  export { assert, default as chai, expect, should } from 'chai';
6
- import sinon from 'sinon';
7
- export { default as sinon } from 'sinon';
6
+ import { spyOn, spy } from 'tinyspy';
7
+ export { spy, spyOn } from 'tinyspy';
8
8
 
9
9
  declare const EXPECTED_COLOR: Formatter;
10
10
  declare const RECEIVED_COLOR: Formatter;
@@ -567,9 +567,10 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
567
567
  declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
568
568
  declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
569
569
 
570
- declare const mock: sinon.SinonMockStatic;
571
- declare const spy: sinon.SinonSpyStatic;
572
- declare const stub: sinon.SinonStubStatic;
570
+ declare const vitest: {
571
+ spyOn: typeof spyOn;
572
+ fn: typeof spy;
573
+ };
573
574
 
574
575
  declare module 'vite' {
575
576
  interface UserConfig {
@@ -636,4 +637,4 @@ declare global {
636
637
  }
637
638
  }
638
639
 
639
- export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConsoleLog, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, mock, spy, stub, suite, test };
640
+ export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConsoleLog, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, suite, test, vitest };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { d as describe, i as it, s as suite, t as test } from './suite-95be5909.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, m as mock, s as spy, e as stub } from './index-6feda5ef.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-16a06164.js';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
- export { default as sinon } from 'sinon';
4
+ export { spy, spyOn } from 'tinyspy';
5
5
  import './index-9e71c815.js';
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'flatted';
2
- import { A as API_PATH } from './constants-2435fa16.js';
2
+ import { A as API_PATH } from './constants-9da0006f.js';
3
3
  import 'path';
4
4
  import 'url';
5
5
 
package/dist/worker.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve, dirname } from 'path';
2
2
  import { n as nanoid } from './index-9e71c815.js';
3
- import { e as distDir } from './constants-2435fa16.js';
3
+ import { e as distDir } from './constants-9da0006f.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath } from 'url';
6
6
  import vm from 'vm';
package/global.d.ts CHANGED
@@ -5,10 +5,9 @@ declare global {
5
5
  const it: typeof import('vitest')['it']
6
6
  const expect: typeof import('vitest')['expect']
7
7
  const assert: typeof import('vitest')['assert']
8
- const sinon: typeof import('vitest')['sinon']
9
8
  const spy: typeof import('vitest')['spy']
10
- const mock: typeof import('vitest')['mock']
11
- const stub: typeof import('vitest')['stub']
9
+ const spyOn: typeof import('vitest')['spyOn']
10
+ const vitest: typeof import('vitest')['vitest']
12
11
  const beforeAll: typeof import('vitest')['beforeAll']
13
12
  const afterAll: typeof import('vitest')['afterAll']
14
13
  const beforeEach: typeof import('vitest')['beforeEach']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -41,8 +41,6 @@
41
41
  "dependencies": {
42
42
  "@types/chai": "^4.3.0",
43
43
  "@types/chai-subset": "^1.3.3",
44
- "@types/sinon": "^10.0.6",
45
- "@types/sinon-chai": "^3.2.6",
46
44
  "chai": "^4.3.4",
47
45
  "chai-subset": "^1.6.0",
48
46
  "fast-glob": "^3.2.7",
@@ -50,9 +48,8 @@
50
48
  "local-pkg": "^0.4.0",
51
49
  "micromatch": "^4.0.4",
52
50
  "piscina": "^3.2.0",
53
- "sinon": "^12.0.1",
54
- "sinon-chai": "^3.7.0",
55
- "source-map": "^0.7.3"
51
+ "source-map": "^0.7.3",
52
+ "tinyspy": "^0.0.6"
56
53
  },
57
54
  "devDependencies": {
58
55
  "@types/diff": "^5.0.1",