vitest 0.0.89 → 0.0.90
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 +1 -1
- package/dist/entry.js +274 -205
- package/dist/index.d.ts +5 -3
- package/package.json +5 -3
package/dist/cli.js
CHANGED
|
@@ -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.
|
|
635
|
+
var version = "0.0.90";
|
|
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", {
|
package/dist/entry.js
CHANGED
|
@@ -714,12 +714,12 @@ function printObjectProperties(val, config, indentation, depth, refs, printer) {
|
|
|
714
714
|
return result;
|
|
715
715
|
}
|
|
716
716
|
|
|
717
|
-
var AsymmetricMatcher$
|
|
717
|
+
var AsymmetricMatcher$3 = {};
|
|
718
718
|
|
|
719
|
-
Object.defineProperty(AsymmetricMatcher$
|
|
719
|
+
Object.defineProperty(AsymmetricMatcher$3, '__esModule', {
|
|
720
720
|
value: true
|
|
721
721
|
});
|
|
722
|
-
AsymmetricMatcher$
|
|
722
|
+
AsymmetricMatcher$3.default = AsymmetricMatcher$3.test = AsymmetricMatcher$3.serialize = void 0;
|
|
723
723
|
|
|
724
724
|
var _collections$3 = collections;
|
|
725
725
|
|
|
@@ -820,17 +820,17 @@ const serialize$7 = (val, config, indentation, depth, refs, printer) => {
|
|
|
820
820
|
return val.toAsymmetricMatcher();
|
|
821
821
|
};
|
|
822
822
|
|
|
823
|
-
AsymmetricMatcher$
|
|
823
|
+
AsymmetricMatcher$3.serialize = serialize$7;
|
|
824
824
|
|
|
825
825
|
const test$6 = val => val && val.$$typeof === asymmetricMatcher;
|
|
826
826
|
|
|
827
|
-
AsymmetricMatcher$
|
|
827
|
+
AsymmetricMatcher$3.test = test$6;
|
|
828
828
|
const plugin$6 = {
|
|
829
829
|
serialize: serialize$7,
|
|
830
830
|
test: test$6
|
|
831
831
|
};
|
|
832
832
|
var _default$7 = plugin$6;
|
|
833
|
-
AsymmetricMatcher$
|
|
833
|
+
AsymmetricMatcher$3.default = _default$7;
|
|
834
834
|
|
|
835
835
|
var ConvertAnsi = {};
|
|
836
836
|
|
|
@@ -2073,7 +2073,7 @@ var _ansiStyles = _interopRequireDefault(ansiStyles.exports);
|
|
|
2073
2073
|
var _collections = collections;
|
|
2074
2074
|
|
|
2075
2075
|
var _AsymmetricMatcher = _interopRequireDefault(
|
|
2076
|
-
AsymmetricMatcher$
|
|
2076
|
+
AsymmetricMatcher$3
|
|
2077
2077
|
);
|
|
2078
2078
|
|
|
2079
2079
|
var _ConvertAnsi = _interopRequireDefault(ConvertAnsi);
|
|
@@ -2663,7 +2663,7 @@ const {
|
|
|
2663
2663
|
Immutable: Immutable$1,
|
|
2664
2664
|
ReactElement: ReactElement$1,
|
|
2665
2665
|
ReactTestComponent: ReactTestComponent$1,
|
|
2666
|
-
AsymmetricMatcher: AsymmetricMatcher$
|
|
2666
|
+
AsymmetricMatcher: AsymmetricMatcher$2
|
|
2667
2667
|
} = plugins_1;
|
|
2668
2668
|
let PLUGINS$1 = [
|
|
2669
2669
|
ReactTestComponent$1,
|
|
@@ -2671,7 +2671,7 @@ let PLUGINS$1 = [
|
|
|
2671
2671
|
DOMElement$1,
|
|
2672
2672
|
DOMCollection$1,
|
|
2673
2673
|
Immutable$1,
|
|
2674
|
-
AsymmetricMatcher$
|
|
2674
|
+
AsymmetricMatcher$2
|
|
2675
2675
|
];
|
|
2676
2676
|
const getSerializers = () => PLUGINS$1;
|
|
2677
2677
|
|
|
@@ -2976,20 +2976,18 @@ function getSnapshotClient() {
|
|
|
2976
2976
|
_client = new SnapshotClient();
|
|
2977
2977
|
return _client;
|
|
2978
2978
|
}
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
utils.addMethod(chai.Assertion.prototype, key, function(message) {
|
|
2983
|
-
const expected = utils.flag(this, "object");
|
|
2984
|
-
getSnapshotClient().assert(expected, message);
|
|
2985
|
-
});
|
|
2986
|
-
}
|
|
2987
|
-
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function(inlineSnapshot, message) {
|
|
2979
|
+
const SnapshotPlugin = (chai, utils) => {
|
|
2980
|
+
for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
|
|
2981
|
+
utils.addMethod(chai.Assertion.prototype, key, function(message) {
|
|
2988
2982
|
const expected = utils.flag(this, "object");
|
|
2989
|
-
getSnapshotClient().assert(expected, message
|
|
2983
|
+
getSnapshotClient().assert(expected, message);
|
|
2990
2984
|
});
|
|
2991
|
-
}
|
|
2992
|
-
|
|
2985
|
+
}
|
|
2986
|
+
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function(inlineSnapshot, message) {
|
|
2987
|
+
const expected = utils.flag(this, "object");
|
|
2988
|
+
getSnapshotClient().assert(expected, message, inlineSnapshot);
|
|
2989
|
+
});
|
|
2990
|
+
};
|
|
2993
2991
|
|
|
2994
2992
|
const EXPECTED_COLOR = c$1.green;
|
|
2995
2993
|
const RECEIVED_COLOR = c$1.red;
|
|
@@ -2997,7 +2995,7 @@ const INVERTED_COLOR = c$1.inverse;
|
|
|
2997
2995
|
const BOLD_WEIGHT = c$1.bold;
|
|
2998
2996
|
const DIM_COLOR = c$1.dim;
|
|
2999
2997
|
const {
|
|
3000
|
-
AsymmetricMatcher,
|
|
2998
|
+
AsymmetricMatcher: AsymmetricMatcher$1,
|
|
3001
2999
|
DOMCollection,
|
|
3002
3000
|
DOMElement,
|
|
3003
3001
|
Immutable,
|
|
@@ -3010,7 +3008,7 @@ const PLUGINS = [
|
|
|
3010
3008
|
DOMElement,
|
|
3011
3009
|
DOMCollection,
|
|
3012
3010
|
Immutable,
|
|
3013
|
-
AsymmetricMatcher
|
|
3011
|
+
AsymmetricMatcher$1
|
|
3014
3012
|
];
|
|
3015
3013
|
function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
|
|
3016
3014
|
const {
|
|
@@ -3106,6 +3104,20 @@ function equals(a, b, customTesters, strictCheck) {
|
|
|
3106
3104
|
function isAsymmetric(obj) {
|
|
3107
3105
|
return !!obj && isA("Function", obj.asymmetricMatch);
|
|
3108
3106
|
}
|
|
3107
|
+
function hasAsymmetric(obj, seen = /* @__PURE__ */ new Set()) {
|
|
3108
|
+
if (seen.has(obj))
|
|
3109
|
+
return false;
|
|
3110
|
+
seen.add(obj);
|
|
3111
|
+
if (isAsymmetric(obj))
|
|
3112
|
+
return true;
|
|
3113
|
+
if (Array.isArray(obj))
|
|
3114
|
+
return obj.some((i) => hasAsymmetric(i, seen));
|
|
3115
|
+
if (obj instanceof Set)
|
|
3116
|
+
return Array.from(obj).some((i) => hasAsymmetric(i, seen));
|
|
3117
|
+
if (isObject(obj))
|
|
3118
|
+
return Object.values(obj).some((v) => hasAsymmetric(v, seen));
|
|
3119
|
+
return false;
|
|
3120
|
+
}
|
|
3109
3121
|
function asymmetricMatch(a, b) {
|
|
3110
3122
|
const asymmetricA = isAsymmetric(a);
|
|
3111
3123
|
const asymmetricB = isAsymmetric(b);
|
|
@@ -3377,201 +3389,258 @@ function JestExtendPlugin(expects) {
|
|
|
3377
3389
|
});
|
|
3378
3390
|
};
|
|
3379
3391
|
}
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
};
|
|
3386
|
-
}
|
|
3392
|
+
const JestExtend = (chai2, utils) => {
|
|
3393
|
+
utils.addMethod(chai2.expect, "extend", (expects) => {
|
|
3394
|
+
chai2.use(JestExtendPlugin(expects));
|
|
3395
|
+
});
|
|
3396
|
+
};
|
|
3387
3397
|
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
utils.addMethod(chai.Assertion.prototype, n, fn);
|
|
3393
|
-
};
|
|
3394
|
-
if (Array.isArray(name))
|
|
3395
|
-
name.forEach((n) => addMethod(n));
|
|
3396
|
-
else
|
|
3397
|
-
addMethod(name);
|
|
3398
|
-
}
|
|
3399
|
-
def("toEqual", function(expected) {
|
|
3400
|
-
return this.eql(expected);
|
|
3401
|
-
});
|
|
3402
|
-
def("toStrictEqual", function(expected) {
|
|
3403
|
-
return this.equal(expected);
|
|
3404
|
-
});
|
|
3405
|
-
def("toBe", function(expected) {
|
|
3406
|
-
return this.equal(expected);
|
|
3407
|
-
});
|
|
3408
|
-
def("toMatchObject", function(expected) {
|
|
3409
|
-
return this.containSubset(expected);
|
|
3410
|
-
});
|
|
3411
|
-
def("toMatch", function(expected) {
|
|
3412
|
-
if (typeof expected === "string")
|
|
3413
|
-
return this.include(expected);
|
|
3414
|
-
else
|
|
3415
|
-
return this.match(expected);
|
|
3416
|
-
});
|
|
3417
|
-
def("toContain", function(item) {
|
|
3418
|
-
return this.contain(item);
|
|
3419
|
-
});
|
|
3420
|
-
def("toContainEqual", function(expected) {
|
|
3421
|
-
const obj = utils.flag(this, "object");
|
|
3422
|
-
const index = Array.from(obj).findIndex((item) => {
|
|
3423
|
-
try {
|
|
3424
|
-
chai.assert.deepEqual(item, expected);
|
|
3425
|
-
} catch {
|
|
3426
|
-
return false;
|
|
3427
|
-
}
|
|
3428
|
-
return true;
|
|
3429
|
-
});
|
|
3430
|
-
this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
|
|
3431
|
-
});
|
|
3432
|
-
def("toBeTruthy", function() {
|
|
3433
|
-
const obj = utils.flag(this, "object");
|
|
3434
|
-
this.assert(Boolean(obj), "expected #{this} to be truthy", "expected #{this} to not be truthy", obj);
|
|
3435
|
-
});
|
|
3436
|
-
def("toBeFalsy", function() {
|
|
3437
|
-
const obj = utils.flag(this, "object");
|
|
3438
|
-
this.assert(!obj, "expected #{this} to be falsy", "expected #{this} to not be falsy", obj);
|
|
3439
|
-
});
|
|
3440
|
-
def("toBeGreaterThan", function(expected) {
|
|
3441
|
-
return this.to.greaterThan(expected);
|
|
3442
|
-
});
|
|
3443
|
-
def("toBeGreaterThanOrEqual", function(expected) {
|
|
3444
|
-
return this.to.greaterThanOrEqual(expected);
|
|
3445
|
-
});
|
|
3446
|
-
def("toBeLessThan", function(expected) {
|
|
3447
|
-
return this.to.lessThan(expected);
|
|
3448
|
-
});
|
|
3449
|
-
def("toBeLessThanOrEqual", function(expected) {
|
|
3450
|
-
return this.to.lessThanOrEqual(expected);
|
|
3451
|
-
});
|
|
3452
|
-
def("toBeNaN", function() {
|
|
3453
|
-
return this.be.NaN;
|
|
3454
|
-
});
|
|
3455
|
-
def("toBeUndefined", function() {
|
|
3456
|
-
return this.be.undefined;
|
|
3457
|
-
});
|
|
3458
|
-
def("toBeNull", function() {
|
|
3459
|
-
return this.be.null;
|
|
3460
|
-
});
|
|
3461
|
-
def("toBeDefined", function() {
|
|
3462
|
-
return this.not.be.undefined;
|
|
3463
|
-
});
|
|
3464
|
-
def("toBeInstanceOf", function(obj) {
|
|
3465
|
-
return this.instanceOf(obj);
|
|
3466
|
-
});
|
|
3467
|
-
def("toHaveLength", function(length) {
|
|
3468
|
-
return this.have.length(length);
|
|
3469
|
-
});
|
|
3470
|
-
def("toHaveProperty", function(...args) {
|
|
3471
|
-
return this.have.deep.nested.property(...args);
|
|
3472
|
-
});
|
|
3473
|
-
def("toBeCloseTo", function(number, numDigits = 2) {
|
|
3474
|
-
utils.expectTypes(this, ["number"]);
|
|
3475
|
-
return this.closeTo(number, numDigits);
|
|
3476
|
-
});
|
|
3477
|
-
function isSpy(putativeSpy) {
|
|
3478
|
-
return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
|
|
3479
|
-
}
|
|
3480
|
-
const assertIsMock = (assertion) => {
|
|
3481
|
-
if (!isSpy(assertion._obj))
|
|
3482
|
-
throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
|
|
3398
|
+
const JestChaiExpect = (chai, utils) => {
|
|
3399
|
+
function def(name, fn) {
|
|
3400
|
+
const addMethod = (n) => {
|
|
3401
|
+
utils.addMethod(chai.Assertion.prototype, n, fn);
|
|
3483
3402
|
};
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3403
|
+
if (Array.isArray(name))
|
|
3404
|
+
name.forEach((n) => addMethod(n));
|
|
3405
|
+
else
|
|
3406
|
+
addMethod(name);
|
|
3407
|
+
}
|
|
3408
|
+
const chaiEqual = chai.Assertion.prototype.equal;
|
|
3409
|
+
def("chaiEqual", function(...args) {
|
|
3410
|
+
return chaiEqual.apply(this, args);
|
|
3411
|
+
});
|
|
3412
|
+
utils.overwriteMethod(chai.Assertion.prototype, "equal", (_super) => {
|
|
3413
|
+
return function(...args) {
|
|
3414
|
+
const expected = args[0];
|
|
3415
|
+
const actual = utils.flag(this, "object");
|
|
3416
|
+
if (hasAsymmetric(expected)) {
|
|
3417
|
+
this.assert(equals(actual, expected, void 0, true), "not match with #{this}", "should not match with #{this}", true);
|
|
3418
|
+
} else {
|
|
3419
|
+
_super.apply(this, args);
|
|
3420
|
+
}
|
|
3487
3421
|
};
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
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);
|
|
3499
|
-
});
|
|
3500
|
-
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
|
3501
|
-
const spy = getSpy(this);
|
|
3502
|
-
const pass = spy.calls.some((callArg) => equals(callArg, args));
|
|
3503
|
-
return this.assert(pass, "expected spy to be called with arguments: #{exp}", "expected spy to not be called with arguments: #{exp}", args);
|
|
3504
|
-
});
|
|
3505
|
-
const ordinalOf = (i) => {
|
|
3506
|
-
const j = i % 10;
|
|
3507
|
-
const k = i % 100;
|
|
3508
|
-
if (j === 1 && k !== 11)
|
|
3509
|
-
return `${i}st`;
|
|
3510
|
-
if (j === 2 && k !== 12)
|
|
3511
|
-
return `${i}nd`;
|
|
3512
|
-
if (j === 3 && k !== 13)
|
|
3513
|
-
return `${i}rd`;
|
|
3514
|
-
return `${i}th`;
|
|
3422
|
+
});
|
|
3423
|
+
utils.overwriteMethod(chai.Assertion.prototype, "eql", (_super) => {
|
|
3424
|
+
return function(...args) {
|
|
3425
|
+
const expected = args[0];
|
|
3426
|
+
const actual = utils.flag(this, "object");
|
|
3427
|
+
if (hasAsymmetric(expected)) {
|
|
3428
|
+
this.assert(equals(actual, expected), "not match with #{this}", "should not match with #{this}", true);
|
|
3429
|
+
} else {
|
|
3430
|
+
_super.apply(this, args);
|
|
3431
|
+
}
|
|
3515
3432
|
};
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
});
|
|
3548
|
-
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
|
3549
|
-
const spy = getSpy(this);
|
|
3550
|
-
const lastResult = spy.returns.at(-1);
|
|
3551
|
-
const pass = equals(lastResult, value);
|
|
3552
|
-
this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
|
|
3553
|
-
});
|
|
3554
|
-
def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
|
|
3555
|
-
const spy = getSpy(this);
|
|
3556
|
-
const isNot = utils.flag(this, "negate");
|
|
3557
|
-
const [callType, callResult] = spy.results[nthCall - 1];
|
|
3558
|
-
const ordinalCall = `${ordinalOf(nthCall)} call`;
|
|
3559
|
-
if (!isNot && callType === "error")
|
|
3560
|
-
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
|
|
3561
|
-
const nthCallReturn = equals(callResult, value);
|
|
3562
|
-
this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call to not return #{exp}`, value, callResult);
|
|
3433
|
+
});
|
|
3434
|
+
def("toEqual", function(expected) {
|
|
3435
|
+
return this.eql(expected);
|
|
3436
|
+
});
|
|
3437
|
+
def("toStrictEqual", function(expected) {
|
|
3438
|
+
return this.chaiEqual(expected);
|
|
3439
|
+
});
|
|
3440
|
+
def("toBe", function(expected) {
|
|
3441
|
+
return this.chaiEqual(expected);
|
|
3442
|
+
});
|
|
3443
|
+
def("toMatchObject", function(expected) {
|
|
3444
|
+
return this.containSubset(expected);
|
|
3445
|
+
});
|
|
3446
|
+
def("toMatch", function(expected) {
|
|
3447
|
+
if (typeof expected === "string")
|
|
3448
|
+
return this.include(expected);
|
|
3449
|
+
else
|
|
3450
|
+
return this.match(expected);
|
|
3451
|
+
});
|
|
3452
|
+
def("toContain", function(item) {
|
|
3453
|
+
return this.contain(item);
|
|
3454
|
+
});
|
|
3455
|
+
def("toContainEqual", function(expected) {
|
|
3456
|
+
const obj = utils.flag(this, "object");
|
|
3457
|
+
const index = Array.from(obj).findIndex((item) => {
|
|
3458
|
+
try {
|
|
3459
|
+
chai.assert.deepEqual(item, expected);
|
|
3460
|
+
} catch {
|
|
3461
|
+
return false;
|
|
3462
|
+
}
|
|
3463
|
+
return true;
|
|
3563
3464
|
});
|
|
3465
|
+
this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
|
|
3466
|
+
});
|
|
3467
|
+
def("toBeTruthy", function() {
|
|
3468
|
+
const obj = utils.flag(this, "object");
|
|
3469
|
+
this.assert(Boolean(obj), "expected #{this} to be truthy", "expected #{this} to not be truthy", obj);
|
|
3470
|
+
});
|
|
3471
|
+
def("toBeFalsy", function() {
|
|
3472
|
+
const obj = utils.flag(this, "object");
|
|
3473
|
+
this.assert(!obj, "expected #{this} to be falsy", "expected #{this} to not be falsy", obj);
|
|
3474
|
+
});
|
|
3475
|
+
def("toBeGreaterThan", function(expected) {
|
|
3476
|
+
return this.to.greaterThan(expected);
|
|
3477
|
+
});
|
|
3478
|
+
def("toBeGreaterThanOrEqual", function(expected) {
|
|
3479
|
+
return this.to.greaterThanOrEqual(expected);
|
|
3480
|
+
});
|
|
3481
|
+
def("toBeLessThan", function(expected) {
|
|
3482
|
+
return this.to.lessThan(expected);
|
|
3483
|
+
});
|
|
3484
|
+
def("toBeLessThanOrEqual", function(expected) {
|
|
3485
|
+
return this.to.lessThanOrEqual(expected);
|
|
3486
|
+
});
|
|
3487
|
+
def("toBeNaN", function() {
|
|
3488
|
+
return this.be.NaN;
|
|
3489
|
+
});
|
|
3490
|
+
def("toBeUndefined", function() {
|
|
3491
|
+
return this.be.undefined;
|
|
3492
|
+
});
|
|
3493
|
+
def("toBeNull", function() {
|
|
3494
|
+
return this.be.null;
|
|
3495
|
+
});
|
|
3496
|
+
def("toBeDefined", function() {
|
|
3497
|
+
return this.not.be.undefined;
|
|
3498
|
+
});
|
|
3499
|
+
def("toBeInstanceOf", function(obj) {
|
|
3500
|
+
return this.instanceOf(obj);
|
|
3501
|
+
});
|
|
3502
|
+
def("toHaveLength", function(length) {
|
|
3503
|
+
return this.have.length(length);
|
|
3504
|
+
});
|
|
3505
|
+
def("toHaveProperty", function(...args) {
|
|
3506
|
+
return this.have.deep.nested.property(...args);
|
|
3507
|
+
});
|
|
3508
|
+
def("toBeCloseTo", function(number, numDigits = 2) {
|
|
3509
|
+
utils.expectTypes(this, ["number"]);
|
|
3510
|
+
return this.closeTo(number, numDigits);
|
|
3511
|
+
});
|
|
3512
|
+
function isSpy(putativeSpy) {
|
|
3513
|
+
return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
|
|
3514
|
+
}
|
|
3515
|
+
const assertIsMock = (assertion) => {
|
|
3516
|
+
if (!isSpy(assertion._obj))
|
|
3517
|
+
throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
|
|
3518
|
+
};
|
|
3519
|
+
const getSpy = (assertion) => {
|
|
3520
|
+
assertIsMock(assertion);
|
|
3521
|
+
return assertion._obj;
|
|
3564
3522
|
};
|
|
3523
|
+
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
|
|
3524
|
+
const spy = getSpy(this);
|
|
3525
|
+
return this.assert(spy.callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number, spy.callCount);
|
|
3526
|
+
});
|
|
3527
|
+
def("toHaveBeenCalledOnce", function() {
|
|
3528
|
+
const spy = getSpy(this);
|
|
3529
|
+
return this.assert(spy.callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1, spy.callCount);
|
|
3530
|
+
});
|
|
3531
|
+
def(["toHaveBeenCalled", "toBeCalled"], function() {
|
|
3532
|
+
const spy = getSpy(this);
|
|
3533
|
+
return this.assert(spy.called, "expected spy to be called at least once", "expected spy to not be called at all", true, spy.called);
|
|
3534
|
+
});
|
|
3535
|
+
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
|
3536
|
+
const spy = getSpy(this);
|
|
3537
|
+
const pass = spy.calls.some((callArg) => equals(callArg, args));
|
|
3538
|
+
return this.assert(pass, "expected spy to be called with arguments: #{exp}", "expected spy to not be called with arguments: #{exp}", args);
|
|
3539
|
+
});
|
|
3540
|
+
const ordinalOf = (i) => {
|
|
3541
|
+
const j = i % 10;
|
|
3542
|
+
const k = i % 100;
|
|
3543
|
+
if (j === 1 && k !== 11)
|
|
3544
|
+
return `${i}st`;
|
|
3545
|
+
if (j === 2 && k !== 12)
|
|
3546
|
+
return `${i}nd`;
|
|
3547
|
+
if (j === 3 && k !== 13)
|
|
3548
|
+
return `${i}rd`;
|
|
3549
|
+
return `${i}th`;
|
|
3550
|
+
};
|
|
3551
|
+
def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
|
|
3552
|
+
const spy = getSpy(this);
|
|
3553
|
+
const nthCall = spy.calls[times - 1];
|
|
3554
|
+
this.assert(equals(nthCall, args), `expected ${ordinalOf(times)} spy call to have been called with #{exp}`, `expected ${ordinalOf(times)} spy call to not have been called with #{exp}`, args, nthCall);
|
|
3555
|
+
});
|
|
3556
|
+
def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
|
|
3557
|
+
const spy = getSpy(this);
|
|
3558
|
+
const lastCall = spy.calls.at(-1);
|
|
3559
|
+
this.assert(equals(lastCall, args), "expected last spy call to have been called with #{exp}", "expected last spy call to not have been called with #{exp}", args, lastCall);
|
|
3560
|
+
});
|
|
3561
|
+
def(["toThrow", "toThrowError"], function(expected) {
|
|
3562
|
+
const negate = utils.flag(this, "negate");
|
|
3563
|
+
if (negate)
|
|
3564
|
+
this.not.to.throw(expected);
|
|
3565
|
+
else
|
|
3566
|
+
this.to.throw(expected);
|
|
3567
|
+
});
|
|
3568
|
+
def(["toHaveReturned", "toReturn"], function() {
|
|
3569
|
+
const spy = getSpy(this);
|
|
3570
|
+
const calledAndNotThrew = spy.called && !spy.results.some(([type]) => type === "error");
|
|
3571
|
+
this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy to not be successfully called", calledAndNotThrew, !calledAndNotThrew);
|
|
3572
|
+
});
|
|
3573
|
+
def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
|
|
3574
|
+
const spy = getSpy(this);
|
|
3575
|
+
const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
|
|
3576
|
+
this.assert(successfullReturns === times, `expected spy to be successfully called ${times} times`, `expected spy to not be successfully called ${times} times`, `expected number of returns: ${times}`, `received number of returns: ${successfullReturns}`);
|
|
3577
|
+
});
|
|
3578
|
+
def(["toHaveReturnedWith", "toReturnWith"], function(value) {
|
|
3579
|
+
const spy = getSpy(this);
|
|
3580
|
+
const pass = spy.results.some(([type, result]) => type === "ok" && equals(value, result));
|
|
3581
|
+
this.assert(pass, "expected spy to be successfully called with #{exp}", "expected spy to not be successfully called with #{exp}", value);
|
|
3582
|
+
});
|
|
3583
|
+
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
|
3584
|
+
const spy = getSpy(this);
|
|
3585
|
+
const lastResult = spy.returns.at(-1);
|
|
3586
|
+
const pass = equals(lastResult, value);
|
|
3587
|
+
this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
|
|
3588
|
+
});
|
|
3589
|
+
def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
|
|
3590
|
+
const spy = getSpy(this);
|
|
3591
|
+
const isNot = utils.flag(this, "negate");
|
|
3592
|
+
const [callType, callResult] = spy.results[nthCall - 1];
|
|
3593
|
+
const ordinalCall = `${ordinalOf(nthCall)} call`;
|
|
3594
|
+
if (!isNot && callType === "error")
|
|
3595
|
+
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
|
|
3596
|
+
const nthCallReturn = equals(callResult, value);
|
|
3597
|
+
this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call to not return #{exp}`, value, callResult);
|
|
3598
|
+
});
|
|
3599
|
+
};
|
|
3600
|
+
|
|
3601
|
+
class AsymmetricMatcher {
|
|
3602
|
+
constructor(sample, inverse = false) {
|
|
3603
|
+
this.sample = sample;
|
|
3604
|
+
this.inverse = inverse;
|
|
3605
|
+
}
|
|
3606
|
+
getMatcherContext() {
|
|
3607
|
+
return {
|
|
3608
|
+
equals,
|
|
3609
|
+
isNot: this.inverse,
|
|
3610
|
+
utils: matcherUtils
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3565
3613
|
}
|
|
3614
|
+
class StringContaining extends AsymmetricMatcher {
|
|
3615
|
+
constructor(sample, inverse = false) {
|
|
3616
|
+
if (!isA("String", sample))
|
|
3617
|
+
throw new Error("Expected is not a string");
|
|
3618
|
+
super(sample, inverse);
|
|
3619
|
+
}
|
|
3620
|
+
asymmetricMatch(other) {
|
|
3621
|
+
const result = isA("String", other) && other.includes(this.sample);
|
|
3622
|
+
return this.inverse ? !result : result;
|
|
3623
|
+
}
|
|
3624
|
+
toString() {
|
|
3625
|
+
return `String${this.inverse ? "Not" : ""}Containing`;
|
|
3626
|
+
}
|
|
3627
|
+
getExpectedType() {
|
|
3628
|
+
return "string";
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
const JestAsymmetricMatchers = (chai, utils) => {
|
|
3632
|
+
utils.addMethod(chai.expect, "stringContaining", (expected) => new StringContaining(expected));
|
|
3633
|
+
};
|
|
3566
3634
|
|
|
3567
3635
|
let installed = false;
|
|
3568
3636
|
async function setupChai() {
|
|
3569
3637
|
if (installed)
|
|
3570
3638
|
return;
|
|
3571
|
-
chai.use(JestExtend
|
|
3572
|
-
chai.use(JestChaiExpect
|
|
3639
|
+
chai.use(JestExtend);
|
|
3640
|
+
chai.use(JestChaiExpect);
|
|
3573
3641
|
chai.use(Subset);
|
|
3574
|
-
chai.use(SnapshotPlugin
|
|
3642
|
+
chai.use(SnapshotPlugin);
|
|
3643
|
+
chai.use(JestAsymmetricMatchers);
|
|
3575
3644
|
installed = true;
|
|
3576
3645
|
}
|
|
3577
3646
|
|
package/dist/index.d.ts
CHANGED
|
@@ -572,8 +572,8 @@ interface JestMockCompat<TArgs extends any[] = any[], TReturns = any> {
|
|
|
572
572
|
mockReturnThis(): this;
|
|
573
573
|
mockReturnValue(obj: TReturns): this;
|
|
574
574
|
mockReturnValueOnce(obj: TReturns): this;
|
|
575
|
-
mockResolvedValue(obj:
|
|
576
|
-
mockResolvedValueOnce(obj:
|
|
575
|
+
mockResolvedValue(obj: Awaited<TReturns>): this;
|
|
576
|
+
mockResolvedValueOnce(obj: Awaited<TReturns>): this;
|
|
577
577
|
mockRejectedValue(obj: any): this;
|
|
578
578
|
mockRejectedValueOnce(obj: any): this;
|
|
579
579
|
}
|
|
@@ -581,7 +581,7 @@ interface JestMockCompatFn<TArgs extends any[] = any, TReturns = any> extends Je
|
|
|
581
581
|
(...args: TArgs): TReturns;
|
|
582
582
|
}
|
|
583
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
|
|
584
|
+
declare type Awaited<T> = T extends Promise<infer R> ? R : never;
|
|
585
585
|
declare function fn<TArgs extends any[] = any[], R = any>(): JestMockCompatFn<TArgs, R>;
|
|
586
586
|
declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): JestMockCompatFn<TArgs, R>;
|
|
587
587
|
|
|
@@ -602,8 +602,10 @@ declare global {
|
|
|
602
602
|
namespace Chai {
|
|
603
603
|
interface ExpectStatic {
|
|
604
604
|
extend(expects: MatchersObject): void;
|
|
605
|
+
stringContaining(expected: string): void;
|
|
605
606
|
}
|
|
606
607
|
interface Assertion {
|
|
608
|
+
chaiEqual(expected: any): void;
|
|
607
609
|
toMatchSnapshot(message?: string): Assertion;
|
|
608
610
|
toMatchInlineSnapshot(snapshot?: string, message?: string): Assertion;
|
|
609
611
|
matchSnapshot(message?: string): Assertion;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -80,7 +80,8 @@
|
|
|
80
80
|
"pkg-types": "^0.3.2",
|
|
81
81
|
"pretty-format": "^27.4.2",
|
|
82
82
|
"rollup": "^2.61.1",
|
|
83
|
-
"strip-ansi": "^7.0.1"
|
|
83
|
+
"strip-ansi": "^7.0.1",
|
|
84
|
+
"typescript": "^4.5.4"
|
|
84
85
|
},
|
|
85
86
|
"peerDependencies": {
|
|
86
87
|
"c8": "*",
|
|
@@ -106,5 +107,6 @@
|
|
|
106
107
|
"build": "rimraf dist && rollup -c",
|
|
107
108
|
"dev": "rollup -c --watch src",
|
|
108
109
|
"typecheck": "tsc --noEmit"
|
|
109
|
-
}
|
|
110
|
+
},
|
|
111
|
+
"readme": "# vitest\n\n[](https://www.npmjs.com/package/vitest)\n\nA blazing fast unit test framework powered by Vite.\n\n> **This project is currently in closed beta exclusively for Sponsors.**<br>\n> Become a Sponsor of [@patak-dev](https://github.com/sponsors/patak-dev) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.\n> Learn more at [vitest.dev](https://vitest.dev)\n"
|
|
110
112
|
}
|