vitest 0.0.93 → 0.0.94

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
@@ -1,7 +1,7 @@
1
1
  import require$$0 from 'readline';
2
2
  import { EventEmitter } from 'events';
3
3
  import { c, e as ensurePackageInstalled } from './utils-576876dc.js';
4
- import { c as createVitest } from './index-880654a3.js';
4
+ import { c as createVitest } from './index-de606d4a.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
@@ -13,7 +13,7 @@ import 'util';
13
13
  import './constants-9cfa4d7b.js';
14
14
  import 'url';
15
15
  import 'perf_hooks';
16
- import './error-bf2213e4.js';
16
+ import './error-81292c96.js';
17
17
  import 'source-map';
18
18
  import './index-5cc247ff.js';
19
19
  import 'assert';
@@ -633,7 +633,7 @@ class CAC extends EventEmitter {
633
633
 
634
634
  const cac = (name = "") => new CAC(name);
635
635
 
636
- var version = "0.0.93";
636
+ var version = "0.0.94";
637
637
 
638
638
  const cli = cac("vitest");
639
639
  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("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", {
package/dist/entry.js CHANGED
@@ -7,10 +7,11 @@ import Subset from 'chai-subset';
7
7
  import path, { basename } from 'path';
8
8
  import { r as rpc, s as send } from './rpc-7de86f29.js';
9
9
  import { g as getNames, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, f as hasTests, h as hasFailed } from './utils-576876dc.js';
10
- import { u as unifiedDiff } from './error-bf2213e4.js';
10
+ import { u as unifiedDiff } from './error-81292c96.js';
11
11
  import { performance } from 'perf_hooks';
12
12
  import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-b8c6cb53.js';
13
13
  import { n as nanoid } from './index-9e71c815.js';
14
+ import { format as format$1 } from 'util';
14
15
  import 'tty';
15
16
  import 'source-map';
16
17
 
@@ -3413,7 +3414,7 @@ const JestChaiExpect = (chai, utils) => {
3413
3414
  const expected = args[0];
3414
3415
  const actual = utils.flag(this, "object");
3415
3416
  if (hasAsymmetric(expected)) {
3416
- this.assert(equals(actual, expected, void 0, true), "not match with #{this}", "should not match with #{this}", true);
3417
+ this.assert(equals(actual, expected, void 0, true), "not match with #{act}", "should not match with #{act}", actual, expected);
3417
3418
  } else {
3418
3419
  _super.apply(this, args);
3419
3420
  }
@@ -3424,7 +3425,7 @@ const JestChaiExpect = (chai, utils) => {
3424
3425
  const expected = args[0];
3425
3426
  const actual = utils.flag(this, "object");
3426
3427
  if (hasAsymmetric(expected)) {
3427
- this.assert(equals(actual, expected), "not match with #{this}", "should not match with #{this}", true);
3428
+ this.assert(equals(actual, expected), "not match with #{exp}", "should not match with #{exp}", actual, expected);
3428
3429
  } else {
3429
3430
  _super.apply(this, args);
3430
3431
  }
@@ -3437,7 +3438,7 @@ const JestChaiExpect = (chai, utils) => {
3437
3438
  return this.chaiEqual(expected);
3438
3439
  });
3439
3440
  def("toBe", function(expected) {
3440
- return this.chaiEqual(expected);
3441
+ return this.equal(expected);
3441
3442
  });
3442
3443
  def("toMatchObject", function(expected) {
3443
3444
  return this.containSubset(expected);
@@ -3781,7 +3782,7 @@ async function setupGlobalEnv(config) {
3781
3782
  setupConsoleLogSpy();
3782
3783
  await setupChai();
3783
3784
  if (config.global)
3784
- (await import('./global-c40aeb86.js')).registerApiGlobally();
3785
+ (await import('./global-473089f7.js')).registerApiGlobally();
3785
3786
  }
3786
3787
  function setupConsoleLogSpy() {
3787
3788
  const stdout = new Writable({
@@ -3841,6 +3842,8 @@ function serializeError(val) {
3841
3842
  return "Promise";
3842
3843
  if (typeof Element !== "undefined" && val instanceof Element)
3843
3844
  return val.tagName;
3845
+ if (typeof val.asymmetricMatch === "function")
3846
+ return `${val.toString()} ${format$1(val.sample)}`;
3844
3847
  Object.keys(val).forEach((key) => {
3845
3848
  val[key] = serializeError(val[key]);
3846
3849
  });
@@ -1,5 +1,6 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { relative } from 'path';
3
+ import { format } from 'util';
3
4
  import { d as notNullish, c } from './utils-576876dc.js';
4
5
  import { SourceMapConsumer } from 'source-map';
5
6
 
@@ -1338,7 +1339,7 @@ function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
1338
1339
  return res.join("\n");
1339
1340
  }
1340
1341
  function stringify(obj) {
1341
- return String(obj);
1342
+ return format(obj);
1342
1343
  }
1343
1344
  const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
1344
1345
  const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/;
@@ -1373,35 +1374,34 @@ function unifiedDiff(actual, expected) {
1373
1374
  if (expectedLinesCount >= diffLimit)
1374
1375
  return;
1375
1376
  expectedLinesCount++;
1377
+ line = line[0] + " " + line.slice(1);
1376
1378
  const isLastLine = expectedLinesCount === diffLimit;
1377
- return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1379
+ return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1378
1380
  }
1379
1381
  if (line[0] === "-") {
1380
1382
  if (actualLinesCount >= diffLimit)
1381
1383
  return;
1382
1384
  actualLinesCount++;
1385
+ line = line[0] + " " + line.slice(1);
1383
1386
  const isLastLine = actualLinesCount === diffLimit;
1384
- return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1387
+ return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1385
1388
  }
1386
1389
  if (line.match(/@@/))
1387
1390
  return "--";
1388
1391
  if (line.match(/\\ No newline/))
1389
1392
  return null;
1390
- return indent + line;
1393
+ return indent + " " + line;
1391
1394
  }
1392
1395
  const msg = createPatch("string", actual, expected);
1393
1396
  const lines = msg.split("\n").splice(5);
1394
1397
  return `
1395
- ${indent}${c.red("- actual")}
1396
- ${indent}${c.green("+ expected")}
1398
+ ${indent}${c.green("- expected")}
1399
+ ${indent}${c.red("+ actual")}
1397
1400
 
1398
1401
  ${lines.map(cleanUp).filter(notBlank).join("\n")}`;
1399
1402
  }
1400
1403
  function formatLine(line) {
1401
- const lineLimitLength = 50;
1402
- if (line.length > lineLimitLength)
1403
- return `${line.slice(0, lineLimitLength)} ${c.dim("[...truncated]")}`;
1404
- return line;
1404
+ return cliTruncate(line, (process.stdout.columns || 40) - 1);
1405
1405
  }
1406
1406
  function renderTruncateMessage(indent) {
1407
1407
  return `
@@ -1,5 +1,5 @@
1
1
  import { g as globalApis } from './constants-9cfa4d7b.js';
2
- import { i as index } from './index-708135df.js';
2
+ import { i as index } from './index-368448f4.js';
3
3
  import 'path';
4
4
  import 'url';
5
5
  import './suite-b8c6cb53.js';
@@ -1,7 +1,7 @@
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-b8c6cb53.js';
2
2
  import chai, { util, assert, should, expect } from 'chai';
3
3
  import * as tinyspy from 'tinyspy';
4
- import { spy, spyOn as spyOn$1 } from 'tinyspy';
4
+ import { spies } from 'tinyspy';
5
5
 
6
6
  const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
7
7
  const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
@@ -136,7 +136,8 @@ class FakeTimers {
136
136
  const spyFactory = (spyType, resultBuilder) => {
137
137
  return (cb, ms = 0) => {
138
138
  const id = ++this._spyid;
139
- const nestedMs = ms + (this._nestedTime[this._scopeId] ?? 0);
139
+ const nestedTo = Object.entries(this._nestedTime).filter(([key]) => Number(key) <= this._scopeId);
140
+ const nestedMs = nestedTo.reduce((total, [, ms2]) => total + ms2, ms);
140
141
  const call = { id, cb, ms, nestedMs, scopeId: this._scopeId };
141
142
  const task = { type: spyType, call, nested: this._isNested };
142
143
  this.pushTask(task);
@@ -306,6 +307,24 @@ class VitestUtils {
306
307
  getTimerCount() {
307
308
  return this._timers.getTimerCount();
308
309
  }
310
+ isMockFunction(fn2) {
311
+ return typeof fn2 === "function" && "__isSpy" in fn2 && fn2.__isSpy;
312
+ }
313
+ clearAllMocks() {
314
+ spies.forEach((spy) => {
315
+ spy.reset();
316
+ });
317
+ }
318
+ resetAllMocks() {
319
+ spies.forEach((spy) => {
320
+ spy.reset();
321
+ });
322
+ }
323
+ restoreAllMocks() {
324
+ spies.forEach((spy) => {
325
+ spy.restore();
326
+ });
327
+ }
309
328
  }
310
329
  const vitest = new VitestUtils();
311
330
  const vi = vitest;
@@ -324,10 +343,10 @@ var index = /*#__PURE__*/Object.freeze({
324
343
  should: should,
325
344
  expect: expect,
326
345
  chai: chai,
327
- spy: spy,
328
- spyOn: spyOn$1,
346
+ spyOn: spyOn,
347
+ fn: fn,
329
348
  vitest: vitest,
330
349
  vi: vi
331
350
  });
332
351
 
333
- export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, vi as e, index as i, vitest as v };
352
+ export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, vi as e, fn as f, index as i, spyOn as s, vitest as v };
@@ -7,7 +7,7 @@ import require$$0 from 'util';
7
7
  import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-9cfa4d7b.js';
8
8
  import { c, g as getNames, s as slash, a as getTests, b as getSuites, n as noop, t as toArray, h as hasFailed } from './utils-576876dc.js';
9
9
  import { performance } from 'perf_hooks';
10
- 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-bf2213e4.js';
10
+ 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-81292c96.js';
11
11
  import { o as onetime, s as signalExit } from './index-5cc247ff.js';
12
12
  import { MessageChannel } from 'worker_threads';
13
13
  import { pathToFileURL } from 'url';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ 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, spyOn } from 'tinyspy';
6
5
 
7
6
  declare const EXPECTED_COLOR: Formatter;
8
7
  declare const RECEIVED_COLOR: Formatter;
@@ -631,21 +630,25 @@ declare function fn<TArgs extends any[] = any[], R = any>(): JestMockCompatFn<TA
631
630
  declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): JestMockCompatFn<TArgs, R>;
632
631
 
633
632
  declare class VitestUtils {
634
- spyOn: typeof spyOn;
635
- fn: typeof fn;
636
- mock: (path: string) => string;
637
633
  private _timers;
638
634
  constructor();
639
635
  useFakeTimers(): void;
640
636
  useRealTimers(): void;
641
- runOnlyPendingTimers(): void;
642
- runAllTimers(): void;
643
- advanceTimersByTime(ms: number): void;
644
- advanceTimersToNextTimer(): void;
645
- runAllTicks(): void;
637
+ runOnlyPendingTimers(): void | Promise<void>;
638
+ runAllTimers(): void | Promise<void>;
639
+ advanceTimersByTime(ms: number): void | Promise<void>;
640
+ advanceTimersToNextTimer(): void | Promise<void>;
641
+ runAllTicks(): void | Promise<void>;
646
642
  setSystemTime(time?: number | Date): void;
647
643
  getRealSystemTime(): number;
648
644
  getTimerCount(): number;
645
+ spyOn: typeof spyOn;
646
+ fn: typeof fn;
647
+ mock: (path: string) => string;
648
+ isMockFunction(fn: any): any;
649
+ clearAllMocks(): void;
650
+ resetAllMocks(): void;
651
+ restoreAllMocks(): void;
649
652
  }
650
653
  declare const vitest: VitestUtils;
651
654
  declare const vi: VitestUtils;
@@ -721,4 +724,4 @@ declare global {
721
724
  }
722
725
  }
723
726
 
724
- export { ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, 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, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, suite, test, vi, vitest };
727
+ export { ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, 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, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, fn, it, spyOn, suite, test, vi, 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-b8c6cb53.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as vi, v as vitest } from './index-708135df.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, f as fn, s as spyOn, e as vi, v as vitest } from './index-368448f4.js';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
- export { spy, spyOn } from 'tinyspy';
5
4
  import './index-9e71c815.js';
5
+ import 'tinyspy';
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- export { c as createVitest } from './index-880654a3.js';
1
+ export { c as createVitest } from './index-de606d4a.js';
2
2
  import 'path';
3
3
  import 'vite';
4
4
  import 'process';
@@ -11,7 +11,7 @@ import './utils-576876dc.js';
11
11
  import 'tty';
12
12
  import 'local-pkg';
13
13
  import 'perf_hooks';
14
- import './error-bf2213e4.js';
14
+ import './error-81292c96.js';
15
15
  import 'source-map';
16
16
  import './index-5cc247ff.js';
17
17
  import 'assert';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.93",
3
+ "version": "0.0.94",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -54,7 +54,7 @@
54
54
  "local-pkg": "^0.4.0",
55
55
  "piscina": "^3.2.0",
56
56
  "source-map": "^0.7.3",
57
- "tinyspy": "^0.1.0"
57
+ "tinyspy": "^0.1.2"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@antfu/install-pkg": "^0.1.0",
@@ -63,7 +63,7 @@
63
63
  "@types/micromatch": "^4.0.2",
64
64
  "@types/natural-compare": "^1.4.1",
65
65
  "@types/node": "^17.0.0",
66
- "@types/prompts": "^2.0.14",
66
+ "@types/prompts": "^2.4.0",
67
67
  "c8": "^7.10.0",
68
68
  "cac": "^6.7.12",
69
69
  "cli-truncate": "^3.1.0",