vitest 0.0.115 → 0.0.119

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/LICENSE.md CHANGED
@@ -1205,34 +1205,6 @@ Repository: https://github.com/boblauer/MockDate.git
1205
1205
 
1206
1206
  ---------------------------------------
1207
1207
 
1208
- ## nanoid
1209
- License: MIT
1210
- By: Andrey Sitnik
1211
- Repository: ai/nanoid
1212
-
1213
- > The MIT License (MIT)
1214
- >
1215
- > Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
1216
- >
1217
- > Permission is hereby granted, free of charge, to any person obtaining a copy of
1218
- > this software and associated documentation files (the "Software"), to deal in
1219
- > the Software without restriction, including without limitation the rights to
1220
- > use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
1221
- > the Software, and to permit persons to whom the Software is furnished to do so,
1222
- > subject to the following conditions:
1223
- >
1224
- > The above copyright notice and this permission notice shall be included in all
1225
- > copies or substantial portions of the Software.
1226
- >
1227
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1228
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
1229
- > FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1230
- > COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1231
- > IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1232
- > CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1233
-
1234
- ---------------------------------------
1235
-
1236
1208
  ## natural-compare
1237
1209
  License: MIT
1238
1210
  By: Lauri Rooden
@@ -1921,6 +1893,33 @@ Repository: chalk/wrap-ansi
1921
1893
 
1922
1894
  ---------------------------------------
1923
1895
 
1896
+ ## ws
1897
+ License: MIT
1898
+ By: Einar Otto Stangvik
1899
+ Repository: websockets/ws
1900
+
1901
+ > Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
1902
+ >
1903
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
1904
+ > of this software and associated documentation files (the "Software"), to deal
1905
+ > in the Software without restriction, including without limitation the rights
1906
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1907
+ > copies of the Software, and to permit persons to whom the Software is
1908
+ > furnished to do so, subject to the following conditions:
1909
+ >
1910
+ > The above copyright notice and this permission notice shall be included in all
1911
+ > copies or substantial portions of the Software.
1912
+ >
1913
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1914
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1915
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1916
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1917
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1918
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
+ > SOFTWARE.
1920
+
1921
+ ---------------------------------------
1922
+
1924
1923
  ## yocto-queue
1925
1924
  License: MIT
1926
1925
  By: Sindre Sorhus
package/dist/cli.js CHANGED
@@ -7,8 +7,8 @@ import process$1 from 'process';
7
7
  import { m as mergeStream, g as getStream, c as crossSpawn } from './index-6e709f57.js';
8
8
  import require$$0, { constants } from 'os';
9
9
  import { s as signalExit } from './index-648e7ab2.js';
10
- import { e as ensurePackageInstalled } from './index-7c024e16.js';
11
- import { c as createVitest } from './index-b4f86684.js';
10
+ import { e as ensurePackageInstalled } from './index-090545ef.js';
11
+ import { c as createVitest } from './index-478354a1.js';
12
12
  import './_commonjsHelpers-c9e3b764.js';
13
13
  import 'fs';
14
14
  import 'stream';
@@ -18,10 +18,10 @@ import 'url';
18
18
  import 'tty';
19
19
  import 'local-pkg';
20
20
  import 'vite';
21
- import './constants-5968a78c.js';
21
+ import './constants-22bbd600.js';
22
22
  import './magic-string.es-94000aea.js';
23
23
  import 'perf_hooks';
24
- import './diff-67678e1f.js';
24
+ import './diff-a295cb37.js';
25
25
  import 'module';
26
26
  import 'worker_threads';
27
27
  import 'tinypool';
@@ -1700,10 +1700,11 @@ function execa(file, args, options) {
1700
1700
  return mergePromise(spawned, handlePromiseOnce);
1701
1701
  }
1702
1702
 
1703
- var version = "0.0.115";
1703
+ var version = "0.0.119";
1704
1704
 
1705
+ const CLOSE_TIMEOUT = 1e3;
1705
1706
  const cli = cac("vitest");
1706
- 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 console.log output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
1707
+ 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 UI", { default: false }).option("-t, --testNamePattern <pattern>", "run test names with the specified pattern").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
1707
1708
  cli.command("run [...filters]").action(run);
1708
1709
  cli.command("watch [...filters]").action(dev);
1709
1710
  cli.command("dev [...filters]").action(dev);
@@ -1750,18 +1751,36 @@ async function run(cliFilters, options) {
1750
1751
  if (!ctx.config.watch)
1751
1752
  await ctx.close();
1752
1753
  }
1753
- if (!ctx.config.watch)
1754
- process.exit();
1754
+ if (!ctx.config.watch) {
1755
+ setTimeout(() => process.exit(), CLOSE_TIMEOUT).unref();
1756
+ }
1757
+ }
1758
+ function closeServerAndExitProcess(ctx) {
1759
+ const closePromise = ctx.close();
1760
+ let timeout;
1761
+ const timeoutPromise = new Promise((resolve, reject) => {
1762
+ timeout = setTimeout(() => reject(new Error(`close timed out after ${CLOSE_TIMEOUT}ms`)), CLOSE_TIMEOUT);
1763
+ });
1764
+ Promise.race([closePromise, timeoutPromise]).then(() => {
1765
+ clearTimeout(timeout);
1766
+ process.exit(0);
1767
+ }, (err) => {
1768
+ clearTimeout(timeout);
1769
+ console.error("error during close", err);
1770
+ process.exit(1);
1771
+ });
1755
1772
  }
1756
1773
  function registerConsoleShortcuts(ctx) {
1757
1774
  require$$0$1.emitKeypressEvents(process.stdin);
1758
1775
  process.stdin.setRawMode(true);
1759
1776
  process.stdin.on("keypress", (str, key) => {
1760
- if (str === "" || str === "" || key && key.ctrl && key.name === "c")
1761
- process.exit();
1777
+ if (str === "" || str === "" || key && key.ctrl && key.name === "c") {
1778
+ closeServerAndExitProcess(ctx);
1779
+ return;
1780
+ }
1762
1781
  if (ctx.runningPromise)
1763
1782
  return;
1764
1783
  if (ctx.isFirstRun)
1765
- process.exit();
1784
+ closeServerAndExitProcess(ctx);
1766
1785
  });
1767
1786
  }
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { k as resolve } from './index-7c024e16.js';
2
+ import { k as resolve } from './index-090545ef.js';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
5
  const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
@@ -1,5 +1,5 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { o as notNullish, c, r as relative } from './index-7c024e16.js';
2
+ import { o as notNullish, c, r as relative } from './index-090545ef.js';
3
3
 
4
4
  function Diff() {}
5
5
  Diff.prototype = {
package/dist/entry.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import fs, { promises } from 'fs';
2
- import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, n as nanoid, l as clearContext, m as defaultSuite, o as setHooks, p as getHooks, q as context, s as setState, r as getFn, b as getState, e as vi } from './vi-2115c609.js';
2
+ import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, b as getState, e as vi } from './vi-092f86e3.js';
3
3
  import { Console } from 'console';
4
4
  import { Writable } from 'stream';
5
5
  import { importModule } from 'local-pkg';
6
6
  import chai$1, { expect, util } from 'chai';
7
7
  import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
8
- import { q as index, s as slash, u as getNames, c as c$1, t as toArray, r as relative, v as interpretOnlyMode, w as partitionSuiteChildren, x as hasTests, h as hasFailed } from './index-7c024e16.js';
8
+ import { u as index, s as slash, v as getNames, c as c$1, t as toArray, r as relative, w as partitionSuiteChildren, x as hasTests, h as hasFailed } from './index-090545ef.js';
9
9
  import { r as rpc } from './rpc-8c7cc374.js';
10
- import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-67678e1f.js';
10
+ import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-a295cb37.js';
11
11
  import { performance } from 'perf_hooks';
12
+ import { createHash } from 'crypto';
12
13
  import { format as format$1 } from 'util';
13
14
  import './jest-mock-4a754991.js';
14
15
  import 'tinyspy';
@@ -402,12 +403,13 @@ async function saveInlineSnapshots(snapshots) {
402
403
  }));
403
404
  }
404
405
  const startRegex = /toMatchInlineSnapshot\s*\(\s*(['"`\)])/m;
405
- function replaceInlineSnap(code, s, index, newSnap) {
406
+ function replaceInlineSnap(code, s, index, newSnap, indent = "") {
406
407
  const startMatch = startRegex.exec(code.slice(index));
407
408
  if (!startMatch)
408
409
  return false;
409
- newSnap = newSnap.replace(/\\/g, "\\\\");
410
- const snapString = newSnap.includes("\n") ? `\`${newSnap.replace(/`/g, "\\`").trimEnd()}\`` : `'${newSnap.replace(/'/g, "\\'")}'`;
410
+ newSnap = newSnap.replace(/\\/g, "\\\\").split("\n").map((i) => (indent + i).trimEnd()).join("\n");
411
+ const isOneline = !newSnap.includes("\n");
412
+ const snapString = isOneline ? `'${newSnap.replace(/'/g, "\\'").trim()}'` : `\`${newSnap.replace(/`/g, "\\`").trimEnd()}\``;
411
413
  const quote = startMatch[1];
412
414
  const startIndex = index + startMatch.index + startMatch[0].length;
413
415
  if (quote === ")") {
@@ -3530,7 +3532,7 @@ async function setupGlobalEnv(config) {
3530
3532
  setupConsoleLogSpy();
3531
3533
  await setupChai();
3532
3534
  if (config.global)
3533
- (await import('./global-bc40af7c.js')).registerApiGlobally();
3535
+ (await import('./global-8f03a13e.js')).registerApiGlobally();
3534
3536
  }
3535
3537
  function setupConsoleLogSpy() {
3536
3538
  const stdout = new Writable({
@@ -3578,7 +3580,7 @@ async function runSetupFiles(config) {
3578
3580
  }));
3579
3581
  }
3580
3582
 
3581
- function serializeError(val) {
3583
+ function serializeError(val, seen = /* @__PURE__ */ new WeakSet()) {
3582
3584
  if (!val || typeof val === "string")
3583
3585
  return val;
3584
3586
  if (typeof val === "function")
@@ -3591,9 +3593,18 @@ function serializeError(val) {
3591
3593
  return val.tagName;
3592
3594
  if (typeof val.asymmetricMatch === "function")
3593
3595
  return `${val.toString()} ${format$1(val.sample)}`;
3594
- Object.keys(val).forEach((key) => {
3595
- val[key] = serializeError(val[key]);
3596
- });
3596
+ if (seen.has(val))
3597
+ return val;
3598
+ seen.add(val);
3599
+ if (Array.isArray(val)) {
3600
+ val = val.map((e) => {
3601
+ return serializeError(e, seen);
3602
+ });
3603
+ } else {
3604
+ Object.keys(val).forEach((key) => {
3605
+ val[key] = serializeError(val[key], seen);
3606
+ });
3607
+ }
3597
3608
  return val;
3598
3609
  }
3599
3610
  function processError(err) {
@@ -3610,12 +3621,16 @@ function processError(err) {
3610
3621
  return serializeError(err);
3611
3622
  }
3612
3623
 
3624
+ function hash(str, length = 10) {
3625
+ return createHash("md5").update(str).digest("hex").slice(0, length);
3626
+ }
3613
3627
  async function collectTests(paths, config) {
3614
3628
  const files = [];
3615
3629
  for (const filepath of paths) {
3630
+ const path = relative(config.root, filepath);
3616
3631
  const file = {
3617
- id: nanoid(),
3618
- name: relative(config.root, filepath),
3632
+ id: hash(path),
3633
+ name: path,
3619
3634
  type: "suite",
3620
3635
  mode: "run",
3621
3636
  computeMode: "serial",
@@ -3647,12 +3662,59 @@ async function collectTests(paths, config) {
3647
3662
  };
3648
3663
  process.stdout.write("\0");
3649
3664
  }
3665
+ calculateHash(file);
3666
+ interpretTaskModes(file, config.testNamePattern);
3650
3667
  files.push(file);
3651
3668
  }
3652
- const tasks = files.reduce((tasks2, file) => tasks2.concat(file.tasks), []);
3653
- interpretOnlyMode(tasks);
3654
3669
  return files;
3655
3670
  }
3671
+ function interpretTaskModes(suite, namePattern, onlyMode) {
3672
+ if (onlyMode === void 0)
3673
+ onlyMode = someTasksAreOnly(suite);
3674
+ suite.tasks.forEach((t) => {
3675
+ if (onlyMode) {
3676
+ if (t.type === "suite" && someTasksAreOnly(t)) {
3677
+ if (t.mode === "only")
3678
+ t.mode = "run";
3679
+ interpretTaskModes(t, namePattern, onlyMode);
3680
+ } else if (t.mode === "run") {
3681
+ t.mode = "skip";
3682
+ } else if (t.mode === "only") {
3683
+ t.mode = "run";
3684
+ }
3685
+ }
3686
+ if (t.type === "test") {
3687
+ if (namePattern && !t.name.match(namePattern))
3688
+ t.mode = "skip";
3689
+ } else if (t.type === "suite") {
3690
+ if (t.mode === "skip")
3691
+ skipAllTasks(t);
3692
+ if (t.mode === "run") {
3693
+ if (t.tasks.every((i) => i.mode !== "run"))
3694
+ t.mode = "skip";
3695
+ }
3696
+ }
3697
+ });
3698
+ }
3699
+ function someTasksAreOnly(suite) {
3700
+ return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
3701
+ }
3702
+ function skipAllTasks(suite) {
3703
+ suite.tasks.forEach((t) => {
3704
+ if (t.mode === "run") {
3705
+ t.mode = "skip";
3706
+ if (t.type === "suite")
3707
+ skipAllTasks(t);
3708
+ }
3709
+ });
3710
+ }
3711
+ function calculateHash(parent) {
3712
+ parent.tasks.forEach((t, idx) => {
3713
+ t.id = `${parent.id}_${idx}`;
3714
+ if (t.type === "suite")
3715
+ calculateHash(t);
3716
+ });
3717
+ }
3656
3718
 
3657
3719
  async function callSuiteHook(suite, name, args) {
3658
3720
  if (name === "beforeEach" && suite.suite)
@@ -3661,8 +3723,24 @@ async function callSuiteHook(suite, name, args) {
3661
3723
  if (name === "afterEach" && suite.suite)
3662
3724
  await callSuiteHook(suite.suite, name, args);
3663
3725
  }
3726
+ const packs = [];
3727
+ let updateTimer;
3728
+ let previousUpdate;
3664
3729
  function updateTask(task) {
3665
- return rpc().onTaskUpdate([task.id, task.result]);
3730
+ packs.push([task.id, task.result]);
3731
+ clearTimeout(updateTimer);
3732
+ updateTimer = setTimeout(() => {
3733
+ previousUpdate = sendTasksUpdate();
3734
+ }, 10);
3735
+ }
3736
+ async function sendTasksUpdate() {
3737
+ clearTimeout(updateTimer);
3738
+ await previousUpdate;
3739
+ if (packs.length) {
3740
+ const p = rpc().onTaskUpdate(packs);
3741
+ packs.length = 0;
3742
+ return p;
3743
+ }
3666
3744
  }
3667
3745
  async function runTest(test) {
3668
3746
  if (test.mode !== "run")
@@ -3764,6 +3842,7 @@ async function startTests(paths, config) {
3764
3842
  rpc().onCollected(files);
3765
3843
  await runSuites(files);
3766
3844
  await getSnapshotClient().saveSnap();
3845
+ await sendTasksUpdate();
3767
3846
  }
3768
3847
  function clearModuleMocks() {
3769
3848
  const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config;
@@ -1,11 +1,11 @@
1
- import { g as globalApis } from './constants-5968a78c.js';
2
- import { i as index } from './index-7f57c252.js';
1
+ import { g as globalApis } from './constants-22bbd600.js';
2
+ import { i as index } from './index-31a38185.js';
3
3
  import 'url';
4
- import './index-7c024e16.js';
4
+ import './index-090545ef.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
- import './vi-2115c609.js';
8
+ import './vi-092f86e3.js';
9
9
  import './_commonjsHelpers-c9e3b764.js';
10
10
  import './jest-mock-4a754991.js';
11
11
  import 'chai';
@@ -282,24 +282,6 @@ function partitionSuiteChildren(suite) {
282
282
  tasksGroups.push(tasksGroup);
283
283
  return tasksGroups;
284
284
  }
285
- function interpretOnlyMode(tasks) {
286
- if (tasks.some((t) => t.mode === "only")) {
287
- tasks.forEach((t) => {
288
- if (t.mode === "run")
289
- t.mode = "skip";
290
- else if (t.mode === "only")
291
- t.mode = "run";
292
- });
293
- }
294
- tasks.forEach((t) => {
295
- if (t.type === "suite") {
296
- if (t.mode === "skip")
297
- t.tasks.forEach((c2) => c2.mode === "run" && (c2.mode = "skip"));
298
- else
299
- interpretOnlyMode(t.tasks);
300
- }
301
- });
302
- }
303
285
  function getTests(suite) {
304
286
  return toArray(suite).flatMap((s) => s.type === "test" ? [s] : s.tasks.flatMap((c2) => c2.type === "test" ? [c2] : getTests(c2)));
305
287
  }
@@ -334,7 +316,8 @@ function getFullName(task) {
334
316
  async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI && process.stdout.isTTY) {
335
317
  if (isPackageExists(dependency))
336
318
  return true;
337
- console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
319
+ process.stderr.write(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
320
+
338
321
  `));
339
322
  if (!promptInstall)
340
323
  return false;
@@ -382,4 +365,4 @@ function toFilePath(id, root) {
382
365
  return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
383
366
  }
384
367
 
385
- export { isAbsolute as a, basename as b, c, dirname as d, ensurePackageInstalled as e, getSuites as f, getFullName as g, hasFailed as h, isObject as i, getTests as j, resolve as k, deepMerge as l, toFilePath as m, noop as n, notNullish as o, mergeSlashes as p, index as q, relative as r, slash as s, toArray as t, getNames as u, interpretOnlyMode as v, partitionSuiteChildren as w, hasTests as x, isWindows as y, getTasks as z };
368
+ export { isAbsolute as a, basename as b, c, dirname as d, ensurePackageInstalled as e, getSuites as f, getFullName as g, hasFailed as h, isObject as i, getTests as j, resolve as k, deepMerge as l, toFilePath as m, noop as n, notNullish as o, mergeSlashes as p, join as q, relative as r, slash as s, toArray as t, index as u, getNames as v, partitionSuiteChildren as w, hasTests as x, isWindows as y, getTasks as z };
@@ -1,4 +1,4 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-2115c609.js';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-092f86e3.js';
2
2
  import chai, { assert, should } from 'chai';
3
3
  import { s as spies, a as spyOn, f as fn } from './jest-mock-4a754991.js';
4
4