vitest 0.0.90 → 0.0.91

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,17 +1,17 @@
1
1
  import readline from 'readline';
2
2
  import { EventEmitter } from 'events';
3
- import { c } from './utils-385e2d09.js';
4
- import { c as createVitest } from './index-733e7378.js';
3
+ import { c } from './utils-5d0cec8a.js';
4
+ import { c as createVitest } from './index-25bef3dd.js';
5
5
  import 'module';
6
6
  import 'tty';
7
7
  import 'path';
8
8
  import 'vite';
9
9
  import 'process';
10
10
  import 'fs';
11
- import './constants-adef7ffb.js';
11
+ import './constants-9cfa4d7b.js';
12
12
  import 'url';
13
13
  import 'perf_hooks';
14
- import './error-309196c9.js';
14
+ import './error-abd1f726.js';
15
15
  import 'source-map';
16
16
  import 'assert';
17
17
  import 'worker_threads';
@@ -632,7 +632,7 @@ class CAC extends EventEmitter {
632
632
 
633
633
  const cac = (name = "") => new CAC(name);
634
634
 
635
- var version = "0.0.90";
635
+ var version = "0.0.91";
636
636
 
637
637
  const cli = cac("vitest");
638
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", {
@@ -22,9 +22,8 @@ const globalApis = [
22
22
  "chai",
23
23
  "expect",
24
24
  "assert",
25
- "spy",
26
- "spyOn",
27
25
  "vitest",
26
+ "vi",
28
27
  "beforeAll",
29
28
  "afterAll",
30
29
  "beforeEach",
package/dist/entry.js CHANGED
@@ -5,9 +5,9 @@ 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, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, d as hasTests, h as hasFailed } from './utils-385e2d09.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-5d0cec8a.js';
9
9
  import fs from 'fs';
10
- import { u as unifiedDiff } from './error-309196c9.js';
10
+ import { u as unifiedDiff } from './error-abd1f726.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';
@@ -3628,8 +3628,22 @@ class StringContaining extends AsymmetricMatcher {
3628
3628
  return "string";
3629
3629
  }
3630
3630
  }
3631
+ class Anything extends AsymmetricMatcher {
3632
+ asymmetricMatch(other) {
3633
+ return other !== void 0 && other !== null;
3634
+ }
3635
+ toString() {
3636
+ return "Anything";
3637
+ }
3638
+ toAsymmetricMatcher() {
3639
+ return "Anything";
3640
+ }
3641
+ }
3631
3642
  const JestAsymmetricMatchers = (chai, utils) => {
3632
3643
  utils.addMethod(chai.expect, "stringContaining", (expected) => new StringContaining(expected));
3644
+ utils.addMethod(chai.expect, "anything", () => {
3645
+ return new Anything();
3646
+ });
3633
3647
  };
3634
3648
 
3635
3649
  let installed = false;
@@ -3652,7 +3666,7 @@ async function setupGlobalEnv(config) {
3652
3666
  setupConsoleLogSpy();
3653
3667
  await setupChai();
3654
3668
  if (config.global)
3655
- (await import('./global-f3eab75a.js')).registerApiGlobally();
3669
+ (await import('./global-c40aeb86.js')).registerApiGlobally();
3656
3670
  }
3657
3671
  function setupConsoleLogSpy() {
3658
3672
  const stdout = new Writable({
@@ -3768,14 +3782,6 @@ async function collectTests(paths, config) {
3768
3782
  }
3769
3783
  const tasks = files.reduce((tasks2, file) => tasks2.concat(file.tasks), []);
3770
3784
  interpretOnlyMode(tasks);
3771
- tasks.forEach((i) => {
3772
- if (i.type === "suite") {
3773
- if (i.mode === "skip")
3774
- i.tasks.forEach((c) => c.mode === "run" && (c.mode = "skip"));
3775
- else
3776
- interpretOnlyMode(i.tasks);
3777
- }
3778
- });
3779
3785
  return files;
3780
3786
  }
3781
3787
 
@@ -1,6 +1,6 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { relative } from 'path';
3
- import { n as notNullish, c } from './utils-385e2d09.js';
3
+ import { n as notNullish, c } from './utils-5d0cec8a.js';
4
4
  import { SourceMapConsumer } from 'source-map';
5
5
 
6
6
  function Diff() {}
@@ -1,5 +1,5 @@
1
- import { g as globalApis } from './constants-adef7ffb.js';
2
- import { i as index } from './index-722fb5a5.js';
1
+ import { g as globalApis } from './constants-9cfa4d7b.js';
2
+ import { i as index } from './index-708135df.js';
3
3
  import 'path';
4
4
  import 'url';
5
5
  import './suite-b8c6cb53.js';
@@ -2,10 +2,10 @@ import path, { isAbsolute, relative, dirname, basename, resolve } from 'path';
2
2
  import { createServer, mergeConfig } from 'vite';
3
3
  import process$2 from 'process';
4
4
  import { promises } from 'fs';
5
- import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-adef7ffb.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';
5
+ import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-9cfa4d7b.js';
6
+ import { c, g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-5d0cec8a.js';
7
7
  import { performance } from 'perf_hooks';
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';
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-abd1f726.js';
9
9
  import assert$1 from 'assert';
10
10
  import require$$2 from 'events';
11
11
  import { MessageChannel } from 'worker_threads';
@@ -1872,7 +1872,7 @@ async function createVitest(options, viteOverrides = {}) {
1872
1872
  ctx.setServer(options, server2);
1873
1873
  haveStarted = true;
1874
1874
  if (options.api)
1875
- server2.middlewares.use((await import('./middleware-650c5fa0.js')).default());
1875
+ server2.middlewares.use((await import('./middleware-52c3b35a.js')).default());
1876
1876
  }
1877
1877
  }
1878
1878
  ],
@@ -0,0 +1,333 @@
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 originalSetTimeout = global.setTimeout;
99
+ const originalSetInterval = global.setInterval;
100
+ const originalClearTimeout = global.clearTimeout;
101
+ const originalClearInterval = global.clearInterval;
102
+ const MAX_LOOPS = 1e4;
103
+ const assertEvery = (assertions, message) => {
104
+ if (assertions.some((a) => !a))
105
+ throw new Error(message);
106
+ };
107
+ const assertMaxLoop = (times) => {
108
+ if (times >= MAX_LOOPS)
109
+ throw new Error("setTimeout/setInterval called 10 000 times. It's possible it stuck in an infinite loop.");
110
+ };
111
+ const getNodeTimeout = (id) => {
112
+ const timer = {
113
+ ref: () => timer,
114
+ unref: () => timer,
115
+ hasRef: () => true,
116
+ refresh: () => timer,
117
+ [Symbol.toPrimitive]: () => id
118
+ };
119
+ return timer;
120
+ };
121
+ class FakeTimers {
122
+ constructor() {
123
+ this._advancedTime = 0;
124
+ this._nestedTime = {};
125
+ this._scopeId = 0;
126
+ this._isNested = false;
127
+ this._isOnlyPending = false;
128
+ this._spyid = 0;
129
+ this._isMocked = false;
130
+ this._tasksQueue = [];
131
+ this._queueCount = 0;
132
+ }
133
+ useFakeTimers() {
134
+ this._isMocked = true;
135
+ this.reset();
136
+ const spyFactory = (spyType, resultBuilder) => {
137
+ return (cb, ms = 0) => {
138
+ const id = ++this._spyid;
139
+ const nestedMs = ms + (this._nestedTime[this._scopeId] ?? 0);
140
+ const call = { id, cb, ms, nestedMs, scopeId: this._scopeId };
141
+ const task = { type: spyType, call, nested: this._isNested };
142
+ this.pushTask(task);
143
+ return resultBuilder(id, cb);
144
+ };
145
+ };
146
+ this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory("timeout" /* Timeout */, getNodeTimeout));
147
+ this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory("interval" /* Interval */, getNodeTimeout));
148
+ const clearTimerFactory = (spyType) => (id) => {
149
+ if (id === void 0)
150
+ return;
151
+ const index = this._tasksQueue.findIndex(({ call, type }) => type === spyType && call.id === Number(id));
152
+ if (index !== -1)
153
+ this._tasksQueue.splice(index, 1);
154
+ };
155
+ this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory("timeout" /* Timeout */));
156
+ this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory("interval" /* Interval */));
157
+ }
158
+ useRealTimers() {
159
+ this._isMocked = false;
160
+ this.reset();
161
+ global.setTimeout = originalSetTimeout;
162
+ global.setInterval = originalSetInterval;
163
+ global.clearTimeout = originalClearTimeout;
164
+ global.clearInterval = originalClearInterval;
165
+ }
166
+ runOnlyPendingTimers() {
167
+ this.assertMocked();
168
+ this._isOnlyPending = true;
169
+ this.runQueue();
170
+ }
171
+ runAllTimers() {
172
+ this.assertMocked();
173
+ this.runQueue();
174
+ }
175
+ advanceTimersByTime(ms) {
176
+ this.assertMocked();
177
+ this._advancedTime += ms;
178
+ this.runQueue();
179
+ }
180
+ advanceTimersToNextTimer() {
181
+ throw new Error("advanceTimersToNextTimer is not implemented");
182
+ }
183
+ runAllTicks() {
184
+ throw new Error("runAllTicks is not implemented");
185
+ }
186
+ setSystemTime(now) {
187
+ throw new Error("setSystemTime is not implemented");
188
+ }
189
+ getRealSystemTime() {
190
+ return Date.now();
191
+ }
192
+ getTimerCount() {
193
+ this.assertMocked();
194
+ return this._tasksQueue.length;
195
+ }
196
+ reset() {
197
+ var _a, _b, _c, _d;
198
+ this._advancedTime = 0;
199
+ this._nestedTime = {};
200
+ this._isNested = false;
201
+ this._isOnlyPending = false;
202
+ this._spyid = 0;
203
+ this._queueCount = 0;
204
+ this._tasksQueue = [];
205
+ (_a = this._clearInterval) == null ? void 0 : _a.mockRestore();
206
+ (_b = this._clearTimeout) == null ? void 0 : _b.mockRestore();
207
+ (_c = this._setInterval) == null ? void 0 : _c.mockRestore();
208
+ (_d = this._setTimeout) == null ? void 0 : _d.mockRestore();
209
+ }
210
+ runQueue() {
211
+ var _a, _b;
212
+ let index = 0;
213
+ while (this._tasksQueue[index]) {
214
+ assertMaxLoop(this._queueCount);
215
+ const task = this._tasksQueue[index];
216
+ const { call, nested, type } = task;
217
+ if (this._advancedTime && call.nestedMs > this._advancedTime)
218
+ break;
219
+ if (this._isOnlyPending && nested) {
220
+ index++;
221
+ continue;
222
+ }
223
+ this._scopeId = call.id;
224
+ this._isNested = true;
225
+ (_a = this._nestedTime)[_b = call.id] ?? (_a[_b] = 0);
226
+ this._nestedTime[call.id] += call.ms;
227
+ if (type === "timeout") {
228
+ this.removeTask(index);
229
+ } else if (type === "interval") {
230
+ call.nestedMs += call.ms;
231
+ const nestedMs = call.nestedMs;
232
+ const closestTask = this._tasksQueue.findIndex(({ type: type2, call: call2 }) => type2 === "interval" && call2.nestedMs < nestedMs);
233
+ if (closestTask !== -1 && closestTask !== index)
234
+ this.ensureQueueOrder();
235
+ }
236
+ call.cb();
237
+ this._queueCount++;
238
+ }
239
+ }
240
+ removeTask(index) {
241
+ if (index === 0)
242
+ this._tasksQueue.shift();
243
+ else
244
+ this._tasksQueue.splice(index, 1);
245
+ }
246
+ pushTask(task) {
247
+ this._tasksQueue.push(task);
248
+ this.ensureQueueOrder();
249
+ }
250
+ ensureQueueOrder() {
251
+ this._tasksQueue.sort((t1, t2) => {
252
+ const diff = t1.call.nestedMs - t2.call.nestedMs;
253
+ if (diff === 0) {
254
+ if (t1.type === "immediate" /* Immediate */ && t2.type !== "immediate" /* Immediate */)
255
+ return 1;
256
+ return 0;
257
+ }
258
+ return diff;
259
+ });
260
+ }
261
+ assertMocked() {
262
+ assertEvery([
263
+ this._isMocked,
264
+ this._setTimeout,
265
+ this._setInterval,
266
+ this._clearTimeout,
267
+ this._clearInterval
268
+ ], 'timers are not mocked. try calling "vitest.useFakeTimers()" first');
269
+ }
270
+ }
271
+
272
+ class VitestUtils {
273
+ constructor() {
274
+ this.spyOn = spyOn;
275
+ this.fn = fn;
276
+ this.mock = (path) => path;
277
+ this._timers = new FakeTimers();
278
+ }
279
+ useFakeTimers() {
280
+ return this._timers.useFakeTimers();
281
+ }
282
+ useRealTimers() {
283
+ return this._timers.useRealTimers();
284
+ }
285
+ runOnlyPendingTimers() {
286
+ return this._timers.runOnlyPendingTimers();
287
+ }
288
+ runAllTimers() {
289
+ return this._timers.runAllTimers();
290
+ }
291
+ advanceTimersByTime(ms) {
292
+ return this._timers.advanceTimersByTime(ms);
293
+ }
294
+ advanceTimersToNextTimer() {
295
+ return this._timers.advanceTimersToNextTimer();
296
+ }
297
+ runAllTicks() {
298
+ return this._timers.runAllTicks();
299
+ }
300
+ setSystemTime(time) {
301
+ return this._timers.setSystemTime(time);
302
+ }
303
+ getRealSystemTime() {
304
+ return this._timers.getRealSystemTime();
305
+ }
306
+ getTimerCount() {
307
+ return this._timers.getTimerCount();
308
+ }
309
+ }
310
+ const vitest = new VitestUtils();
311
+ const vi = vitest;
312
+
313
+ var index = /*#__PURE__*/Object.freeze({
314
+ __proto__: null,
315
+ suite: suite,
316
+ test: test,
317
+ describe: describe,
318
+ it: it,
319
+ beforeAll: beforeAll,
320
+ afterAll: afterAll,
321
+ beforeEach: beforeEach,
322
+ afterEach: afterEach,
323
+ assert: assert,
324
+ should: should,
325
+ expect: expect,
326
+ chai: chai,
327
+ spy: spy,
328
+ spyOn: spyOn$1,
329
+ vitest: vitest,
330
+ vi: vi
331
+ });
332
+
333
+ export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, vi as e, index as i, vitest as v };
package/dist/index.d.ts CHANGED
@@ -108,6 +108,28 @@ declare type MatchersObject<T extends MatcherState = MatcherState> = {
108
108
  [id: string]: RawMatcherFn<T>;
109
109
  };
110
110
 
111
+ interface AsymmetricMatcherInterface {
112
+ asymmetricMatch(other: unknown): boolean;
113
+ toString(): string;
114
+ getExpectedType?(): string;
115
+ toAsymmetricMatcher?(): string;
116
+ }
117
+ declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
118
+ protected sample: T;
119
+ protected inverse: boolean;
120
+ constructor(sample: T, inverse?: boolean);
121
+ protected getMatcherContext(): State;
122
+ abstract asymmetricMatch(other: unknown): boolean;
123
+ abstract toString(): string;
124
+ getExpectedType?(): string;
125
+ toAsymmetricMatcher?(): string;
126
+ }
127
+ declare class Anything extends AsymmetricMatcher<void> {
128
+ asymmetricMatch(other: unknown): boolean;
129
+ toString(): string;
130
+ toAsymmetricMatcher(): string;
131
+ }
132
+
111
133
  declare type Awaitable<T> = T | PromiseLike<T>;
112
134
  declare type Nullable<T> = T | null | undefined;
113
135
  declare type Arrayable<T> = T | Array<T>;
@@ -585,10 +607,25 @@ declare type Awaited<T> = T extends Promise<infer R> ? R : never;
585
607
  declare function fn<TArgs extends any[] = any[], R = any>(): JestMockCompatFn<TArgs, R>;
586
608
  declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): JestMockCompatFn<TArgs, R>;
587
609
 
588
- declare const vitest: {
610
+ declare class VitestUtils {
589
611
  spyOn: typeof spyOn;
590
612
  fn: typeof fn;
591
- };
613
+ mock: (path: string) => string;
614
+ private _timers;
615
+ constructor();
616
+ useFakeTimers(): void;
617
+ useRealTimers(): void;
618
+ runOnlyPendingTimers(): void;
619
+ runAllTimers(): void;
620
+ advanceTimersByTime(ms: number): void;
621
+ advanceTimersToNextTimer(): void;
622
+ runAllTicks(): void;
623
+ setSystemTime(time?: number | Date): void;
624
+ getRealSystemTime(): number;
625
+ getTimerCount(): number;
626
+ }
627
+ declare const vitest: VitestUtils;
628
+ declare const vi: VitestUtils;
592
629
 
593
630
  declare module 'vite' {
594
631
  interface UserConfig {
@@ -603,6 +640,7 @@ declare global {
603
640
  interface ExpectStatic {
604
641
  extend(expects: MatchersObject): void;
605
642
  stringContaining(expected: string): void;
643
+ anything(): Anything;
606
644
  }
607
645
  interface Assertion {
608
646
  chaiEqual(expected: any): void;
@@ -657,4 +695,4 @@ declare global {
657
695
  }
658
696
  }
659
697
 
660
- export { ArgumentsType, Arrayable, Awaitable, 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, vitest };
698
+ export { ArgumentsType, Arrayable, Awaitable, 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 };
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, v as vitest } from './index-722fb5a5.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';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
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-adef7ffb.js';
2
+ import { A as API_PATH } from './constants-9cfa4d7b.js';
3
3
  import 'path';
4
4
  import 'url';
5
5
 
package/dist/node.js CHANGED
@@ -1,15 +1,15 @@
1
- export { c as createVitest } from './index-733e7378.js';
1
+ export { c as createVitest } from './index-25bef3dd.js';
2
2
  import 'path';
3
3
  import 'vite';
4
4
  import 'process';
5
5
  import 'fs';
6
- import './constants-adef7ffb.js';
6
+ import './constants-9cfa4d7b.js';
7
7
  import 'url';
8
- import './utils-385e2d09.js';
8
+ import './utils-5d0cec8a.js';
9
9
  import 'module';
10
10
  import 'tty';
11
11
  import 'perf_hooks';
12
- import './error-309196c9.js';
12
+ import './error-abd1f726.js';
13
13
  import 'source-map';
14
14
  import 'assert';
15
15
  import 'events';
@@ -91,15 +91,23 @@ function partitionSuiteChildren(suite) {
91
91
  tasksGroups.push(tasksGroup);
92
92
  return tasksGroups;
93
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";
94
+ function interpretOnlyMode(tasks) {
95
+ if (tasks.some((t) => t.mode === "only")) {
96
+ tasks.forEach((t) => {
97
+ if (t.mode === "run")
98
+ t.mode = "skip";
99
+ else if (t.mode === "only")
100
+ t.mode = "run";
101
101
  });
102
102
  }
103
+ tasks.forEach((t) => {
104
+ if (t.type === "suite") {
105
+ if (t.mode === "skip")
106
+ t.tasks.forEach((c2) => c2.mode === "run" && (c2.mode = "skip"));
107
+ else
108
+ interpretOnlyMode(t.tasks);
109
+ }
110
+ });
103
111
  }
104
112
  function getTests(suite) {
105
113
  return toArray(suite).flatMap((s) => s.tasks.flatMap((c2) => c2.type === "test" ? [c2] : getTests(c2)));
package/dist/utils.js CHANGED
@@ -1,3 +1,3 @@
1
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';
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-5d0cec8a.js';
3
3
  import 'tty';
package/dist/worker.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import path, { resolve as resolve$3, dirname as dirname$3 } from 'path';
2
2
  import { n as nanoid } from './index-9e71c815.js';
3
- import { c as distDir } from './constants-adef7ffb.js';
3
+ import { c as distDir } from './constants-9cfa4d7b.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-385e2d09.js';
7
+ import { s as slash } from './utils-5d0cec8a.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';
@@ -8392,11 +8392,10 @@ async function shouldExternalize(id, config) {
8392
8392
  return id.includes("/node_modules/") && await isValidNodeImport(id);
8393
8393
  }
8394
8394
  function toFilePath(id, root) {
8395
- id = slash(id);
8396
- let absolute = id.startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$3(root)) ? id : id.startsWith("/") ? slash(resolve$3(root, id.slice(1))) : id;
8395
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$3(root)) ? id : id.startsWith("/") ? slash(resolve$3(root, id.slice(1))) : id;
8397
8396
  if (absolute.startsWith("//"))
8398
8397
  absolute = absolute.slice(1);
8399
- return isWindows && absolute.startsWith("/") ? pathToFileURL(absolute.slice(1)).href : absolute;
8398
+ return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
8400
8399
  }
8401
8400
  function matchExternalizePattern(id, patterns) {
8402
8401
  for (const ex of patterns) {
@@ -8411,8 +8410,8 @@ function matchExternalizePattern(id, patterns) {
8411
8410
  return false;
8412
8411
  }
8413
8412
  function patchWindowsImportPath(path) {
8414
- if (path.match(/^\w:\//))
8415
- return `/${path}`;
8413
+ if (path.match(/^\w:\\/))
8414
+ return `file:///${slash(path)}`;
8416
8415
  else
8417
8416
  return path;
8418
8417
  }
package/global.d.ts CHANGED
@@ -5,9 +5,8 @@ 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 spy: typeof import('vitest')['spy']
9
- const spyOn: typeof import('vitest')['spyOn']
10
8
  const vitest: typeof import('vitest')['vitest']
9
+ const vi: typeof import('vitest')['vitest']
11
10
  const beforeAll: typeof import('vitest')['beforeAll']
12
11
  const afterAll: typeof import('vitest')['afterAll']
13
12
  const beforeEach: typeof import('vitest')['beforeEach']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.90",
3
+ "version": "0.0.91",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -63,7 +63,7 @@
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.13",
66
+ "@types/node": "^17.0.0",
67
67
  "c8": "^7.10.0",
68
68
  "cac": "^6.7.12",
69
69
  "cli-truncate": "^3.1.0",
@@ -1,122 +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-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 };