vitest 0.0.83 → 0.0.88

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-a65fcd00.js';
3
- import { c as createVitest } from './index-6c8eed3e.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.83";
634
+ var version = "0.0.88";
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", {
package/dist/entry.js CHANGED
@@ -7,7 +7,7 @@ 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, u as unifiedDiff } from './error-a65fcd00.js';
10
+ import { c as c$1, u as unifiedDiff } from './error-c5d734a1.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-0e21bf9b.js';
13
13
  import { n as nanoid } from './index-9e71c815.js';
@@ -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;
@@ -3106,42 +3106,34 @@ function isAsymmetric(obj) {
3106
3106
  return !!obj && isA("Function", obj.asymmetricMatch);
3107
3107
  }
3108
3108
  function asymmetricMatch(a, b) {
3109
- var asymmetricA = isAsymmetric(a), asymmetricB = isAsymmetric(b);
3110
- if (asymmetricA && asymmetricB) {
3109
+ const asymmetricA = isAsymmetric(a);
3110
+ const asymmetricB = isAsymmetric(b);
3111
+ if (asymmetricA && asymmetricB)
3111
3112
  return void 0;
3112
- }
3113
- if (asymmetricA) {
3113
+ if (asymmetricA)
3114
3114
  return a.asymmetricMatch(b);
3115
- }
3116
- if (asymmetricB) {
3115
+ if (asymmetricB)
3117
3116
  return b.asymmetricMatch(a);
3118
- }
3119
3117
  }
3120
3118
  function eq(a, b, aStack, bStack, customTesters, hasKey2) {
3121
- var result = true;
3122
- var asymmetricResult = asymmetricMatch(a, b);
3123
- if (asymmetricResult !== void 0) {
3119
+ let result = true;
3120
+ const asymmetricResult = asymmetricMatch(a, b);
3121
+ if (asymmetricResult !== void 0)
3124
3122
  return asymmetricResult;
3125
- }
3126
- for (var i = 0; i < customTesters.length; i++) {
3127
- var customTesterResult = customTesters[i](a, b);
3128
- 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)
3129
3126
  return customTesterResult;
3130
- }
3131
- }
3132
- if (a instanceof Error && b instanceof Error) {
3133
- return a.message == b.message;
3134
3127
  }
3135
- 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))
3136
3131
  return true;
3137
- }
3138
- if (a === null || b === null) {
3132
+ if (a === null || b === null)
3139
3133
  return a === b;
3140
- }
3141
- var className = Object.prototype.toString.call(a);
3142
- if (className != Object.prototype.toString.call(b)) {
3134
+ const className = Object.prototype.toString.call(a);
3135
+ if (className !== Object.prototype.toString.call(b))
3143
3136
  return false;
3144
- }
3145
3137
  switch (className) {
3146
3138
  case "[object Boolean]":
3147
3139
  case "[object String]":
@@ -3154,51 +3146,45 @@ function eq(a, b, aStack, bStack, customTesters, hasKey2) {
3154
3146
  return Object.is(a.valueOf(), b.valueOf());
3155
3147
  }
3156
3148
  case "[object Date]":
3157
- return +a == +b;
3149
+ return +a === +b;
3158
3150
  case "[object RegExp]":
3159
3151
  return a.source === b.source && a.flags === b.flags;
3160
3152
  }
3161
- if (typeof a !== "object" || typeof b !== "object") {
3153
+ if (typeof a !== "object" || typeof b !== "object")
3162
3154
  return false;
3163
- }
3164
- if (isDomNode(a) && isDomNode(b)) {
3155
+ if (isDomNode(a) && isDomNode(b))
3165
3156
  return a.isEqualNode(b);
3166
- }
3167
- var length = aStack.length;
3157
+ let length = aStack.length;
3168
3158
  while (length--) {
3169
- if (aStack[length] === a) {
3159
+ if (aStack[length] === a)
3170
3160
  return bStack[length] === b;
3171
- } else if (bStack[length] === b) {
3161
+ else if (bStack[length] === b)
3172
3162
  return false;
3173
- }
3174
3163
  }
3175
3164
  aStack.push(a);
3176
3165
  bStack.push(b);
3177
- if (className == "[object Array]" && a.length !== b.length) {
3166
+ if (className === "[object Array]" && a.length !== b.length)
3178
3167
  return false;
3179
- }
3180
- var aKeys = keys(a, hasKey2), key;
3181
- var size = aKeys.length;
3182
- 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)
3183
3172
  return false;
3184
- }
3185
3173
  while (size--) {
3186
3174
  key = aKeys[size];
3187
3175
  result = hasKey2(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, hasKey2);
3188
- if (!result) {
3176
+ if (!result)
3189
3177
  return false;
3190
- }
3191
3178
  }
3192
3179
  aStack.pop();
3193
3180
  bStack.pop();
3194
3181
  return result;
3195
3182
  }
3196
3183
  function keys(obj, hasKey2) {
3197
- var keys2 = [];
3198
- for (var key in obj) {
3199
- if (hasKey2(obj, key)) {
3184
+ const keys2 = [];
3185
+ for (const key in obj) {
3186
+ if (hasKey2(obj, key))
3200
3187
  keys2.push(key);
3201
- }
3202
3188
  }
3203
3189
  return keys2.concat(Object.getOwnPropertySymbols(obj).filter((symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable));
3204
3190
  }
@@ -3209,7 +3195,7 @@ function hasKey(obj, key) {
3209
3195
  return Object.prototype.hasOwnProperty.call(obj, key);
3210
3196
  }
3211
3197
  function isA(typeName, value) {
3212
- return Object.prototype.toString.apply(value) === "[object " + typeName + "]";
3198
+ return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
3213
3199
  }
3214
3200
  function isDomNode(obj) {
3215
3201
  return obj !== null && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string" && typeof obj.isEqualNode === "function";
@@ -3226,17 +3212,14 @@ function isImmutableUnorderedSet(maybeSet) {
3226
3212
  const IteratorSymbol = Symbol.iterator;
3227
3213
  const hasIterator = (object) => !!(object != null && object[IteratorSymbol]);
3228
3214
  const iterableEquality = (a, b, aStack = [], bStack = []) => {
3229
- 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))
3230
3216
  return void 0;
3231
- }
3232
- if (a.constructor !== b.constructor) {
3217
+ if (a.constructor !== b.constructor)
3233
3218
  return false;
3234
- }
3235
3219
  let length = aStack.length;
3236
3220
  while (length--) {
3237
- if (aStack[length] === a) {
3221
+ if (aStack[length] === a)
3238
3222
  return bStack[length] === b;
3239
- }
3240
3223
  }
3241
3224
  aStack.push(a);
3242
3225
  bStack.push(b);
@@ -3251,9 +3234,8 @@ const iterableEquality = (a, b, aStack = [], bStack = []) => {
3251
3234
  let has = false;
3252
3235
  for (const bValue of b) {
3253
3236
  const isEqual = equals(aValue, bValue, [iterableEqualityWithStack]);
3254
- if (isEqual === true) {
3237
+ if (isEqual === true)
3255
3238
  has = true;
3256
- }
3257
3239
  }
3258
3240
  if (has === false) {
3259
3241
  allFound = false;
@@ -3279,9 +3261,8 @@ const iterableEquality = (a, b, aStack = [], bStack = []) => {
3279
3261
  iterableEqualityWithStack
3280
3262
  ]);
3281
3263
  }
3282
- if (matchedValue === true) {
3264
+ if (matchedValue === true)
3283
3265
  has = true;
3284
- }
3285
3266
  }
3286
3267
  if (has === false) {
3287
3268
  allFound = false;
@@ -3297,35 +3278,30 @@ const iterableEquality = (a, b, aStack = [], bStack = []) => {
3297
3278
  const bIterator = b[IteratorSymbol]();
3298
3279
  for (const aValue of a) {
3299
3280
  const nextB = bIterator.next();
3300
- if (nextB.done || !equals(aValue, nextB.value, [iterableEqualityWithStack])) {
3281
+ if (nextB.done || !equals(aValue, nextB.value, [iterableEqualityWithStack]))
3301
3282
  return false;
3302
- }
3303
3283
  }
3304
- if (!bIterator.next().done) {
3284
+ if (!bIterator.next().done)
3305
3285
  return false;
3306
- }
3307
3286
  aStack.pop();
3308
3287
  bStack.pop();
3309
3288
  return true;
3310
3289
  };
3311
3290
  const hasPropertyInObject = (object, key) => {
3312
3291
  const shouldTerminate = !object || typeof object !== "object" || object === Object.prototype;
3313
- if (shouldTerminate) {
3292
+ if (shouldTerminate)
3314
3293
  return false;
3315
- }
3316
3294
  return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
3317
3295
  };
3318
3296
  const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
3319
3297
  const subsetEquality = (object, subset) => {
3320
3298
  const subsetEqualityWithContext = (seenReferences = new WeakMap()) => (object2, subset2) => {
3321
- if (!isObjectWithKeys(subset2)) {
3299
+ if (!isObjectWithKeys(subset2))
3322
3300
  return void 0;
3323
- }
3324
3301
  return Object.keys(subset2).every((key) => {
3325
3302
  if (isObjectWithKeys(subset2[key])) {
3326
- if (seenReferences.has(subset2[key])) {
3303
+ if (seenReferences.has(subset2[key]))
3327
3304
  return equals(object2[key], subset2[key], [iterableEquality]);
3328
- }
3329
3305
  seenReferences.set(subset2[key], true);
3330
3306
  }
3331
3307
  const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
@@ -3652,22 +3628,21 @@ async function runSetupFiles(config) {
3652
3628
  }));
3653
3629
  }
3654
3630
 
3655
- function serialize(err) {
3656
- if (typeof err !== "object")
3657
- return err;
3658
- Object.keys(err).forEach((key) => {
3659
- const val = err[key];
3660
- if (typeof val === "function")
3661
- err[key] = `Function<${val.name}>`;
3662
- if (typeof val !== "object")
3663
- return;
3664
- if ("then" in val)
3665
- err[key] = "Promise";
3666
- if (typeof Element !== "undefined" && val instanceof Element)
3667
- err[key] = val.tagName;
3668
- 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]);
3669
3644
  });
3670
- return err;
3645
+ return val;
3671
3646
  }
3672
3647
  function processError(err) {
3673
3648
  if (!err)
@@ -3676,7 +3651,7 @@ function processError(err) {
3676
3651
  err.stackStr = String(err.stack);
3677
3652
  if (err.name)
3678
3653
  err.nameStr = String(err.name);
3679
- return serialize(err);
3654
+ return serializeError(err);
3680
3655
  }
3681
3656
 
3682
3657
  async function collectTests(paths, config) {
@@ -3732,7 +3707,11 @@ async function collectTests(paths, config) {
3732
3707
  }
3733
3708
 
3734
3709
  async function callSuiteHook(suite, name, args) {
3710
+ if (name === "beforeEach" && suite.suite)
3711
+ await callSuiteHook(suite.suite, name, args);
3735
3712
  await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)));
3713
+ if (name === "afterEach" && suite.suite)
3714
+ await callSuiteHook(suite.suite, name, args);
3736
3715
  }
3737
3716
  function updateTask(task) {
3738
3717
  return rpc("onTaskUpdate", [task.id, task.result]);
@@ -1358,6 +1358,8 @@ function posToNumber(source, pos) {
1358
1358
  const lines = source.split(splitRE);
1359
1359
  const { line, column } = pos;
1360
1360
  let start = 0;
1361
+ if (line > lines.length)
1362
+ return source.length;
1361
1363
  for (let i = 0; i < line - 1; i++)
1362
1364
  start += lines[i].length + 1;
1363
1365
  return start + column;
@@ -1425,6 +1427,8 @@ function parseStack(stack) {
1425
1427
  return stackFrames.filter(notNullish);
1426
1428
  }
1427
1429
  function unifiedDiff(actual, expected) {
1430
+ if (actual === expected)
1431
+ return "";
1428
1432
  const diffLimit = 10;
1429
1433
  const indent = " ";
1430
1434
  let expectedLinesCount = 0;
@@ -5,8 +5,8 @@ import { promises } from 'fs';
5
5
  import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-adef7ffb.js';
6
6
  import { g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-9dcc4050.js';
7
7
  import { performance } from 'perf_hooks';
8
- import { s as stringWidth, a as ansiStyles, b as stripAnsi, d as sliceAnsi, c, F as F_POINTER, e as F_DOWN, f as F_LONG_DASH, g as F_DOWN_RIGHT, h as F_DOT, i as F_CHECK, j as F_CROSS, k as cliTruncate, l as F_RIGHT, p as printError } from './error-a65fcd00.js';
9
- import require$$0 from 'assert';
8
+ import { s as stringWidth, a as ansiStyles, b as stripAnsi, d as sliceAnsi, c, F as F_POINTER, e as F_DOWN, f as F_LONG_DASH, g as F_DOWN_RIGHT, h as F_DOT, i as F_CHECK, j as F_CROSS, k as cliTruncate, l as F_RIGHT, p as printError } from './error-c5d734a1.js';
9
+ import assert$1 from 'assert';
10
10
  import require$$2 from 'events';
11
11
  import { MessageChannel } from 'worker_threads';
12
12
  import { pathToFileURL } from 'url';
@@ -644,7 +644,7 @@ const processOk = function (process) {
644
644
  if (!processOk(process$1)) {
645
645
  signalExit$1.exports = function () {};
646
646
  } else {
647
- var assert = require$$0;
647
+ var assert = assert$1;
648
648
  var signals = signals$1.exports;
649
649
  var isWin = /^win/i.test(process$1.platform);
650
650
 
@@ -1576,14 +1576,29 @@ function resolveConfig(options, viteConfig) {
1576
1576
  }
1577
1577
 
1578
1578
  async function transformRequest(server, id) {
1579
+ let result = null;
1579
1580
  if (id.match(/\.(?:[cm]?[jt]sx?|json)$/)) {
1580
- return await server.transformRequest(id, { ssr: true });
1581
+ result = await server.transformRequest(id, { ssr: true });
1581
1582
  } else {
1582
- const result = await server.transformRequest(id);
1583
- if (!result)
1584
- return void 0;
1585
- return await server.ssrTransform(result.code, result.map, id);
1583
+ result = await server.transformRequest(id);
1584
+ if (result)
1585
+ result = await server.ssrTransform(result.code, result.map, id);
1586
1586
  }
1587
+ if (result && process.env.NODE_V8_COVERAGE)
1588
+ withInlineSourcemap(result);
1589
+ return result;
1590
+ }
1591
+ let SOURCEMAPPING_URL = "sourceMa";
1592
+ SOURCEMAPPING_URL += "ppingURL";
1593
+ async function withInlineSourcemap(result) {
1594
+ const { code, map } = result;
1595
+ if (code.includes(`${SOURCEMAPPING_URL}=`))
1596
+ return result;
1597
+ if (map)
1598
+ result.code = `${code}
1599
+
1600
+ //# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}`;
1601
+ return result;
1587
1602
  }
1588
1603
 
1589
1604
  function createPool(ctx) {
@@ -1594,21 +1609,24 @@ function createPool(ctx) {
1594
1609
  }
1595
1610
  const workerPath = new URL("./dist/worker.js", pathToFileURL(distDir)).href;
1596
1611
  function createFakePool(ctx) {
1597
- const runTestFiles = async (files, invalidates) => {
1598
- const { default: run } = await import(workerPath);
1599
- const { workerPort, port } = createChannel(ctx);
1600
- const data = {
1601
- port: workerPort,
1602
- config: ctx.config,
1603
- files,
1604
- invalidates
1612
+ const runWithFiles = (name) => {
1613
+ return async (files, invalidates) => {
1614
+ const worker = await import(workerPath);
1615
+ const { workerPort, port } = createChannel(ctx);
1616
+ const data = {
1617
+ port: workerPort,
1618
+ config: ctx.config,
1619
+ files,
1620
+ invalidates
1621
+ };
1622
+ await worker[name](data, { transferList: [workerPort] });
1623
+ port.close();
1624
+ workerPort.close();
1605
1625
  };
1606
- await run(data, { transferList: [workerPort] });
1607
- port.close();
1608
- workerPort.close();
1609
1626
  };
1610
1627
  return {
1611
- runTestFiles,
1628
+ runTests: runWithFiles("run"),
1629
+ collectTests: runWithFiles("collect"),
1612
1630
  close: async () => {
1613
1631
  }
1614
1632
  };
@@ -1623,22 +1641,25 @@ function createWorkerPool(ctx) {
1623
1641
  if (ctx.config.minThreads != null)
1624
1642
  options.minThreads = ctx.config.minThreads;
1625
1643
  const piscina = new Piscina(options);
1626
- const runTestFiles = async (files, invalidates) => {
1627
- await Promise.all(files.map(async (file) => {
1628
- const { workerPort, port } = createChannel(ctx);
1629
- const data = {
1630
- port: workerPort,
1631
- config: ctx.config,
1632
- files: [file],
1633
- invalidates
1634
- };
1635
- await piscina.run(data, { transferList: [workerPort] });
1636
- port.close();
1637
- workerPort.close();
1638
- }));
1644
+ const runWithFiles = (name) => {
1645
+ return async (files, invalidates) => {
1646
+ await Promise.all(files.map(async (file) => {
1647
+ const { workerPort, port } = createChannel(ctx);
1648
+ const data = {
1649
+ port: workerPort,
1650
+ config: ctx.config,
1651
+ files: [file],
1652
+ invalidates
1653
+ };
1654
+ await piscina.run(data, { transferList: [workerPort], name });
1655
+ port.close();
1656
+ workerPort.close();
1657
+ }));
1658
+ };
1639
1659
  };
1640
1660
  return {
1641
- runTestFiles,
1661
+ runTests: runWithFiles("run"),
1662
+ collectTests: runWithFiles("collect"),
1642
1663
  close: () => piscina.destroy()
1643
1664
  };
1644
1665
  }
@@ -1661,7 +1682,7 @@ function createChannel(ctx) {
1661
1682
  case "snapshotSaved":
1662
1683
  return send(() => ctx.snapshot.add(args[0]));
1663
1684
  case "fetch":
1664
- return send(() => transformRequest(ctx.server, ...args));
1685
+ return send(() => transformRequest(ctx.server, ...args).then((r) => r == null ? void 0 : r.code));
1665
1686
  case "onCollected":
1666
1687
  ctx.state.collectFiles(args[0]);
1667
1688
  ctx.reporters.forEach((r) => {
@@ -1757,7 +1778,7 @@ async function startWatcher(ctx) {
1757
1778
  async function start(tests, id, invalidates) {
1758
1779
  var _a;
1759
1780
  await ctx.report("onWatcherRerun", tests, id);
1760
- await ((_a = ctx.pool) == null ? void 0 : _a.runTestFiles(tests, invalidates));
1781
+ await ((_a = ctx.pool) == null ? void 0 : _a.runTests(tests, invalidates));
1761
1782
  await ctx.report("onFinished", ctx.state.getFiles(tests));
1762
1783
  await ctx.report("onWatcherStart");
1763
1784
  }
@@ -1817,7 +1838,7 @@ class Vitest {
1817
1838
  }
1818
1839
  if (!this.pool)
1819
1840
  this.pool = createPool(this);
1820
- await this.pool.runTestFiles(testFilepaths);
1841
+ await this.pool.runTests(testFilepaths);
1821
1842
  if (hasFailed(this.state.getFiles()))
1822
1843
  process.exitCode = 1;
1823
1844
  await this.report("onFinished", this.state.getFiles());
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Formatter } from 'picocolors/types';
2
- import { TransformResult } from 'vite';
3
2
  import { OptionsReceived } from 'pretty-format';
4
3
  import { MessagePort } from 'worker_threads';
5
4
  export { assert, default as chai, expect, should } from 'chai';
@@ -117,7 +116,7 @@ declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
117
116
  interface ModuleCache {
118
117
  promise?: Promise<any>;
119
118
  exports?: any;
120
- transformResult?: TransformResult;
119
+ code?: string;
121
120
  }
122
121
  interface EnvironmentReturn {
123
122
  teardown: (global: any) => Awaitable<void>;
@@ -420,7 +419,7 @@ interface WorkerContext {
420
419
  invalidates?: string[];
421
420
  }
422
421
  interface RpcMap {
423
- fetch: [[id: string], TransformResult | null | undefined];
422
+ fetch: [[id: string], string | undefined];
424
423
  log: [[UserConsoleLog], void];
425
424
  processExit: [[code?: number], void];
426
425
  onCollected: [[files: File[]], void];