vitest 0.18.0 → 0.19.1

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.
Files changed (36) hide show
  1. package/LICENSE.md +6 -6
  2. package/dist/browser.d.ts +1850 -0
  3. package/dist/browser.mjs +20 -0
  4. package/dist/{chunk-api-setup.63babd7c.mjs → chunk-api-setup.0cf2c96a.mjs} +37 -11
  5. package/dist/{chunk-constants.8eb2ed35.mjs → chunk-constants.38b43a44.mjs} +3 -3
  6. package/dist/{chunk-env-node.26c72624.mjs → chunk-defaults.ed196a9a.mjs} +458 -455
  7. package/dist/{chunk-install-pkg.2dcb2c04.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
  8. package/dist/chunk-integrations-globals.1018e651.mjs +24 -0
  9. package/dist/chunk-node-git.9058b82a.mjs +1139 -0
  10. package/dist/chunk-runtime-chain.f2e00f4c.mjs +2039 -0
  11. package/dist/{vendor-entry.78de67ab.mjs → chunk-runtime-error.606e0393.mjs} +167 -183
  12. package/dist/{chunk-runtime-chain.eb764dff.mjs → chunk-runtime-hooks.d4cadf47.mjs} +33 -2012
  13. package/dist/{chunk-runtime-mocker.79ccc3de.mjs → chunk-runtime-mocker.dfdfd57b.mjs} +70 -22
  14. package/dist/{chunk-runtime-rpc.cc6a06a2.mjs → chunk-runtime-rpc.45d8ee19.mjs} +1 -1
  15. package/dist/{chunk-utils-global.1b22c4fd.mjs → chunk-utils-global.2aa95025.mjs} +11 -6
  16. package/dist/{chunk-utils-source-map.957e7756.mjs → chunk-utils-source-map.8b066ce2.mjs} +2 -2
  17. package/dist/{chunk-vite-node-externalize.0791f2ed.mjs → chunk-vite-node-externalize.e9af6472.mjs} +105 -1174
  18. package/dist/chunk-vite-node-utils.ad73f2ab.mjs +1433 -0
  19. package/dist/cli.mjs +9 -11
  20. package/dist/config.cjs +4 -1
  21. package/dist/config.d.ts +1 -0
  22. package/dist/config.mjs +4 -1
  23. package/dist/entry.mjs +54 -10
  24. package/dist/index.d.ts +56 -27
  25. package/dist/index.mjs +12 -9
  26. package/dist/node.d.ts +37 -18
  27. package/dist/node.mjs +10 -12
  28. package/dist/spy.mjs +102 -2
  29. package/dist/suite.mjs +13 -0
  30. package/dist/vendor-index.61438b77.mjs +335 -0
  31. package/dist/{vendor-index.4bf9c627.mjs → vendor-index.62ce5c33.mjs} +11 -343
  32. package/dist/worker.mjs +6 -6
  33. package/package.json +20 -12
  34. package/dist/chunk-integrations-globals.61e4d6ae.mjs +0 -26
  35. package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
  36. package/dist/chunk-vite-node-utils.af8ead96.mjs +0 -9195
package/dist/spy.mjs CHANGED
@@ -1,2 +1,102 @@
1
- export { f as fn, i as isMockFunction, a as spies, s as spyOn } from './chunk-integrations-spy.674b628e.mjs';
2
- import 'tinyspy';
1
+ import * as tinyspy from 'tinyspy';
2
+
3
+ const spies = /* @__PURE__ */ new Set();
4
+ function isMockFunction(fn2) {
5
+ return typeof fn2 === "function" && "_isMockFunction" in fn2 && fn2._isMockFunction;
6
+ }
7
+ function spyOn(obj, method, accessType) {
8
+ const dictionary = {
9
+ get: "getter",
10
+ set: "setter"
11
+ };
12
+ const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
13
+ const stub = tinyspy.spyOn(obj, objMethod);
14
+ return enhanceSpy(stub);
15
+ }
16
+ let callOrder = 0;
17
+ function enhanceSpy(spy) {
18
+ const stub = spy;
19
+ let implementation;
20
+ let instances = [];
21
+ let invocations = [];
22
+ const mockContext = {
23
+ get calls() {
24
+ return stub.calls;
25
+ },
26
+ get instances() {
27
+ return instances;
28
+ },
29
+ get invocationCallOrder() {
30
+ return invocations;
31
+ },
32
+ get results() {
33
+ return stub.results.map(([callType, value]) => {
34
+ const type = callType === "error" ? "throw" : "return";
35
+ return { type, value };
36
+ });
37
+ },
38
+ get lastCall() {
39
+ return stub.calls[stub.calls.length - 1];
40
+ }
41
+ };
42
+ let onceImplementations = [];
43
+ let name = stub.name;
44
+ stub.getMockName = () => name || "vi.fn()";
45
+ stub.mockName = (n) => {
46
+ name = n;
47
+ return stub;
48
+ };
49
+ stub.mockClear = () => {
50
+ stub.reset();
51
+ instances = [];
52
+ invocations = [];
53
+ return stub;
54
+ };
55
+ stub.mockReset = () => {
56
+ stub.mockClear();
57
+ implementation = () => void 0;
58
+ onceImplementations = [];
59
+ return stub;
60
+ };
61
+ stub.mockRestore = () => {
62
+ stub.mockReset();
63
+ implementation = void 0;
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.mockImplementationOnce(() => Promise.reject(val));
84
+ Object.defineProperty(stub, "mock", {
85
+ get: () => mockContext
86
+ });
87
+ stub.willCall(function(...args) {
88
+ instances.push(this);
89
+ invocations.push(++callOrder);
90
+ const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
91
+ });
92
+ return impl.apply(this, args);
93
+ });
94
+ spies.add(stub);
95
+ return stub;
96
+ }
97
+ function fn(implementation) {
98
+ return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
99
+ }) }, "fn"));
100
+ }
101
+
102
+ export { fn, isMockFunction, spies, spyOn };
package/dist/suite.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import 'util';
2
+ import './chunk-utils-global.2aa95025.mjs';
3
+ export { e as clearCollectorContext, o as createSuiteHooks, f as defaultSuite, d as describe, g as getCurrentSuite, i as it, s as suite, t as test } from './chunk-runtime-chain.f2e00f4c.mjs';
4
+ import 'path';
5
+ import 'tty';
6
+ import 'local-pkg';
7
+ import 'chai';
8
+ import './vendor-_commonjsHelpers.4da45ef5.mjs';
9
+ import './chunk-runtime-rpc.45d8ee19.mjs';
10
+ import 'fs';
11
+ import './chunk-utils-source-map.8b066ce2.mjs';
12
+ import './spy.mjs';
13
+ import 'tinyspy';
@@ -0,0 +1,335 @@
1
+ import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
2
+ import assert$1 from 'assert';
3
+ import require$$2 from 'events';
4
+
5
+ var onetime$1 = {exports: {}};
6
+
7
+ var mimicFn$2 = {exports: {}};
8
+
9
+ const mimicFn$1 = (to, from) => {
10
+ for (const prop of Reflect.ownKeys(from)) {
11
+ Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
12
+ }
13
+
14
+ return to;
15
+ };
16
+
17
+ mimicFn$2.exports = mimicFn$1;
18
+ // TODO: Remove this for the next major release
19
+ mimicFn$2.exports.default = mimicFn$1;
20
+
21
+ const mimicFn = mimicFn$2.exports;
22
+
23
+ const calledFunctions = new WeakMap();
24
+
25
+ const onetime = (function_, options = {}) => {
26
+ if (typeof function_ !== 'function') {
27
+ throw new TypeError('Expected a function');
28
+ }
29
+
30
+ let returnValue;
31
+ let callCount = 0;
32
+ const functionName = function_.displayName || function_.name || '<anonymous>';
33
+
34
+ const onetime = function (...arguments_) {
35
+ calledFunctions.set(onetime, ++callCount);
36
+
37
+ if (callCount === 1) {
38
+ returnValue = function_.apply(this, arguments_);
39
+ function_ = null;
40
+ } else if (options.throw === true) {
41
+ throw new Error(`Function \`${functionName}\` can only be called once`);
42
+ }
43
+
44
+ return returnValue;
45
+ };
46
+
47
+ mimicFn(onetime, function_);
48
+ calledFunctions.set(onetime, callCount);
49
+
50
+ return onetime;
51
+ };
52
+
53
+ onetime$1.exports = onetime;
54
+ // TODO: Remove this for the next major release
55
+ onetime$1.exports.default = onetime;
56
+
57
+ onetime$1.exports.callCount = function_ => {
58
+ if (!calledFunctions.has(function_)) {
59
+ throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
60
+ }
61
+
62
+ return calledFunctions.get(function_);
63
+ };
64
+
65
+ var signalExit = {exports: {}};
66
+
67
+ var signals$1 = {exports: {}};
68
+
69
+ var hasRequiredSignals;
70
+
71
+ function requireSignals () {
72
+ if (hasRequiredSignals) return signals$1.exports;
73
+ hasRequiredSignals = 1;
74
+ (function (module) {
75
+ // This is not the set of all possible signals.
76
+ //
77
+ // It IS, however, the set of all signals that trigger
78
+ // an exit on either Linux or BSD systems. Linux is a
79
+ // superset of the signal names supported on BSD, and
80
+ // the unknown signals just fail to register, so we can
81
+ // catch that easily enough.
82
+ //
83
+ // Don't bother with SIGKILL. It's uncatchable, which
84
+ // means that we can't fire any callbacks anyway.
85
+ //
86
+ // If a user does happen to register a handler on a non-
87
+ // fatal signal like SIGWINCH or something, and then
88
+ // exit, it'll end up firing `process.emit('exit')`, so
89
+ // the handler will be fired anyway.
90
+ //
91
+ // SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
92
+ // artificially, inherently leave the process in a
93
+ // state from which it is not safe to try and enter JS
94
+ // listeners.
95
+ module.exports = [
96
+ 'SIGABRT',
97
+ 'SIGALRM',
98
+ 'SIGHUP',
99
+ 'SIGINT',
100
+ 'SIGTERM'
101
+ ];
102
+
103
+ if (process.platform !== 'win32') {
104
+ module.exports.push(
105
+ 'SIGVTALRM',
106
+ 'SIGXCPU',
107
+ 'SIGXFSZ',
108
+ 'SIGUSR2',
109
+ 'SIGTRAP',
110
+ 'SIGSYS',
111
+ 'SIGQUIT',
112
+ 'SIGIOT'
113
+ // should detect profiler and enable/disable accordingly.
114
+ // see #21
115
+ // 'SIGPROF'
116
+ );
117
+ }
118
+
119
+ if (process.platform === 'linux') {
120
+ module.exports.push(
121
+ 'SIGIO',
122
+ 'SIGPOLL',
123
+ 'SIGPWR',
124
+ 'SIGSTKFLT',
125
+ 'SIGUNUSED'
126
+ );
127
+ }
128
+ } (signals$1));
129
+ return signals$1.exports;
130
+ }
131
+
132
+ // Note: since nyc uses this module to output coverage, any lines
133
+ // that are in the direct sync flow of nyc's outputCoverage are
134
+ // ignored, since we can never get coverage for them.
135
+ // grab a reference to node's real process object right away
136
+ var process$1 = commonjsGlobal.process;
137
+
138
+ const processOk = function (process) {
139
+ return process &&
140
+ typeof process === 'object' &&
141
+ typeof process.removeListener === 'function' &&
142
+ typeof process.emit === 'function' &&
143
+ typeof process.reallyExit === 'function' &&
144
+ typeof process.listeners === 'function' &&
145
+ typeof process.kill === 'function' &&
146
+ typeof process.pid === 'number' &&
147
+ typeof process.on === 'function'
148
+ };
149
+
150
+ // some kind of non-node environment, just no-op
151
+ /* istanbul ignore if */
152
+ if (!processOk(process$1)) {
153
+ signalExit.exports = function () {
154
+ return function () {}
155
+ };
156
+ } else {
157
+ var assert = assert$1;
158
+ var signals = requireSignals();
159
+ var isWin = /^win/i.test(process$1.platform);
160
+
161
+ var EE = require$$2;
162
+ /* istanbul ignore if */
163
+ if (typeof EE !== 'function') {
164
+ EE = EE.EventEmitter;
165
+ }
166
+
167
+ var emitter;
168
+ if (process$1.__signal_exit_emitter__) {
169
+ emitter = process$1.__signal_exit_emitter__;
170
+ } else {
171
+ emitter = process$1.__signal_exit_emitter__ = new EE();
172
+ emitter.count = 0;
173
+ emitter.emitted = {};
174
+ }
175
+
176
+ // Because this emitter is a global, we have to check to see if a
177
+ // previous version of this library failed to enable infinite listeners.
178
+ // I know what you're about to say. But literally everything about
179
+ // signal-exit is a compromise with evil. Get used to it.
180
+ if (!emitter.infinite) {
181
+ emitter.setMaxListeners(Infinity);
182
+ emitter.infinite = true;
183
+ }
184
+
185
+ signalExit.exports = function (cb, opts) {
186
+ /* istanbul ignore if */
187
+ if (!processOk(commonjsGlobal.process)) {
188
+ return function () {}
189
+ }
190
+ assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
191
+
192
+ if (loaded === false) {
193
+ load();
194
+ }
195
+
196
+ var ev = 'exit';
197
+ if (opts && opts.alwaysLast) {
198
+ ev = 'afterexit';
199
+ }
200
+
201
+ var remove = function () {
202
+ emitter.removeListener(ev, cb);
203
+ if (emitter.listeners('exit').length === 0 &&
204
+ emitter.listeners('afterexit').length === 0) {
205
+ unload();
206
+ }
207
+ };
208
+ emitter.on(ev, cb);
209
+
210
+ return remove
211
+ };
212
+
213
+ var unload = function unload () {
214
+ if (!loaded || !processOk(commonjsGlobal.process)) {
215
+ return
216
+ }
217
+ loaded = false;
218
+
219
+ signals.forEach(function (sig) {
220
+ try {
221
+ process$1.removeListener(sig, sigListeners[sig]);
222
+ } catch (er) {}
223
+ });
224
+ process$1.emit = originalProcessEmit;
225
+ process$1.reallyExit = originalProcessReallyExit;
226
+ emitter.count -= 1;
227
+ };
228
+ signalExit.exports.unload = unload;
229
+
230
+ var emit = function emit (event, code, signal) {
231
+ /* istanbul ignore if */
232
+ if (emitter.emitted[event]) {
233
+ return
234
+ }
235
+ emitter.emitted[event] = true;
236
+ emitter.emit(event, code, signal);
237
+ };
238
+
239
+ // { <signal>: <listener fn>, ... }
240
+ var sigListeners = {};
241
+ signals.forEach(function (sig) {
242
+ sigListeners[sig] = function listener () {
243
+ /* istanbul ignore if */
244
+ if (!processOk(commonjsGlobal.process)) {
245
+ return
246
+ }
247
+ // If there are no other listeners, an exit is coming!
248
+ // Simplest way: remove us and then re-send the signal.
249
+ // We know that this will kill the process, so we can
250
+ // safely emit now.
251
+ var listeners = process$1.listeners(sig);
252
+ if (listeners.length === emitter.count) {
253
+ unload();
254
+ emit('exit', null, sig);
255
+ /* istanbul ignore next */
256
+ emit('afterexit', null, sig);
257
+ /* istanbul ignore next */
258
+ if (isWin && sig === 'SIGHUP') {
259
+ // "SIGHUP" throws an `ENOSYS` error on Windows,
260
+ // so use a supported signal instead
261
+ sig = 'SIGINT';
262
+ }
263
+ /* istanbul ignore next */
264
+ process$1.kill(process$1.pid, sig);
265
+ }
266
+ };
267
+ });
268
+
269
+ signalExit.exports.signals = function () {
270
+ return signals
271
+ };
272
+
273
+ var loaded = false;
274
+
275
+ var load = function load () {
276
+ if (loaded || !processOk(commonjsGlobal.process)) {
277
+ return
278
+ }
279
+ loaded = true;
280
+
281
+ // This is the number of onSignalExit's that are in play.
282
+ // It's important so that we can count the correct number of
283
+ // listeners on signals, and don't wait for the other one to
284
+ // handle it instead of us.
285
+ emitter.count += 1;
286
+
287
+ signals = signals.filter(function (sig) {
288
+ try {
289
+ process$1.on(sig, sigListeners[sig]);
290
+ return true
291
+ } catch (er) {
292
+ return false
293
+ }
294
+ });
295
+
296
+ process$1.emit = processEmit;
297
+ process$1.reallyExit = processReallyExit;
298
+ };
299
+ signalExit.exports.load = load;
300
+
301
+ var originalProcessReallyExit = process$1.reallyExit;
302
+ var processReallyExit = function processReallyExit (code) {
303
+ /* istanbul ignore if */
304
+ if (!processOk(commonjsGlobal.process)) {
305
+ return
306
+ }
307
+ process$1.exitCode = code || /* istanbul ignore next */ 0;
308
+ emit('exit', process$1.exitCode, null);
309
+ /* istanbul ignore next */
310
+ emit('afterexit', process$1.exitCode, null);
311
+ /* istanbul ignore next */
312
+ originalProcessReallyExit.call(process$1, process$1.exitCode);
313
+ };
314
+
315
+ var originalProcessEmit = process$1.emit;
316
+ var processEmit = function processEmit (ev, arg) {
317
+ if (ev === 'exit' && processOk(commonjsGlobal.process)) {
318
+ /* istanbul ignore else */
319
+ if (arg !== undefined) {
320
+ process$1.exitCode = arg;
321
+ }
322
+ var ret = originalProcessEmit.apply(this, arguments);
323
+ /* istanbul ignore next */
324
+ emit('exit', process$1.exitCode, null);
325
+ /* istanbul ignore next */
326
+ emit('afterexit', process$1.exitCode, null);
327
+ /* istanbul ignore next */
328
+ return ret
329
+ } else {
330
+ return originalProcessEmit.apply(this, arguments)
331
+ }
332
+ };
333
+ }
334
+
335
+ export { onetime$1 as o, signalExit as s };