vitest 0.0.80 → 0.0.84

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.
@@ -2,8 +2,8 @@ import { resolve } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
- const defaultIncludes = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
6
- const defaultExcludes = ["**/node_modules/**", "**/dist/**"];
5
+ const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
6
+ const defaultExclude = ["**/node_modules/**", "**/dist/**"];
7
7
  const defaultPort = 51204;
8
8
  const API_PATH = "/__vitest_api__";
9
9
  const configFiles = [
@@ -31,4 +31,4 @@ const globalApis = [
31
31
  "afterEach"
32
32
  ];
33
33
 
34
- export { API_PATH as A, defaultExcludes as a, defaultPort as b, configFiles as c, defaultIncludes as d, distDir as e, globalApis as g };
34
+ export { API_PATH as A, defaultExclude as a, defaultPort as b, distDir as c, defaultInclude as d, configFiles as e, globalApis as g };
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 { d as c$1, m as generateDiff } from './error-c9295525.js';
10
+ import { c as c$1, u as unifiedDiff } from './error-c651f5ae.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);
@@ -3499,7 +3497,15 @@ function JestChaiExpect() {
3499
3497
  utils.expectTypes(this, ["number"]);
3500
3498
  return this.closeTo(number, numDigits);
3501
3499
  });
3500
+ function isSpy(putativeSpy) {
3501
+ return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
3502
+ }
3503
+ const assertIsMock = (assertion) => {
3504
+ if (!isSpy(assertion._obj))
3505
+ throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
3506
+ };
3502
3507
  const getSpy = (assertion) => {
3508
+ assertIsMock(assertion);
3503
3509
  return assertion._obj;
3504
3510
  };
3505
3511
  def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
@@ -3552,7 +3558,7 @@ function JestChaiExpect() {
3552
3558
  def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
3553
3559
  const spy = getSpy(this);
3554
3560
  const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
3555
- 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}`, `recieved number of returns: ${successfullReturns}`);
3561
+ 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}`);
3556
3562
  });
3557
3563
  def(["toHaveReturnedWith", "toReturnWith"], function(value) {
3558
3564
  const spy = getSpy(this);
@@ -3597,7 +3603,7 @@ async function setupGlobalEnv(config) {
3597
3603
  setupConsoleLogSpy();
3598
3604
  await setupChai();
3599
3605
  if (config.global)
3600
- (await import('./global-6446cca1.js')).registerApiGlobally();
3606
+ (await import('./global-e172af93.js')).registerApiGlobally();
3601
3607
  }
3602
3608
  function setupConsoleLogSpy() {
3603
3609
  const stdout = new Writable({
@@ -3646,22 +3652,21 @@ async function runSetupFiles(config) {
3646
3652
  }));
3647
3653
  }
3648
3654
 
3649
- function serialize(err) {
3650
- if (typeof err !== "object")
3651
- return err;
3652
- Object.keys(err).forEach((key) => {
3653
- const val = err[key];
3654
- if (typeof val === "function")
3655
- err[key] = `Function<${val.name}>`;
3656
- if (typeof val !== "object")
3657
- return;
3658
- if ("then" in val)
3659
- err[key] = "Promise";
3660
- if (typeof Element !== "undefined" && val instanceof Element)
3661
- err[key] = val.tagName;
3662
- serialize(err[key]);
3655
+ function serializeError(val) {
3656
+ if (!val)
3657
+ return val;
3658
+ if (typeof val === "function")
3659
+ return `Function<${val.name}>`;
3660
+ if (typeof val !== "object")
3661
+ return val;
3662
+ if (val instanceof Promise || "then" in val)
3663
+ return "Promise";
3664
+ if (typeof Element !== "undefined" && val instanceof Element)
3665
+ return val.tagName;
3666
+ Object.keys(val).forEach((key) => {
3667
+ val[key] = serializeError(val[key]);
3663
3668
  });
3664
- return err;
3669
+ return val;
3665
3670
  }
3666
3671
  function processError(err) {
3667
3672
  if (!err)
@@ -3670,7 +3675,7 @@ function processError(err) {
3670
3675
  err.stackStr = String(err.stack);
3671
3676
  if (err.name)
3672
3677
  err.nameStr = String(err.name);
3673
- return serialize(err);
3678
+ return serializeError(err);
3674
3679
  }
3675
3680
 
3676
3681
  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";
@@ -1303,7 +1332,7 @@ async function printStack(ctx, stack, highlight, onStack) {
1303
1332
  const color = frame === highlight ? c.yellow : c.gray;
1304
1333
  const path = relative(ctx.config.root, frame.file);
1305
1334
  ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
1306
- onStack == null ? void 0 : onStack(frame, pos);
1335
+ await (onStack == null ? void 0 : onStack(frame, pos));
1307
1336
  if (frame.file in ctx.state.filesMap)
1308
1337
  break;
1309
1338
  }
@@ -1395,21 +1424,28 @@ function parseStack(stack) {
1395
1424
  });
1396
1425
  return stackFrames.filter(notNullish);
1397
1426
  }
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
1427
  function unifiedDiff(actual, expected) {
1428
+ if (actual === expected)
1429
+ return "";
1430
+ const diffLimit = 10;
1407
1431
  const indent = " ";
1432
+ let expectedLinesCount = 0;
1433
+ let actualLinesCount = 0;
1408
1434
  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)}`);
1435
+ if (line[0] === "+") {
1436
+ if (expectedLinesCount >= diffLimit)
1437
+ return;
1438
+ expectedLinesCount++;
1439
+ const isLastLine = expectedLinesCount === diffLimit;
1440
+ return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1441
+ }
1442
+ if (line[0] === "-") {
1443
+ if (actualLinesCount >= diffLimit)
1444
+ return;
1445
+ actualLinesCount++;
1446
+ const isLastLine = actualLinesCount === diffLimit;
1447
+ return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1448
+ }
1413
1449
  if (line.match(/@@/))
1414
1450
  return "--";
1415
1451
  if (line.match(/\\ No newline/))
@@ -1424,8 +1460,18 @@ ${indent}${c.green("+ expected")}
1424
1460
 
1425
1461
  ${lines.map(cleanUp).filter(notBlank).join("\n")}`;
1426
1462
  }
1463
+ function formatLine(line) {
1464
+ const lineLimitLength = 50;
1465
+ if (line.length > lineLimitLength)
1466
+ return `${line.slice(0, lineLimitLength)} ${c.dim("[...truncated]")}`;
1467
+ return line;
1468
+ }
1469
+ function renderTruncateMessage(indent) {
1470
+ return `
1471
+ ${indent}${c.dim("[...truncated]")}`;
1472
+ }
1427
1473
  function notBlank(line) {
1428
1474
  return typeof line !== "undefined" && line !== null;
1429
1475
  }
1430
1476
 
1431
- export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, c 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 };
1477
+ 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
- import { g as globalApis } from './constants-9da0006f.js';
2
- import { i as index } from './index-16a06164.js';
1
+ import { g as globalApis } from './constants-adef7ffb.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