vitest 0.0.101 → 0.0.105

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
@@ -1001,6 +1001,21 @@ Repository: sindresorhus/log-update
1001
1001
 
1002
1002
  ---------------------------------------
1003
1003
 
1004
+ ## magic-string
1005
+ License: MIT
1006
+ By: Rich Harris
1007
+ Repository: https://github.com/rich-harris/magic-string
1008
+
1009
+ > Copyright 2018 Rich Harris
1010
+ >
1011
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1012
+ >
1013
+ > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1014
+ >
1015
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1016
+
1017
+ ---------------------------------------
1018
+
1004
1019
  ## merge-stream
1005
1020
  License: MIT
1006
1021
  By: Stephen Sugden
@@ -1132,6 +1147,35 @@ Repository: unjs/mlly
1132
1147
 
1133
1148
  ---------------------------------------
1134
1149
 
1150
+ ## mockdate
1151
+ License: MIT
1152
+ By: Bob Lauer
1153
+ Repository: https://github.com/boblauer/MockDate.git
1154
+
1155
+ > The MIT License (MIT)
1156
+ >
1157
+ > Copyright (c) 2014 Bob Lauer
1158
+ >
1159
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
1160
+ > of this software and associated documentation files (the "Software"), to deal
1161
+ > in the Software without restriction, including without limitation the rights
1162
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1163
+ > copies of the Software, and to permit persons to whom the Software is
1164
+ > furnished to do so, subject to the following conditions:
1165
+ >
1166
+ > The above copyright notice and this permission notice shall be included in all
1167
+ > copies or substantial portions of the Software.
1168
+ >
1169
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1170
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1171
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1172
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1173
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1174
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1175
+ > SOFTWARE.
1176
+
1177
+ ---------------------------------------
1178
+
1135
1179
  ## nanoid
1136
1180
  License: MIT
1137
1181
  By: Andrey Sitnik
@@ -1699,6 +1743,35 @@ Repository: 7rulnik/source-map
1699
1743
 
1700
1744
  ---------------------------------------
1701
1745
 
1746
+ ## sourcemap-codec
1747
+ License: MIT
1748
+ By: Rich Harris
1749
+ Repository: https://github.com/Rich-Harris/sourcemap-codec
1750
+
1751
+ > The MIT License
1752
+ >
1753
+ > Copyright (c) 2015 Rich Harris
1754
+ >
1755
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
1756
+ > of this software and associated documentation files (the "Software"), to deal
1757
+ > in the Software without restriction, including without limitation the rights
1758
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1759
+ > copies of the Software, and to permit persons to whom the Software is
1760
+ > furnished to do so, subject to the following conditions:
1761
+ >
1762
+ > The above copyright notice and this permission notice shall be included in
1763
+ > all copies or substantial portions of the Software.
1764
+ >
1765
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1766
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1767
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1768
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1769
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1770
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1771
+ > THE SOFTWARE.
1772
+
1773
+ ---------------------------------------
1774
+
1702
1775
  ## string-width
1703
1776
  License: MIT
1704
1777
  By: Sindre Sorhus
package/dist/cli.js CHANGED
@@ -1,22 +1,23 @@
1
1
  import require$$0 from 'readline';
2
2
  import { EventEmitter } from 'events';
3
- import { e as ensurePackageInstalled } from './utils-c8e62373.js';
4
- import { c as createVitest } from './index-37755855.js';
3
+ import { e as ensurePackageInstalled } from './utils-5307e690.js';
4
+ import { c as createVitest } from './index-1da01554.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
+ import 'chai';
9
+ import 'tinyspy';
8
10
  import 'vite';
9
11
  import 'process';
10
12
  import 'fs';
11
13
  import 'os';
12
14
  import 'util';
13
15
  import 'stream';
14
- import './constants-a1417084.js';
16
+ import './constants-9320a46c.js';
15
17
  import 'url';
16
18
  import 'perf_hooks';
17
- import './error-d97062cd.js';
18
- import './index-825cb54c.js';
19
- import './_commonjsHelpers-bdec4bbd.js';
19
+ import './error-4e165107.js';
20
+ import './index-4cf13e25.js';
20
21
  import 'assert';
21
22
  import 'worker_threads';
22
23
  import 'tinypool';
@@ -634,12 +635,10 @@ class CAC extends EventEmitter {
634
635
 
635
636
  const cac = (name = "") => new CAC(name);
636
637
 
637
- var version = "0.0.101";
638
+ var version = "0.0.105";
638
639
 
639
640
  const cli = cac("vitest");
640
- cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open Vitest UI").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", {
641
- default: "node"
642
- }).help();
641
+ cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open Vitest UI").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent").option("--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();
643
642
  cli.command("run [...filters]").action(run);
644
643
  cli.command("watch [...filters]").action(dev);
645
644
  cli.command("dev [...filters]").action(dev);
@@ -679,8 +678,8 @@ function registerConsoleShortcuts(ctx) {
679
678
  if (process.stdin.isTTY) {
680
679
  require$$0.emitKeypressEvents(process.stdin);
681
680
  process.stdin.setRawMode(true);
682
- process.stdin.on("keypress", (str) => {
683
- if (str === "" || str === "")
681
+ process.stdin.on("keypress", (str, key) => {
682
+ if (str === "" || str === "" || key && key.ctrl && key.name === "c")
684
683
  process.exit();
685
684
  if (ctx.runningPromise)
686
685
  return;
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { h as resolve } from './utils-c8e62373.js';
2
+ import { m as resolve } from './utils-5307e690.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}"];
package/dist/entry.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import fs, { promises } from 'fs';
2
+ import { w as commonjsRequire, q as commonjsGlobal, x as index, g as getNames, c as c$1, t as toArray, k as basename, y as interpretOnlyMode, z as partitionSuiteChildren, A as hasTests, o as hasFailed, B as clearModuleMocks, b as vi } from './utils-5307e690.js';
2
3
  import { Console } from 'console';
3
4
  import { Writable } from 'stream';
4
5
  import { importModule } from 'local-pkg';
5
6
  import chai$1, { expect, util } from 'chai';
6
- import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-bdec4bbd.js';
7
- import { l as index, g as getNames, c as c$1, t as toArray, b as basename, m as interpretOnlyMode, p as partitionSuiteChildren, o as hasTests, j as hasFailed } from './utils-c8e62373.js';
8
7
  import { r as rpc, s as send } from './rpc-7de86f29.js';
9
- import { u as unifiedDiff } from './error-d97062cd.js';
8
+ import { u as unifiedDiff } from './error-4e165107.js';
10
9
  import { performance } from 'perf_hooks';
11
- import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-4f3fb0b5.js';
10
+ import { c as clearContext, b as defaultSuite, e as setHooks, f as getHooks, h as context, j as getFn } from './suite-101bab76.js';
12
11
  import { n as nanoid } from './index-9e71c815.js';
13
12
  import { format as format$1 } from 'util';
14
13
  import 'tty';
15
14
  import 'path';
15
+ import 'tinyspy';
16
16
 
17
17
  var node = {
18
18
  name: "node",
@@ -3851,6 +3851,23 @@ class Any extends AsymmetricMatcher {
3851
3851
  return `Any<${this.fnNameFor(this.sample)}>`;
3852
3852
  }
3853
3853
  }
3854
+ class StringMatching extends AsymmetricMatcher {
3855
+ constructor(sample, inverse = false) {
3856
+ if (!isA("String", sample) && !isA("RegExp", sample))
3857
+ throw new Error("Expected is not a String or a RegExp");
3858
+ super(new RegExp(sample), inverse);
3859
+ }
3860
+ asymmetricMatch(other) {
3861
+ const result = isA("String", other) && this.sample.test(other);
3862
+ return this.inverse ? !result : result;
3863
+ }
3864
+ toString() {
3865
+ return `String${this.inverse ? "Not" : ""}Matching`;
3866
+ }
3867
+ getExpectedType() {
3868
+ return "string";
3869
+ }
3870
+ }
3854
3871
  const JestAsymmetricMatchers = (chai, utils) => {
3855
3872
  utils.addMethod(chai.expect, "stringContaining", (expected) => new StringContaining(expected));
3856
3873
  utils.addMethod(chai.expect, "anything", () => {
@@ -3865,6 +3882,9 @@ const JestAsymmetricMatchers = (chai, utils) => {
3865
3882
  utils.addMethod(chai.expect, "arrayContaining", (expected) => {
3866
3883
  return new ArrayContaining(expected);
3867
3884
  });
3885
+ utils.addMethod(chai.expect, "stringMatching", (expected) => {
3886
+ return new StringMatching(expected);
3887
+ });
3868
3888
  };
3869
3889
 
3870
3890
  let installed = false;
@@ -3887,7 +3907,7 @@ async function setupGlobalEnv(config) {
3887
3907
  setupConsoleLogSpy();
3888
3908
  await setupChai();
3889
3909
  if (config.global)
3890
- (await import('./global-5b58e48f.js')).registerApiGlobally();
3910
+ (await import('./global-a3634033.js')).registerApiGlobally();
3891
3911
  }
3892
3912
  function setupConsoleLogSpy() {
3893
3913
  const stdout = new Writable({
@@ -3976,12 +3996,12 @@ async function collectTests(paths, config) {
3976
3996
  filepath,
3977
3997
  tasks: []
3978
3998
  };
3979
- setHooks(file, createSuiteHooks());
3980
3999
  clearContext();
3981
4000
  try {
3982
4001
  await runSetupFiles(config);
3983
4002
  await import(filepath);
3984
4003
  const defaultTasks = await defaultSuite.collect(file);
4004
+ setHooks(file, getHooks(defaultTasks));
3985
4005
  for (const c of [...defaultTasks.tasks, ...context.tasks]) {
3986
4006
  if (c.type === "test") {
3987
4007
  file.tasks.push(c);
@@ -4026,6 +4046,7 @@ async function runTest(test) {
4026
4046
  state: "run"
4027
4047
  };
4028
4048
  updateTask(test);
4049
+ clearModuleMocks();
4029
4050
  getSnapshotClient().setTest(test);
4030
4051
  process.__vitest_worker__.current = test;
4031
4052
  try {
@@ -4123,9 +4144,12 @@ async function run(files, config) {
4123
4144
  const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
4124
4145
  if (!["node", "jsdom", "happy-dom"].includes(env))
4125
4146
  throw new Error(`Unsupported environment: ${env}`);
4147
+ process.__vitest_worker__.filepath = file;
4148
+ vi.restoreAllMocks();
4126
4149
  await withEnv(env, async () => {
4127
4150
  await startTests([file], config);
4128
4151
  });
4152
+ process.__vitest_worker__.filepath = void 0;
4129
4153
  }
4130
4154
  }
4131
4155
 
@@ -1,6 +1,6 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { format } from 'util';
3
- import { k as notNullish, c, r as relative } from './utils-c8e62373.js';
3
+ import { p as notNullish, c, r as relative } from './utils-5307e690.js';
4
4
 
5
5
  function Diff() {}
6
6
  Diff.prototype = {
@@ -4615,6 +4615,7 @@ function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
4615
4615
  const lines = source.split(splitRE);
4616
4616
  let count = 0;
4617
4617
  let res = [];
4618
+ const columns = process.stdout.columns || 80;
4618
4619
  function lineNo(no = "") {
4619
4620
  return c.gray(`${String(no).padStart(3, " ")}| `);
4620
4621
  }
@@ -4627,7 +4628,7 @@ function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
4627
4628
  const lineLength = lines[j].length;
4628
4629
  if (lineLength > 200)
4629
4630
  return "";
4630
- res.push(lineNo(j + 1) + cliTruncate(lines[j], process.stdout.columns - 5 - indent));
4631
+ res.push(lineNo(j + 1) + cliTruncate(lines[j], columns - 5 - indent));
4631
4632
  if (j === i) {
4632
4633
  const pad = start - (count - lineLength);
4633
4634
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
@@ -4724,7 +4725,7 @@ ${indent}${c.red("+ actual")}
4724
4725
  ${cleanLines.map((l) => l()).join("\n")}`;
4725
4726
  }
4726
4727
  function formatLine(line) {
4727
- return cliTruncate(line, (process.stdout.columns || 40) - 1);
4728
+ return cliTruncate(line, (process.stdout.columns || 80) - 1);
4728
4729
  }
4729
4730
  function renderTruncateMessage(indent) {
4730
4731
  return `
@@ -1,14 +1,14 @@
1
- import { g as globalApis } from './constants-a1417084.js';
2
- import { i as index } from './index-f580d714.js';
1
+ import { g as globalApis } from './constants-9320a46c.js';
2
+ import { i as index } from './index-a76b4291.js';
3
3
  import 'url';
4
- import './utils-c8e62373.js';
4
+ import './utils-5307e690.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
- import './suite-4f3fb0b5.js';
9
- import './index-9e71c815.js';
10
8
  import 'chai';
11
9
  import 'tinyspy';
10
+ import './suite-101bab76.js';
11
+ import './index-9e71c815.js';
12
12
 
13
13
  function registerApiGlobally() {
14
14
  globalApis.forEach((api) => {