vitest 0.0.88 → 0.0.89

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/bin/vitest.mjs CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  import { fileURLToPath } from 'url'
4
4
  import { resolve } from 'path'
5
+ import { checkPeerDependency } from '../dist/utils.js'
5
6
 
6
7
  const argv = process.argv.slice(2)
7
8
 
8
9
  if (argv.includes('--coverage')) {
10
+ checkPeerDependency('c8/bin/c8.js')
9
11
  const filename = fileURLToPath(import.meta.url)
10
12
  const entry = resolve(filename, '../../dist/cli.js')
11
13
  process.argv.splice(2, 0, process.argv[0], entry)
package/dist/cli.js CHANGED
@@ -1,22 +1,23 @@
1
+ import readline from 'readline';
1
2
  import { EventEmitter } from 'events';
2
- import { c } from './error-c5d734a1.js';
3
- import { c as createVitest } from './index-af5d5277.js';
4
- import 'fs';
5
- import 'path';
3
+ import { c } from './utils-385e2d09.js';
4
+ import { c as createVitest } from './index-733e7378.js';
5
+ import 'module';
6
6
  import 'tty';
7
- import 'source-map';
8
- import './utils-9dcc4050.js';
7
+ import 'path';
9
8
  import 'vite';
10
9
  import 'process';
10
+ import 'fs';
11
11
  import './constants-adef7ffb.js';
12
12
  import 'url';
13
13
  import 'perf_hooks';
14
+ import './error-309196c9.js';
15
+ import 'source-map';
14
16
  import 'assert';
15
17
  import 'worker_threads';
16
18
  import 'piscina';
17
19
  import 'fast-glob';
18
20
  import 'micromatch';
19
- import 'readline';
20
21
 
21
22
  function toArr(any) {
22
23
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -631,7 +632,7 @@ class CAC extends EventEmitter {
631
632
 
632
633
  const cac = (name = "") => new CAC(name);
633
634
 
634
- var version = "0.0.88";
635
+ var version = "0.0.89";
635
636
 
636
637
  const cli = cac("vitest");
637
638
  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", {
@@ -657,8 +658,9 @@ async function run(cliFilters, options) {
657
658
  const ctx = await createVitest(options);
658
659
  process.__vitest__ = ctx;
659
660
  process.chdir(ctx.config.root);
661
+ registerConsoleShortcuts(ctx);
660
662
  try {
661
- await ctx.run(cliFilters);
663
+ await ctx.start(cliFilters);
662
664
  } catch (e) {
663
665
  process.exitCode = 1;
664
666
  throw e;
@@ -667,3 +669,17 @@ async function run(cliFilters, options) {
667
669
  await ctx.close();
668
670
  }
669
671
  }
672
+ function registerConsoleShortcuts(ctx) {
673
+ if (process.stdin.isTTY) {
674
+ readline.emitKeypressEvents(process.stdin);
675
+ process.stdin.setRawMode(true);
676
+ process.stdin.on("keypress", (str) => {
677
+ if (str === "" || str === "")
678
+ process.exit();
679
+ if (ctx.runningPromise)
680
+ return;
681
+ if (ctx.isFirstRun)
682
+ process.exit();
683
+ });
684
+ }
685
+ }
package/dist/entry.js CHANGED
@@ -5,12 +5,13 @@ import chai, { expect, util } from 'chai';
5
5
  import Subset from 'chai-subset';
6
6
  import path, { basename } from 'path';
7
7
  import { r as rpc, s as send } from './rpc-7de86f29.js';
8
- import { g as getNames, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
8
+ import { g as getNames, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, d as hasTests, h as hasFailed } from './utils-385e2d09.js';
9
9
  import fs from 'fs';
10
- import { c as c$1, u as unifiedDiff } from './error-c5d734a1.js';
10
+ import { u as unifiedDiff } from './error-309196c9.js';
11
11
  import { performance } from 'perf_hooks';
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-0e21bf9b.js';
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 'module';
14
15
  import 'tty';
15
16
  import 'source-map';
16
17
 
@@ -2761,7 +2762,7 @@ class SnapshotState {
2761
2762
  this._snapshotData = data;
2762
2763
  this._dirty = dirty;
2763
2764
  this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
2764
- this._counters = new Map();
2765
+ this._counters = /* @__PURE__ */ new Map();
2765
2766
  this._index = 0;
2766
2767
  this.expand = options.expand || false;
2767
2768
  this.added = 0;
@@ -2783,7 +2784,7 @@ class SnapshotState {
2783
2784
  }
2784
2785
  clear() {
2785
2786
  this._snapshotData = this._initialData;
2786
- this._counters = new Map();
2787
+ this._counters = /* @__PURE__ */ new Map();
2787
2788
  this._index = 0;
2788
2789
  this.added = 0;
2789
2790
  this.matched = 0;
@@ -3295,7 +3296,7 @@ const hasPropertyInObject = (object, key) => {
3295
3296
  };
3296
3297
  const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
3297
3298
  const subsetEquality = (object, subset) => {
3298
- const subsetEqualityWithContext = (seenReferences = new WeakMap()) => (object2, subset2) => {
3299
+ const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
3299
3300
  if (!isObjectWithKeys(subset2))
3300
3301
  return void 0;
3301
3302
  return Object.keys(subset2).every((key) => {
@@ -3485,13 +3486,16 @@ function JestChaiExpect() {
3485
3486
  return assertion._obj;
3486
3487
  };
3487
3488
  def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
3488
- return this.assert(getSpy(this).callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number);
3489
+ const spy = getSpy(this);
3490
+ return this.assert(spy.callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number, spy.callCount);
3489
3491
  });
3490
3492
  def("toHaveBeenCalledOnce", function() {
3491
- return this.assert(getSpy(this).callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1);
3493
+ const spy = getSpy(this);
3494
+ return this.assert(spy.callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1, spy.callCount);
3492
3495
  });
3493
3496
  def(["toHaveBeenCalled", "toBeCalled"], function() {
3494
- return this.assert(getSpy(this).called, "expected spy to be called at least once", "expected spy to not be called at all", true);
3497
+ const spy = getSpy(this);
3498
+ return this.assert(spy.called, "expected spy to be called at least once", "expected spy to not be called at all", true, spy.called);
3495
3499
  });
3496
3500
  def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
3497
3501
  const spy = getSpy(this);
@@ -3579,7 +3583,7 @@ async function setupGlobalEnv(config) {
3579
3583
  setupConsoleLogSpy();
3580
3584
  await setupChai();
3581
3585
  if (config.global)
3582
- (await import('./global-e172af93.js')).registerApiGlobally();
3586
+ (await import('./global-f3eab75a.js')).registerApiGlobally();
3583
3587
  }
3584
3588
  function setupConsoleLogSpy() {
3585
3589
  const stdout = new Writable({
@@ -1,71 +1,7 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { relative } from 'path';
3
- import require$$0 from 'tty';
3
+ import { n as notNullish, c } from './utils-385e2d09.js';
4
4
  import { SourceMapConsumer } from 'source-map';
5
- import { n as notNullish } from './utils-9dcc4050.js';
6
-
7
- var picocolors = {exports: {}};
8
-
9
- let tty = require$$0;
10
-
11
- let isColorSupported =
12
- !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
13
- ("FORCE_COLOR" in process.env ||
14
- process.argv.includes("--color") ||
15
- process.platform === "win32" ||
16
- (tty.isatty(1) && process.env.TERM !== "dumb") ||
17
- "CI" in process.env);
18
-
19
- let formatter =
20
- (open, close, replace = open) =>
21
- input => {
22
- let string = "" + input;
23
- let index = string.indexOf(close, open.length);
24
- return ~index
25
- ? open + replaceClose(string, close, replace, index) + close
26
- : open + string + close
27
- };
28
-
29
- let replaceClose = (string, close, replace, index) => {
30
- let start = string.substring(0, index) + replace;
31
- let end = string.substring(index + close.length);
32
- let nextIndex = end.indexOf(close);
33
- return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
34
- };
35
-
36
- let createColors = (enabled = isColorSupported) => ({
37
- isColorSupported: enabled,
38
- reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
39
- bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
40
- dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
41
- italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
42
- underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
43
- inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
44
- hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
45
- strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
46
- black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
47
- red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
48
- green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
49
- yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
50
- blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
51
- magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
52
- cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
53
- white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
54
- gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
55
- bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
56
- bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
57
- bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
58
- bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
59
- bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
60
- bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
61
- bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
62
- bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
63
- });
64
-
65
- picocolors.exports = createColors();
66
- picocolors.exports.createColors = createColors;
67
-
68
- var c = picocolors.exports;
69
5
 
70
6
  function Diff() {}
71
7
  Diff.prototype = {
@@ -1254,8 +1190,7 @@ const F_CHECK = "\u221A";
1254
1190
  const F_CROSS = "\xD7";
1255
1191
  const F_LONG_DASH = "\u23AF";
1256
1192
 
1257
- async function printError(error) {
1258
- const ctx = process.__vitest__;
1193
+ async function printError(error, ctx) {
1259
1194
  let e = error;
1260
1195
  if (typeof error === "string") {
1261
1196
  e = {
@@ -1476,4 +1411,4 @@ function notBlank(line) {
1476
1411
  return typeof line !== "undefined" && line !== null;
1477
1412
  }
1478
1413
 
1479
- export { F_POINTER as F, ansiStyles as a, stripAnsi as b, c, sliceAnsi as d, F_DOWN as e, F_LONG_DASH as f, F_DOWN_RIGHT as g, F_DOT as h, F_CHECK as i, F_CROSS as j, cliTruncate as k, F_RIGHT as l, printError as p, stringWidth as s, unifiedDiff as u };
1414
+ 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 };
@@ -1,8 +1,8 @@
1
1
  import { g as globalApis } from './constants-adef7ffb.js';
2
- import { i as index } from './index-906ac3f9.js';
2
+ import { i as index } from './index-722fb5a5.js';
3
3
  import 'path';
4
4
  import 'url';
5
- import './suite-0e21bf9b.js';
5
+ import './suite-b8c6cb53.js';
6
6
  import './index-9e71c815.js';
7
7
  import 'chai';
8
8
  import 'tinyspy';
@@ -0,0 +1,122 @@
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
+ import chai, { util, assert, should, expect } from 'chai';
3
+ import * as tinyspy from 'tinyspy';
4
+ import { spy, spyOn as spyOn$1 } from 'tinyspy';
5
+
6
+ const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
7
+ const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
8
+ const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
9
+ const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
10
+
11
+ function spyOn(obj, method, accessType) {
12
+ const dictionary = {
13
+ get: "getter",
14
+ set: "setter"
15
+ };
16
+ const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
17
+ const stub = tinyspy.spyOn(obj, objMethod);
18
+ return enhanceSpy(stub);
19
+ }
20
+ function enhanceSpy(spy) {
21
+ const stub = spy;
22
+ let implementation;
23
+ const instances = [];
24
+ const mockContext = {
25
+ get calls() {
26
+ return stub.calls;
27
+ },
28
+ get instances() {
29
+ return instances;
30
+ },
31
+ get invocationCallOrder() {
32
+ return [];
33
+ },
34
+ get results() {
35
+ return stub.results.map(([callType, value]) => {
36
+ const type = callType === "error" ? "throw" : "return";
37
+ return { type, value };
38
+ });
39
+ }
40
+ };
41
+ let onceImplementations = [];
42
+ let name = "";
43
+ Object.defineProperty(stub, "name", {
44
+ get: () => name
45
+ });
46
+ stub.getMockName = () => name || "vi.fn()";
47
+ stub.mockName = (n) => {
48
+ name = n;
49
+ return stub;
50
+ };
51
+ stub.mockClear = () => {
52
+ stub.reset();
53
+ return stub;
54
+ };
55
+ stub.mockReset = () => {
56
+ stub.reset();
57
+ return stub;
58
+ };
59
+ stub.mockRestore = () => {
60
+ implementation = void 0;
61
+ onceImplementations = [];
62
+ stub.reset();
63
+ stub.restore();
64
+ return stub;
65
+ };
66
+ stub.getMockImplementation = () => implementation;
67
+ stub.mockImplementation = (fn2) => {
68
+ implementation = fn2;
69
+ return stub;
70
+ };
71
+ stub.mockImplementationOnce = (fn2) => {
72
+ onceImplementations.push(fn2);
73
+ return stub;
74
+ };
75
+ stub.mockReturnThis = () => stub.mockImplementation(function() {
76
+ return this;
77
+ });
78
+ stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
79
+ stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
80
+ stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
81
+ stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
82
+ stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
83
+ stub.mockRejectedValueOnce = (val) => stub.mockImplementation(() => Promise.reject(val));
84
+ util.addProperty(stub, "mock", () => mockContext);
85
+ stub.willCall(function(...args) {
86
+ instances.push(this);
87
+ const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
88
+ });
89
+ return impl.apply(this, args);
90
+ });
91
+ return stub;
92
+ }
93
+ function fn(implementation) {
94
+ return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
95
+ }) }, "fn"));
96
+ }
97
+
98
+ const vitest = {
99
+ spyOn,
100
+ fn
101
+ };
102
+
103
+ var index = /*#__PURE__*/Object.freeze({
104
+ __proto__: null,
105
+ suite: suite,
106
+ test: test,
107
+ describe: describe,
108
+ it: it,
109
+ beforeAll: beforeAll,
110
+ afterAll: afterAll,
111
+ beforeEach: beforeEach,
112
+ afterEach: afterEach,
113
+ assert: assert,
114
+ should: should,
115
+ expect: expect,
116
+ chai: chai,
117
+ spy: spy,
118
+ spyOn: spyOn$1,
119
+ vitest: vitest
120
+ });
121
+
122
+ export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, index as i, vitest as v };
@@ -3,9 +3,9 @@ import { createServer, mergeConfig } from 'vite';
3
3
  import process$2 from 'process';
4
4
  import { promises } from 'fs';
5
5
  import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-adef7ffb.js';
6
- import { g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-9dcc4050.js';
6
+ import { c, g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-385e2d09.js';
7
7
  import { performance } from 'perf_hooks';
8
- import { s as stringWidth, a as ansiStyles, b as stripAnsi, d as sliceAnsi, c, F as F_POINTER, e as F_DOWN, f as F_LONG_DASH, g as F_DOWN_RIGHT, h as F_DOT, i as F_CHECK, j as F_CROSS, k as cliTruncate, l as F_RIGHT, p as printError } from './error-c5d734a1.js';
8
+ 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-309196c9.js';
9
9
  import assert$1 from 'assert';
10
10
  import require$$2 from 'events';
11
11
  import { MessageChannel } from 'worker_threads';
@@ -13,7 +13,6 @@ import { pathToFileURL } from 'url';
13
13
  import Piscina from 'piscina';
14
14
  import fg from 'fast-glob';
15
15
  import mm from 'micromatch';
16
- import readline from 'readline';
17
16
 
18
17
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
19
18
 
@@ -1157,8 +1156,8 @@ createLogUpdate(process$2.stderr);
1157
1156
 
1158
1157
  const DURATION_LONG = 300;
1159
1158
  const MAX_HEIGHT = 20;
1160
- const spinnerMap = new WeakMap();
1161
- const outputMap = new WeakMap();
1159
+ const spinnerMap = /* @__PURE__ */ new WeakMap();
1160
+ const outputMap = /* @__PURE__ */ new WeakMap();
1162
1161
  const pointer = c.yellow(F_POINTER);
1163
1162
  const skipped = c.yellow(F_DOWN);
1164
1163
  function divider(text, left, right) {
@@ -1414,7 +1413,7 @@ class ConsoleReporter {
1414
1413
  for (const suite of failedSuites) {
1415
1414
  this.error(c.red(`
1416
1415
  - ${getFullName(suite)}`));
1417
- await printError((_a = suite.result) == null ? void 0 : _a.error);
1416
+ await printError((_a = suite.result) == null ? void 0 : _a.error, this.ctx);
1418
1417
  errorDivider();
1419
1418
  }
1420
1419
  }
@@ -1423,7 +1422,7 @@ class ConsoleReporter {
1423
1422
  this.error();
1424
1423
  for (const test of failedTests) {
1425
1424
  this.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
1426
- await printError((_b = test.result) == null ? void 0 : _b.error);
1425
+ await printError((_b = test.result) == null ? void 0 : _b.error, this.ctx);
1427
1426
  errorDivider();
1428
1427
  }
1429
1428
  }
@@ -1490,13 +1489,17 @@ ${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")
1490
1489
  process[log.type].write(`${log.content}
1491
1490
  `);
1492
1491
  }
1492
+ onServerRestart() {
1493
+ this.console.clear();
1494
+ this.log(c.cyan("Restarted due to config changes..."));
1495
+ }
1493
1496
  }
1494
1497
 
1495
1498
  class StateManager {
1496
1499
  constructor() {
1497
1500
  this.filesMap = {};
1498
1501
  this.idMap = {};
1499
- this.taskFileMap = new WeakMap();
1502
+ this.taskFileMap = /* @__PURE__ */ new WeakMap();
1500
1503
  }
1501
1504
  getFiles(keys) {
1502
1505
  if (keys)
@@ -1553,8 +1556,8 @@ function resolveConfig(options, viteConfig) {
1553
1556
  const resolved = __spreadProps(__spreadValues(__spreadValues({}, options), viteConfig.test), {
1554
1557
  root: viteConfig.root
1555
1558
  });
1556
- resolved.depsInline = ((_a = resolved.deps) == null ? void 0 : _a.inline) || [];
1557
- resolved.depsExternal = ((_b = resolved.deps) == null ? void 0 : _b.external) || [];
1559
+ resolved.depsInline = [...((_a = resolved.deps) == null ? void 0 : _a.inline) || []];
1560
+ resolved.depsExternal = [...((_b = resolved.deps) == null ? void 0 : _b.external) || []];
1558
1561
  resolved.environment = resolved.environment || "node";
1559
1562
  resolved.threads = resolved.threads ?? true;
1560
1563
  resolved.interpretDefault = resolved.interpretDefault ?? true;
@@ -1714,138 +1717,129 @@ function isTargetFile(id, config) {
1714
1717
  return false;
1715
1718
  return mm.isMatch(id, config.include);
1716
1719
  }
1717
- async function globTestFiles(config) {
1718
- return await fg(config.include, {
1720
+ async function globTestFiles(config, filters) {
1721
+ let files = await fg(config.include, {
1719
1722
  absolute: true,
1720
1723
  cwd: config.root,
1721
1724
  ignore: config.exclude
1722
1725
  });
1726
+ if (filters == null ? void 0 : filters.length)
1727
+ files = files.filter((i) => filters.some((f) => i.includes(f)));
1728
+ return files;
1723
1729
  }
1724
1730
 
1725
- const WATCHER_DEBOUNCE = 50;
1726
- async function startWatcher(ctx) {
1727
- const { server } = ctx;
1728
- ctx.reporters.forEach((r) => {
1729
- var _a;
1730
- return (_a = r.onWatcherStart) == null ? void 0 : _a.call(r);
1731
- });
1732
- let timer;
1733
- const changedTests = new Set();
1734
- const seen = new Set();
1735
- let isFirstRun = true;
1736
- let promise;
1737
- server.watcher.on("change", (id) => {
1738
- id = slash(id);
1739
- getAffectedTests(ctx, id, changedTests, seen);
1740
- if (changedTests.size === 0)
1741
- return;
1742
- rerunFile(id);
1743
- });
1744
- server.watcher.on("unlink", (id) => {
1745
- id = slash(id);
1746
- seen.add(id);
1747
- if (id in ctx.state.filesMap) {
1748
- delete ctx.state.filesMap[id];
1749
- changedTests.delete(id);
1750
- }
1751
- });
1752
- server.watcher.on("add", async (id) => {
1753
- id = slash(id);
1754
- if (isTargetFile(id, ctx.config)) {
1755
- changedTests.add(id);
1756
- rerunFile(id);
1757
- }
1758
- });
1759
- async function rerunFile(id) {
1760
- await promise;
1761
- clearTimeout(timer);
1762
- timer = setTimeout(async () => {
1763
- if (changedTests.size === 0) {
1764
- seen.clear();
1765
- return;
1766
- }
1767
- isFirstRun = false;
1768
- const invalidates = Array.from(seen);
1769
- const tests = Array.from(changedTests);
1770
- changedTests.clear();
1771
- seen.clear();
1772
- promise = start(tests, id, invalidates).then(() => {
1773
- promise = void 0;
1774
- });
1775
- await promise;
1776
- }, WATCHER_DEBOUNCE);
1731
+ const WATCHER_DEBOUNCE = 100;
1732
+ class Vitest {
1733
+ constructor() {
1734
+ this.config = void 0;
1735
+ this.server = void 0;
1736
+ this.state = void 0;
1737
+ this.snapshot = void 0;
1738
+ this.reporters = void 0;
1739
+ this.invalidates = /* @__PURE__ */ new Set();
1740
+ this.changedTests = /* @__PURE__ */ new Set();
1741
+ this.isFirstRun = true;
1742
+ this.console = globalThis.console;
1777
1743
  }
1778
- async function start(tests, id, invalidates) {
1744
+ setServer(options, server) {
1779
1745
  var _a;
1780
- await ctx.report("onWatcherRerun", tests, id);
1781
- await ((_a = ctx.pool) == null ? void 0 : _a.runTests(tests, invalidates));
1782
- await ctx.report("onFinished", ctx.state.getFiles(tests));
1783
- await ctx.report("onWatcherStart");
1784
- }
1785
- if (process.stdin.isTTY) {
1786
- readline.emitKeypressEvents(process.stdin);
1787
- process.stdin.setRawMode(true);
1788
- process.stdin.on("keypress", (str) => {
1789
- if (str === "" || str === "")
1790
- process.exit();
1791
- if (promise)
1792
- return;
1793
- if (isFirstRun)
1794
- process.exit();
1795
- });
1796
- }
1797
- await new Promise(() => {
1798
- });
1799
- }
1800
- function getAffectedTests(ctx, id, set = new Set(), seen = new Set()) {
1801
- if (seen.has(id) || set.has(id) || id.includes("/node_modules/") || id.includes("/vitest/dist/"))
1802
- return set;
1803
- seen.add(id);
1804
- if (id in ctx.state.filesMap) {
1805
- set.add(id);
1806
- return set;
1807
- }
1808
- const mod = ctx.server.moduleGraph.getModuleById(id);
1809
- if (mod) {
1810
- mod.importers.forEach((i) => {
1811
- if (i.id)
1812
- getAffectedTests(ctx, i.id, set, seen);
1813
- });
1814
- }
1815
- return set;
1816
- }
1817
-
1818
- class Vitest {
1819
- constructor(options, server) {
1746
+ (_a = this.pool) == null ? void 0 : _a.close();
1747
+ this.pool = void 0;
1820
1748
  const resolved = resolveConfig(options, server.config);
1821
1749
  this.server = server;
1822
1750
  this.config = resolved;
1823
1751
  this.state = new StateManager();
1824
1752
  this.snapshot = new SnapshotManager(resolved);
1825
1753
  this.reporters = toArray(resolved.reporters);
1826
- this.console = globalThis.console;
1827
1754
  if (!this.reporters.length)
1828
1755
  this.reporters.push(new ConsoleReporter(this));
1756
+ if (this.config.watch)
1757
+ this.registerWatcher();
1758
+ this.runningPromise = void 0;
1829
1759
  }
1830
- async run(filters) {
1831
- let testFilepaths = await globTestFiles(this.config);
1832
- if (filters == null ? void 0 : filters.length)
1833
- testFilepaths = testFilepaths.filter((i) => filters.some((f) => i.includes(f)));
1834
- if (!testFilepaths.length) {
1760
+ async start(filters) {
1761
+ const files = await globTestFiles(this.config, filters);
1762
+ if (!files.length) {
1835
1763
  console.error("No test files found");
1836
1764
  process.exitCode = 1;
1765
+ }
1766
+ await this.runFiles(files);
1767
+ if (this.config.watch) {
1768
+ await this.report("onWatcherStart");
1769
+ await new Promise(() => {
1770
+ });
1771
+ }
1772
+ }
1773
+ async runFiles(files) {
1774
+ await this.runningPromise;
1775
+ this.runningPromise = (async () => {
1776
+ if (!this.pool)
1777
+ this.pool = createPool(this);
1778
+ const invalidates = Array.from(this.invalidates);
1779
+ this.invalidates.clear();
1780
+ await this.pool.runTests(files, invalidates);
1781
+ if (hasFailed(this.state.getFiles()))
1782
+ process.exitCode = 1;
1783
+ await this.report("onFinished", this.state.getFiles());
1784
+ })().finally(() => {
1785
+ this.runningPromise = void 0;
1786
+ });
1787
+ return await this.runningPromise;
1788
+ }
1789
+ registerWatcher() {
1790
+ let timer;
1791
+ const scheduleRerun = async (id) => {
1792
+ await this.runningPromise;
1793
+ clearTimeout(timer);
1794
+ timer = setTimeout(async () => {
1795
+ if (this.changedTests.size === 0) {
1796
+ this.invalidates.clear();
1797
+ return;
1798
+ }
1799
+ this.isFirstRun = false;
1800
+ const files = Array.from(this.changedTests);
1801
+ await this.report("onWatcherRerun", files, id);
1802
+ await this.runFiles(files);
1803
+ await this.report("onWatcherStart");
1804
+ }, WATCHER_DEBOUNCE);
1805
+ };
1806
+ this.server.watcher.on("change", (id) => {
1807
+ id = slash(id);
1808
+ this.handleFileChanged(id);
1809
+ if (this.changedTests.size)
1810
+ scheduleRerun(id);
1811
+ });
1812
+ this.server.watcher.on("unlink", (id) => {
1813
+ id = slash(id);
1814
+ this.invalidates.add(id);
1815
+ if (id in this.state.filesMap) {
1816
+ delete this.state.filesMap[id];
1817
+ this.changedTests.delete(id);
1818
+ }
1819
+ });
1820
+ this.server.watcher.on("add", async (id) => {
1821
+ id = slash(id);
1822
+ if (isTargetFile(id, this.config)) {
1823
+ this.changedTests.add(id);
1824
+ scheduleRerun(id);
1825
+ }
1826
+ });
1827
+ }
1828
+ handleFileChanged(id) {
1829
+ if (this.changedTests.has(id) || this.invalidates.has(id) || id.includes("/node_modules/") || id.includes("/vitest/dist/"))
1830
+ return;
1831
+ this.invalidates.add(id);
1832
+ if (id in this.state.filesMap) {
1833
+ this.changedTests.add(id);
1837
1834
  return;
1838
1835
  }
1839
- if (!this.pool)
1840
- this.pool = createPool(this);
1841
- await this.pool.runTests(testFilepaths);
1842
- if (hasFailed(this.state.getFiles()))
1843
- process.exitCode = 1;
1844
- await this.report("onFinished", this.state.getFiles());
1845
- if (this.config.watch)
1846
- await startWatcher(this);
1847
- else
1848
- await this.pool.close();
1836
+ const mod = this.server.moduleGraph.getModuleById(id);
1837
+ if (mod) {
1838
+ mod.importers.forEach((i) => {
1839
+ if (i.id)
1840
+ this.handleFileChanged(i.id);
1841
+ });
1842
+ }
1849
1843
  }
1850
1844
  async close() {
1851
1845
  var _a;
@@ -1859,14 +1853,11 @@ class Vitest {
1859
1853
  }));
1860
1854
  }
1861
1855
  }
1862
- async function createVitest(options, viteOverrides) {
1863
- const server = await startServer(options, viteOverrides);
1864
- const instance = new Vitest(options, server);
1865
- return instance;
1866
- }
1867
- async function startServer(options, viteOverrides = {}) {
1856
+ async function createVitest(options, viteOverrides = {}) {
1857
+ const ctx = new Vitest();
1868
1858
  const root = resolve(options.root || process.cwd());
1869
1859
  const configPath = options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
1860
+ let haveStarted = false;
1870
1861
  const config = {
1871
1862
  root,
1872
1863
  logLevel: "error",
@@ -1876,6 +1867,10 @@ async function startServer(options, viteOverrides = {}) {
1876
1867
  {
1877
1868
  name: "vitest",
1878
1869
  async configureServer(server2) {
1870
+ if (haveStarted)
1871
+ await ctx.report("onServerRestart");
1872
+ ctx.setServer(options, server2);
1873
+ haveStarted = true;
1879
1874
  if (options.api)
1880
1875
  server2.middlewares.use((await import('./middleware-650c5fa0.js')).default());
1881
1876
  }
@@ -1895,7 +1890,7 @@ async function startServer(options, viteOverrides = {}) {
1895
1890
  await server.pluginContainer.buildStart({});
1896
1891
  if (typeof options.api === "number")
1897
1892
  await server.listen(options.api);
1898
- return server;
1893
+ return ctx;
1899
1894
  }
1900
1895
 
1901
1896
  export { createVitest as c };
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
- import { spyOn, spy } from 'tinyspy';
6
5
  export { spy, spyOn } from 'tinyspy';
7
6
 
8
7
  declare const EXPECTED_COLOR: Formatter;
@@ -220,6 +219,7 @@ interface Reporter {
220
219
  onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
221
220
  onWatcherStart?: () => Awaitable<void>;
222
221
  onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
222
+ onServerRestart?: () => Awaitable<void>;
223
223
  onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
224
224
  }
225
225
 
@@ -540,9 +540,54 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
540
540
  declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
541
541
  declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
542
542
 
543
+ interface MockResultReturn<T> {
544
+ type: 'return';
545
+ value: T;
546
+ }
547
+ interface MockResultIncomplete {
548
+ type: 'incomplete';
549
+ value: undefined;
550
+ }
551
+ interface MockResultThrow {
552
+ type: 'throw';
553
+ value: any;
554
+ }
555
+ declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
556
+ interface JestMockCompatContext<T, Y> {
557
+ calls: Y[];
558
+ instances: T[];
559
+ invocationCallOrder: number[];
560
+ results: MockResult<T>[];
561
+ }
562
+ interface JestMockCompat<TArgs extends any[] = any[], TReturns = any> {
563
+ getMockName(): string;
564
+ mockName(n: string): this;
565
+ mock: JestMockCompatContext<TArgs, TReturns>;
566
+ mockClear(): this;
567
+ mockReset(): this;
568
+ mockRestore(): void;
569
+ getMockImplementation(): ((...args: TArgs) => TReturns) | undefined;
570
+ mockImplementation(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
571
+ mockImplementationOnce(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
572
+ mockReturnThis(): this;
573
+ mockReturnValue(obj: TReturns): this;
574
+ mockReturnValueOnce(obj: TReturns): this;
575
+ mockResolvedValue(obj: Unpromisify<TReturns>): this;
576
+ mockResolvedValueOnce(obj: Unpromisify<TReturns>): this;
577
+ mockRejectedValue(obj: any): this;
578
+ mockRejectedValueOnce(obj: any): this;
579
+ }
580
+ interface JestMockCompatFn<TArgs extends any[] = any, TReturns = any> extends JestMockCompat<TArgs, TReturns> {
581
+ (...args: TArgs): TReturns;
582
+ }
583
+ declare function spyOn<T, K extends keyof T>(obj: T, method: K, accessType?: 'get' | 'set'): T[K] extends (...args: infer TArgs) => infer TReturnValue ? JestMockCompat<TArgs, TReturnValue> : JestMockCompat;
584
+ declare type Unpromisify<T> = T extends Promise<infer R> ? R : never;
585
+ declare function fn<TArgs extends any[] = any[], R = any>(): JestMockCompatFn<TArgs, R>;
586
+ declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): JestMockCompatFn<TArgs, R>;
587
+
543
588
  declare const vitest: {
544
589
  spyOn: typeof spyOn;
545
- fn: typeof spy;
590
+ fn: typeof fn;
546
591
  };
547
592
 
548
593
  declare module 'vite' {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { d as describe, i as it, s as suite, t as test } from './suite-0e21bf9b.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-906ac3f9.js';
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, v as vitest } from './index-722fb5a5.js';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
4
  export { spy, spyOn } from 'tinyspy';
5
5
  import './index-9e71c815.js';
package/dist/node.js CHANGED
@@ -1,14 +1,15 @@
1
- export { c as createVitest } from './index-af5d5277.js';
1
+ export { c as createVitest } from './index-733e7378.js';
2
2
  import 'path';
3
3
  import 'vite';
4
4
  import 'process';
5
5
  import 'fs';
6
6
  import './constants-adef7ffb.js';
7
7
  import 'url';
8
- import './utils-9dcc4050.js';
9
- import 'perf_hooks';
10
- import './error-c5d734a1.js';
8
+ import './utils-385e2d09.js';
9
+ import 'module';
11
10
  import 'tty';
11
+ import 'perf_hooks';
12
+ import './error-309196c9.js';
12
13
  import 'source-map';
13
14
  import 'assert';
14
15
  import 'events';
@@ -16,4 +17,3 @@ import 'worker_threads';
16
17
  import 'piscina';
17
18
  import 'fast-glob';
18
19
  import 'micromatch';
19
- import 'readline';
@@ -48,8 +48,8 @@ function normalizeTest(fn, timeout) {
48
48
  return withTimeout(ensureAsyncTest(fn), timeout);
49
49
  }
50
50
 
51
- const fnMap = new WeakMap();
52
- const hooksMap = new WeakMap();
51
+ const fnMap = /* @__PURE__ */ new WeakMap();
52
+ const hooksMap = /* @__PURE__ */ new WeakMap();
53
53
  function setFn(key, fn) {
54
54
  fnMap.set(key, fn);
55
55
  }
@@ -0,0 +1,143 @@
1
+ import { createRequire } from 'module';
2
+ import require$$0 from 'tty';
3
+
4
+ var picocolors = {exports: {}};
5
+
6
+ let tty = require$$0;
7
+
8
+ let isColorSupported =
9
+ !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
10
+ ("FORCE_COLOR" in process.env ||
11
+ process.argv.includes("--color") ||
12
+ process.platform === "win32" ||
13
+ (tty.isatty(1) && process.env.TERM !== "dumb") ||
14
+ "CI" in process.env);
15
+
16
+ let formatter =
17
+ (open, close, replace = open) =>
18
+ input => {
19
+ let string = "" + input;
20
+ let index = string.indexOf(close, open.length);
21
+ return ~index
22
+ ? open + replaceClose(string, close, replace, index) + close
23
+ : open + string + close
24
+ };
25
+
26
+ let replaceClose = (string, close, replace, index) => {
27
+ let start = string.substring(0, index) + replace;
28
+ let end = string.substring(index + close.length);
29
+ let nextIndex = end.indexOf(close);
30
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
31
+ };
32
+
33
+ let createColors = (enabled = isColorSupported) => ({
34
+ isColorSupported: enabled,
35
+ reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
36
+ bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
37
+ dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
38
+ italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
39
+ underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
40
+ inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
41
+ hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
42
+ strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
43
+ black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
44
+ red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
45
+ green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
46
+ yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
47
+ blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
48
+ magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
49
+ cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
50
+ white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
51
+ gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
52
+ bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
53
+ bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
54
+ bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
55
+ bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
56
+ bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
57
+ bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
58
+ bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
59
+ bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
60
+ });
61
+
62
+ picocolors.exports = createColors();
63
+ picocolors.exports.createColors = createColors;
64
+
65
+ var c = picocolors.exports;
66
+
67
+ function toArray(array) {
68
+ array = array || [];
69
+ if (Array.isArray(array))
70
+ return array;
71
+ return [array];
72
+ }
73
+ function notNullish(v) {
74
+ return v != null;
75
+ }
76
+ function slash(str) {
77
+ return str.replace(/\\/g, "/");
78
+ }
79
+ function partitionSuiteChildren(suite) {
80
+ let tasksGroup = [];
81
+ const tasksGroups = [];
82
+ for (const c2 of suite.tasks) {
83
+ if (tasksGroup.length === 0 || c2.computeMode === tasksGroup[0].computeMode) {
84
+ tasksGroup.push(c2);
85
+ } else {
86
+ tasksGroups.push(tasksGroup);
87
+ tasksGroup = [c2];
88
+ }
89
+ }
90
+ if (tasksGroup.length > 0)
91
+ tasksGroups.push(tasksGroup);
92
+ return tasksGroups;
93
+ }
94
+ function interpretOnlyMode(items) {
95
+ if (items.some((i) => i.mode === "only")) {
96
+ items.forEach((i) => {
97
+ if (i.mode === "run")
98
+ i.mode = "skip";
99
+ else if (i.mode === "only")
100
+ i.mode = "run";
101
+ });
102
+ }
103
+ }
104
+ function getTests(suite) {
105
+ return toArray(suite).flatMap((s) => s.tasks.flatMap((c2) => c2.type === "test" ? [c2] : getTests(c2)));
106
+ }
107
+ function getTasks(tasks) {
108
+ return toArray(tasks).flatMap((s) => s.type === "test" ? [s] : [s, ...getTasks(s.tasks)]);
109
+ }
110
+ function getSuites(suite) {
111
+ return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
112
+ }
113
+ function hasTests(suite) {
114
+ return toArray(suite).some((s) => s.tasks.some((c2) => c2.type === "test" || hasTests(c2)));
115
+ }
116
+ function hasFailed(suite) {
117
+ return toArray(suite).some((s) => {
118
+ var _a;
119
+ return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
120
+ });
121
+ }
122
+ function getNames(task) {
123
+ const names = [task.name];
124
+ let current = task;
125
+ while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
126
+ current = current.suite || current.file;
127
+ if (current == null ? void 0 : current.name)
128
+ names.unshift(current.name);
129
+ }
130
+ return names;
131
+ }
132
+ function checkPeerDependency(dependency) {
133
+ const require = createRequire(import.meta.url);
134
+ try {
135
+ require.resolve(dependency);
136
+ } catch {
137
+ console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Cound not find '${dependency}' peer dependency, please try installing it
138
+ `));
139
+ process.exit(1);
140
+ }
141
+ }
142
+
143
+ export { getTests as a, getSuites as b, c, hasTests as d, getTasks as e, checkPeerDependency as f, getNames as g, hasFailed as h, interpretOnlyMode as i, notNullish as n, partitionSuiteChildren as p, slash as s, toArray as t };
package/dist/utils.js ADDED
@@ -0,0 +1,3 @@
1
+ import 'module';
2
+ export { f as checkPeerDependency, g as getNames, b as getSuites, e as getTasks, a as getTests, h as hasFailed, d as hasTests, i as interpretOnlyMode, n as notNullish, p as partitionSuiteChildren, s as slash, t as toArray } from './utils-385e2d09.js';
3
+ import 'tty';
package/dist/worker.js CHANGED
@@ -4,11 +4,12 @@ import { c as distDir } from './constants-adef7ffb.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath, URL as URL$1 } from 'url';
6
6
  import vm from 'vm';
7
- import { s as slash } from './utils-9dcc4050.js';
7
+ import { s as slash } from './utils-385e2d09.js';
8
8
  import fs, { realpathSync, statSync, Stats, promises } from 'fs';
9
9
  import assert from 'assert';
10
10
  import { format as format$3, inspect } from 'util';
11
11
  import { s as send } from './rpc-7de86f29.js';
12
+ import 'tty';
12
13
 
13
14
  function normalizeWindowsPath$2(input = "") {
14
15
  if (!input.includes("\\")) {
@@ -8192,7 +8193,7 @@ function getProtocol(id) {
8192
8193
  return proto ? proto.groups.proto : null;
8193
8194
  }
8194
8195
  const ESM_RE = /([\s;]|^)(import[\w,{}\s*]*from|import\s*['"*{]|export\b\s*(?:[*{]|default|type|function|const|var|let|async function)|import\.meta\b)/m;
8195
- const BUILTIN_EXTENSIONS = new Set([".mjs", ".cjs", ".node", ".wasm"]);
8196
+ const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
8196
8197
  function hasESMSyntax(code) {
8197
8198
  return ESM_RE.test(code);
8198
8199
  }
@@ -8270,7 +8271,7 @@ async function interpretedImport(path, interpretDefault) {
8270
8271
  }
8271
8272
  async function executeInViteNode(options) {
8272
8273
  const { moduleCache, root, files, fetch } = options;
8273
- const externalCache = new Map();
8274
+ const externalCache = /* @__PURE__ */ new Map();
8274
8275
  builtinModules.forEach((m) => externalCache.set(m, true));
8275
8276
  const result = [];
8276
8277
  for (const file of files)
@@ -8417,7 +8418,7 @@ function patchWindowsImportPath(path) {
8417
8418
  }
8418
8419
 
8419
8420
  let _viteNode;
8420
- const moduleCache = new Map();
8421
+ const moduleCache = /* @__PURE__ */ new Map();
8421
8422
  async function startViteNode(ctx) {
8422
8423
  if (_viteNode)
8423
8424
  return _viteNode;
@@ -8449,7 +8450,7 @@ async function startViteNode(ctx) {
8449
8450
  function init(ctx) {
8450
8451
  process.stdout.write("\0");
8451
8452
  const { config, port } = ctx;
8452
- const rpcPromiseMap = new Map();
8453
+ const rpcPromiseMap = /* @__PURE__ */ new Map();
8453
8454
  process.__vitest_worker__ = {
8454
8455
  moduleCache,
8455
8456
  config,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.88",
3
+ "version": "0.0.89",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -56,14 +56,14 @@
56
56
  "micromatch": "^4.0.4",
57
57
  "piscina": "^3.2.0",
58
58
  "source-map": "^0.7.3",
59
- "tinyspy": "^0.0.13"
59
+ "tinyspy": "^0.1.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/diff": "^5.0.1",
63
63
  "@types/jsdom": "^16.2.13",
64
64
  "@types/micromatch": "^4.0.2",
65
65
  "@types/natural-compare": "^1.4.1",
66
- "@types/node": "^16.11.12",
66
+ "@types/node": "^16.11.13",
67
67
  "c8": "^7.10.0",
68
68
  "cac": "^6.7.12",
69
69
  "cli-truncate": "^3.1.0",
@@ -1,34 +0,0 @@
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-0e21bf9b.js';
2
- import chai, { assert, should, expect } from 'chai';
3
- import { spyOn, spy } from 'tinyspy';
4
-
5
- const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
6
- const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
7
- const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
8
- const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
9
-
10
- const vitest = {
11
- spyOn,
12
- fn: spy
13
- };
14
-
15
- var index = /*#__PURE__*/Object.freeze({
16
- __proto__: null,
17
- suite: suite,
18
- test: test,
19
- describe: describe,
20
- it: it,
21
- beforeAll: beforeAll,
22
- afterAll: afterAll,
23
- beforeEach: beforeEach,
24
- afterEach: afterEach,
25
- assert: assert,
26
- should: should,
27
- expect: expect,
28
- chai: chai,
29
- spy: spy,
30
- spyOn: spyOn,
31
- vitest: vitest
32
- });
33
-
34
- export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, index as i, vitest as v };
@@ -1,64 +0,0 @@
1
- function toArray(array) {
2
- array = array || [];
3
- if (Array.isArray(array))
4
- return array;
5
- return [array];
6
- }
7
- function notNullish(v) {
8
- return v != null;
9
- }
10
- function slash(str) {
11
- return str.replace(/\\/g, "/");
12
- }
13
- function partitionSuiteChildren(suite) {
14
- let tasksGroup = [];
15
- const tasksGroups = [];
16
- for (const c of suite.tasks) {
17
- if (tasksGroup.length === 0 || c.computeMode === tasksGroup[0].computeMode) {
18
- tasksGroup.push(c);
19
- } else {
20
- tasksGroups.push(tasksGroup);
21
- tasksGroup = [c];
22
- }
23
- }
24
- if (tasksGroup.length > 0)
25
- tasksGroups.push(tasksGroup);
26
- return tasksGroups;
27
- }
28
- function interpretOnlyMode(items) {
29
- if (items.some((i) => i.mode === "only")) {
30
- items.forEach((i) => {
31
- if (i.mode === "run")
32
- i.mode = "skip";
33
- else if (i.mode === "only")
34
- i.mode = "run";
35
- });
36
- }
37
- }
38
- function getTests(suite) {
39
- return toArray(suite).flatMap((s) => s.tasks.flatMap((c) => c.type === "test" ? [c] : getTests(c)));
40
- }
41
- function getSuites(suite) {
42
- return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
43
- }
44
- function hasTests(suite) {
45
- return toArray(suite).some((s) => s.tasks.some((c) => c.type === "test" || hasTests(c)));
46
- }
47
- function hasFailed(suite) {
48
- return toArray(suite).some((s) => {
49
- var _a;
50
- return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
51
- });
52
- }
53
- function getNames(task) {
54
- const names = [task.name];
55
- let current = task;
56
- while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
57
- current = current.suite || current.file;
58
- if (current == null ? void 0 : current.name)
59
- names.unshift(current.name);
60
- }
61
- return names;
62
- }
63
-
64
- export { getTests as a, getSuites as b, hasTests as c, getNames as g, hasFailed as h, interpretOnlyMode as i, notNullish as n, partitionSuiteChildren as p, slash as s, toArray as t };