vitest 0.0.122 → 0.0.126
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/README.md +1 -3
- package/dist/cli.js +12 -6
- package/dist/{constants-22bbd600.js → constants-8b3a9b31.js} +1 -1
- package/dist/{diff-a295cb37.js → diff-3adb959a.js} +34 -20
- package/dist/entry.js +18 -27
- package/dist/externalize-2f63779d.js +9258 -0
- package/dist/{global-71c4f178.js → global-eb23b22e.js} +6 -6
- package/dist/{index-3cd686b2.js → index-4b6e78b4.js} +3 -2
- package/dist/{index-090545ef.js → index-9fdde2e8.js} +25 -27
- package/dist/{index-123a18df.js → index-e04b9e4c.js} +66 -28
- package/dist/index.d.ts +49 -14
- package/dist/index.js +4 -4
- package/dist/{jest-mock-038a01b3.js → jest-mock-30625866.js} +4 -1
- package/dist/node.d.ts +47 -9
- package/dist/node.js +5 -5
- package/dist/{setup-c9c7cb5b.js → setup-b0d2ca33.js} +50 -4
- package/dist/{vi-c99184a5.js → vi-5ff3926d.js} +42 -41
- package/dist/worker.js +27 -9244
- package/package.json +13 -8
- package/dist/utils.js +0 -5
|
@@ -9,11 +9,16 @@ import require$$2 from 'events';
|
|
|
9
9
|
import require$$1 from 'https';
|
|
10
10
|
import require$$2$1 from 'http';
|
|
11
11
|
import require$$7 from 'url';
|
|
12
|
-
import { A as API_PATH } from './constants-
|
|
13
|
-
import './
|
|
12
|
+
import { A as API_PATH } from './constants-8b3a9b31.js';
|
|
13
|
+
import { s as shouldExternalize } from './externalize-2f63779d.js';
|
|
14
|
+
import { o as interpretSourcePos, n as parseStacktrace } from './diff-3adb959a.js';
|
|
15
|
+
import './index-9fdde2e8.js';
|
|
14
16
|
import 'tty';
|
|
15
17
|
import 'local-pkg';
|
|
16
18
|
import 'path';
|
|
19
|
+
import 'module';
|
|
20
|
+
import 'assert';
|
|
21
|
+
import 'util';
|
|
17
22
|
|
|
18
23
|
/*! (c) 2020 Andrea Giammarchi */
|
|
19
24
|
|
|
@@ -4266,9 +4271,12 @@ function setup(ctx) {
|
|
|
4266
4271
|
getFiles() {
|
|
4267
4272
|
return ctx.state.getFiles();
|
|
4268
4273
|
},
|
|
4269
|
-
|
|
4274
|
+
readFile(id) {
|
|
4270
4275
|
return promises.readFile(id, "utf-8");
|
|
4271
4276
|
},
|
|
4277
|
+
writeFile(id, content) {
|
|
4278
|
+
return promises.writeFile(id, content, "utf-8");
|
|
4279
|
+
},
|
|
4272
4280
|
async rerun(files) {
|
|
4273
4281
|
await ctx.report("onWatcherRerun", files);
|
|
4274
4282
|
await ctx.runFiles(files);
|
|
@@ -4276,6 +4284,35 @@ function setup(ctx) {
|
|
|
4276
4284
|
},
|
|
4277
4285
|
getConfig() {
|
|
4278
4286
|
return ctx.config;
|
|
4287
|
+
},
|
|
4288
|
+
async getModuleGraph(id) {
|
|
4289
|
+
const graph = {};
|
|
4290
|
+
function clearId(id2) {
|
|
4291
|
+
return (id2 == null ? void 0 : id2.replace(/\?v=\w+$/, "")) || "";
|
|
4292
|
+
}
|
|
4293
|
+
function get(mod, seen = new Set()) {
|
|
4294
|
+
if (!mod || !mod.id || seen.has(mod))
|
|
4295
|
+
return;
|
|
4296
|
+
seen.add(mod);
|
|
4297
|
+
const mods = Array.from(mod.importedModules).filter((i) => i.id && !i.id.includes("/vitest/dist/"));
|
|
4298
|
+
graph[clearId(mod.id)] = mods.map((i) => clearId(i.id));
|
|
4299
|
+
mods.forEach((m) => get(m, seen));
|
|
4300
|
+
}
|
|
4301
|
+
get(ctx.server.moduleGraph.getModuleById(id));
|
|
4302
|
+
const externalized = [];
|
|
4303
|
+
const inlined = [];
|
|
4304
|
+
await Promise.all(Object.keys(graph).map(async (i) => {
|
|
4305
|
+
const rewrote = await shouldExternalize(i, ctx.config);
|
|
4306
|
+
if (rewrote)
|
|
4307
|
+
externalized.push(rewrote);
|
|
4308
|
+
else
|
|
4309
|
+
inlined.push(i);
|
|
4310
|
+
}));
|
|
4311
|
+
return {
|
|
4312
|
+
graph,
|
|
4313
|
+
externalized,
|
|
4314
|
+
inlined
|
|
4315
|
+
};
|
|
4279
4316
|
}
|
|
4280
4317
|
},
|
|
4281
4318
|
post(msg) {
|
|
@@ -4302,12 +4339,21 @@ class WebSocketReporter {
|
|
|
4302
4339
|
this.clients = clients;
|
|
4303
4340
|
}
|
|
4304
4341
|
onCollected(files) {
|
|
4342
|
+
if (this.clients.size === 0)
|
|
4343
|
+
return;
|
|
4305
4344
|
this.clients.forEach((client) => {
|
|
4306
4345
|
var _a;
|
|
4307
4346
|
(_a = client.onCollected) == null ? void 0 : _a.call(client, files);
|
|
4308
4347
|
});
|
|
4309
4348
|
}
|
|
4310
|
-
onTaskUpdate(packs) {
|
|
4349
|
+
async onTaskUpdate(packs) {
|
|
4350
|
+
if (this.clients.size === 0)
|
|
4351
|
+
return;
|
|
4352
|
+
await Promise.all(packs.map(async (i) => {
|
|
4353
|
+
var _a;
|
|
4354
|
+
if ((_a = i[1]) == null ? void 0 : _a.error)
|
|
4355
|
+
await interpretSourcePos(parseStacktrace(i[1].error), this.ctx);
|
|
4356
|
+
}));
|
|
4311
4357
|
this.clients.forEach((client) => {
|
|
4312
4358
|
var _a;
|
|
4313
4359
|
(_a = client.onTaskUpdate) == null ? void 0 : _a.call(client, packs);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as noop, i as isObject } from './index-
|
|
1
|
+
import { n as noop, i as isObject } from './index-9fdde2e8.js';
|
|
2
|
+
import { i as isMockFunction, a as spyOn, f as fn, s as spies } from './jest-mock-30625866.js';
|
|
2
3
|
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-c9e3b764.js';
|
|
3
|
-
import { a as spyOn, f as fn, s as spies } from './jest-mock-038a01b3.js';
|
|
4
4
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defProps = Object.defineProperties;
|
|
@@ -125,23 +125,23 @@ function createSuiteHooks() {
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
function createSuiteCollector(name, factory = () => {
|
|
128
|
-
}, mode,
|
|
128
|
+
}, mode, concurrent) {
|
|
129
129
|
const tasks = [];
|
|
130
130
|
const factoryQueue = [];
|
|
131
131
|
let suite2;
|
|
132
132
|
initSuite();
|
|
133
133
|
const test2 = createChainable(["concurrent", "skip", "only", "todo", "fails"], function(name2, fn, timeout) {
|
|
134
134
|
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
135
|
-
const computeMode = this.concurrent ? "concurrent" : void 0;
|
|
136
135
|
const test3 = {
|
|
137
136
|
id: "",
|
|
138
137
|
type: "test",
|
|
139
138
|
name: name2,
|
|
140
139
|
mode: mode2,
|
|
141
|
-
computeMode: computeMode ?? (suiteComputeMode ?? "serial"),
|
|
142
140
|
suite: void 0,
|
|
143
141
|
fails: this.fails
|
|
144
142
|
};
|
|
143
|
+
if (this.concurrent || concurrent)
|
|
144
|
+
test3.concurrent = true;
|
|
145
145
|
setFn(test3, normalizeTest(fn || noop, timeout));
|
|
146
146
|
tasks.push(test3);
|
|
147
147
|
});
|
|
@@ -162,7 +162,6 @@ function createSuiteCollector(name, factory = () => {
|
|
|
162
162
|
suite2 = {
|
|
163
163
|
id: "",
|
|
164
164
|
type: "suite",
|
|
165
|
-
computeMode: "serial",
|
|
166
165
|
name,
|
|
167
166
|
mode,
|
|
168
167
|
tasks: []
|
|
@@ -194,8 +193,7 @@ function createSuiteCollector(name, factory = () => {
|
|
|
194
193
|
function createSuite() {
|
|
195
194
|
return createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
|
|
196
195
|
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
197
|
-
|
|
198
|
-
return createSuiteCollector(name, factory, mode, computeMode);
|
|
196
|
+
return createSuiteCollector(name, factory, mode, this.concurrent);
|
|
199
197
|
});
|
|
200
198
|
}
|
|
201
199
|
|
|
@@ -2863,12 +2861,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2863
2861
|
def("toContainEqual", function(expected) {
|
|
2864
2862
|
const obj = utils.flag(this, "object");
|
|
2865
2863
|
const index = Array.from(obj).findIndex((item) => {
|
|
2866
|
-
|
|
2867
|
-
chai.assert.deepEqual(item, expected);
|
|
2868
|
-
} catch {
|
|
2869
|
-
return false;
|
|
2870
|
-
}
|
|
2871
|
-
return true;
|
|
2864
|
+
return equals(item, expected);
|
|
2872
2865
|
});
|
|
2873
2866
|
this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
|
|
2874
2867
|
});
|
|
@@ -2917,15 +2910,24 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2917
2910
|
def("toHaveProperty", function(...args) {
|
|
2918
2911
|
return this.have.deep.nested.property(...args);
|
|
2919
2912
|
});
|
|
2920
|
-
def("toBeCloseTo", function(
|
|
2921
|
-
|
|
2922
|
-
|
|
2913
|
+
def("toBeCloseTo", function(received, precision = 2) {
|
|
2914
|
+
const expected = this._obj;
|
|
2915
|
+
let pass = false;
|
|
2916
|
+
let expectedDiff = 0;
|
|
2917
|
+
let receivedDiff = 0;
|
|
2918
|
+
if (received === Infinity && expected === Infinity) {
|
|
2919
|
+
pass = true;
|
|
2920
|
+
} else if (received === -Infinity && expected === -Infinity) {
|
|
2921
|
+
pass = true;
|
|
2922
|
+
} else {
|
|
2923
|
+
expectedDiff = Math.pow(10, -precision) / 2;
|
|
2924
|
+
receivedDiff = Math.abs(expected - received);
|
|
2925
|
+
pass = receivedDiff < expectedDiff;
|
|
2926
|
+
}
|
|
2927
|
+
return this.assert(pass, `expected #{this} to be close to #{exp}, recieved difference is ${receivedDiff}, but expected ${expectedDiff}`, `expected #{this} to not be close to #{exp}, recieved difference is ${receivedDiff}, but expected ${expectedDiff}`, received, expected);
|
|
2923
2928
|
});
|
|
2924
|
-
function isSpy(putativeSpy) {
|
|
2925
|
-
return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
|
|
2926
|
-
}
|
|
2927
2929
|
const assertIsMock = (assertion) => {
|
|
2928
|
-
if (!
|
|
2930
|
+
if (!isMockFunction(assertion._obj))
|
|
2929
2931
|
throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
|
|
2930
2932
|
};
|
|
2931
2933
|
const getSpy = (assertion) => {
|
|
@@ -2935,23 +2937,26 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2935
2937
|
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
|
|
2936
2938
|
const spy = getSpy(this);
|
|
2937
2939
|
const spyName = spy.getMockName();
|
|
2938
|
-
|
|
2940
|
+
const callCount = spy.mock.calls.length;
|
|
2941
|
+
return this.assert(callCount === number, `expected "${spyName}" to be called #{exp} times`, `expected "${spyName}" to not be called #{exp} times`, number, callCount);
|
|
2939
2942
|
});
|
|
2940
2943
|
def("toHaveBeenCalledOnce", function() {
|
|
2941
2944
|
const spy = getSpy(this);
|
|
2942
2945
|
const spyName = spy.getMockName();
|
|
2943
|
-
|
|
2946
|
+
const callCount = spy.mock.calls.length;
|
|
2947
|
+
return this.assert(callCount === 1, `expected "${spyName}" to be called once`, `expected "${spyName}" to not be called once`, 1, callCount);
|
|
2944
2948
|
});
|
|
2945
2949
|
def(["toHaveBeenCalled", "toBeCalled"], function() {
|
|
2946
2950
|
const spy = getSpy(this);
|
|
2947
2951
|
const spyName = spy.getMockName();
|
|
2948
|
-
|
|
2952
|
+
const called = spy.mock.calls.length > 0;
|
|
2953
|
+
return this.assert(called, `expected "${spyName}" to be called at least once`, `expected "${spyName}" to not be called at all`, true, called);
|
|
2949
2954
|
});
|
|
2950
2955
|
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
|
2951
2956
|
const spy = getSpy(this);
|
|
2952
2957
|
const spyName = spy.getMockName();
|
|
2953
|
-
const pass = spy.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
|
|
2954
|
-
return this.assert(pass, `expected "${spyName}" to be called with arguments: #{exp}`, `expected "${spyName}" to not be called with arguments: #{exp}`, args, spy.calls);
|
|
2958
|
+
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
|
|
2959
|
+
return this.assert(pass, `expected "${spyName}" to be called with arguments: #{exp}`, `expected "${spyName}" to not be called with arguments: #{exp}`, args, spy.mock.calls);
|
|
2955
2960
|
});
|
|
2956
2961
|
const ordinalOf = (i) => {
|
|
2957
2962
|
const j = i % 10;
|
|
@@ -2967,44 +2972,40 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2967
2972
|
def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
|
|
2968
2973
|
const spy = getSpy(this);
|
|
2969
2974
|
const spyName = spy.getMockName();
|
|
2970
|
-
const nthCall = spy.calls[times - 1];
|
|
2975
|
+
const nthCall = spy.mock.calls[times - 1];
|
|
2971
2976
|
this.assert(equals(nthCall, args, [iterableEquality]), `expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`, `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`, args, nthCall);
|
|
2972
2977
|
});
|
|
2973
2978
|
def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
|
|
2974
2979
|
const spy = getSpy(this);
|
|
2975
2980
|
const spyName = spy.getMockName();
|
|
2976
|
-
const lastCall = spy.calls[spy.calls.length - 1];
|
|
2981
|
+
const lastCall = spy.mock.calls[spy.calls.length - 1];
|
|
2977
2982
|
this.assert(equals(lastCall, args, [iterableEquality]), `expected last "${spyName}" call to have been called with #{exp}`, `expected last "${spyName}" call to not have been called with #{exp}`, args, lastCall);
|
|
2978
2983
|
});
|
|
2979
2984
|
def(["toThrow", "toThrowError"], function(expected) {
|
|
2980
|
-
|
|
2981
|
-
if (negate)
|
|
2982
|
-
this.not.to.throw(expected);
|
|
2983
|
-
else
|
|
2984
|
-
this.to.throw(expected);
|
|
2985
|
+
return this.to.throw(expected);
|
|
2985
2986
|
});
|
|
2986
2987
|
def(["toHaveReturned", "toReturn"], function() {
|
|
2987
2988
|
const spy = getSpy(this);
|
|
2988
2989
|
const spyName = spy.getMockName();
|
|
2989
|
-
const calledAndNotThrew = spy.
|
|
2990
|
+
const calledAndNotThrew = spy.mock.calls.length > 0 && !spy.mock.results.some(({ type }) => type === "throw");
|
|
2990
2991
|
this.assert(calledAndNotThrew, `expected "${spyName}" to be successfully called at least once`, `expected "${spyName}" to not be successfully called`, calledAndNotThrew, !calledAndNotThrew);
|
|
2991
2992
|
});
|
|
2992
2993
|
def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
|
|
2993
2994
|
const spy = getSpy(this);
|
|
2994
2995
|
const spyName = spy.getMockName();
|
|
2995
|
-
const successfullReturns = spy.results.reduce((success,
|
|
2996
|
+
const successfullReturns = spy.mock.results.reduce((success, { type }) => type === "throw" ? success : ++success, 0);
|
|
2996
2997
|
this.assert(successfullReturns === times, `expected "${spyName}" to be successfully called ${times} times`, `expected "${spyName}" to not be successfully called ${times} times`, `expected number of returns: ${times}`, `received number of returns: ${successfullReturns}`);
|
|
2997
2998
|
});
|
|
2998
2999
|
def(["toHaveReturnedWith", "toReturnWith"], function(value) {
|
|
2999
3000
|
const spy = getSpy(this);
|
|
3000
3001
|
const spyName = spy.getMockName();
|
|
3001
|
-
const pass = spy.results.some((
|
|
3002
|
+
const pass = spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result));
|
|
3002
3003
|
this.assert(pass, `expected "${spyName}" to be successfully called with #{exp}`, `expected "${spyName}" to not be successfully called with #{exp}`, value);
|
|
3003
3004
|
});
|
|
3004
3005
|
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
|
3005
3006
|
const spy = getSpy(this);
|
|
3006
3007
|
const spyName = spy.getMockName();
|
|
3007
|
-
const lastResult = spy.
|
|
3008
|
+
const { value: lastResult } = spy.mock.results[spy.returns.length - 1];
|
|
3008
3009
|
const pass = equals(lastResult, value);
|
|
3009
3010
|
this.assert(pass, `expected last "${spyName}" call to return #{exp}`, `expected last "${spyName}" call to not return #{exp}`, value, lastResult);
|
|
3010
3011
|
});
|
|
@@ -3012,9 +3013,9 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
3012
3013
|
const spy = getSpy(this);
|
|
3013
3014
|
const spyName = spy.getMockName();
|
|
3014
3015
|
const isNot = utils.flag(this, "negate");
|
|
3015
|
-
const
|
|
3016
|
+
const { type: callType, value: callResult } = spy.mock.results[nthCall - 1];
|
|
3016
3017
|
const ordinalCall = `${ordinalOf(nthCall)} call`;
|
|
3017
|
-
if (!isNot && callType === "
|
|
3018
|
+
if (!isNot && callType === "throw")
|
|
3018
3019
|
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
|
|
3019
3020
|
const nthCallReturn = equals(callResult, value);
|
|
3020
3021
|
this.assert(nthCallReturn, `expected ${ordinalCall} "${spyName}" call to return #{exp}`, `expected ${ordinalCall} "${spyName}" call to not return #{exp}`, value, callResult);
|
|
@@ -3364,7 +3365,7 @@ class FakeTimers {
|
|
|
3364
3365
|
this._setInterval,
|
|
3365
3366
|
this._clearTimeout,
|
|
3366
3367
|
this._clearInterval
|
|
3367
|
-
], 'timers are not mocked. try calling "
|
|
3368
|
+
], 'timers are not mocked. try calling "vi.useFakeTimers()" first');
|
|
3368
3369
|
}
|
|
3369
3370
|
}
|
|
3370
3371
|
|
|
@@ -3421,7 +3422,7 @@ class VitestUtils {
|
|
|
3421
3422
|
return item;
|
|
3422
3423
|
}
|
|
3423
3424
|
isMockFunction(fn2) {
|
|
3424
|
-
return
|
|
3425
|
+
return isMockFunction(fn2);
|
|
3425
3426
|
}
|
|
3426
3427
|
clearAllMocks() {
|
|
3427
3428
|
__vitest__clearMocks__({ clearMocks: true });
|