vitest 0.0.85 → 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/bin/vitest.mjs +2 -0
- package/dist/cli.js +25 -9
- package/dist/entry.js +286 -209
- package/dist/{error-c651f5ae.js → error-309196c9.js} +5 -68
- package/dist/{global-e172af93.js → global-f3eab75a.js} +2 -2
- package/dist/index-722fb5a5.js +122 -0
- package/dist/{index-c033f95e.js → index-733e7378.js} +157 -156
- package/dist/index.d.ts +49 -2
- package/dist/index.js +2 -2
- package/dist/node.js +5 -5
- package/dist/{suite-0e21bf9b.js → suite-b8c6cb53.js} +2 -2
- package/dist/utils-385e2d09.js +143 -0
- package/dist/utils.js +3 -0
- package/dist/worker.js +8259 -35
- package/package.json +10 -5
- package/dist/index-906ac3f9.js +0 -34
- package/dist/utils-9dcc4050.js +0 -64
package/dist/entry.js
CHANGED
|
@@ -5,12 +5,13 @@ import chai, { expect, util } from 'chai';
|
|
|
5
5
|
import Subset from 'chai-subset';
|
|
6
6
|
import path, { basename } from 'path';
|
|
7
7
|
import { r as rpc, s as send } from './rpc-7de86f29.js';
|
|
8
|
-
import { g as getNames, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren,
|
|
8
|
+
import { g as getNames, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, d as hasTests, h as hasFailed } from './utils-385e2d09.js';
|
|
9
9
|
import fs from 'fs';
|
|
10
|
-
import {
|
|
10
|
+
import { u as unifiedDiff } from './error-309196c9.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
|
-
import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-
|
|
12
|
+
import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-b8c6cb53.js';
|
|
13
13
|
import { n as nanoid } from './index-9e71c815.js';
|
|
14
|
+
import 'module';
|
|
14
15
|
import 'tty';
|
|
15
16
|
import 'source-map';
|
|
16
17
|
|
|
@@ -713,12 +714,12 @@ function printObjectProperties(val, config, indentation, depth, refs, printer) {
|
|
|
713
714
|
return result;
|
|
714
715
|
}
|
|
715
716
|
|
|
716
|
-
var AsymmetricMatcher$
|
|
717
|
+
var AsymmetricMatcher$3 = {};
|
|
717
718
|
|
|
718
|
-
Object.defineProperty(AsymmetricMatcher$
|
|
719
|
+
Object.defineProperty(AsymmetricMatcher$3, '__esModule', {
|
|
719
720
|
value: true
|
|
720
721
|
});
|
|
721
|
-
AsymmetricMatcher$
|
|
722
|
+
AsymmetricMatcher$3.default = AsymmetricMatcher$3.test = AsymmetricMatcher$3.serialize = void 0;
|
|
722
723
|
|
|
723
724
|
var _collections$3 = collections;
|
|
724
725
|
|
|
@@ -819,17 +820,17 @@ const serialize$7 = (val, config, indentation, depth, refs, printer) => {
|
|
|
819
820
|
return val.toAsymmetricMatcher();
|
|
820
821
|
};
|
|
821
822
|
|
|
822
|
-
AsymmetricMatcher$
|
|
823
|
+
AsymmetricMatcher$3.serialize = serialize$7;
|
|
823
824
|
|
|
824
825
|
const test$6 = val => val && val.$$typeof === asymmetricMatcher;
|
|
825
826
|
|
|
826
|
-
AsymmetricMatcher$
|
|
827
|
+
AsymmetricMatcher$3.test = test$6;
|
|
827
828
|
const plugin$6 = {
|
|
828
829
|
serialize: serialize$7,
|
|
829
830
|
test: test$6
|
|
830
831
|
};
|
|
831
832
|
var _default$7 = plugin$6;
|
|
832
|
-
AsymmetricMatcher$
|
|
833
|
+
AsymmetricMatcher$3.default = _default$7;
|
|
833
834
|
|
|
834
835
|
var ConvertAnsi = {};
|
|
835
836
|
|
|
@@ -2072,7 +2073,7 @@ var _ansiStyles = _interopRequireDefault(ansiStyles.exports);
|
|
|
2072
2073
|
var _collections = collections;
|
|
2073
2074
|
|
|
2074
2075
|
var _AsymmetricMatcher = _interopRequireDefault(
|
|
2075
|
-
AsymmetricMatcher$
|
|
2076
|
+
AsymmetricMatcher$3
|
|
2076
2077
|
);
|
|
2077
2078
|
|
|
2078
2079
|
var _ConvertAnsi = _interopRequireDefault(ConvertAnsi);
|
|
@@ -2662,7 +2663,7 @@ const {
|
|
|
2662
2663
|
Immutable: Immutable$1,
|
|
2663
2664
|
ReactElement: ReactElement$1,
|
|
2664
2665
|
ReactTestComponent: ReactTestComponent$1,
|
|
2665
|
-
AsymmetricMatcher: AsymmetricMatcher$
|
|
2666
|
+
AsymmetricMatcher: AsymmetricMatcher$2
|
|
2666
2667
|
} = plugins_1;
|
|
2667
2668
|
let PLUGINS$1 = [
|
|
2668
2669
|
ReactTestComponent$1,
|
|
@@ -2670,7 +2671,7 @@ let PLUGINS$1 = [
|
|
|
2670
2671
|
DOMElement$1,
|
|
2671
2672
|
DOMCollection$1,
|
|
2672
2673
|
Immutable$1,
|
|
2673
|
-
AsymmetricMatcher$
|
|
2674
|
+
AsymmetricMatcher$2
|
|
2674
2675
|
];
|
|
2675
2676
|
const getSerializers = () => PLUGINS$1;
|
|
2676
2677
|
|
|
@@ -2761,7 +2762,7 @@ class SnapshotState {
|
|
|
2761
2762
|
this._snapshotData = data;
|
|
2762
2763
|
this._dirty = dirty;
|
|
2763
2764
|
this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
|
|
2764
|
-
this._counters = new Map();
|
|
2765
|
+
this._counters = /* @__PURE__ */ new Map();
|
|
2765
2766
|
this._index = 0;
|
|
2766
2767
|
this.expand = options.expand || false;
|
|
2767
2768
|
this.added = 0;
|
|
@@ -2783,7 +2784,7 @@ class SnapshotState {
|
|
|
2783
2784
|
}
|
|
2784
2785
|
clear() {
|
|
2785
2786
|
this._snapshotData = this._initialData;
|
|
2786
|
-
this._counters = new Map();
|
|
2787
|
+
this._counters = /* @__PURE__ */ new Map();
|
|
2787
2788
|
this._index = 0;
|
|
2788
2789
|
this.added = 0;
|
|
2789
2790
|
this.matched = 0;
|
|
@@ -2975,20 +2976,18 @@ function getSnapshotClient() {
|
|
|
2975
2976
|
_client = new SnapshotClient();
|
|
2976
2977
|
return _client;
|
|
2977
2978
|
}
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
utils.addMethod(chai.Assertion.prototype, key, function(message) {
|
|
2982
|
-
const expected = utils.flag(this, "object");
|
|
2983
|
-
getSnapshotClient().assert(expected, message);
|
|
2984
|
-
});
|
|
2985
|
-
}
|
|
2986
|
-
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) {
|
|
2987
2982
|
const expected = utils.flag(this, "object");
|
|
2988
|
-
getSnapshotClient().assert(expected, message
|
|
2983
|
+
getSnapshotClient().assert(expected, message);
|
|
2989
2984
|
});
|
|
2990
|
-
}
|
|
2991
|
-
|
|
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
|
+
};
|
|
2992
2991
|
|
|
2993
2992
|
const EXPECTED_COLOR = c$1.green;
|
|
2994
2993
|
const RECEIVED_COLOR = c$1.red;
|
|
@@ -2996,7 +2995,7 @@ const INVERTED_COLOR = c$1.inverse;
|
|
|
2996
2995
|
const BOLD_WEIGHT = c$1.bold;
|
|
2997
2996
|
const DIM_COLOR = c$1.dim;
|
|
2998
2997
|
const {
|
|
2999
|
-
AsymmetricMatcher,
|
|
2998
|
+
AsymmetricMatcher: AsymmetricMatcher$1,
|
|
3000
2999
|
DOMCollection,
|
|
3001
3000
|
DOMElement,
|
|
3002
3001
|
Immutable,
|
|
@@ -3009,7 +3008,7 @@ const PLUGINS = [
|
|
|
3009
3008
|
DOMElement,
|
|
3010
3009
|
DOMCollection,
|
|
3011
3010
|
Immutable,
|
|
3012
|
-
AsymmetricMatcher
|
|
3011
|
+
AsymmetricMatcher$1
|
|
3013
3012
|
];
|
|
3014
3013
|
function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
|
|
3015
3014
|
const {
|
|
@@ -3105,6 +3104,20 @@ function equals(a, b, customTesters, strictCheck) {
|
|
|
3105
3104
|
function isAsymmetric(obj) {
|
|
3106
3105
|
return !!obj && isA("Function", obj.asymmetricMatch);
|
|
3107
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
|
+
}
|
|
3108
3121
|
function asymmetricMatch(a, b) {
|
|
3109
3122
|
const asymmetricA = isAsymmetric(a);
|
|
3110
3123
|
const asymmetricB = isAsymmetric(b);
|
|
@@ -3295,7 +3308,7 @@ const hasPropertyInObject = (object, key) => {
|
|
|
3295
3308
|
};
|
|
3296
3309
|
const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
|
|
3297
3310
|
const subsetEquality = (object, subset) => {
|
|
3298
|
-
const subsetEqualityWithContext = (seenReferences = new WeakMap()) => (object2, subset2) => {
|
|
3311
|
+
const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
|
|
3299
3312
|
if (!isObjectWithKeys(subset2))
|
|
3300
3313
|
return void 0;
|
|
3301
3314
|
return Object.keys(subset2).every((key) => {
|
|
@@ -3376,198 +3389,258 @@ function JestExtendPlugin(expects) {
|
|
|
3376
3389
|
});
|
|
3377
3390
|
};
|
|
3378
3391
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
};
|
|
3385
|
-
}
|
|
3392
|
+
const JestExtend = (chai2, utils) => {
|
|
3393
|
+
utils.addMethod(chai2.expect, "extend", (expects) => {
|
|
3394
|
+
chai2.use(JestExtendPlugin(expects));
|
|
3395
|
+
});
|
|
3396
|
+
};
|
|
3386
3397
|
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
utils.addMethod(chai.Assertion.prototype, n, fn);
|
|
3392
|
-
};
|
|
3393
|
-
if (Array.isArray(name))
|
|
3394
|
-
name.forEach((n) => addMethod(n));
|
|
3395
|
-
else
|
|
3396
|
-
addMethod(name);
|
|
3397
|
-
}
|
|
3398
|
-
def("toEqual", function(expected) {
|
|
3399
|
-
return this.eql(expected);
|
|
3400
|
-
});
|
|
3401
|
-
def("toStrictEqual", function(expected) {
|
|
3402
|
-
return this.equal(expected);
|
|
3403
|
-
});
|
|
3404
|
-
def("toBe", function(expected) {
|
|
3405
|
-
return this.equal(expected);
|
|
3406
|
-
});
|
|
3407
|
-
def("toMatchObject", function(expected) {
|
|
3408
|
-
return this.containSubset(expected);
|
|
3409
|
-
});
|
|
3410
|
-
def("toMatch", function(expected) {
|
|
3411
|
-
if (typeof expected === "string")
|
|
3412
|
-
return this.include(expected);
|
|
3413
|
-
else
|
|
3414
|
-
return this.match(expected);
|
|
3415
|
-
});
|
|
3416
|
-
def("toContain", function(item) {
|
|
3417
|
-
return this.contain(item);
|
|
3418
|
-
});
|
|
3419
|
-
def("toContainEqual", function(expected) {
|
|
3420
|
-
const obj = utils.flag(this, "object");
|
|
3421
|
-
const index = Array.from(obj).findIndex((item) => {
|
|
3422
|
-
try {
|
|
3423
|
-
chai.assert.deepEqual(item, expected);
|
|
3424
|
-
} catch {
|
|
3425
|
-
return false;
|
|
3426
|
-
}
|
|
3427
|
-
return true;
|
|
3428
|
-
});
|
|
3429
|
-
this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
|
|
3430
|
-
});
|
|
3431
|
-
def("toBeTruthy", function() {
|
|
3432
|
-
const obj = utils.flag(this, "object");
|
|
3433
|
-
this.assert(Boolean(obj), "expected #{this} to be truthy", "expected #{this} to not be truthy", obj);
|
|
3434
|
-
});
|
|
3435
|
-
def("toBeFalsy", function() {
|
|
3436
|
-
const obj = utils.flag(this, "object");
|
|
3437
|
-
this.assert(!obj, "expected #{this} to be falsy", "expected #{this} to not be falsy", obj);
|
|
3438
|
-
});
|
|
3439
|
-
def("toBeGreaterThan", function(expected) {
|
|
3440
|
-
return this.to.greaterThan(expected);
|
|
3441
|
-
});
|
|
3442
|
-
def("toBeGreaterThanOrEqual", function(expected) {
|
|
3443
|
-
return this.to.greaterThanOrEqual(expected);
|
|
3444
|
-
});
|
|
3445
|
-
def("toBeLessThan", function(expected) {
|
|
3446
|
-
return this.to.lessThan(expected);
|
|
3447
|
-
});
|
|
3448
|
-
def("toBeLessThanOrEqual", function(expected) {
|
|
3449
|
-
return this.to.lessThanOrEqual(expected);
|
|
3450
|
-
});
|
|
3451
|
-
def("toBeNaN", function() {
|
|
3452
|
-
return this.be.NaN;
|
|
3453
|
-
});
|
|
3454
|
-
def("toBeUndefined", function() {
|
|
3455
|
-
return this.be.undefined;
|
|
3456
|
-
});
|
|
3457
|
-
def("toBeNull", function() {
|
|
3458
|
-
return this.be.null;
|
|
3459
|
-
});
|
|
3460
|
-
def("toBeDefined", function() {
|
|
3461
|
-
return this.not.be.undefined;
|
|
3462
|
-
});
|
|
3463
|
-
def("toBeInstanceOf", function(obj) {
|
|
3464
|
-
return this.instanceOf(obj);
|
|
3465
|
-
});
|
|
3466
|
-
def("toHaveLength", function(length) {
|
|
3467
|
-
return this.have.length(length);
|
|
3468
|
-
});
|
|
3469
|
-
def("toHaveProperty", function(...args) {
|
|
3470
|
-
return this.have.deep.nested.property(...args);
|
|
3471
|
-
});
|
|
3472
|
-
def("toBeCloseTo", function(number, numDigits = 2) {
|
|
3473
|
-
utils.expectTypes(this, ["number"]);
|
|
3474
|
-
return this.closeTo(number, numDigits);
|
|
3475
|
-
});
|
|
3476
|
-
function isSpy(putativeSpy) {
|
|
3477
|
-
return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
|
|
3478
|
-
}
|
|
3479
|
-
const assertIsMock = (assertion) => {
|
|
3480
|
-
if (!isSpy(assertion._obj))
|
|
3481
|
-
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);
|
|
3482
3402
|
};
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
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
|
+
}
|
|
3486
3421
|
};
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
const spy = getSpy(this);
|
|
3498
|
-
const pass = spy.calls.some((callArg) => equals(callArg, args));
|
|
3499
|
-
return this.assert(pass, "expected spy to be called with arguments: #{exp}", "expected spy to not be called with arguments: #{exp}", args);
|
|
3500
|
-
});
|
|
3501
|
-
const ordinalOf = (i) => {
|
|
3502
|
-
const j = i % 10;
|
|
3503
|
-
const k = i % 100;
|
|
3504
|
-
if (j === 1 && k !== 11)
|
|
3505
|
-
return `${i}st`;
|
|
3506
|
-
if (j === 2 && k !== 12)
|
|
3507
|
-
return `${i}nd`;
|
|
3508
|
-
if (j === 3 && k !== 13)
|
|
3509
|
-
return `${i}rd`;
|
|
3510
|
-
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
|
+
}
|
|
3511
3432
|
};
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
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
|
-
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
|
3545
|
-
const spy = getSpy(this);
|
|
3546
|
-
const lastResult = spy.returns.at(-1);
|
|
3547
|
-
const pass = equals(lastResult, value);
|
|
3548
|
-
this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
|
|
3549
|
-
});
|
|
3550
|
-
def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
|
|
3551
|
-
const spy = getSpy(this);
|
|
3552
|
-
const isNot = utils.flag(this, "negate");
|
|
3553
|
-
const [callType, callResult] = spy.results[nthCall - 1];
|
|
3554
|
-
const ordinalCall = `${ordinalOf(nthCall)} call`;
|
|
3555
|
-
if (!isNot && callType === "error")
|
|
3556
|
-
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
|
|
3557
|
-
const nthCallReturn = equals(callResult, value);
|
|
3558
|
-
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;
|
|
3559
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;
|
|
3560
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
|
+
}
|
|
3561
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
|
+
};
|
|
3562
3634
|
|
|
3563
3635
|
let installed = false;
|
|
3564
3636
|
async function setupChai() {
|
|
3565
3637
|
if (installed)
|
|
3566
3638
|
return;
|
|
3567
|
-
chai.use(JestExtend
|
|
3568
|
-
chai.use(JestChaiExpect
|
|
3639
|
+
chai.use(JestExtend);
|
|
3640
|
+
chai.use(JestChaiExpect);
|
|
3569
3641
|
chai.use(Subset);
|
|
3570
|
-
chai.use(SnapshotPlugin
|
|
3642
|
+
chai.use(SnapshotPlugin);
|
|
3643
|
+
chai.use(JestAsymmetricMatchers);
|
|
3571
3644
|
installed = true;
|
|
3572
3645
|
}
|
|
3573
3646
|
|
|
@@ -3579,7 +3652,7 @@ async function setupGlobalEnv(config) {
|
|
|
3579
3652
|
setupConsoleLogSpy();
|
|
3580
3653
|
await setupChai();
|
|
3581
3654
|
if (config.global)
|
|
3582
|
-
(await import('./global-
|
|
3655
|
+
(await import('./global-f3eab75a.js')).registerApiGlobally();
|
|
3583
3656
|
}
|
|
3584
3657
|
function setupConsoleLogSpy() {
|
|
3585
3658
|
const stdout = new Writable({
|
|
@@ -3707,7 +3780,11 @@ async function collectTests(paths, config) {
|
|
|
3707
3780
|
}
|
|
3708
3781
|
|
|
3709
3782
|
async function callSuiteHook(suite, name, args) {
|
|
3783
|
+
if (name === "beforeEach" && suite.suite)
|
|
3784
|
+
await callSuiteHook(suite.suite, name, args);
|
|
3710
3785
|
await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)));
|
|
3786
|
+
if (name === "afterEach" && suite.suite)
|
|
3787
|
+
await callSuiteHook(suite.suite, name, args);
|
|
3711
3788
|
}
|
|
3712
3789
|
function updateTask(task) {
|
|
3713
3790
|
return rpc("onTaskUpdate", [task.id, task.result]);
|