vitest 0.0.89 → 0.0.93

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/entry.js CHANGED
@@ -1,3 +1,4 @@
1
+ import fs, { promises } from 'fs';
1
2
  import { Console } from 'console';
2
3
  import { Writable } from 'stream';
3
4
  import { importModule } from 'local-pkg';
@@ -5,13 +6,11 @@ import chai, { expect, util } from 'chai';
5
6
  import Subset from 'chai-subset';
6
7
  import path, { basename } from 'path';
7
8
  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';
9
- import fs from 'fs';
10
- import { u as unifiedDiff } from './error-309196c9.js';
9
+ import { g as getNames, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, f as hasTests, h as hasFailed } from './utils-576876dc.js';
10
+ import { u as unifiedDiff } from './error-bf2213e4.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';
14
- import 'module';
15
14
  import 'tty';
16
15
  import 'source-map';
17
16
 
@@ -714,12 +713,12 @@ function printObjectProperties(val, config, indentation, depth, refs, printer) {
714
713
  return result;
715
714
  }
716
715
 
717
- var AsymmetricMatcher$2 = {};
716
+ var AsymmetricMatcher$3 = {};
718
717
 
719
- Object.defineProperty(AsymmetricMatcher$2, '__esModule', {
718
+ Object.defineProperty(AsymmetricMatcher$3, '__esModule', {
720
719
  value: true
721
720
  });
722
- AsymmetricMatcher$2.default = AsymmetricMatcher$2.test = AsymmetricMatcher$2.serialize = void 0;
721
+ AsymmetricMatcher$3.default = AsymmetricMatcher$3.test = AsymmetricMatcher$3.serialize = void 0;
723
722
 
724
723
  var _collections$3 = collections;
725
724
 
@@ -820,17 +819,17 @@ const serialize$7 = (val, config, indentation, depth, refs, printer) => {
820
819
  return val.toAsymmetricMatcher();
821
820
  };
822
821
 
823
- AsymmetricMatcher$2.serialize = serialize$7;
822
+ AsymmetricMatcher$3.serialize = serialize$7;
824
823
 
825
824
  const test$6 = val => val && val.$$typeof === asymmetricMatcher;
826
825
 
827
- AsymmetricMatcher$2.test = test$6;
826
+ AsymmetricMatcher$3.test = test$6;
828
827
  const plugin$6 = {
829
828
  serialize: serialize$7,
830
829
  test: test$6
831
830
  };
832
831
  var _default$7 = plugin$6;
833
- AsymmetricMatcher$2.default = _default$7;
832
+ AsymmetricMatcher$3.default = _default$7;
834
833
 
835
834
  var ConvertAnsi = {};
836
835
 
@@ -2073,7 +2072,7 @@ var _ansiStyles = _interopRequireDefault(ansiStyles.exports);
2073
2072
  var _collections = collections;
2074
2073
 
2075
2074
  var _AsymmetricMatcher = _interopRequireDefault(
2076
- AsymmetricMatcher$2
2075
+ AsymmetricMatcher$3
2077
2076
  );
2078
2077
 
2079
2078
  var _ConvertAnsi = _interopRequireDefault(ConvertAnsi);
@@ -2663,7 +2662,7 @@ const {
2663
2662
  Immutable: Immutable$1,
2664
2663
  ReactElement: ReactElement$1,
2665
2664
  ReactTestComponent: ReactTestComponent$1,
2666
- AsymmetricMatcher: AsymmetricMatcher$1
2665
+ AsymmetricMatcher: AsymmetricMatcher$2
2667
2666
  } = plugins_1;
2668
2667
  let PLUGINS$1 = [
2669
2668
  ReactTestComponent$1,
@@ -2671,7 +2670,7 @@ let PLUGINS$1 = [
2671
2670
  DOMElement$1,
2672
2671
  DOMCollection$1,
2673
2672
  Immutable$1,
2674
- AsymmetricMatcher$1
2673
+ AsymmetricMatcher$2
2675
2674
  ];
2676
2675
  const getSerializers = () => PLUGINS$1;
2677
2676
 
@@ -2976,20 +2975,18 @@ function getSnapshotClient() {
2976
2975
  _client = new SnapshotClient();
2977
2976
  return _client;
2978
2977
  }
2979
- function SnapshotPlugin() {
2980
- return function(chai, utils) {
2981
- for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
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) {
2978
+ const SnapshotPlugin = (chai, utils) => {
2979
+ for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
2980
+ utils.addMethod(chai.Assertion.prototype, key, function(message) {
2988
2981
  const expected = utils.flag(this, "object");
2989
- getSnapshotClient().assert(expected, message, inlineSnapshot);
2982
+ getSnapshotClient().assert(expected, message);
2990
2983
  });
2991
- };
2992
- }
2984
+ }
2985
+ utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function(inlineSnapshot, message) {
2986
+ const expected = utils.flag(this, "object");
2987
+ getSnapshotClient().assert(expected, message, inlineSnapshot);
2988
+ });
2989
+ };
2993
2990
 
2994
2991
  const EXPECTED_COLOR = c$1.green;
2995
2992
  const RECEIVED_COLOR = c$1.red;
@@ -2997,7 +2994,7 @@ const INVERTED_COLOR = c$1.inverse;
2997
2994
  const BOLD_WEIGHT = c$1.bold;
2998
2995
  const DIM_COLOR = c$1.dim;
2999
2996
  const {
3000
- AsymmetricMatcher,
2997
+ AsymmetricMatcher: AsymmetricMatcher$1,
3001
2998
  DOMCollection,
3002
2999
  DOMElement,
3003
3000
  Immutable,
@@ -3010,7 +3007,7 @@ const PLUGINS = [
3010
3007
  DOMElement,
3011
3008
  DOMCollection,
3012
3009
  Immutable,
3013
- AsymmetricMatcher
3010
+ AsymmetricMatcher$1
3014
3011
  ];
3015
3012
  function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
3016
3013
  const {
@@ -3106,6 +3103,20 @@ function equals(a, b, customTesters, strictCheck) {
3106
3103
  function isAsymmetric(obj) {
3107
3104
  return !!obj && isA("Function", obj.asymmetricMatch);
3108
3105
  }
3106
+ function hasAsymmetric(obj, seen = /* @__PURE__ */ new Set()) {
3107
+ if (seen.has(obj))
3108
+ return false;
3109
+ seen.add(obj);
3110
+ if (isAsymmetric(obj))
3111
+ return true;
3112
+ if (Array.isArray(obj))
3113
+ return obj.some((i) => hasAsymmetric(i, seen));
3114
+ if (obj instanceof Set)
3115
+ return Array.from(obj).some((i) => hasAsymmetric(i, seen));
3116
+ if (isObject(obj))
3117
+ return Object.values(obj).some((v) => hasAsymmetric(v, seen));
3118
+ return false;
3119
+ }
3109
3120
  function asymmetricMatch(a, b) {
3110
3121
  const asymmetricA = isAsymmetric(a);
3111
3122
  const asymmetricB = isAsymmetric(b);
@@ -3377,201 +3388,388 @@ function JestExtendPlugin(expects) {
3377
3388
  });
3378
3389
  };
3379
3390
  }
3380
- function JestExtend() {
3381
- return (chai2, utils) => {
3382
- utils.addMethod(chai2.expect, "extend", (expects) => {
3383
- chai2.use(JestExtendPlugin(expects));
3384
- });
3385
- };
3386
- }
3391
+ const JestExtend = (chai2, utils) => {
3392
+ utils.addMethod(chai2.expect, "extend", (expects) => {
3393
+ chai2.use(JestExtendPlugin(expects));
3394
+ });
3395
+ };
3387
3396
 
3388
- function JestChaiExpect() {
3389
- return (chai, utils) => {
3390
- function def(name, fn) {
3391
- const addMethod = (n) => {
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!`);
3397
+ const JestChaiExpect = (chai, utils) => {
3398
+ function def(name, fn) {
3399
+ const addMethod = (n) => {
3400
+ utils.addMethod(chai.Assertion.prototype, n, fn);
3483
3401
  };
3484
- const getSpy = (assertion) => {
3485
- assertIsMock(assertion);
3486
- return assertion._obj;
3402
+ if (Array.isArray(name))
3403
+ name.forEach((n) => addMethod(n));
3404
+ else
3405
+ addMethod(name);
3406
+ }
3407
+ const chaiEqual = chai.Assertion.prototype.equal;
3408
+ def("chaiEqual", function(...args) {
3409
+ return chaiEqual.apply(this, args);
3410
+ });
3411
+ utils.overwriteMethod(chai.Assertion.prototype, "equal", (_super) => {
3412
+ return function(...args) {
3413
+ const expected = args[0];
3414
+ const actual = utils.flag(this, "object");
3415
+ if (hasAsymmetric(expected)) {
3416
+ this.assert(equals(actual, expected, void 0, true), "not match with #{this}", "should not match with #{this}", true);
3417
+ } else {
3418
+ _super.apply(this, args);
3419
+ }
3487
3420
  };
3488
- def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
3489
- const spy = getSpy(this);
3490
- return this.assert(spy.callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number, spy.callCount);
3491
- });
3492
- def("toHaveBeenCalledOnce", function() {
3493
- const spy = getSpy(this);
3494
- return this.assert(spy.callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1, spy.callCount);
3495
- });
3496
- def(["toHaveBeenCalled", "toBeCalled"], function() {
3497
- const spy = getSpy(this);
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`;
3421
+ });
3422
+ utils.overwriteMethod(chai.Assertion.prototype, "eql", (_super) => {
3423
+ return function(...args) {
3424
+ const expected = args[0];
3425
+ const actual = utils.flag(this, "object");
3426
+ if (hasAsymmetric(expected)) {
3427
+ this.assert(equals(actual, expected), "not match with #{this}", "should not match with #{this}", true);
3428
+ } else {
3429
+ _super.apply(this, args);
3430
+ }
3515
3431
  };
3516
- def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
3517
- const spy = getSpy(this);
3518
- const nthCall = spy.calls[times - 1];
3519
- 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);
3520
- });
3521
- def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
3522
- const spy = getSpy(this);
3523
- const lastCall = spy.calls.at(-1);
3524
- 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);
3525
- });
3526
- def(["toThrow", "toThrowError"], function(expected) {
3527
- const negate = utils.flag(this, "negate");
3528
- if (negate)
3529
- this.not.to.throw(expected);
3530
- else
3531
- this.to.throw(expected);
3532
- });
3533
- def(["toHaveReturned", "toReturn"], function() {
3534
- const spy = getSpy(this);
3535
- const calledAndNotThrew = spy.called && !spy.results.some(([type]) => type === "error");
3536
- this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy to not be successfully called", calledAndNotThrew, !calledAndNotThrew);
3537
- });
3538
- def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
3539
- const spy = getSpy(this);
3540
- const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
3541
- 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}`);
3542
- });
3543
- def(["toHaveReturnedWith", "toReturnWith"], function(value) {
3544
- const spy = getSpy(this);
3545
- const pass = spy.results.some(([type, result]) => type === "ok" && equals(value, result));
3546
- this.assert(pass, "expected spy to be successfully called with #{exp}", "expected spy to not be successfully called with #{exp}", value);
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);
3432
+ });
3433
+ def("toEqual", function(expected) {
3434
+ return this.eql(expected);
3435
+ });
3436
+ def("toStrictEqual", function(expected) {
3437
+ return this.chaiEqual(expected);
3438
+ });
3439
+ def("toBe", function(expected) {
3440
+ return this.chaiEqual(expected);
3441
+ });
3442
+ def("toMatchObject", function(expected) {
3443
+ return this.containSubset(expected);
3444
+ });
3445
+ def("toMatch", function(expected) {
3446
+ if (typeof expected === "string")
3447
+ return this.include(expected);
3448
+ else
3449
+ return this.match(expected);
3450
+ });
3451
+ def("toContain", function(item) {
3452
+ return this.contain(item);
3453
+ });
3454
+ def("toContainEqual", function(expected) {
3455
+ const obj = utils.flag(this, "object");
3456
+ const index = Array.from(obj).findIndex((item) => {
3457
+ try {
3458
+ chai.assert.deepEqual(item, expected);
3459
+ } catch {
3460
+ return false;
3461
+ }
3462
+ return true;
3563
3463
  });
3464
+ this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
3465
+ });
3466
+ def("toBeTruthy", function() {
3467
+ const obj = utils.flag(this, "object");
3468
+ this.assert(Boolean(obj), "expected #{this} to be truthy", "expected #{this} to not be truthy", obj);
3469
+ });
3470
+ def("toBeFalsy", function() {
3471
+ const obj = utils.flag(this, "object");
3472
+ this.assert(!obj, "expected #{this} to be falsy", "expected #{this} to not be falsy", obj);
3473
+ });
3474
+ def("toBeGreaterThan", function(expected) {
3475
+ return this.to.greaterThan(expected);
3476
+ });
3477
+ def("toBeGreaterThanOrEqual", function(expected) {
3478
+ return this.to.greaterThanOrEqual(expected);
3479
+ });
3480
+ def("toBeLessThan", function(expected) {
3481
+ return this.to.lessThan(expected);
3482
+ });
3483
+ def("toBeLessThanOrEqual", function(expected) {
3484
+ return this.to.lessThanOrEqual(expected);
3485
+ });
3486
+ def("toBeNaN", function() {
3487
+ return this.be.NaN;
3488
+ });
3489
+ def("toBeUndefined", function() {
3490
+ return this.be.undefined;
3491
+ });
3492
+ def("toBeNull", function() {
3493
+ return this.be.null;
3494
+ });
3495
+ def("toBeDefined", function() {
3496
+ return this.not.be.undefined;
3497
+ });
3498
+ def("toBeInstanceOf", function(obj) {
3499
+ return this.instanceOf(obj);
3500
+ });
3501
+ def("toHaveLength", function(length) {
3502
+ return this.have.length(length);
3503
+ });
3504
+ def("toHaveProperty", function(...args) {
3505
+ return this.have.deep.nested.property(...args);
3506
+ });
3507
+ def("toBeCloseTo", function(number, numDigits = 2) {
3508
+ utils.expectTypes(this, ["number"]);
3509
+ return this.closeTo(number, numDigits);
3510
+ });
3511
+ function isSpy(putativeSpy) {
3512
+ return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
3513
+ }
3514
+ const assertIsMock = (assertion) => {
3515
+ if (!isSpy(assertion._obj))
3516
+ throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
3564
3517
  };
3518
+ const getSpy = (assertion) => {
3519
+ assertIsMock(assertion);
3520
+ return assertion._obj;
3521
+ };
3522
+ def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
3523
+ const spy = getSpy(this);
3524
+ return this.assert(spy.callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number, spy.callCount);
3525
+ });
3526
+ def("toHaveBeenCalledOnce", function() {
3527
+ const spy = getSpy(this);
3528
+ return this.assert(spy.callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1, spy.callCount);
3529
+ });
3530
+ def(["toHaveBeenCalled", "toBeCalled"], function() {
3531
+ const spy = getSpy(this);
3532
+ return this.assert(spy.called, "expected spy to be called at least once", "expected spy to not be called at all", true, spy.called);
3533
+ });
3534
+ def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
3535
+ const spy = getSpy(this);
3536
+ const pass = spy.calls.some((callArg) => equals(callArg, args));
3537
+ return this.assert(pass, "expected spy to be called with arguments: #{exp}", "expected spy to not be called with arguments: #{exp}", args, spy.calls);
3538
+ });
3539
+ const ordinalOf = (i) => {
3540
+ const j = i % 10;
3541
+ const k = i % 100;
3542
+ if (j === 1 && k !== 11)
3543
+ return `${i}st`;
3544
+ if (j === 2 && k !== 12)
3545
+ return `${i}nd`;
3546
+ if (j === 3 && k !== 13)
3547
+ return `${i}rd`;
3548
+ return `${i}th`;
3549
+ };
3550
+ def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
3551
+ const spy = getSpy(this);
3552
+ const nthCall = spy.calls[times - 1];
3553
+ 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);
3554
+ });
3555
+ def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
3556
+ const spy = getSpy(this);
3557
+ const lastCall = spy.calls.at(-1);
3558
+ 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);
3559
+ });
3560
+ def(["toThrow", "toThrowError"], function(expected) {
3561
+ const negate = utils.flag(this, "negate");
3562
+ if (negate)
3563
+ this.not.to.throw(expected);
3564
+ else
3565
+ this.to.throw(expected);
3566
+ });
3567
+ def(["toHaveReturned", "toReturn"], function() {
3568
+ const spy = getSpy(this);
3569
+ const calledAndNotThrew = spy.called && !spy.results.some(([type]) => type === "error");
3570
+ this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy to not be successfully called", calledAndNotThrew, !calledAndNotThrew);
3571
+ });
3572
+ def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
3573
+ const spy = getSpy(this);
3574
+ const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
3575
+ 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}`);
3576
+ });
3577
+ def(["toHaveReturnedWith", "toReturnWith"], function(value) {
3578
+ const spy = getSpy(this);
3579
+ const pass = spy.results.some(([type, result]) => type === "ok" && equals(value, result));
3580
+ this.assert(pass, "expected spy to be successfully called with #{exp}", "expected spy to not be successfully called with #{exp}", value);
3581
+ });
3582
+ def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
3583
+ const spy = getSpy(this);
3584
+ const lastResult = spy.returns.at(-1);
3585
+ const pass = equals(lastResult, value);
3586
+ this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
3587
+ });
3588
+ def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
3589
+ const spy = getSpy(this);
3590
+ const isNot = utils.flag(this, "negate");
3591
+ const [callType, callResult] = spy.results[nthCall - 1];
3592
+ const ordinalCall = `${ordinalOf(nthCall)} call`;
3593
+ if (!isNot && callType === "error")
3594
+ chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
3595
+ const nthCallReturn = equals(callResult, value);
3596
+ this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call to not return #{exp}`, value, callResult);
3597
+ });
3598
+ };
3599
+
3600
+ class AsymmetricMatcher {
3601
+ constructor(sample, inverse = false) {
3602
+ this.sample = sample;
3603
+ this.inverse = inverse;
3604
+ }
3605
+ getMatcherContext() {
3606
+ return {
3607
+ equals,
3608
+ isNot: this.inverse,
3609
+ utils: matcherUtils
3610
+ };
3611
+ }
3612
+ }
3613
+ class StringContaining extends AsymmetricMatcher {
3614
+ constructor(sample, inverse = false) {
3615
+ if (!isA("String", sample))
3616
+ throw new Error("Expected is not a string");
3617
+ super(sample, inverse);
3618
+ }
3619
+ asymmetricMatch(other) {
3620
+ const result = isA("String", other) && other.includes(this.sample);
3621
+ return this.inverse ? !result : result;
3622
+ }
3623
+ toString() {
3624
+ return `String${this.inverse ? "Not" : ""}Containing`;
3625
+ }
3626
+ getExpectedType() {
3627
+ return "string";
3628
+ }
3629
+ }
3630
+ class Anything extends AsymmetricMatcher {
3631
+ asymmetricMatch(other) {
3632
+ return other != null;
3633
+ }
3634
+ toString() {
3635
+ return "Anything";
3636
+ }
3637
+ toAsymmetricMatcher() {
3638
+ return "Anything";
3639
+ }
3640
+ }
3641
+ class ObjectContaining extends AsymmetricMatcher {
3642
+ constructor(sample, inverse = false) {
3643
+ super(sample, inverse);
3644
+ }
3645
+ getPrototype(obj) {
3646
+ if (Object.getPrototypeOf)
3647
+ return Object.getPrototypeOf(obj);
3648
+ if (obj.constructor.prototype === obj)
3649
+ return null;
3650
+ return obj.constructor.prototype;
3651
+ }
3652
+ hasProperty(obj, property) {
3653
+ if (!obj)
3654
+ return false;
3655
+ if (Object.prototype.hasOwnProperty.call(obj, property))
3656
+ return true;
3657
+ return this.hasProperty(this.getPrototype(obj), property);
3658
+ }
3659
+ asymmetricMatch(other) {
3660
+ if (typeof this.sample !== "object") {
3661
+ throw new TypeError(`You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`);
3662
+ }
3663
+ let result = true;
3664
+ for (const property in this.sample) {
3665
+ if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property])) {
3666
+ result = false;
3667
+ break;
3668
+ }
3669
+ }
3670
+ return this.inverse ? !result : result;
3671
+ }
3672
+ toString() {
3673
+ return `Object${this.inverse ? "Not" : ""}Containing`;
3674
+ }
3675
+ getExpectedType() {
3676
+ return "object";
3677
+ }
3565
3678
  }
3679
+ class ArrayContaining extends AsymmetricMatcher {
3680
+ constructor(sample, inverse = false) {
3681
+ super(sample, inverse);
3682
+ }
3683
+ asymmetricMatch(other) {
3684
+ if (!Array.isArray(this.sample)) {
3685
+ throw new TypeError(`You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`);
3686
+ }
3687
+ const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every((item) => other.some((another) => equals(item, another)));
3688
+ return this.inverse ? !result : result;
3689
+ }
3690
+ toString() {
3691
+ return `Array${this.inverse ? "Not" : ""}Containing`;
3692
+ }
3693
+ getExpectedType() {
3694
+ return "array";
3695
+ }
3696
+ }
3697
+ class Any extends AsymmetricMatcher {
3698
+ constructor(sample) {
3699
+ if (typeof sample === "undefined") {
3700
+ throw new TypeError("any() expects to be passed a constructor function. Please pass one or use anything() to match any object.");
3701
+ }
3702
+ super(sample);
3703
+ }
3704
+ fnNameFor(func) {
3705
+ if (func.name)
3706
+ return func.name;
3707
+ const functionToString = Function.prototype.toString;
3708
+ const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
3709
+ return matches ? matches[1] : "<anonymous>";
3710
+ }
3711
+ asymmetricMatch(other) {
3712
+ if (this.sample === String)
3713
+ return typeof other == "string" || other instanceof String;
3714
+ if (this.sample === Number)
3715
+ return typeof other == "number" || other instanceof Number;
3716
+ if (this.sample === Function)
3717
+ return typeof other == "function" || other instanceof Function;
3718
+ if (this.sample === Boolean)
3719
+ return typeof other == "boolean" || other instanceof Boolean;
3720
+ if (this.sample === BigInt)
3721
+ return typeof other == "bigint" || other instanceof BigInt;
3722
+ if (this.sample === Symbol)
3723
+ return typeof other == "symbol" || other instanceof Symbol;
3724
+ if (this.sample === Object)
3725
+ return typeof other == "object";
3726
+ return other instanceof this.sample;
3727
+ }
3728
+ toString() {
3729
+ return "Any";
3730
+ }
3731
+ getExpectedType() {
3732
+ if (this.sample === String)
3733
+ return "string";
3734
+ if (this.sample === Number)
3735
+ return "number";
3736
+ if (this.sample === Function)
3737
+ return "function";
3738
+ if (this.sample === Object)
3739
+ return "object";
3740
+ if (this.sample === Boolean)
3741
+ return "boolean";
3742
+ return this.fnNameFor(this.sample);
3743
+ }
3744
+ toAsymmetricMatcher() {
3745
+ return `Any<${this.fnNameFor(this.sample)}>`;
3746
+ }
3747
+ }
3748
+ const JestAsymmetricMatchers = (chai, utils) => {
3749
+ utils.addMethod(chai.expect, "stringContaining", (expected) => new StringContaining(expected));
3750
+ utils.addMethod(chai.expect, "anything", () => {
3751
+ return new Anything();
3752
+ });
3753
+ utils.addMethod(chai.expect, "objectContaining", (expected) => {
3754
+ return new ObjectContaining(expected);
3755
+ });
3756
+ utils.addMethod(chai.expect, "any", (expected) => {
3757
+ return new Any(expected);
3758
+ });
3759
+ utils.addMethod(chai.expect, "arrayContaining", (expected) => {
3760
+ return new ArrayContaining(expected);
3761
+ });
3762
+ };
3566
3763
 
3567
3764
  let installed = false;
3568
3765
  async function setupChai() {
3569
3766
  if (installed)
3570
3767
  return;
3571
- chai.use(JestExtend());
3572
- chai.use(JestChaiExpect());
3768
+ chai.use(JestExtend);
3769
+ chai.use(JestChaiExpect);
3573
3770
  chai.use(Subset);
3574
- chai.use(SnapshotPlugin());
3771
+ chai.use(SnapshotPlugin);
3772
+ chai.use(JestAsymmetricMatchers);
3575
3773
  installed = true;
3576
3774
  }
3577
3775
 
@@ -3583,7 +3781,7 @@ async function setupGlobalEnv(config) {
3583
3781
  setupConsoleLogSpy();
3584
3782
  await setupChai();
3585
3783
  if (config.global)
3586
- (await import('./global-f3eab75a.js')).registerApiGlobally();
3784
+ (await import('./global-c40aeb86.js')).registerApiGlobally();
3587
3785
  }
3588
3786
  function setupConsoleLogSpy() {
3589
3787
  const stdout = new Writable({
@@ -3699,14 +3897,6 @@ async function collectTests(paths, config) {
3699
3897
  }
3700
3898
  const tasks = files.reduce((tasks2, file) => tasks2.concat(file.tasks), []);
3701
3899
  interpretOnlyMode(tasks);
3702
- tasks.forEach((i) => {
3703
- if (i.type === "suite") {
3704
- if (i.mode === "skip")
3705
- i.tasks.forEach((c) => c.mode === "run" && (c.mode = "skip"));
3706
- else
3707
- interpretOnlyMode(i.tasks);
3708
- }
3709
- });
3710
3900
  return files;
3711
3901
  }
3712
3902
 
@@ -3809,10 +3999,17 @@ async function startTests(paths, config) {
3809
3999
  }
3810
4000
 
3811
4001
  async function run(files, config) {
4002
+ var _a;
3812
4003
  await setupGlobalEnv(config);
3813
- await withEnv(config.environment, async () => {
3814
- await startTests(files, config);
3815
- });
4004
+ for (const file of files) {
4005
+ const code = await promises.readFile(file, "utf-8");
4006
+ const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
4007
+ if (!["node", "jsdom", "happy-dom"].includes(env))
4008
+ throw new Error(`Unsupported environment: ${env}`);
4009
+ await withEnv(env, async () => {
4010
+ await startTests([file], config);
4011
+ });
4012
+ }
3816
4013
  }
3817
4014
 
3818
4015
  export { run };