vitest 0.9.2 → 0.10.0

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.
Files changed (30) hide show
  1. package/LICENSE.md +7 -0
  2. package/dist/{chunk-api-setup.7290422e.js → chunk-api-setup.d70fc960.js} +5 -5
  3. package/dist/{chunk-constants.e59013dc.js → chunk-constants.d540b1d1.js} +1 -1
  4. package/dist/{chunk-defaults.9aa0ce42.js → chunk-defaults.04d5d90b.js} +1 -1
  5. package/dist/{chunk-install-pkg.7dd40977.js → chunk-install-pkg.73b84ae1.js} +113 -115
  6. package/dist/chunk-integrations-globals.d2c09cd2.js +29 -0
  7. package/dist/chunk-integrations-spy.f036df6f.js +102 -0
  8. package/dist/{chunk-runtime-chain.94cf66a4.js → chunk-runtime-chain.f863f182.js} +934 -897
  9. package/dist/{chunk-runtime-mocker.7f4b1850.js → chunk-runtime-mocker.111ac858.js} +3 -3
  10. package/dist/{chunk-runtime-rpc.4b80b6bd.js → chunk-runtime-rpc.8f648236.js} +1 -1
  11. package/dist/{chunk-utils-global.10dcdfa6.js → chunk-utils-global.37a7c822.js} +8 -10
  12. package/dist/{chunk-utils-timers.4800834c.js → chunk-utils-timers.12bc05d1.js} +1404 -1057
  13. package/dist/{chunk-vite-node-externalize.ddf2a6fb.js → chunk-vite-node-externalize.5c678054.js} +1773 -4417
  14. package/dist/{chunk-vite-node-utils.7f0053fb.js → chunk-vite-node-utils.33447cc0.js} +71 -71
  15. package/dist/cli.js +13 -13
  16. package/dist/entry.js +15 -919
  17. package/dist/index.d.ts +92 -25
  18. package/dist/index.js +8 -8
  19. package/dist/node.d.ts +25 -7
  20. package/dist/node.js +12 -12
  21. package/dist/spy.js +2 -102
  22. package/dist/vendor-_commonjsHelpers.addc3445.js +3 -0
  23. package/dist/vendor-entry.369fd6c9.js +949 -0
  24. package/dist/vendor-index.405e58ef.js +6291 -0
  25. package/dist/{vendor-index.87b2fc14.js → vendor-index.40be925a.js} +167 -152
  26. package/dist/worker.js +6 -6
  27. package/package.json +11 -11
  28. package/dist/chunk-integrations-globals.c040aaa9.js +0 -23
  29. package/dist/vendor-_commonjsHelpers.34b404ce.js +0 -7
  30. package/dist/vendor-index.ee829ed6.js +0 -5707
@@ -1,11 +1,11 @@
1
- import require$$0, { format } from 'util';
2
- import { g as getWorkerState, i as isObject, t as toArray, n as noop, a as index$1, b as getCallLastIndex, s as slash, c as getNames, d as assertTypes, e as c, r as resetModules } from './chunk-utils-global.10dcdfa6.js';
3
- import { s as setTimeout, c as clearTimeout, p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, d as stringify, m as matcherUtils } from './chunk-utils-timers.4800834c.js';
4
- import chai$1, { expect as expect$1, util, assert, should } from 'chai';
5
- import { c as commonjsRequire, a as commonjsGlobal } from './vendor-_commonjsHelpers.34b404ce.js';
6
- import { r as rpc } from './chunk-runtime-rpc.4b80b6bd.js';
1
+ import chai$1, { expect as expect$1, util } from 'chai';
2
+ import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
3
+ import { r as rpc } from './chunk-runtime-rpc.8f648236.js';
4
+ import { i as isObject, a as index, g as getCallLastIndex, s as slash, b as getWorkerState, c as getNames, d as assertTypes, p as picocolors, n as noop, t as toArray, r as resetModules } from './chunk-utils-global.37a7c822.js';
7
5
  import fs, { promises } from 'fs';
8
- import { isMockFunction, spyOn, fn, spies } from './spy.js';
6
+ import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils, c as setTimeout, d as clearTimeout } from './chunk-utils-timers.12bc05d1.js';
7
+ import { i as isMockFunction, s as spyOn, f as fn, a as spies } from './chunk-integrations-spy.f036df6f.js';
8
+ import require$$0, { format } from 'util';
9
9
 
10
10
  var __defProp$4 = Object.defineProperty;
11
11
  var __defProps$2 = Object.defineProperties;
@@ -45,313 +45,92 @@ function createChainable(keys, fn) {
45
45
  return chain;
46
46
  }
47
47
 
48
- const context = {
49
- tasks: [],
50
- currentSuite: null
51
- };
52
- function collectTask(task) {
53
- var _a;
54
- (_a = context.currentSuite) == null ? void 0 : _a.tasks.push(task);
55
- }
56
- async function runWithSuite(suite, fn) {
57
- const prev = context.currentSuite;
58
- context.currentSuite = suite;
59
- await fn();
60
- context.currentSuite = prev;
61
- }
62
- function getDefaultTestTimeout() {
63
- return getWorkerState().config.testTimeout;
64
- }
65
- function getDefaultHookTimeout() {
66
- return getWorkerState().config.hookTimeout;
67
- }
68
- function withTimeout(fn, timeout = getDefaultTestTimeout(), isHook = false) {
69
- if (timeout <= 0 || timeout === Infinity)
70
- return fn;
71
- return (...args) => {
72
- return Promise.race([fn(...args), new Promise((resolve, reject) => {
73
- const timer = setTimeout(() => {
74
- clearTimeout(timer);
75
- reject(new Error(makeTimeoutMsg(isHook, timeout)));
76
- }, timeout);
77
- timer.unref();
78
- })]);
79
- };
80
- }
81
- function makeTimeoutMsg(isHook, timeout) {
82
- return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
83
- If this is a long-running test, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
84
- }
85
- function ensureAsyncTest(fn) {
86
- if (!fn.length)
87
- return fn;
88
- return () => new Promise((resolve, reject) => {
89
- const done = (...args) => args[0] ? reject(args[0]) : resolve();
90
- fn(done);
91
- });
92
- }
93
- function normalizeTest(fn, timeout) {
94
- return withTimeout(ensureAsyncTest(fn), timeout);
95
- }
96
-
97
- const fnMap = /* @__PURE__ */ new WeakMap();
98
- const hooksMap = /* @__PURE__ */ new WeakMap();
99
- function setFn(key, fn) {
100
- fnMap.set(key, fn);
101
- }
102
- function getFn(key) {
103
- return fnMap.get(key);
104
- }
105
- function setHooks(key, hooks) {
106
- hooksMap.set(key, hooks);
107
- }
108
- function getHooks(key) {
109
- return hooksMap.get(key);
110
- }
111
-
112
- const suite = createSuite();
113
- const test = createTest(function(name, fn, timeout) {
114
- getCurrentSuite().test.fn.call(this, name, fn, timeout);
115
- });
116
- function formatTitle(template, items, idx) {
117
- if (template.includes("%#")) {
118
- template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
119
- }
120
- const count = template.split("%").length - 1;
121
- let formatted = format(template, ...items.slice(0, count));
122
- if (isObject(items[0])) {
123
- formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
124
- return items[0][key];
125
- });
126
- }
127
- return formatted;
128
- }
129
- const describe = suite;
130
- const it = test;
131
- const defaultSuite = suite("");
132
- function clearContext() {
133
- context.tasks.length = 0;
134
- defaultSuite.clear();
135
- context.currentSuite = defaultSuite;
136
- }
137
- function getCurrentSuite() {
138
- return context.currentSuite || defaultSuite;
139
- }
140
- function createSuiteHooks() {
141
- return {
142
- beforeAll: [],
143
- afterAll: [],
144
- beforeEach: [],
145
- afterEach: []
146
- };
147
- }
148
- function createSuiteCollector(name, factory = () => {
149
- }, mode, concurrent) {
150
- const tasks = [];
151
- const factoryQueue = [];
152
- let suite2;
153
- initSuite();
154
- const test2 = createTest(function(name2, fn, timeout) {
155
- const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
156
- const test3 = {
157
- id: "",
158
- type: "test",
159
- name: name2,
160
- mode: mode2,
161
- suite: void 0,
162
- fails: this.fails
163
- };
164
- if (this.concurrent || concurrent)
165
- test3.concurrent = true;
166
- setFn(test3, normalizeTest(fn || noop, timeout));
167
- tasks.push(test3);
168
- });
169
- const collector = {
170
- type: "collector",
171
- name,
172
- mode,
173
- test: test2,
174
- tasks,
175
- collect,
176
- clear,
177
- on: addHook
178
- };
179
- function addHook(name2, ...fn) {
180
- getHooks(suite2)[name2].push(...fn);
181
- }
182
- function initSuite() {
183
- suite2 = {
184
- id: "",
185
- type: "suite",
186
- name,
187
- mode,
188
- tasks: []
189
- };
190
- setHooks(suite2, createSuiteHooks());
191
- }
192
- function clear() {
193
- tasks.length = 0;
194
- factoryQueue.length = 0;
195
- initSuite();
196
- }
197
- async function collect(file) {
198
- factoryQueue.length = 0;
199
- if (factory)
200
- await runWithSuite(collector, () => factory(test2));
201
- const allChildren = [];
202
- for (const i of [...factoryQueue, ...tasks])
203
- allChildren.push(i.type === "collector" ? await i.collect(file) : i);
204
- suite2.file = file;
205
- suite2.tasks = allChildren;
206
- allChildren.forEach((task) => {
207
- task.suite = suite2;
208
- if (file)
209
- task.file = file;
210
- });
211
- return suite2;
212
- }
213
- collectTask(collector);
214
- return collector;
215
- }
216
- function createSuite() {
217
- const suite2 = createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
218
- const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
219
- return createSuiteCollector(name, factory, mode, this.concurrent);
220
- });
221
- suite2.each = (cases) => {
222
- return (name, fn) => {
223
- cases.forEach((i, idx) => {
224
- const items = toArray(i);
225
- suite2(formatTitle(name, items, idx), () => fn(...items));
226
- });
227
- };
228
- };
229
- return suite2;
230
- }
231
- function createTest(fn) {
232
- const test2 = createChainable(["concurrent", "skip", "only", "todo", "fails"], fn);
233
- test2.each = (cases) => {
234
- return (name, fn2) => {
235
- cases.forEach((i, idx) => {
236
- const items = toArray(i);
237
- test2(formatTitle(name, items, idx), () => fn2(...items));
238
- });
239
- };
240
- };
241
- return test2;
242
- }
243
-
244
- const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
245
- const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
246
- const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
247
- const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
248
-
249
- const filesCount = /* @__PURE__ */ new Map();
250
- const cache = /* @__PURE__ */ new Map();
251
- function runOnce(fn, key) {
252
- const filepath = getWorkerState().filepath || "__unknown_files__";
253
- if (!key) {
254
- filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
255
- key = String(filesCount.get(filepath));
256
- }
257
- const id = `${filepath}:${key}`;
258
- if (!cache.has(id))
259
- cache.set(id, fn());
260
- return cache.get(id);
261
- }
262
- function isFirstRun() {
263
- let firstRun = false;
264
- runOnce(() => {
265
- firstRun = true;
266
- }, "__vitest_first_run__");
267
- return firstRun;
268
- }
269
- function resetRunOnceCounter() {
270
- filesCount.clear();
48
+ function commonjsRequire(path) {
49
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
271
50
  }
272
51
 
273
52
  var chaiSubset = {exports: {}};
274
53
 
275
54
  (function (module, exports) {
276
- (function() {
277
- (function(chaiSubset) {
278
- if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
279
- return module.exports = chaiSubset;
280
- } else {
281
- return chai.use(chaiSubset);
282
- }
283
- })(function(chai, utils) {
284
- var Assertion = chai.Assertion;
285
- var assertionPrototype = Assertion.prototype;
286
-
287
- Assertion.addMethod('containSubset', function (expected) {
288
- var actual = utils.flag(this, 'object');
289
- var showDiff = chai.config.showDiff;
290
-
291
- assertionPrototype.assert.call(this,
292
- compare(expected, actual),
293
- 'expected #{act} to contain subset #{exp}',
294
- 'expected #{act} to not contain subset #{exp}',
295
- expected,
296
- actual,
297
- showDiff
298
- );
299
- });
300
-
301
- chai.assert.containSubset = function(val, exp, msg) {
302
- new chai.Assertion(val, msg).to.be.containSubset(exp);
303
- };
304
-
305
- function compare(expected, actual) {
306
- if (expected === actual) {
307
- return true;
308
- }
309
- if (typeof(actual) !== typeof(expected)) {
310
- return false;
311
- }
312
- if (typeof(expected) !== 'object' || expected === null) {
313
- return expected === actual;
314
- }
315
- if (!!expected && !actual) {
316
- return false;
55
+ (function() {
56
+ (function(chaiSubset) {
57
+ if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
58
+ return module.exports = chaiSubset;
59
+ } else {
60
+ return chai.use(chaiSubset);
317
61
  }
62
+ })(function(chai, utils) {
63
+ var Assertion = chai.Assertion;
64
+ var assertionPrototype = Assertion.prototype;
65
+
66
+ Assertion.addMethod('containSubset', function (expected) {
67
+ var actual = utils.flag(this, 'object');
68
+ var showDiff = chai.config.showDiff;
69
+
70
+ assertionPrototype.assert.call(this,
71
+ compare(expected, actual),
72
+ 'expected #{act} to contain subset #{exp}',
73
+ 'expected #{act} to not contain subset #{exp}',
74
+ expected,
75
+ actual,
76
+ showDiff
77
+ );
78
+ });
318
79
 
319
- if (Array.isArray(expected)) {
320
- if (typeof(actual.length) !== 'number') {
80
+ chai.assert.containSubset = function(val, exp, msg) {
81
+ new chai.Assertion(val, msg).to.be.containSubset(exp);
82
+ };
83
+
84
+ function compare(expected, actual) {
85
+ if (expected === actual) {
86
+ return true;
87
+ }
88
+ if (typeof(actual) !== typeof(expected)) {
321
89
  return false;
322
90
  }
323
- var aa = Array.prototype.slice.call(actual);
324
- return expected.every(function (exp) {
325
- return aa.some(function (act) {
326
- return compare(exp, act);
327
- });
328
- });
329
- }
330
-
331
- if (expected instanceof Date) {
332
- if (actual instanceof Date) {
333
- return expected.getTime() === actual.getTime();
334
- } else {
91
+ if (typeof(expected) !== 'object' || expected === null) {
92
+ return expected === actual;
93
+ }
94
+ if (!!expected && !actual) {
335
95
  return false;
336
96
  }
337
- }
338
97
 
339
- return Object.keys(expected).every(function (key) {
340
- var eo = expected[key];
341
- var ao = actual[key];
342
- if (typeof(eo) === 'object' && eo !== null && ao !== null) {
343
- return compare(eo, ao);
98
+ if (Array.isArray(expected)) {
99
+ if (typeof(actual.length) !== 'number') {
100
+ return false;
101
+ }
102
+ var aa = Array.prototype.slice.call(actual);
103
+ return expected.every(function (exp) {
104
+ return aa.some(function (act) {
105
+ return compare(exp, act);
106
+ });
107
+ });
344
108
  }
345
- if (typeof(eo) === 'function') {
346
- return eo(ao);
109
+
110
+ if (expected instanceof Date) {
111
+ if (actual instanceof Date) {
112
+ return expected.getTime() === actual.getTime();
113
+ } else {
114
+ return false;
115
+ }
347
116
  }
348
- return ao === eo;
349
- });
350
- }
351
- });
352
117
 
353
- }).call(commonjsGlobal);
354
- }(chaiSubset));
118
+ return Object.keys(expected).every(function (key) {
119
+ var eo = expected[key];
120
+ var ao = actual[key];
121
+ if (typeof(eo) === 'object' && eo !== null && ao !== null) {
122
+ return compare(eo, ao);
123
+ }
124
+ if (typeof(eo) === 'function') {
125
+ return eo(ao);
126
+ }
127
+ return ao === eo;
128
+ });
129
+ }
130
+ });
131
+
132
+ }).call(commonjsGlobal);
133
+ } (chaiSubset));
355
134
 
356
135
  var Subset = chaiSubset.exports;
357
136
 
@@ -597,7 +376,7 @@ const sparseArrayEquality = (a, b) => {
597
376
  return equals(a, b, [iterableEquality, typeEquality], true) && equals(aKeys, bKeys);
598
377
  };
599
378
 
600
- var naturalCompare$2 = {exports: {}};
379
+ var naturalCompare$1 = {exports: {}};
601
380
 
602
381
  /*
603
382
  * @version 1.4.0
@@ -649,13 +428,11 @@ var naturalCompare = function(a, b) {
649
428
  };
650
429
 
651
430
  try {
652
- naturalCompare$2.exports = naturalCompare;
431
+ naturalCompare$1.exports = naturalCompare;
653
432
  } catch (e) {
654
433
  String.naturalCompare = naturalCompare;
655
434
  }
656
435
 
657
- var naturalCompare$1 = naturalCompare$2.exports;
658
-
659
436
  const {
660
437
  DOMCollection,
661
438
  DOMElement,
@@ -740,7 +517,7 @@ function printBacktickString(str) {
740
517
  }
741
518
  function ensureDirectoryExists(filePath) {
742
519
  try {
743
- fs.mkdirSync(index$1.join(index$1.dirname(filePath)), { recursive: true });
520
+ fs.mkdirSync(index.join(index.dirname(filePath)), { recursive: true });
744
521
  } catch {
745
522
  }
746
523
  }
@@ -748,7 +525,7 @@ function normalizeNewlines(string) {
748
525
  return string.replace(/\r\n|\r/g, "\n");
749
526
  }
750
527
  async function saveSnapshotFile(snapshotData, snapshotPath) {
751
- const snapshots = Object.keys(snapshotData).sort(naturalCompare$1).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
528
+ const snapshots = Object.keys(snapshotData).sort(naturalCompare$1.exports).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
752
529
  ensureDirectoryExists(snapshotPath);
753
530
  await promises.writeFile(snapshotPath, `${writeSnapshotVersion()}
754
531
 
@@ -911,9 +688,10 @@ var __spreadValues$2 = (a, b) => {
911
688
  return a;
912
689
  };
913
690
  class SnapshotState {
914
- constructor(snapshotPath, options) {
915
- this._snapshotPath = snapshotPath;
916
- const { data, dirty } = getSnapshotData(this._snapshotPath, options.updateSnapshot);
691
+ constructor(testFilePath, snapshotPath, options) {
692
+ this.testFilePath = testFilePath;
693
+ this.snapshotPath = snapshotPath;
694
+ const { data, dirty } = getSnapshotData(this.snapshotPath, options.updateSnapshot);
917
695
  this._initialData = data;
918
696
  this._snapshotData = data;
919
697
  this._dirty = dirty;
@@ -968,6 +746,7 @@ ${JSON.stringify(stacks)}`);
968
746
  this.matched = 0;
969
747
  this.unmatched = 0;
970
748
  this.updated = 0;
749
+ this._dirty = false;
971
750
  }
972
751
  async save() {
973
752
  const hasExternalSnapshots = Object.keys(this._snapshotData).length;
@@ -979,13 +758,13 @@ ${JSON.stringify(stacks)}`);
979
758
  };
980
759
  if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
981
760
  if (hasExternalSnapshots)
982
- await saveSnapshotFile(this._snapshotData, this._snapshotPath);
761
+ await saveSnapshotFile(this._snapshotData, this.snapshotPath);
983
762
  if (hasInlineSnapshots)
984
763
  await saveInlineSnapshots(this._inlineSnapshots);
985
764
  status.saved = true;
986
- } else if (!hasExternalSnapshots && fs.existsSync(this._snapshotPath)) {
765
+ } else if (!hasExternalSnapshots && fs.existsSync(this.snapshotPath)) {
987
766
  if (this._updateSnapshot === "all")
988
- fs.unlinkSync(this._snapshotPath);
767
+ fs.unlinkSync(this.snapshotPath);
989
768
  status.deleted = true;
990
769
  }
991
770
  return status;
@@ -1022,7 +801,7 @@ ${JSON.stringify(stacks)}`);
1022
801
  const expectedTrimmed = prepareExpected(expected);
1023
802
  const pass = expectedTrimmed === prepareExpected(receivedSerialized);
1024
803
  const hasSnapshot = expected !== void 0;
1025
- const snapshotIsPersisted = isInline || fs.existsSync(this._snapshotPath);
804
+ const snapshotIsPersisted = isInline || fs.existsSync(this.snapshotPath);
1026
805
  if (pass && !isInline) {
1027
806
  this._snapshotData[key] = receivedSerialized;
1028
807
  }
@@ -1070,26 +849,57 @@ ${JSON.stringify(stacks)}`);
1070
849
  }
1071
850
  }
1072
851
  }
852
+ async pack() {
853
+ const snapshot = {
854
+ filepath: this.testFilePath,
855
+ added: 0,
856
+ fileDeleted: false,
857
+ matched: 0,
858
+ unchecked: 0,
859
+ uncheckedKeys: [],
860
+ unmatched: 0,
861
+ updated: 0
862
+ };
863
+ const uncheckedCount = this.getUncheckedCount();
864
+ const uncheckedKeys = this.getUncheckedKeys();
865
+ if (uncheckedCount)
866
+ this.removeUncheckedKeys();
867
+ const status = await this.save();
868
+ snapshot.fileDeleted = status.deleted;
869
+ snapshot.added = this.added;
870
+ snapshot.matched = this.matched;
871
+ snapshot.unmatched = this.unmatched;
872
+ snapshot.updated = this.updated;
873
+ snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
874
+ snapshot.uncheckedKeys = Array.from(uncheckedKeys);
875
+ return snapshot;
876
+ }
1073
877
  }
1074
878
 
1075
879
  class SnapshotClient {
1076
880
  constructor() {
1077
- this.testFile = "";
881
+ this.snapshotStateMap = /* @__PURE__ */ new Map();
1078
882
  }
1079
883
  async setTest(test) {
884
+ var _a;
1080
885
  this.test = test;
1081
- if (this.testFile !== this.test.file.filepath) {
1082
- if (this.snapshotState)
1083
- this.saveSnap();
1084
- this.testFile = this.test.file.filepath;
1085
- this.snapshotState = new SnapshotState(await rpc().resolveSnapshotPath(this.testFile), getWorkerState().config.snapshotOptions);
886
+ if (((_a = this.snapshotState) == null ? void 0 : _a.testFilePath) !== this.test.file.filepath) {
887
+ this.saveCurrent();
888
+ const filePath = this.test.file.filepath;
889
+ if (!this.getSnapshotState(test)) {
890
+ this.snapshotStateMap.set(filePath, new SnapshotState(filePath, await rpc().resolveSnapshotPath(filePath), getWorkerState().config.snapshotOptions));
891
+ }
892
+ this.snapshotState = this.getSnapshotState(test);
1086
893
  }
1087
894
  }
895
+ getSnapshotState(test) {
896
+ return this.snapshotStateMap.get(test.file.filepath);
897
+ }
1088
898
  clearTest() {
1089
899
  this.test = void 0;
1090
900
  }
1091
- assert(received, message, isInline = false, properties, inlineSnapshot, error) {
1092
- if (!this.test)
901
+ assert(received, test = this.test, message, isInline = false, properties, inlineSnapshot, error) {
902
+ if (!test)
1093
903
  throw new Error("Snapshot cannot be used outside of test");
1094
904
  if (typeof properties === "object") {
1095
905
  if (typeof received !== "object" || !received)
@@ -1106,10 +916,11 @@ class SnapshotClient {
1106
916
  }
1107
917
  }
1108
918
  const testName = [
1109
- ...getNames(this.test).slice(1),
919
+ ...getNames(test).slice(1),
1110
920
  ...message ? [message] : []
1111
921
  ].join(" > ");
1112
- const { actual, expected, key, pass } = this.snapshotState.match({
922
+ const snapshotState = this.getSnapshotState(test);
923
+ const { actual, expected, key, pass } = snapshotState.match({
1113
924
  testName,
1114
925
  received,
1115
926
  isInline,
@@ -1125,39 +936,16 @@ class SnapshotClient {
1125
936
  }
1126
937
  }
1127
938
  }
1128
- async saveSnap() {
1129
- if (!this.testFile || !this.snapshotState)
939
+ async saveCurrent() {
940
+ if (!this.snapshotState)
1130
941
  return;
1131
- const result = await packSnapshotState(this.testFile, this.snapshotState);
942
+ const result = await this.snapshotState.pack();
1132
943
  await rpc().snapshotSaved(result);
1133
- this.testFile = "";
1134
944
  this.snapshotState = void 0;
1135
945
  }
1136
- }
1137
- async function packSnapshotState(filepath, state) {
1138
- const snapshot = {
1139
- filepath,
1140
- added: 0,
1141
- fileDeleted: false,
1142
- matched: 0,
1143
- unchecked: 0,
1144
- uncheckedKeys: [],
1145
- unmatched: 0,
1146
- updated: 0
1147
- };
1148
- const uncheckedCount = state.getUncheckedCount();
1149
- const uncheckedKeys = state.getUncheckedKeys();
1150
- if (uncheckedCount)
1151
- state.removeUncheckedKeys();
1152
- const status = await state.save();
1153
- snapshot.fileDeleted = status.deleted;
1154
- snapshot.added = state.added;
1155
- snapshot.matched = state.matched;
1156
- snapshot.unmatched = state.unmatched;
1157
- snapshot.updated = state.updated;
1158
- snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
1159
- snapshot.uncheckedKeys = Array.from(uncheckedKeys);
1160
- return snapshot;
946
+ clear() {
947
+ this.snapshotStateMap.clear();
948
+ }
1161
949
  }
1162
950
 
1163
951
  let _client;
@@ -1180,16 +968,18 @@ const SnapshotPlugin = (chai, utils) => {
1180
968
  for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
1181
969
  utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
1182
970
  const expected = utils.flag(this, "object");
971
+ const test = utils.flag(this, "vitest-test");
1183
972
  if (typeof properties === "string" && typeof message === "undefined") {
1184
973
  message = properties;
1185
974
  properties = void 0;
1186
975
  }
1187
- getSnapshotClient().assert(expected, message, false, properties);
976
+ getSnapshotClient().assert(expected, test, message, false, properties);
1188
977
  });
1189
978
  }
1190
979
  utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __VITEST_INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
1191
980
  const expected = utils.flag(this, "object");
1192
981
  const error = utils.flag(this, "error");
982
+ const test = utils.flag(this, "vitest-test");
1193
983
  if (typeof properties === "string") {
1194
984
  message = inlineSnapshot;
1195
985
  inlineSnapshot = properties;
@@ -1197,16 +987,18 @@ const SnapshotPlugin = (chai, utils) => {
1197
987
  }
1198
988
  if (inlineSnapshot)
1199
989
  inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
1200
- getSnapshotClient().assert(expected, message, true, properties, inlineSnapshot, error);
990
+ getSnapshotClient().assert(expected, test, message, true, properties, inlineSnapshot, error);
1201
991
  });
1202
992
  utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
1203
993
  const expected = utils.flag(this, "object");
1204
- getSnapshotClient().assert(getErrorString(expected), message);
994
+ const test = utils.flag(this, "vitest-test");
995
+ getSnapshotClient().assert(getErrorString(expected), test, message);
1205
996
  });
1206
997
  utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __VITEST_INLINE_SNAPSHOT__(inlineSnapshot, message) {
1207
998
  const expected = utils.flag(this, "object");
1208
999
  const error = utils.flag(this, "error");
1209
- getSnapshotClient().assert(getErrorString(expected), message, true, void 0, inlineSnapshot, error);
1000
+ const test = utils.flag(this, "vitest-test");
1001
+ getSnapshotClient().assert(getErrorString(expected), test, message, true, void 0, inlineSnapshot, error);
1210
1002
  });
1211
1003
  };
1212
1004
 
@@ -1253,6 +1045,10 @@ const JestChaiExpect = (chai, utils) => {
1253
1045
  };
1254
1046
  });
1255
1047
  });
1048
+ def("withTest", function(test) {
1049
+ utils.flag(this, "vitest-test", test);
1050
+ return this;
1051
+ });
1256
1052
  def("toEqual", function(expected) {
1257
1053
  const actual = utils.flag(this, "object");
1258
1054
  const equal = equals(actual, expected, [iterableEquality]);
@@ -1392,11 +1188,11 @@ const JestChaiExpect = (chai, utils) => {
1392
1188
  return `${i}th`;
1393
1189
  };
1394
1190
  const formatCalls = (spy, msg, actualCall) => {
1395
- msg += c.gray(`
1191
+ msg += picocolors.exports.gray(`
1396
1192
 
1397
1193
  Received:
1398
1194
  ${spy.mock.calls.map((callArg, i) => {
1399
- let methodCall = c.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
1195
+ let methodCall = picocolors.exports.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
1400
1196
 
1401
1197
  `);
1402
1198
  if (actualCall)
@@ -1406,9 +1202,9 @@ ${spy.mock.calls.map((callArg, i) => {
1406
1202
  methodCall += "\n";
1407
1203
  return methodCall;
1408
1204
  }).join("\n")}`);
1409
- msg += c.gray(`
1205
+ msg += picocolors.exports.gray(`
1410
1206
 
1411
- Number of calls: ${c.bold(spy.mock.calls.length)}
1207
+ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1412
1208
  `);
1413
1209
  return msg;
1414
1210
  };
@@ -1538,6 +1334,9 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
1538
1334
  const nthCallReturn = equals(callResult, value);
1539
1335
  this.assert(nthCallReturn, `expected ${ordinalCall} "${spyName}" call to return #{exp}`, `expected ${ordinalCall} "${spyName}" call to not return #{exp}`, value, callResult);
1540
1336
  });
1337
+ def("toSatisfy", function() {
1338
+ return this.be.satisfy;
1339
+ });
1541
1340
  utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() {
1542
1341
  utils.flag(this, "promise", "resolves");
1543
1342
  utils.flag(this, "error", new Error("resolves"));
@@ -1837,90 +1636,341 @@ const getMatcherState = (assertion) => {
1837
1636
  equals,
1838
1637
  suppressedErrors: []
1839
1638
  });
1840
- return {
1841
- state: matcherState,
1842
- isNot,
1843
- obj
1639
+ return {
1640
+ state: matcherState,
1641
+ isNot,
1642
+ obj
1643
+ };
1644
+ };
1645
+ class JestExtendError extends Error {
1646
+ constructor(message, actual, expected) {
1647
+ super(message);
1648
+ this.actual = actual;
1649
+ this.expected = expected;
1650
+ }
1651
+ }
1652
+ function JestExtendPlugin(expect, matchers) {
1653
+ return (c, utils) => {
1654
+ Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
1655
+ function expectSyncWrapper(...args) {
1656
+ const { state, isNot, obj } = getMatcherState(this);
1657
+ const { pass, message, actual, expected } = expectAssertion.call(state, obj, ...args);
1658
+ if (pass && isNot || !pass && !isNot)
1659
+ throw new JestExtendError(message(), actual, expected);
1660
+ }
1661
+ async function expectAsyncWrapper(...args) {
1662
+ const { state, isNot, obj } = getMatcherState(this);
1663
+ const { pass, message, actual, expected } = await expectAssertion.call(state, obj, ...args);
1664
+ if (pass && isNot || !pass && !isNot)
1665
+ throw new JestExtendError(message(), actual, expected);
1666
+ }
1667
+ const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
1668
+ utils.addMethod(c.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
1669
+ class CustomMatcher extends AsymmetricMatcher {
1670
+ constructor(inverse = false, ...sample) {
1671
+ super(sample, inverse);
1672
+ }
1673
+ asymmetricMatch(other) {
1674
+ const { pass } = expectAssertion.call(this.getMatcherContext(), other, ...this.sample);
1675
+ return this.inverse ? !pass : pass;
1676
+ }
1677
+ toString() {
1678
+ return `${this.inverse ? "not." : ""}${expectAssertionName}`;
1679
+ }
1680
+ getExpectedType() {
1681
+ return "any";
1682
+ }
1683
+ toAsymmetricMatcher() {
1684
+ return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
1685
+ }
1686
+ }
1687
+ Object.defineProperty(expect, expectAssertionName, {
1688
+ configurable: true,
1689
+ enumerable: true,
1690
+ value: (...sample) => new CustomMatcher(false, ...sample),
1691
+ writable: true
1692
+ });
1693
+ Object.defineProperty(expect.not, expectAssertionName, {
1694
+ configurable: true,
1695
+ enumerable: true,
1696
+ value: (...sample) => new CustomMatcher(true, ...sample),
1697
+ writable: true
1698
+ });
1699
+ });
1700
+ };
1701
+ }
1702
+ const JestExtend = (chai, utils) => {
1703
+ utils.addMethod(chai.expect, "extend", (expect, expects) => {
1704
+ chai.use(JestExtendPlugin(expect, expects));
1705
+ });
1706
+ };
1707
+
1708
+ chai$1.use(JestExtend);
1709
+ chai$1.use(JestChaiExpect);
1710
+ chai$1.use(Subset);
1711
+ chai$1.use(SnapshotPlugin);
1712
+ chai$1.use(JestAsymmetricMatchers);
1713
+
1714
+ function createExpect(test) {
1715
+ const expect2 = (value, message) => {
1716
+ const { assertionCalls } = getState();
1717
+ setState({ assertionCalls: assertionCalls + 1 });
1718
+ const assert2 = chai$1.expect(value, message);
1719
+ if (test)
1720
+ return assert2.withTest(test);
1721
+ else
1722
+ return assert2;
1723
+ };
1724
+ Object.assign(expect2, chai$1.expect);
1725
+ expect2.getState = getState;
1726
+ expect2.setState = setState;
1727
+ expect2.extend = (matchers) => chai$1.expect.extend(expect2, matchers);
1728
+ return expect2;
1729
+ }
1730
+ const expect = createExpect();
1731
+
1732
+ const collectorContext = {
1733
+ tasks: [],
1734
+ currentSuite: null
1735
+ };
1736
+ function collectTask(task) {
1737
+ var _a;
1738
+ (_a = collectorContext.currentSuite) == null ? void 0 : _a.tasks.push(task);
1739
+ }
1740
+ async function runWithSuite(suite, fn) {
1741
+ const prev = collectorContext.currentSuite;
1742
+ collectorContext.currentSuite = suite;
1743
+ await fn();
1744
+ collectorContext.currentSuite = prev;
1745
+ }
1746
+ function getDefaultTestTimeout() {
1747
+ return getWorkerState().config.testTimeout;
1748
+ }
1749
+ function getDefaultHookTimeout() {
1750
+ return getWorkerState().config.hookTimeout;
1751
+ }
1752
+ function withTimeout(fn, timeout = getDefaultTestTimeout(), isHook = false) {
1753
+ if (timeout <= 0 || timeout === Infinity)
1754
+ return fn;
1755
+ return (...args) => {
1756
+ return Promise.race([fn(...args), new Promise((resolve, reject) => {
1757
+ const timer = setTimeout(() => {
1758
+ clearTimeout(timer);
1759
+ reject(new Error(makeTimeoutMsg(isHook, timeout)));
1760
+ }, timeout);
1761
+ timer.unref();
1762
+ })]);
1763
+ };
1764
+ }
1765
+ function createTestContext(test) {
1766
+ const context = function() {
1767
+ throw new Error("done() callback is deperated, use promise instead");
1768
+ };
1769
+ context.meta = test;
1770
+ let _expect;
1771
+ Object.defineProperty(context, "expect", {
1772
+ get() {
1773
+ if (!_expect)
1774
+ _expect = createExpect(test);
1775
+ return _expect;
1776
+ }
1777
+ });
1778
+ return context;
1779
+ }
1780
+ function makeTimeoutMsg(isHook, timeout) {
1781
+ return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
1782
+ If this is a long-running test, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
1783
+ }
1784
+
1785
+ const fnMap = /* @__PURE__ */ new WeakMap();
1786
+ const hooksMap = /* @__PURE__ */ new WeakMap();
1787
+ function setFn(key, fn) {
1788
+ fnMap.set(key, fn);
1789
+ }
1790
+ function getFn(key) {
1791
+ return fnMap.get(key);
1792
+ }
1793
+ function setHooks(key, hooks) {
1794
+ hooksMap.set(key, hooks);
1795
+ }
1796
+ function getHooks(key) {
1797
+ return hooksMap.get(key);
1798
+ }
1799
+
1800
+ const suite = createSuite();
1801
+ const test = createTest(function(name, fn, timeout) {
1802
+ getCurrentSuite().test.fn.call(this, name, fn, timeout);
1803
+ });
1804
+ function formatTitle(template, items, idx) {
1805
+ if (template.includes("%#")) {
1806
+ template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
1807
+ }
1808
+ const count = template.split("%").length - 1;
1809
+ let formatted = format(template, ...items.slice(0, count));
1810
+ if (isObject(items[0])) {
1811
+ formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
1812
+ return items[0][key];
1813
+ });
1814
+ }
1815
+ return formatted;
1816
+ }
1817
+ const describe = suite;
1818
+ const it = test;
1819
+ const defaultSuite = suite("");
1820
+ function clearCollectorContext() {
1821
+ collectorContext.tasks.length = 0;
1822
+ defaultSuite.clear();
1823
+ collectorContext.currentSuite = defaultSuite;
1824
+ }
1825
+ function getCurrentSuite() {
1826
+ return collectorContext.currentSuite || defaultSuite;
1827
+ }
1828
+ function createSuiteHooks() {
1829
+ return {
1830
+ beforeAll: [],
1831
+ afterAll: [],
1832
+ beforeEach: [],
1833
+ afterEach: []
1834
+ };
1835
+ }
1836
+ function createSuiteCollector(name, factory = () => {
1837
+ }, mode, concurrent) {
1838
+ const tasks = [];
1839
+ const factoryQueue = [];
1840
+ let suite2;
1841
+ initSuite();
1842
+ const test2 = createTest(function(name2, fn = noop, timeout) {
1843
+ const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
1844
+ const test3 = {
1845
+ id: "",
1846
+ type: "test",
1847
+ name: name2,
1848
+ mode: mode2,
1849
+ suite: void 0,
1850
+ fails: this.fails
1851
+ };
1852
+ if (this.concurrent || concurrent)
1853
+ test3.concurrent = true;
1854
+ const context = createTestContext(test3);
1855
+ Object.defineProperty(test3, "context", {
1856
+ value: context,
1857
+ enumerable: false
1858
+ });
1859
+ setFn(test3, withTimeout(() => fn(context), timeout));
1860
+ tasks.push(test3);
1861
+ });
1862
+ const collector = {
1863
+ type: "collector",
1864
+ name,
1865
+ mode,
1866
+ test: test2,
1867
+ tasks,
1868
+ collect,
1869
+ clear,
1870
+ on: addHook
1844
1871
  };
1845
- };
1846
- class JestExtendError extends Error {
1847
- constructor(message, actual, expected) {
1848
- super(message);
1849
- this.actual = actual;
1850
- this.expected = expected;
1872
+ function addHook(name2, ...fn) {
1873
+ getHooks(suite2)[name2].push(...fn);
1874
+ }
1875
+ function initSuite() {
1876
+ suite2 = {
1877
+ id: "",
1878
+ type: "suite",
1879
+ name,
1880
+ mode,
1881
+ tasks: []
1882
+ };
1883
+ setHooks(suite2, createSuiteHooks());
1851
1884
  }
1885
+ function clear() {
1886
+ tasks.length = 0;
1887
+ factoryQueue.length = 0;
1888
+ initSuite();
1889
+ }
1890
+ async function collect(file) {
1891
+ factoryQueue.length = 0;
1892
+ if (factory)
1893
+ await runWithSuite(collector, () => factory(test2));
1894
+ const allChildren = [];
1895
+ for (const i of [...factoryQueue, ...tasks])
1896
+ allChildren.push(i.type === "collector" ? await i.collect(file) : i);
1897
+ suite2.file = file;
1898
+ suite2.tasks = allChildren;
1899
+ allChildren.forEach((task) => {
1900
+ task.suite = suite2;
1901
+ if (file)
1902
+ task.file = file;
1903
+ });
1904
+ return suite2;
1905
+ }
1906
+ collectTask(collector);
1907
+ return collector;
1852
1908
  }
1853
- function JestExtendPlugin(expect, matchers) {
1854
- return (c, utils) => {
1855
- Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
1856
- function expectSyncWrapper(...args) {
1857
- const { state, isNot, obj } = getMatcherState(this);
1858
- const { pass, message, actual, expected } = expectAssertion.call(state, obj, ...args);
1859
- if (pass && isNot || !pass && !isNot)
1860
- throw new JestExtendError(message(), actual, expected);
1861
- }
1862
- async function expectAsyncWrapper(...args) {
1863
- const { state, isNot, obj } = getMatcherState(this);
1864
- const { pass, message, actual, expected } = await expectAssertion.call(state, obj, ...args);
1865
- if (pass && isNot || !pass && !isNot)
1866
- throw new JestExtendError(message(), actual, expected);
1867
- }
1868
- const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
1869
- utils.addMethod(c.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
1870
- class CustomMatcher extends AsymmetricMatcher {
1871
- constructor(inverse = false, ...sample) {
1872
- super(sample, inverse);
1873
- }
1874
- asymmetricMatch(other) {
1875
- const { pass } = expectAssertion.call(this.getMatcherContext(), other, ...this.sample);
1876
- return this.inverse ? !pass : pass;
1877
- }
1878
- toString() {
1879
- return `${this.inverse ? "not." : ""}${expectAssertionName}`;
1880
- }
1881
- getExpectedType() {
1882
- return "any";
1883
- }
1884
- toAsymmetricMatcher() {
1885
- return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
1886
- }
1887
- }
1888
- Object.defineProperty(expect, expectAssertionName, {
1889
- configurable: true,
1890
- enumerable: true,
1891
- value: (...sample) => new CustomMatcher(false, ...sample),
1892
- writable: true
1909
+ function createSuite() {
1910
+ const suite2 = createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
1911
+ const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
1912
+ return createSuiteCollector(name, factory, mode, this.concurrent);
1913
+ });
1914
+ suite2.each = (cases) => {
1915
+ return (name, fn) => {
1916
+ cases.forEach((i, idx) => {
1917
+ const items = toArray(i);
1918
+ suite2(formatTitle(name, items, idx), () => fn(...items));
1893
1919
  });
1894
- Object.defineProperty(expect.not, expectAssertionName, {
1895
- configurable: true,
1896
- enumerable: true,
1897
- value: (...sample) => new CustomMatcher(true, ...sample),
1898
- writable: true
1920
+ };
1921
+ };
1922
+ return suite2;
1923
+ }
1924
+ function createTest(fn) {
1925
+ const test2 = createChainable(["concurrent", "skip", "only", "todo", "fails"], fn);
1926
+ test2.each = (cases) => {
1927
+ return (name, fn2) => {
1928
+ cases.forEach((i, idx) => {
1929
+ const items = toArray(i);
1930
+ test2(formatTitle(name, items, idx), () => fn2(...items));
1899
1931
  });
1900
- });
1932
+ };
1901
1933
  };
1934
+ return test2;
1902
1935
  }
1903
- const JestExtend = (chai, utils) => {
1904
- utils.addMethod(chai.expect, "extend", (expect, expects) => {
1905
- chai.use(JestExtendPlugin(expect, expects));
1906
- });
1907
- };
1908
1936
 
1909
- chai$1.use(JestExtend);
1910
- chai$1.use(JestChaiExpect);
1911
- chai$1.use(Subset);
1912
- chai$1.use(SnapshotPlugin);
1913
- chai$1.use(JestAsymmetricMatchers);
1937
+ const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
1938
+ const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
1939
+ const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
1940
+ const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
1914
1941
 
1915
- const expect = (value, message) => {
1916
- const { assertionCalls } = getState();
1917
- setState({ assertionCalls: assertionCalls + 1 });
1918
- return chai$1.expect(value, message);
1919
- };
1920
- Object.assign(expect, chai$1.expect);
1921
- expect.getState = getState;
1922
- expect.setState = setState;
1923
- expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
1942
+ function withCallback(fn) {
1943
+ return new Promise((resolve, reject) => fn((err) => {
1944
+ if (err)
1945
+ reject(err);
1946
+ else
1947
+ resolve();
1948
+ }));
1949
+ }
1950
+
1951
+ const filesCount = /* @__PURE__ */ new Map();
1952
+ const cache = /* @__PURE__ */ new Map();
1953
+ function runOnce(fn, key) {
1954
+ const filepath = getWorkerState().filepath || "__unknown_files__";
1955
+ if (!key) {
1956
+ filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
1957
+ key = String(filesCount.get(filepath));
1958
+ }
1959
+ const id = `${filepath}:${key}`;
1960
+ if (!cache.has(id))
1961
+ cache.set(id, fn());
1962
+ return cache.get(id);
1963
+ }
1964
+ function isFirstRun() {
1965
+ let firstRun = false;
1966
+ runOnce(() => {
1967
+ firstRun = true;
1968
+ }, "__vitest_first_run__");
1969
+ return firstRun;
1970
+ }
1971
+ function resetRunOnceCounter() {
1972
+ filesCount.clear();
1973
+ }
1924
1974
 
1925
1975
  /**
1926
1976
  * A reference to the global object
@@ -2083,62 +2133,62 @@ var deprecated = {};
2083
2133
 
2084
2134
  (function (exports) {
2085
2135
 
2086
- /**
2087
- * Returns a function that will invoke the supplied function and print a
2088
- * deprecation warning to the console each time it is called.
2089
- *
2090
- * @param {Function} func
2091
- * @param {string} msg
2092
- * @returns {Function}
2093
- */
2094
- exports.wrap = function(func, msg) {
2095
- var wrapped = function() {
2096
- exports.printWarning(msg);
2097
- return func.apply(this, arguments);
2098
- };
2099
- if (func.prototype) {
2100
- wrapped.prototype = func.prototype;
2101
- }
2102
- return wrapped;
2103
- };
2104
-
2105
- /**
2106
- * Returns a string which can be supplied to `wrap()` to notify the user that a
2107
- * particular part of the sinon API has been deprecated.
2108
- *
2109
- * @param {string} packageName
2110
- * @param {string} funcName
2111
- * @returns {string}
2112
- */
2113
- exports.defaultMsg = function(packageName, funcName) {
2114
- return (
2115
- packageName +
2116
- "." +
2117
- funcName +
2118
- " is deprecated and will be removed from the public API in a future version of " +
2119
- packageName +
2120
- "."
2121
- );
2122
- };
2123
-
2124
- /**
2125
- * Prints a warning on the console, when it exists
2126
- *
2127
- * @param {string} msg
2128
- * @returns {undefined}
2129
- */
2130
- exports.printWarning = function(msg) {
2131
- /* istanbul ignore next */
2132
- if (typeof process === "object" && process.emitWarning) {
2133
- // Emit Warnings in Node
2134
- process.emitWarning(msg);
2135
- } else if (console.info) {
2136
- console.info(msg);
2137
- } else {
2138
- console.log(msg);
2139
- }
2140
- };
2141
- }(deprecated));
2136
+ /**
2137
+ * Returns a function that will invoke the supplied function and print a
2138
+ * deprecation warning to the console each time it is called.
2139
+ *
2140
+ * @param {Function} func
2141
+ * @param {string} msg
2142
+ * @returns {Function}
2143
+ */
2144
+ exports.wrap = function(func, msg) {
2145
+ var wrapped = function() {
2146
+ exports.printWarning(msg);
2147
+ return func.apply(this, arguments);
2148
+ };
2149
+ if (func.prototype) {
2150
+ wrapped.prototype = func.prototype;
2151
+ }
2152
+ return wrapped;
2153
+ };
2154
+
2155
+ /**
2156
+ * Returns a string which can be supplied to `wrap()` to notify the user that a
2157
+ * particular part of the sinon API has been deprecated.
2158
+ *
2159
+ * @param {string} packageName
2160
+ * @param {string} funcName
2161
+ * @returns {string}
2162
+ */
2163
+ exports.defaultMsg = function(packageName, funcName) {
2164
+ return (
2165
+ packageName +
2166
+ "." +
2167
+ funcName +
2168
+ " is deprecated and will be removed from the public API in a future version of " +
2169
+ packageName +
2170
+ "."
2171
+ );
2172
+ };
2173
+
2174
+ /**
2175
+ * Prints a warning on the console, when it exists
2176
+ *
2177
+ * @param {string} msg
2178
+ * @returns {undefined}
2179
+ */
2180
+ exports.printWarning = function(msg) {
2181
+ /* istanbul ignore next */
2182
+ if (typeof process === "object" && process.emitWarning) {
2183
+ // Emit Warnings in Node
2184
+ process.emitWarning(msg);
2185
+ } else if (console.info) {
2186
+ console.info(msg);
2187
+ } else {
2188
+ console.log(msg);
2189
+ }
2190
+ };
2191
+ } (deprecated));
2142
2192
 
2143
2193
  /**
2144
2194
  * Returns true when fn returns true for all members of obj.
@@ -2233,392 +2283,392 @@ var prototypes = {
2233
2283
  var typeDetect = {exports: {}};
2234
2284
 
2235
2285
  (function (module, exports) {
2236
- (function (global, factory) {
2237
- module.exports = factory() ;
2238
- }(commonjsGlobal, (function () {
2239
- /* !
2240
- * type-detect
2241
- * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
2242
- * MIT Licensed
2243
- */
2244
- var promiseExists = typeof Promise === 'function';
2245
-
2246
- /* eslint-disable no-undef */
2247
- var globalObject = typeof self === 'object' ? self : commonjsGlobal; // eslint-disable-line id-blacklist
2248
-
2249
- var symbolExists = typeof Symbol !== 'undefined';
2250
- var mapExists = typeof Map !== 'undefined';
2251
- var setExists = typeof Set !== 'undefined';
2252
- var weakMapExists = typeof WeakMap !== 'undefined';
2253
- var weakSetExists = typeof WeakSet !== 'undefined';
2254
- var dataViewExists = typeof DataView !== 'undefined';
2255
- var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
2256
- var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
2257
- var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
2258
- var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
2259
- var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
2260
- var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
2261
- var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
2262
- var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
2263
- var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
2264
- var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
2265
- var toStringLeftSliceLength = 8;
2266
- var toStringRightSliceLength = -1;
2267
- /**
2268
- * ### typeOf (obj)
2269
- *
2270
- * Uses `Object.prototype.toString` to determine the type of an object,
2271
- * normalising behaviour across engine versions & well optimised.
2272
- *
2273
- * @param {Mixed} object
2274
- * @return {String} object type
2275
- * @api public
2276
- */
2277
- function typeDetect(obj) {
2278
- /* ! Speed optimisation
2279
- * Pre:
2280
- * string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
2281
- * boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
2282
- * number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
2283
- * undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
2284
- * function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
2285
- * Post:
2286
- * string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
2287
- * boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
2288
- * number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
2289
- * undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
2290
- * function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
2291
- */
2292
- var typeofObj = typeof obj;
2293
- if (typeofObj !== 'object') {
2294
- return typeofObj;
2295
- }
2296
-
2297
- /* ! Speed optimisation
2298
- * Pre:
2299
- * null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
2300
- * Post:
2301
- * null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
2302
- */
2303
- if (obj === null) {
2304
- return 'null';
2305
- }
2306
-
2307
- /* ! Spec Conformance
2308
- * Test: `Object.prototype.toString.call(window)``
2309
- * - Node === "[object global]"
2310
- * - Chrome === "[object global]"
2311
- * - Firefox === "[object Window]"
2312
- * - PhantomJS === "[object Window]"
2313
- * - Safari === "[object Window]"
2314
- * - IE 11 === "[object Window]"
2315
- * - IE Edge === "[object Window]"
2316
- * Test: `Object.prototype.toString.call(this)``
2317
- * - Chrome Worker === "[object global]"
2318
- * - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
2319
- * - Safari Worker === "[object DedicatedWorkerGlobalScope]"
2320
- * - IE 11 Worker === "[object WorkerGlobalScope]"
2321
- * - IE Edge Worker === "[object WorkerGlobalScope]"
2322
- */
2323
- if (obj === globalObject) {
2324
- return 'global';
2325
- }
2326
-
2327
- /* ! Speed optimisation
2328
- * Pre:
2329
- * array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
2330
- * Post:
2331
- * array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
2332
- */
2333
- if (
2334
- Array.isArray(obj) &&
2335
- (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
2336
- ) {
2337
- return 'Array';
2338
- }
2339
-
2340
- // Not caching existence of `window` and related properties due to potential
2341
- // for `window` to be unset before tests in quasi-browser environments.
2342
- if (typeof window === 'object' && window !== null) {
2343
- /* ! Spec Conformance
2344
- * (https://html.spec.whatwg.org/multipage/browsers.html#location)
2345
- * WhatWG HTML$7.7.3 - The `Location` interface
2346
- * Test: `Object.prototype.toString.call(window.location)``
2347
- * - IE <=11 === "[object Object]"
2348
- * - IE Edge <=13 === "[object Object]"
2349
- */
2350
- if (typeof window.location === 'object' && obj === window.location) {
2351
- return 'Location';
2352
- }
2353
-
2354
- /* ! Spec Conformance
2355
- * (https://html.spec.whatwg.org/#document)
2356
- * WhatWG HTML$3.1.1 - The `Document` object
2357
- * Note: Most browsers currently adher to the W3C DOM Level 2 spec
2358
- * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
2359
- * which suggests that browsers should use HTMLTableCellElement for
2360
- * both TD and TH elements. WhatWG separates these.
2361
- * WhatWG HTML states:
2362
- * > For historical reasons, Window objects must also have a
2363
- * > writable, configurable, non-enumerable property named
2364
- * > HTMLDocument whose value is the Document interface object.
2365
- * Test: `Object.prototype.toString.call(document)``
2366
- * - Chrome === "[object HTMLDocument]"
2367
- * - Firefox === "[object HTMLDocument]"
2368
- * - Safari === "[object HTMLDocument]"
2369
- * - IE <=10 === "[object Document]"
2370
- * - IE 11 === "[object HTMLDocument]"
2371
- * - IE Edge <=13 === "[object HTMLDocument]"
2372
- */
2373
- if (typeof window.document === 'object' && obj === window.document) {
2374
- return 'Document';
2375
- }
2376
-
2377
- if (typeof window.navigator === 'object') {
2378
- /* ! Spec Conformance
2379
- * (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
2380
- * WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
2381
- * Test: `Object.prototype.toString.call(navigator.mimeTypes)``
2382
- * - IE <=10 === "[object MSMimeTypesCollection]"
2383
- */
2384
- if (typeof window.navigator.mimeTypes === 'object' &&
2385
- obj === window.navigator.mimeTypes) {
2386
- return 'MimeTypeArray';
2387
- }
2388
-
2389
- /* ! Spec Conformance
2390
- * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
2391
- * WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
2392
- * Test: `Object.prototype.toString.call(navigator.plugins)``
2393
- * - IE <=10 === "[object MSPluginsCollection]"
2394
- */
2395
- if (typeof window.navigator.plugins === 'object' &&
2396
- obj === window.navigator.plugins) {
2397
- return 'PluginArray';
2398
- }
2399
- }
2400
-
2401
- if ((typeof window.HTMLElement === 'function' ||
2402
- typeof window.HTMLElement === 'object') &&
2403
- obj instanceof window.HTMLElement) {
2404
- /* ! Spec Conformance
2405
- * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
2406
- * WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
2407
- * Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
2408
- * - IE <=10 === "[object HTMLBlockElement]"
2409
- */
2410
- if (obj.tagName === 'BLOCKQUOTE') {
2411
- return 'HTMLQuoteElement';
2412
- }
2413
-
2414
- /* ! Spec Conformance
2415
- * (https://html.spec.whatwg.org/#htmltabledatacellelement)
2416
- * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
2417
- * Note: Most browsers currently adher to the W3C DOM Level 2 spec
2418
- * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
2419
- * which suggests that browsers should use HTMLTableCellElement for
2420
- * both TD and TH elements. WhatWG separates these.
2421
- * Test: Object.prototype.toString.call(document.createElement('td'))
2422
- * - Chrome === "[object HTMLTableCellElement]"
2423
- * - Firefox === "[object HTMLTableCellElement]"
2424
- * - Safari === "[object HTMLTableCellElement]"
2425
- */
2426
- if (obj.tagName === 'TD') {
2427
- return 'HTMLTableDataCellElement';
2428
- }
2429
-
2430
- /* ! Spec Conformance
2431
- * (https://html.spec.whatwg.org/#htmltableheadercellelement)
2432
- * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
2433
- * Note: Most browsers currently adher to the W3C DOM Level 2 spec
2434
- * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
2435
- * which suggests that browsers should use HTMLTableCellElement for
2436
- * both TD and TH elements. WhatWG separates these.
2437
- * Test: Object.prototype.toString.call(document.createElement('th'))
2438
- * - Chrome === "[object HTMLTableCellElement]"
2439
- * - Firefox === "[object HTMLTableCellElement]"
2440
- * - Safari === "[object HTMLTableCellElement]"
2441
- */
2442
- if (obj.tagName === 'TH') {
2443
- return 'HTMLTableHeaderCellElement';
2444
- }
2445
- }
2446
- }
2447
-
2448
- /* ! Speed optimisation
2449
- * Pre:
2450
- * Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
2451
- * Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
2452
- * Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
2453
- * Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
2454
- * Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
2455
- * Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
2456
- * Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
2457
- * Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
2458
- * Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
2459
- * Post:
2460
- * Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
2461
- * Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
2462
- * Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
2463
- * Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
2464
- * Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
2465
- * Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
2466
- * Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
2467
- * Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
2468
- * Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
2469
- */
2470
- var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
2471
- if (typeof stringTag === 'string') {
2472
- return stringTag;
2473
- }
2474
-
2475
- var objPrototype = Object.getPrototypeOf(obj);
2476
- /* ! Speed optimisation
2477
- * Pre:
2478
- * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
2479
- * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
2480
- * Post:
2481
- * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
2482
- * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
2483
- */
2484
- if (objPrototype === RegExp.prototype) {
2485
- return 'RegExp';
2486
- }
2487
-
2488
- /* ! Speed optimisation
2489
- * Pre:
2490
- * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
2491
- * Post:
2492
- * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
2493
- */
2494
- if (objPrototype === Date.prototype) {
2495
- return 'Date';
2496
- }
2497
-
2498
- /* ! Spec Conformance
2499
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
2500
- * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
2501
- * Test: `Object.prototype.toString.call(Promise.resolve())``
2502
- * - Chrome <=47 === "[object Object]"
2503
- * - Edge <=20 === "[object Object]"
2504
- * - Firefox 29-Latest === "[object Promise]"
2505
- * - Safari 7.1-Latest === "[object Promise]"
2506
- */
2507
- if (promiseExists && objPrototype === Promise.prototype) {
2508
- return 'Promise';
2509
- }
2510
-
2511
- /* ! Speed optimisation
2512
- * Pre:
2513
- * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
2514
- * Post:
2515
- * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
2516
- */
2517
- if (setExists && objPrototype === Set.prototype) {
2518
- return 'Set';
2519
- }
2520
-
2521
- /* ! Speed optimisation
2522
- * Pre:
2523
- * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
2524
- * Post:
2525
- * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
2526
- */
2527
- if (mapExists && objPrototype === Map.prototype) {
2528
- return 'Map';
2529
- }
2530
-
2531
- /* ! Speed optimisation
2532
- * Pre:
2533
- * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
2534
- * Post:
2535
- * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
2536
- */
2537
- if (weakSetExists && objPrototype === WeakSet.prototype) {
2538
- return 'WeakSet';
2539
- }
2540
-
2541
- /* ! Speed optimisation
2542
- * Pre:
2543
- * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
2544
- * Post:
2545
- * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
2546
- */
2547
- if (weakMapExists && objPrototype === WeakMap.prototype) {
2548
- return 'WeakMap';
2549
- }
2550
-
2551
- /* ! Spec Conformance
2552
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
2553
- * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
2554
- * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
2555
- * - Edge <=13 === "[object Object]"
2556
- */
2557
- if (dataViewExists && objPrototype === DataView.prototype) {
2558
- return 'DataView';
2559
- }
2560
-
2561
- /* ! Spec Conformance
2562
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
2563
- * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
2564
- * Test: `Object.prototype.toString.call(new Map().entries())``
2565
- * - Edge <=13 === "[object Object]"
2566
- */
2567
- if (mapExists && objPrototype === mapIteratorPrototype) {
2568
- return 'Map Iterator';
2569
- }
2570
-
2571
- /* ! Spec Conformance
2572
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
2573
- * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
2574
- * Test: `Object.prototype.toString.call(new Set().entries())``
2575
- * - Edge <=13 === "[object Object]"
2576
- */
2577
- if (setExists && objPrototype === setIteratorPrototype) {
2578
- return 'Set Iterator';
2579
- }
2580
-
2581
- /* ! Spec Conformance
2582
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
2583
- * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
2584
- * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
2585
- * - Edge <=13 === "[object Object]"
2586
- */
2587
- if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
2588
- return 'Array Iterator';
2589
- }
2590
-
2591
- /* ! Spec Conformance
2592
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
2593
- * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
2594
- * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
2595
- * - Edge <=13 === "[object Object]"
2596
- */
2597
- if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
2598
- return 'String Iterator';
2599
- }
2600
-
2601
- /* ! Speed optimisation
2602
- * Pre:
2603
- * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
2604
- * Post:
2605
- * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
2606
- */
2607
- if (objPrototype === null) {
2608
- return 'Object';
2609
- }
2610
-
2611
- return Object
2612
- .prototype
2613
- .toString
2614
- .call(obj)
2615
- .slice(toStringLeftSliceLength, toStringRightSliceLength);
2616
- }
2286
+ (function (global, factory) {
2287
+ module.exports = factory() ;
2288
+ }(commonjsGlobal, (function () {
2289
+ /* !
2290
+ * type-detect
2291
+ * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
2292
+ * MIT Licensed
2293
+ */
2294
+ var promiseExists = typeof Promise === 'function';
2295
+
2296
+ /* eslint-disable no-undef */
2297
+ var globalObject = typeof self === 'object' ? self : commonjsGlobal; // eslint-disable-line id-blacklist
2298
+
2299
+ var symbolExists = typeof Symbol !== 'undefined';
2300
+ var mapExists = typeof Map !== 'undefined';
2301
+ var setExists = typeof Set !== 'undefined';
2302
+ var weakMapExists = typeof WeakMap !== 'undefined';
2303
+ var weakSetExists = typeof WeakSet !== 'undefined';
2304
+ var dataViewExists = typeof DataView !== 'undefined';
2305
+ var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
2306
+ var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
2307
+ var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
2308
+ var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
2309
+ var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
2310
+ var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
2311
+ var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
2312
+ var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
2313
+ var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
2314
+ var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
2315
+ var toStringLeftSliceLength = 8;
2316
+ var toStringRightSliceLength = -1;
2317
+ /**
2318
+ * ### typeOf (obj)
2319
+ *
2320
+ * Uses `Object.prototype.toString` to determine the type of an object,
2321
+ * normalising behaviour across engine versions & well optimised.
2322
+ *
2323
+ * @param {Mixed} object
2324
+ * @return {String} object type
2325
+ * @api public
2326
+ */
2327
+ function typeDetect(obj) {
2328
+ /* ! Speed optimisation
2329
+ * Pre:
2330
+ * string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
2331
+ * boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
2332
+ * number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
2333
+ * undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
2334
+ * function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
2335
+ * Post:
2336
+ * string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
2337
+ * boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
2338
+ * number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
2339
+ * undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
2340
+ * function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
2341
+ */
2342
+ var typeofObj = typeof obj;
2343
+ if (typeofObj !== 'object') {
2344
+ return typeofObj;
2345
+ }
2346
+
2347
+ /* ! Speed optimisation
2348
+ * Pre:
2349
+ * null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
2350
+ * Post:
2351
+ * null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
2352
+ */
2353
+ if (obj === null) {
2354
+ return 'null';
2355
+ }
2356
+
2357
+ /* ! Spec Conformance
2358
+ * Test: `Object.prototype.toString.call(window)``
2359
+ * - Node === "[object global]"
2360
+ * - Chrome === "[object global]"
2361
+ * - Firefox === "[object Window]"
2362
+ * - PhantomJS === "[object Window]"
2363
+ * - Safari === "[object Window]"
2364
+ * - IE 11 === "[object Window]"
2365
+ * - IE Edge === "[object Window]"
2366
+ * Test: `Object.prototype.toString.call(this)``
2367
+ * - Chrome Worker === "[object global]"
2368
+ * - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
2369
+ * - Safari Worker === "[object DedicatedWorkerGlobalScope]"
2370
+ * - IE 11 Worker === "[object WorkerGlobalScope]"
2371
+ * - IE Edge Worker === "[object WorkerGlobalScope]"
2372
+ */
2373
+ if (obj === globalObject) {
2374
+ return 'global';
2375
+ }
2376
+
2377
+ /* ! Speed optimisation
2378
+ * Pre:
2379
+ * array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
2380
+ * Post:
2381
+ * array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
2382
+ */
2383
+ if (
2384
+ Array.isArray(obj) &&
2385
+ (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
2386
+ ) {
2387
+ return 'Array';
2388
+ }
2389
+
2390
+ // Not caching existence of `window` and related properties due to potential
2391
+ // for `window` to be unset before tests in quasi-browser environments.
2392
+ if (typeof window === 'object' && window !== null) {
2393
+ /* ! Spec Conformance
2394
+ * (https://html.spec.whatwg.org/multipage/browsers.html#location)
2395
+ * WhatWG HTML$7.7.3 - The `Location` interface
2396
+ * Test: `Object.prototype.toString.call(window.location)``
2397
+ * - IE <=11 === "[object Object]"
2398
+ * - IE Edge <=13 === "[object Object]"
2399
+ */
2400
+ if (typeof window.location === 'object' && obj === window.location) {
2401
+ return 'Location';
2402
+ }
2403
+
2404
+ /* ! Spec Conformance
2405
+ * (https://html.spec.whatwg.org/#document)
2406
+ * WhatWG HTML$3.1.1 - The `Document` object
2407
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
2408
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
2409
+ * which suggests that browsers should use HTMLTableCellElement for
2410
+ * both TD and TH elements. WhatWG separates these.
2411
+ * WhatWG HTML states:
2412
+ * > For historical reasons, Window objects must also have a
2413
+ * > writable, configurable, non-enumerable property named
2414
+ * > HTMLDocument whose value is the Document interface object.
2415
+ * Test: `Object.prototype.toString.call(document)``
2416
+ * - Chrome === "[object HTMLDocument]"
2417
+ * - Firefox === "[object HTMLDocument]"
2418
+ * - Safari === "[object HTMLDocument]"
2419
+ * - IE <=10 === "[object Document]"
2420
+ * - IE 11 === "[object HTMLDocument]"
2421
+ * - IE Edge <=13 === "[object HTMLDocument]"
2422
+ */
2423
+ if (typeof window.document === 'object' && obj === window.document) {
2424
+ return 'Document';
2425
+ }
2426
+
2427
+ if (typeof window.navigator === 'object') {
2428
+ /* ! Spec Conformance
2429
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
2430
+ * WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
2431
+ * Test: `Object.prototype.toString.call(navigator.mimeTypes)``
2432
+ * - IE <=10 === "[object MSMimeTypesCollection]"
2433
+ */
2434
+ if (typeof window.navigator.mimeTypes === 'object' &&
2435
+ obj === window.navigator.mimeTypes) {
2436
+ return 'MimeTypeArray';
2437
+ }
2438
+
2439
+ /* ! Spec Conformance
2440
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
2441
+ * WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
2442
+ * Test: `Object.prototype.toString.call(navigator.plugins)``
2443
+ * - IE <=10 === "[object MSPluginsCollection]"
2444
+ */
2445
+ if (typeof window.navigator.plugins === 'object' &&
2446
+ obj === window.navigator.plugins) {
2447
+ return 'PluginArray';
2448
+ }
2449
+ }
2450
+
2451
+ if ((typeof window.HTMLElement === 'function' ||
2452
+ typeof window.HTMLElement === 'object') &&
2453
+ obj instanceof window.HTMLElement) {
2454
+ /* ! Spec Conformance
2455
+ * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
2456
+ * WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
2457
+ * Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
2458
+ * - IE <=10 === "[object HTMLBlockElement]"
2459
+ */
2460
+ if (obj.tagName === 'BLOCKQUOTE') {
2461
+ return 'HTMLQuoteElement';
2462
+ }
2463
+
2464
+ /* ! Spec Conformance
2465
+ * (https://html.spec.whatwg.org/#htmltabledatacellelement)
2466
+ * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
2467
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
2468
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
2469
+ * which suggests that browsers should use HTMLTableCellElement for
2470
+ * both TD and TH elements. WhatWG separates these.
2471
+ * Test: Object.prototype.toString.call(document.createElement('td'))
2472
+ * - Chrome === "[object HTMLTableCellElement]"
2473
+ * - Firefox === "[object HTMLTableCellElement]"
2474
+ * - Safari === "[object HTMLTableCellElement]"
2475
+ */
2476
+ if (obj.tagName === 'TD') {
2477
+ return 'HTMLTableDataCellElement';
2478
+ }
2479
+
2480
+ /* ! Spec Conformance
2481
+ * (https://html.spec.whatwg.org/#htmltableheadercellelement)
2482
+ * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
2483
+ * Note: Most browsers currently adher to the W3C DOM Level 2 spec
2484
+ * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
2485
+ * which suggests that browsers should use HTMLTableCellElement for
2486
+ * both TD and TH elements. WhatWG separates these.
2487
+ * Test: Object.prototype.toString.call(document.createElement('th'))
2488
+ * - Chrome === "[object HTMLTableCellElement]"
2489
+ * - Firefox === "[object HTMLTableCellElement]"
2490
+ * - Safari === "[object HTMLTableCellElement]"
2491
+ */
2492
+ if (obj.tagName === 'TH') {
2493
+ return 'HTMLTableHeaderCellElement';
2494
+ }
2495
+ }
2496
+ }
2497
+
2498
+ /* ! Speed optimisation
2499
+ * Pre:
2500
+ * Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
2501
+ * Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
2502
+ * Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
2503
+ * Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
2504
+ * Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
2505
+ * Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
2506
+ * Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
2507
+ * Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
2508
+ * Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
2509
+ * Post:
2510
+ * Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
2511
+ * Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
2512
+ * Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
2513
+ * Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
2514
+ * Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
2515
+ * Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
2516
+ * Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
2517
+ * Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
2518
+ * Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
2519
+ */
2520
+ var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
2521
+ if (typeof stringTag === 'string') {
2522
+ return stringTag;
2523
+ }
2524
+
2525
+ var objPrototype = Object.getPrototypeOf(obj);
2526
+ /* ! Speed optimisation
2527
+ * Pre:
2528
+ * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
2529
+ * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
2530
+ * Post:
2531
+ * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
2532
+ * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
2533
+ */
2534
+ if (objPrototype === RegExp.prototype) {
2535
+ return 'RegExp';
2536
+ }
2537
+
2538
+ /* ! Speed optimisation
2539
+ * Pre:
2540
+ * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
2541
+ * Post:
2542
+ * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
2543
+ */
2544
+ if (objPrototype === Date.prototype) {
2545
+ return 'Date';
2546
+ }
2547
+
2548
+ /* ! Spec Conformance
2549
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
2550
+ * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
2551
+ * Test: `Object.prototype.toString.call(Promise.resolve())``
2552
+ * - Chrome <=47 === "[object Object]"
2553
+ * - Edge <=20 === "[object Object]"
2554
+ * - Firefox 29-Latest === "[object Promise]"
2555
+ * - Safari 7.1-Latest === "[object Promise]"
2556
+ */
2557
+ if (promiseExists && objPrototype === Promise.prototype) {
2558
+ return 'Promise';
2559
+ }
2560
+
2561
+ /* ! Speed optimisation
2562
+ * Pre:
2563
+ * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
2564
+ * Post:
2565
+ * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
2566
+ */
2567
+ if (setExists && objPrototype === Set.prototype) {
2568
+ return 'Set';
2569
+ }
2570
+
2571
+ /* ! Speed optimisation
2572
+ * Pre:
2573
+ * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
2574
+ * Post:
2575
+ * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
2576
+ */
2577
+ if (mapExists && objPrototype === Map.prototype) {
2578
+ return 'Map';
2579
+ }
2580
+
2581
+ /* ! Speed optimisation
2582
+ * Pre:
2583
+ * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
2584
+ * Post:
2585
+ * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
2586
+ */
2587
+ if (weakSetExists && objPrototype === WeakSet.prototype) {
2588
+ return 'WeakSet';
2589
+ }
2590
+
2591
+ /* ! Speed optimisation
2592
+ * Pre:
2593
+ * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
2594
+ * Post:
2595
+ * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
2596
+ */
2597
+ if (weakMapExists && objPrototype === WeakMap.prototype) {
2598
+ return 'WeakMap';
2599
+ }
2600
+
2601
+ /* ! Spec Conformance
2602
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
2603
+ * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
2604
+ * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
2605
+ * - Edge <=13 === "[object Object]"
2606
+ */
2607
+ if (dataViewExists && objPrototype === DataView.prototype) {
2608
+ return 'DataView';
2609
+ }
2610
+
2611
+ /* ! Spec Conformance
2612
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
2613
+ * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
2614
+ * Test: `Object.prototype.toString.call(new Map().entries())``
2615
+ * - Edge <=13 === "[object Object]"
2616
+ */
2617
+ if (mapExists && objPrototype === mapIteratorPrototype) {
2618
+ return 'Map Iterator';
2619
+ }
2620
+
2621
+ /* ! Spec Conformance
2622
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
2623
+ * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
2624
+ * Test: `Object.prototype.toString.call(new Set().entries())``
2625
+ * - Edge <=13 === "[object Object]"
2626
+ */
2627
+ if (setExists && objPrototype === setIteratorPrototype) {
2628
+ return 'Set Iterator';
2629
+ }
2630
+
2631
+ /* ! Spec Conformance
2632
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
2633
+ * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
2634
+ * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
2635
+ * - Edge <=13 === "[object Object]"
2636
+ */
2637
+ if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
2638
+ return 'Array Iterator';
2639
+ }
2640
+
2641
+ /* ! Spec Conformance
2642
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
2643
+ * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
2644
+ * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
2645
+ * - Edge <=13 === "[object Object]"
2646
+ */
2647
+ if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
2648
+ return 'String Iterator';
2649
+ }
2650
+
2651
+ /* ! Speed optimisation
2652
+ * Pre:
2653
+ * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
2654
+ * Post:
2655
+ * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
2656
+ */
2657
+ if (objPrototype === null) {
2658
+ return 'Object';
2659
+ }
2660
+
2661
+ return Object
2662
+ .prototype
2663
+ .toString
2664
+ .call(obj)
2665
+ .slice(toStringLeftSliceLength, toStringRightSliceLength);
2666
+ }
2617
2667
 
2618
- return typeDetect;
2668
+ return typeDetect;
2619
2669
 
2620
- })));
2621
- }(typeDetect));
2670
+ })));
2671
+ } (typeDetect));
2622
2672
 
2623
2673
  var type = typeDetect.exports;
2624
2674
 
@@ -3086,6 +3136,7 @@ function withGlobal(_global) {
3086
3136
  target.parse = source.parse;
3087
3137
  target.UTC = source.UTC;
3088
3138
  target.prototype.toUTCString = source.prototype.toUTCString;
3139
+ target.isFake = true;
3089
3140
 
3090
3141
  return target;
3091
3142
  }
@@ -4296,6 +4347,14 @@ function withGlobal(_global) {
4296
4347
  );
4297
4348
  }
4298
4349
 
4350
+ if (_global.Date.isFake === true) {
4351
+ // Timers are already faked; this is a problem.
4352
+ // Make the user reset timers before continuing.
4353
+ throw new TypeError(
4354
+ "Can't install fake timers twice on the same global object."
4355
+ );
4356
+ }
4357
+
4299
4358
  // eslint-disable-next-line no-param-reassign
4300
4359
  config = typeof config !== "undefined" ? config : {};
4301
4360
  config.shouldAdvanceTime = config.shouldAdvanceTime || false;
@@ -4686,26 +4745,4 @@ function isWatchMode() {
4686
4745
  return getRunningMode() === "watch";
4687
4746
  }
4688
4747
 
4689
- var index = /*#__PURE__*/Object.freeze({
4690
- __proto__: null,
4691
- suite: suite,
4692
- test: test,
4693
- describe: describe,
4694
- it: it,
4695
- runOnce: runOnce,
4696
- isFirstRun: isFirstRun,
4697
- beforeAll: beforeAll,
4698
- afterAll: afterAll,
4699
- beforeEach: beforeEach,
4700
- afterEach: afterEach,
4701
- assert: assert,
4702
- should: should,
4703
- chai: chai$1,
4704
- expect: expect,
4705
- vitest: vitest,
4706
- vi: vi,
4707
- getRunningMode: getRunningMode,
4708
- isWatchMode: isWatchMode
4709
- });
4710
-
4711
- export { RealDate as R, context as a, getSnapshotClient as b, clearContext as c, defaultSuite as d, setState as e, getFn as f, getHooks as g, getState as h, index as i, suite as j, describe as k, it as l, runOnce as m, isFirstRun as n, beforeAll as o, afterAll as p, beforeEach as q, resetRunOnceCounter as r, setHooks as s, test as t, afterEach as u, vi as v, expect as w, vitest as x, getRunningMode as y, isWatchMode as z };
4748
+ export { getState as A, RealDate as R, isFirstRun as a, beforeAll as b, afterAll as c, describe as d, beforeEach as e, afterEach as f, createExpect as g, expect as h, it as i, vi as j, getRunningMode as k, isWatchMode as l, resetRunOnceCounter as m, clearCollectorContext as n, defaultSuite as o, setHooks as p, getHooks as q, runOnce as r, suite as s, test as t, collectorContext as u, vitest as v, withCallback as w, getSnapshotClient as x, setState as y, getFn as z };