vitest 0.0.82 → 0.0.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
- import { c } from './error-dd23da12.js';
3
- import { c as createVitest } from './index-9a2ee1fc.js';
2
+ import { c } from './error-c5d734a1.js';
3
+ import { c as createVitest } from './index-af5d5277.js';
4
4
  import 'fs';
5
5
  import 'path';
6
6
  import 'tty';
@@ -631,7 +631,7 @@ class CAC extends EventEmitter {
631
631
 
632
632
  const cac = (name = "") => new CAC(name);
633
633
 
634
- var version = "0.0.82";
634
+ var version = "0.0.87";
635
635
 
636
636
  const cli = cac("vitest");
637
637
  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", {
@@ -656,6 +656,7 @@ async function run(cliFilters, options) {
656
656
  }
657
657
  const ctx = await createVitest(options);
658
658
  process.__vitest__ = ctx;
659
+ process.chdir(ctx.config.root);
659
660
  try {
660
661
  await ctx.run(cliFilters);
661
662
  } catch (e) {
package/dist/entry.js CHANGED
@@ -7,9 +7,9 @@ import path, { basename } from 'path';
7
7
  import { r as rpc, s as send } from './rpc-7de86f29.js';
8
8
  import { g as getNames, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
9
9
  import fs from 'fs';
10
- import { c as c$1, m as generateDiff } from './error-dd23da12.js';
10
+ import { c as c$1, u as unifiedDiff } from './error-c5d734a1.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-95be5909.js';
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-0e21bf9b.js';
13
13
  import { n as nanoid } from './index-9e71c815.js';
14
14
  import 'tty';
15
15
  import 'source-map';
@@ -743,7 +743,7 @@ const asymmetricMatcher =
743
743
  : 0x1357a5;
744
744
  const SPACE$2 = ' ';
745
745
 
746
- const serialize$8 = (val, config, indentation, depth, refs, printer) => {
746
+ const serialize$7 = (val, config, indentation, depth, refs, printer) => {
747
747
  const stringedValue = val.toString();
748
748
 
749
749
  if (
@@ -819,13 +819,13 @@ const serialize$8 = (val, config, indentation, depth, refs, printer) => {
819
819
  return val.toAsymmetricMatcher();
820
820
  };
821
821
 
822
- AsymmetricMatcher$2.serialize = serialize$8;
822
+ AsymmetricMatcher$2.serialize = serialize$7;
823
823
 
824
824
  const test$6 = val => val && val.$$typeof === asymmetricMatcher;
825
825
 
826
826
  AsymmetricMatcher$2.test = test$6;
827
827
  const plugin$6 = {
828
- serialize: serialize$8,
828
+ serialize: serialize$7,
829
829
  test: test$6
830
830
  };
831
831
  var _default$7 = plugin$6;
@@ -926,12 +926,12 @@ const test$5 = val =>
926
926
 
927
927
  ConvertAnsi.test = test$5;
928
928
 
929
- const serialize$7 = (val, config, indentation, depth, refs, printer) =>
929
+ const serialize$6 = (val, config, indentation, depth, refs, printer) =>
930
930
  printer(toHumanReadableAnsi(val), config, indentation, depth, refs);
931
931
 
932
- ConvertAnsi.serialize = serialize$7;
932
+ ConvertAnsi.serialize = serialize$6;
933
933
  const plugin$5 = {
934
- serialize: serialize$7,
934
+ serialize: serialize$6,
935
935
  test: test$5
936
936
  };
937
937
  var _default$6 = plugin$5;
@@ -972,7 +972,7 @@ DOMCollection$2.test = test$4;
972
972
  const isNamedNodeMap = collection =>
973
973
  collection.constructor.name === 'NamedNodeMap';
974
974
 
975
- const serialize$6 = (collection, config, indentation, depth, refs, printer) => {
975
+ const serialize$5 = (collection, config, indentation, depth, refs, printer) => {
976
976
  const name = collection.constructor.name;
977
977
 
978
978
  if (++depth > config.maxDepth) {
@@ -1010,9 +1010,9 @@ const serialize$6 = (collection, config, indentation, depth, refs, printer) => {
1010
1010
  );
1011
1011
  };
1012
1012
 
1013
- DOMCollection$2.serialize = serialize$6;
1013
+ DOMCollection$2.serialize = serialize$5;
1014
1014
  const plugin$4 = {
1015
- serialize: serialize$6,
1015
+ serialize: serialize$5,
1016
1016
  test: test$4
1017
1017
  };
1018
1018
  var _default$5 = plugin$4;
@@ -1260,7 +1260,7 @@ function nodeIsFragment(node) {
1260
1260
  return node.nodeType === FRAGMENT_NODE;
1261
1261
  }
1262
1262
 
1263
- const serialize$5 = (node, config, indentation, depth, refs, printer) => {
1263
+ const serialize$4 = (node, config, indentation, depth, refs, printer) => {
1264
1264
  if (nodeIsText(node)) {
1265
1265
  return (0, _markup$2.printText)(node.data, config);
1266
1266
  }
@@ -1310,9 +1310,9 @@ const serialize$5 = (node, config, indentation, depth, refs, printer) => {
1310
1310
  );
1311
1311
  };
1312
1312
 
1313
- DOMElement$2.serialize = serialize$5;
1313
+ DOMElement$2.serialize = serialize$4;
1314
1314
  const plugin$3 = {
1315
- serialize: serialize$5,
1315
+ serialize: serialize$4,
1316
1316
  test: test$3
1317
1317
  };
1318
1318
  var _default$4 = plugin$3;
@@ -1495,7 +1495,7 @@ const printImmutableValues = (
1495
1495
  ) +
1496
1496
  ']';
1497
1497
 
1498
- const serialize$4 = (val, config, indentation, depth, refs, printer) => {
1498
+ const serialize$3 = (val, config, indentation, depth, refs, printer) => {
1499
1499
  if (val[IS_MAP_SENTINEL]) {
1500
1500
  return printImmutableEntries(
1501
1501
  val,
@@ -1552,7 +1552,7 @@ const serialize$4 = (val, config, indentation, depth, refs, printer) => {
1552
1552
  }; // Explicitly comparing sentinel properties to true avoids false positive
1553
1553
  // when mock identity-obj-proxy returns the key as the value for any key.
1554
1554
 
1555
- Immutable$2.serialize = serialize$4;
1555
+ Immutable$2.serialize = serialize$3;
1556
1556
 
1557
1557
  const test$2 = val =>
1558
1558
  val &&
@@ -1560,7 +1560,7 @@ const test$2 = val =>
1560
1560
 
1561
1561
  Immutable$2.test = test$2;
1562
1562
  const plugin$2 = {
1563
- serialize: serialize$4,
1563
+ serialize: serialize$3,
1564
1564
  test: test$2
1565
1565
  };
1566
1566
  var _default$3 = plugin$2;
@@ -1943,7 +1943,7 @@ const getPropKeys$1 = element => {
1943
1943
  .sort();
1944
1944
  };
1945
1945
 
1946
- const serialize$3 = (element, config, indentation, depth, refs, printer) =>
1946
+ const serialize$2 = (element, config, indentation, depth, refs, printer) =>
1947
1947
  ++depth > config.maxDepth
1948
1948
  ? (0, _markup$1.printElementAsLeaf)(getType(element), config)
1949
1949
  : (0, _markup$1.printElement)(
@@ -1969,13 +1969,13 @@ const serialize$3 = (element, config, indentation, depth, refs, printer) =>
1969
1969
  indentation
1970
1970
  );
1971
1971
 
1972
- ReactElement$2.serialize = serialize$3;
1972
+ ReactElement$2.serialize = serialize$2;
1973
1973
 
1974
1974
  const test$1 = val => val != null && ReactIs.isElement(val);
1975
1975
 
1976
1976
  ReactElement$2.test = test$1;
1977
1977
  const plugin$1 = {
1978
- serialize: serialize$3,
1978
+ serialize: serialize$2,
1979
1979
  test: test$1
1980
1980
  };
1981
1981
  var _default$2 = plugin$1;
@@ -2019,7 +2019,7 @@ const getPropKeys = object => {
2019
2019
  : [];
2020
2020
  };
2021
2021
 
2022
- const serialize$2 = (object, config, indentation, depth, refs, printer) =>
2022
+ const serialize$1 = (object, config, indentation, depth, refs, printer) =>
2023
2023
  ++depth > config.maxDepth
2024
2024
  ? (0, _markup.printElementAsLeaf)(object.type, config)
2025
2025
  : (0, _markup.printElement)(
@@ -2049,13 +2049,13 @@ const serialize$2 = (object, config, indentation, depth, refs, printer) =>
2049
2049
  indentation
2050
2050
  );
2051
2051
 
2052
- ReactTestComponent$2.serialize = serialize$2;
2052
+ ReactTestComponent$2.serialize = serialize$1;
2053
2053
 
2054
2054
  const test = val => val && val.$$typeof === testSymbol;
2055
2055
 
2056
2056
  ReactTestComponent$2.test = test;
2057
2057
  const plugin = {
2058
- serialize: serialize$2,
2058
+ serialize: serialize$1,
2059
2059
  test
2060
2060
  };
2061
2061
  var _default$1 = plugin;
@@ -2721,7 +2721,7 @@ ${string}
2721
2721
  const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
2722
2722
  const escapeRegex = true;
2723
2723
  const printFunctionName = false;
2724
- function serialize$1(val, indent = 2, formatOverrides = {}) {
2724
+ function serialize(val, indent = 2, formatOverrides = {}) {
2725
2725
  return normalizeNewlines(format_1(val, __spreadValues$1({
2726
2726
  escapeRegex,
2727
2727
  indent,
@@ -2835,7 +2835,7 @@ class SnapshotState {
2835
2835
  key = testNameToKey(testName, count);
2836
2836
  if (!(isInline && this._snapshotData[key] !== void 0))
2837
2837
  this._uncheckedKeys.delete(key);
2838
- const receivedSerialized = addExtraLineBreaks(serialize$1(received, void 0, this._snapshotFormat));
2838
+ const receivedSerialized = addExtraLineBreaks(serialize(received, void 0, this._snapshotFormat));
2839
2839
  const expected = isInline ? inlineSnapshot : this._snapshotData[key];
2840
2840
  const pass = (expected == null ? void 0 : expected.trim()) === (receivedSerialized == null ? void 0 : receivedSerialized.trim());
2841
2841
  const hasSnapshot = expected !== void 0;
@@ -3080,7 +3080,7 @@ const stringify = (object, maxDepth = 10) => {
3080
3080
  const printReceived = (object) => RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
3081
3081
  const printExpected = (value) => EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
3082
3082
  function diff(a, b, options) {
3083
- return generateDiff(stringify(a), stringify(b));
3083
+ return unifiedDiff(stringify(a), stringify(b));
3084
3084
  }
3085
3085
 
3086
3086
  var matcherUtils = /*#__PURE__*/Object.freeze({
@@ -3097,9 +3097,7 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
3097
3097
  diff: diff
3098
3098
  });
3099
3099
 
3100
- // src/math.ts
3101
- var isObject = (val) => toString.call(val) === "[object Object]";
3102
-
3100
+ const isObject = (val) => toString.call(val) === "[object Object]";
3103
3101
  function equals(a, b, customTesters, strictCheck) {
3104
3102
  customTesters = customTesters || [];
3105
3103
  return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
@@ -3108,42 +3106,34 @@ function isAsymmetric(obj) {
3108
3106
  return !!obj && isA("Function", obj.asymmetricMatch);
3109
3107
  }
3110
3108
  function asymmetricMatch(a, b) {
3111
- var asymmetricA = isAsymmetric(a), asymmetricB = isAsymmetric(b);
3112
- if (asymmetricA && asymmetricB) {
3109
+ const asymmetricA = isAsymmetric(a);
3110
+ const asymmetricB = isAsymmetric(b);
3111
+ if (asymmetricA && asymmetricB)
3113
3112
  return void 0;
3114
- }
3115
- if (asymmetricA) {
3113
+ if (asymmetricA)
3116
3114
  return a.asymmetricMatch(b);
3117
- }
3118
- if (asymmetricB) {
3115
+ if (asymmetricB)
3119
3116
  return b.asymmetricMatch(a);
3120
- }
3121
3117
  }
3122
3118
  function eq(a, b, aStack, bStack, customTesters, hasKey2) {
3123
- var result = true;
3124
- var asymmetricResult = asymmetricMatch(a, b);
3125
- if (asymmetricResult !== void 0) {
3119
+ let result = true;
3120
+ const asymmetricResult = asymmetricMatch(a, b);
3121
+ if (asymmetricResult !== void 0)
3126
3122
  return asymmetricResult;
3127
- }
3128
- for (var i = 0; i < customTesters.length; i++) {
3129
- var customTesterResult = customTesters[i](a, b);
3130
- if (customTesterResult !== void 0) {
3123
+ for (let i = 0; i < customTesters.length; i++) {
3124
+ const customTesterResult = customTesters[i](a, b);
3125
+ if (customTesterResult !== void 0)
3131
3126
  return customTesterResult;
3132
- }
3133
- }
3134
- if (a instanceof Error && b instanceof Error) {
3135
- return a.message == b.message;
3136
3127
  }
3137
- if (Object.is(a, b)) {
3128
+ if (a instanceof Error && b instanceof Error)
3129
+ return a.message === b.message;
3130
+ if (Object.is(a, b))
3138
3131
  return true;
3139
- }
3140
- if (a === null || b === null) {
3132
+ if (a === null || b === null)
3141
3133
  return a === b;
3142
- }
3143
- var className = Object.prototype.toString.call(a);
3144
- if (className != Object.prototype.toString.call(b)) {
3134
+ const className = Object.prototype.toString.call(a);
3135
+ if (className !== Object.prototype.toString.call(b))
3145
3136
  return false;
3146
- }
3147
3137
  switch (className) {
3148
3138
  case "[object Boolean]":
3149
3139
  case "[object String]":
@@ -3156,51 +3146,45 @@ function eq(a, b, aStack, bStack, customTesters, hasKey2) {
3156
3146
  return Object.is(a.valueOf(), b.valueOf());
3157
3147
  }
3158
3148
  case "[object Date]":
3159
- return +a == +b;
3149
+ return +a === +b;
3160
3150
  case "[object RegExp]":
3161
3151
  return a.source === b.source && a.flags === b.flags;
3162
3152
  }
3163
- if (typeof a !== "object" || typeof b !== "object") {
3153
+ if (typeof a !== "object" || typeof b !== "object")
3164
3154
  return false;
3165
- }
3166
- if (isDomNode(a) && isDomNode(b)) {
3155
+ if (isDomNode(a) && isDomNode(b))
3167
3156
  return a.isEqualNode(b);
3168
- }
3169
- var length = aStack.length;
3157
+ let length = aStack.length;
3170
3158
  while (length--) {
3171
- if (aStack[length] === a) {
3159
+ if (aStack[length] === a)
3172
3160
  return bStack[length] === b;
3173
- } else if (bStack[length] === b) {
3161
+ else if (bStack[length] === b)
3174
3162
  return false;
3175
- }
3176
3163
  }
3177
3164
  aStack.push(a);
3178
3165
  bStack.push(b);
3179
- if (className == "[object Array]" && a.length !== b.length) {
3166
+ if (className === "[object Array]" && a.length !== b.length)
3180
3167
  return false;
3181
- }
3182
- var aKeys = keys(a, hasKey2), key;
3183
- var size = aKeys.length;
3184
- if (keys(b, hasKey2).length !== size) {
3168
+ const aKeys = keys(a, hasKey2);
3169
+ let key;
3170
+ let size = aKeys.length;
3171
+ if (keys(b, hasKey2).length !== size)
3185
3172
  return false;
3186
- }
3187
3173
  while (size--) {
3188
3174
  key = aKeys[size];
3189
3175
  result = hasKey2(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, hasKey2);
3190
- if (!result) {
3176
+ if (!result)
3191
3177
  return false;
3192
- }
3193
3178
  }
3194
3179
  aStack.pop();
3195
3180
  bStack.pop();
3196
3181
  return result;
3197
3182
  }
3198
3183
  function keys(obj, hasKey2) {
3199
- var keys2 = [];
3200
- for (var key in obj) {
3201
- if (hasKey2(obj, key)) {
3184
+ const keys2 = [];
3185
+ for (const key in obj) {
3186
+ if (hasKey2(obj, key))
3202
3187
  keys2.push(key);
3203
- }
3204
3188
  }
3205
3189
  return keys2.concat(Object.getOwnPropertySymbols(obj).filter((symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable));
3206
3190
  }
@@ -3211,7 +3195,7 @@ function hasKey(obj, key) {
3211
3195
  return Object.prototype.hasOwnProperty.call(obj, key);
3212
3196
  }
3213
3197
  function isA(typeName, value) {
3214
- return Object.prototype.toString.apply(value) === "[object " + typeName + "]";
3198
+ return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
3215
3199
  }
3216
3200
  function isDomNode(obj) {
3217
3201
  return obj !== null && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string" && typeof obj.isEqualNode === "function";
@@ -3228,17 +3212,14 @@ function isImmutableUnorderedSet(maybeSet) {
3228
3212
  const IteratorSymbol = Symbol.iterator;
3229
3213
  const hasIterator = (object) => !!(object != null && object[IteratorSymbol]);
3230
3214
  const iterableEquality = (a, b, aStack = [], bStack = []) => {
3231
- if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b)) {
3215
+ if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b))
3232
3216
  return void 0;
3233
- }
3234
- if (a.constructor !== b.constructor) {
3217
+ if (a.constructor !== b.constructor)
3235
3218
  return false;
3236
- }
3237
3219
  let length = aStack.length;
3238
3220
  while (length--) {
3239
- if (aStack[length] === a) {
3221
+ if (aStack[length] === a)
3240
3222
  return bStack[length] === b;
3241
- }
3242
3223
  }
3243
3224
  aStack.push(a);
3244
3225
  bStack.push(b);
@@ -3253,9 +3234,8 @@ const iterableEquality = (a, b, aStack = [], bStack = []) => {
3253
3234
  let has = false;
3254
3235
  for (const bValue of b) {
3255
3236
  const isEqual = equals(aValue, bValue, [iterableEqualityWithStack]);
3256
- if (isEqual === true) {
3237
+ if (isEqual === true)
3257
3238
  has = true;
3258
- }
3259
3239
  }
3260
3240
  if (has === false) {
3261
3241
  allFound = false;
@@ -3281,9 +3261,8 @@ const iterableEquality = (a, b, aStack = [], bStack = []) => {
3281
3261
  iterableEqualityWithStack
3282
3262
  ]);
3283
3263
  }
3284
- if (matchedValue === true) {
3264
+ if (matchedValue === true)
3285
3265
  has = true;
3286
- }
3287
3266
  }
3288
3267
  if (has === false) {
3289
3268
  allFound = false;
@@ -3299,35 +3278,30 @@ const iterableEquality = (a, b, aStack = [], bStack = []) => {
3299
3278
  const bIterator = b[IteratorSymbol]();
3300
3279
  for (const aValue of a) {
3301
3280
  const nextB = bIterator.next();
3302
- if (nextB.done || !equals(aValue, nextB.value, [iterableEqualityWithStack])) {
3281
+ if (nextB.done || !equals(aValue, nextB.value, [iterableEqualityWithStack]))
3303
3282
  return false;
3304
- }
3305
3283
  }
3306
- if (!bIterator.next().done) {
3284
+ if (!bIterator.next().done)
3307
3285
  return false;
3308
- }
3309
3286
  aStack.pop();
3310
3287
  bStack.pop();
3311
3288
  return true;
3312
3289
  };
3313
3290
  const hasPropertyInObject = (object, key) => {
3314
3291
  const shouldTerminate = !object || typeof object !== "object" || object === Object.prototype;
3315
- if (shouldTerminate) {
3292
+ if (shouldTerminate)
3316
3293
  return false;
3317
- }
3318
3294
  return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
3319
3295
  };
3320
3296
  const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
3321
3297
  const subsetEquality = (object, subset) => {
3322
3298
  const subsetEqualityWithContext = (seenReferences = new WeakMap()) => (object2, subset2) => {
3323
- if (!isObjectWithKeys(subset2)) {
3299
+ if (!isObjectWithKeys(subset2))
3324
3300
  return void 0;
3325
- }
3326
3301
  return Object.keys(subset2).every((key) => {
3327
3302
  if (isObjectWithKeys(subset2[key])) {
3328
- if (seenReferences.has(subset2[key])) {
3303
+ if (seenReferences.has(subset2[key]))
3329
3304
  return equals(object2[key], subset2[key], [iterableEquality]);
3330
- }
3331
3305
  seenReferences.set(subset2[key], true);
3332
3306
  }
3333
3307
  const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
@@ -3605,7 +3579,7 @@ async function setupGlobalEnv(config) {
3605
3579
  setupConsoleLogSpy();
3606
3580
  await setupChai();
3607
3581
  if (config.global)
3608
- (await import('./global-cae0ce06.js')).registerApiGlobally();
3582
+ (await import('./global-e172af93.js')).registerApiGlobally();
3609
3583
  }
3610
3584
  function setupConsoleLogSpy() {
3611
3585
  const stdout = new Writable({
@@ -3654,22 +3628,21 @@ async function runSetupFiles(config) {
3654
3628
  }));
3655
3629
  }
3656
3630
 
3657
- function serialize(err) {
3658
- if (typeof err !== "object")
3659
- return err;
3660
- Object.keys(err).forEach((key) => {
3661
- const val = err[key];
3662
- if (typeof val === "function")
3663
- err[key] = `Function<${val.name}>`;
3664
- if (typeof val !== "object")
3665
- return;
3666
- if ("then" in val)
3667
- err[key] = "Promise";
3668
- if (typeof Element !== "undefined" && val instanceof Element)
3669
- err[key] = val.tagName;
3670
- serialize(err[key]);
3631
+ function serializeError(val) {
3632
+ if (!val)
3633
+ return val;
3634
+ if (typeof val === "function")
3635
+ return `Function<${val.name}>`;
3636
+ if (typeof val !== "object")
3637
+ return val;
3638
+ if (val instanceof Promise || "then" in val)
3639
+ return "Promise";
3640
+ if (typeof Element !== "undefined" && val instanceof Element)
3641
+ return val.tagName;
3642
+ Object.keys(val).forEach((key) => {
3643
+ val[key] = serializeError(val[key]);
3671
3644
  });
3672
- return err;
3645
+ return val;
3673
3646
  }
3674
3647
  function processError(err) {
3675
3648
  if (!err)
@@ -3678,7 +3651,7 @@ function processError(err) {
3678
3651
  err.stackStr = String(err.stack);
3679
3652
  if (err.name)
3680
3653
  err.nameStr = String(err.name);
3681
- return serialize(err);
3654
+ return serializeError(err);
3682
3655
  }
3683
3656
 
3684
3657
  async function collectTests(paths, config) {
@@ -1266,7 +1266,7 @@ async function printError(error) {
1266
1266
  const stackStr = e.stack || e.stackStr || "";
1267
1267
  const stacks = parseStack(stackStr);
1268
1268
  if (!stacks.length) {
1269
- console.error(e);
1269
+ ctx.console.error(e);
1270
1270
  } else {
1271
1271
  const nearest = stacks.find((stack) => {
1272
1272
  return !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file);
@@ -1279,9 +1279,38 @@ async function printError(error) {
1279
1279
  }
1280
1280
  });
1281
1281
  }
1282
+ handleImportOutsideModuleError(stackStr, ctx);
1282
1283
  if (e.showDiff)
1283
1284
  displayDiff(e.actual, e.expected);
1284
1285
  }
1286
+ const esmErrors = [
1287
+ "Cannot use import statement outside a module",
1288
+ "Unexpected token 'export'"
1289
+ ];
1290
+ function handleImportOutsideModuleError(stack, ctx) {
1291
+ if (!esmErrors.some((e) => stack.includes(e)))
1292
+ return;
1293
+ const path = stack.split("\n")[0].trim();
1294
+ let name = path.split("/node_modules/").pop() || "";
1295
+ if (name == null ? void 0 : name.startsWith("@"))
1296
+ name = name.split("/").slice(0, 2).join("/");
1297
+ else
1298
+ name = name.split("/")[0];
1299
+ ctx.console.error(c.yellow(`Module ${path} seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package ${c.bold(`"${name}"`)} asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
1300
+
1301
+ As a temporary workaround you can try to inline the package by updating your config:
1302
+
1303
+ ` + c.gray(c.dim("// vitest.config.js")) + "\n" + c.green(`export default {
1304
+ test: {
1305
+ deps: {
1306
+ inline: [
1307
+ ${c.yellow(c.bold(`"${name}"`))}
1308
+ ]
1309
+ }
1310
+ }
1311
+ }
1312
+ `)));
1313
+ }
1285
1314
  async function getSourcePos(ctx, nearest) {
1286
1315
  const mod = ctx.server.moduleGraph.getModuleById(nearest.file);
1287
1316
  const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
@@ -1289,7 +1318,7 @@ async function getSourcePos(ctx, nearest) {
1289
1318
  return pos;
1290
1319
  }
1291
1320
  function displayDiff(actual, expected) {
1292
- console.error(c.gray(generateDiff(stringify(actual), stringify(expected))));
1321
+ console.error(c.gray(unifiedDiff(stringify(actual), stringify(expected))));
1293
1322
  }
1294
1323
  function printErrorMessage(error) {
1295
1324
  const errorName = error.name || error.nameStr || "Unknown Error";
@@ -1329,6 +1358,8 @@ function posToNumber(source, pos) {
1329
1358
  const lines = source.split(splitRE);
1330
1359
  const { line, column } = pos;
1331
1360
  let start = 0;
1361
+ if (line > lines.length)
1362
+ return source.length;
1332
1363
  for (let i = 0; i < line - 1; i++)
1333
1364
  start += lines[i].length + 1;
1334
1365
  return start + column;
@@ -1395,21 +1426,28 @@ function parseStack(stack) {
1395
1426
  });
1396
1427
  return stackFrames.filter(notNullish);
1397
1428
  }
1398
- function generateDiff(actual, expected) {
1399
- const diffSize = 2048;
1400
- if (actual.length > diffSize)
1401
- actual = `${actual.substring(0, diffSize)} ... Lines skipped`;
1402
- if (expected.length > diffSize)
1403
- expected = `${expected.substring(0, diffSize)} ... Lines skipped`;
1404
- return unifiedDiff(actual, expected);
1405
- }
1406
1429
  function unifiedDiff(actual, expected) {
1430
+ if (actual === expected)
1431
+ return "";
1432
+ const diffLimit = 10;
1407
1433
  const indent = " ";
1434
+ let expectedLinesCount = 0;
1435
+ let actualLinesCount = 0;
1408
1436
  function cleanUp(line) {
1409
- if (line[0] === "+")
1410
- return indent + c.green(`${line[0]}${line.slice(1)}`);
1411
- if (line[0] === "-")
1412
- return indent + c.red(`${line[0]}${line.slice(1)}`);
1437
+ if (line[0] === "+") {
1438
+ if (expectedLinesCount >= diffLimit)
1439
+ return;
1440
+ expectedLinesCount++;
1441
+ const isLastLine = expectedLinesCount === diffLimit;
1442
+ return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1443
+ }
1444
+ if (line[0] === "-") {
1445
+ if (actualLinesCount >= diffLimit)
1446
+ return;
1447
+ actualLinesCount++;
1448
+ const isLastLine = actualLinesCount === diffLimit;
1449
+ return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1450
+ }
1413
1451
  if (line.match(/@@/))
1414
1452
  return "--";
1415
1453
  if (line.match(/\\ No newline/))
@@ -1424,8 +1462,18 @@ ${indent}${c.green("+ expected")}
1424
1462
 
1425
1463
  ${lines.map(cleanUp).filter(notBlank).join("\n")}`;
1426
1464
  }
1465
+ function formatLine(line) {
1466
+ const lineLimitLength = 50;
1467
+ if (line.length > lineLimitLength)
1468
+ return `${line.slice(0, lineLimitLength)} ${c.dim("[...truncated]")}`;
1469
+ return line;
1470
+ }
1471
+ function renderTruncateMessage(indent) {
1472
+ return `
1473
+ ${indent}${c.dim("[...truncated]")}`;
1474
+ }
1427
1475
  function notBlank(line) {
1428
1476
  return typeof line !== "undefined" && line !== null;
1429
1477
  }
1430
1478
 
1431
- export { F_POINTER as F, ansiStyles as a, stripAnsi as b, c, sliceAnsi as d, F_DOWN as e, F_LONG_DASH as f, F_DOWN_RIGHT as g, F_DOT as h, F_CHECK as i, F_CROSS as j, cliTruncate as k, F_RIGHT as l, generateDiff as m, printError as p, stringWidth as s };
1479
+ export { F_POINTER as F, ansiStyles as a, stripAnsi as b, c, sliceAnsi as d, F_DOWN as e, F_LONG_DASH as f, F_DOWN_RIGHT as g, F_DOT as h, F_CHECK as i, F_CROSS as j, cliTruncate as k, F_RIGHT as l, printError as p, stringWidth as s, unifiedDiff as u };
@@ -1,8 +1,8 @@
1
1
  import { g as globalApis } from './constants-adef7ffb.js';
2
- import { i as index } from './index-16a06164.js';
2
+ import { i as index } from './index-906ac3f9.js';
3
3
  import 'path';
4
4
  import 'url';
5
- import './suite-95be5909.js';
5
+ import './suite-0e21bf9b.js';
6
6
  import './index-9e71c815.js';
7
7
  import 'chai';
8
8
  import 'tinyspy';
@@ -1,4 +1,4 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-95be5909.js';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-0e21bf9b.js';
2
2
  import chai, { assert, should, expect } from 'chai';
3
3
  import { spyOn, spy } from 'tinyspy';
4
4