vitest 0.0.97 → 0.0.98

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/bin/vitest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { fileURLToPath } from 'url'
4
- import { resolve } from 'path'
4
+ import { resolve } from 'pathe'
5
5
  import { ensurePackageInstalled } from '../dist/utils.js'
6
6
 
7
7
  const argv = process.argv.slice(2)
package/dist/cli.js CHANGED
@@ -1,19 +1,20 @@
1
1
  import require$$0 from 'readline';
2
2
  import { EventEmitter } from 'events';
3
- import { c, e as ensurePackageInstalled } from './utils-70b78878.js';
4
- import { c as createVitest } from './index-ca1a0bda.js';
3
+ import { e as ensurePackageInstalled, c } from './utils-70b78878.js';
4
+ import { c as createVitest } from './index-0697046c.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
+ import './index-1488b423.js';
7
8
  import 'path';
8
9
  import 'vite';
9
10
  import 'process';
10
11
  import 'fs';
11
12
  import 'fast-glob';
12
13
  import 'util';
13
- import './constants-9cfa4d7b.js';
14
+ import './constants-e78c749a.js';
14
15
  import 'url';
15
16
  import 'perf_hooks';
16
- import './error-7405ce56.js';
17
+ import './error-2437ee7f.js';
17
18
  import 'source-map';
18
19
  import './index-5cc247ff.js';
19
20
  import 'assert';
@@ -633,7 +634,7 @@ class CAC extends EventEmitter {
633
634
 
634
635
  const cac = (name = "") => new CAC(name);
635
636
 
636
- var version = "0.0.97";
637
+ var version = "0.0.98";
637
638
 
638
639
  const cli = cac("vitest");
639
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("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", {
@@ -653,10 +654,6 @@ async function dev(cliFilters, argv) {
653
654
  async function run(cliFilters, options) {
654
655
  process.env.VITEST = "true";
655
656
  process.env.NODE_ENV = "test";
656
- if (!options.silent) {
657
- console.log(c.magenta(c.bold("\nVitest is in closed beta exclusively for Sponsors")));
658
- console.log(c.yellow("Learn more at https://vitest.dev"));
659
- }
660
657
  const ctx = await createVitest(options);
661
658
  process.chdir(ctx.config.root);
662
659
  registerConsoleShortcuts(ctx);
@@ -1,5 +1,5 @@
1
- import { resolve } from 'path';
2
1
  import { fileURLToPath } from 'url';
2
+ import { a as resolve } from './index-1488b423.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
@@ -4,14 +4,15 @@ import { Writable } from 'stream';
4
4
  import { importModule } from 'local-pkg';
5
5
  import chai, { expect, util } from 'chai';
6
6
  import Subset from 'chai-subset';
7
- import path, { basename } from 'path';
7
+ import { c as index, b as basename } from './index-1488b423.js';
8
8
  import { r as rpc, s as send } from './rpc-7de86f29.js';
9
9
  import { g as getNames, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, f as hasTests, h as hasFailed } from './utils-70b78878.js';
10
- import { u as unifiedDiff } from './error-7405ce56.js';
10
+ import { u as unifiedDiff } from './error-2437ee7f.js';
11
11
  import { performance } from 'perf_hooks';
12
12
  import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-b8c6cb53.js';
13
13
  import { n as nanoid } from './index-9e71c815.js';
14
14
  import { format as format$1 } from 'util';
15
+ import 'path';
15
16
  import 'tty';
16
17
  import 'source-map';
17
18
 
@@ -2738,7 +2739,7 @@ function printBacktickString(str) {
2738
2739
  }
2739
2740
  function ensureDirectoryExists(filePath) {
2740
2741
  try {
2741
- fs.mkdirSync(path.join(path.dirname(filePath)), { recursive: true });
2742
+ fs.mkdirSync(index.join(index.dirname(filePath)), { recursive: true });
2742
2743
  } catch {
2743
2744
  }
2744
2745
  }
@@ -2917,7 +2918,7 @@ class SnapshotState {
2917
2918
  }
2918
2919
  }
2919
2920
 
2920
- const resolveSnapshotPath = (testPath) => path.join(path.join(path.dirname(testPath), "__snapshots__"), `${path.basename(testPath)}.snap`);
2921
+ const resolveSnapshotPath = (testPath) => index.join(index.join(index.dirname(testPath), "__snapshots__"), `${index.basename(testPath)}.snap`);
2921
2922
  class SnapshotClient {
2922
2923
  constructor() {
2923
2924
  this.testFile = "";
@@ -3576,7 +3577,7 @@ const JestChaiExpect = (chai, utils) => {
3576
3577
  });
3577
3578
  def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
3578
3579
  const spy = getSpy(this);
3579
- const lastCall = spy.calls.at(-1);
3580
+ const lastCall = spy.calls[spy.calls.length - 1];
3580
3581
  this.assert(equals(lastCall, args), "expected last spy call to have been called with #{exp}", "expected last spy call to not have been called with #{exp}", args, lastCall);
3581
3582
  });
3582
3583
  def(["toThrow", "toThrowError"], function(expected) {
@@ -3603,7 +3604,7 @@ const JestChaiExpect = (chai, utils) => {
3603
3604
  });
3604
3605
  def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
3605
3606
  const spy = getSpy(this);
3606
- const lastResult = spy.returns.at(-1);
3607
+ const lastResult = spy.returns[spy.returns.length - 1];
3607
3608
  const pass = equals(lastResult, value);
3608
3609
  this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
3609
3610
  });
@@ -3803,7 +3804,7 @@ async function setupGlobalEnv(config) {
3803
3804
  setupConsoleLogSpy();
3804
3805
  await setupChai();
3805
3806
  if (config.global)
3806
- (await import('./global-473089f7.js')).registerApiGlobally();
3807
+ (await import('./global-97ee5fb8.js')).registerApiGlobally();
3807
3808
  }
3808
3809
  function setupConsoleLogSpy() {
3809
3810
  const stdout = new Writable({
@@ -1,6 +1,6 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { relative } from 'path';
3
2
  import { format } from 'util';
3
+ import { r as relative } from './index-1488b423.js';
4
4
  import { d as notNullish, c } from './utils-70b78878.js';
5
5
  import { SourceMapConsumer } from 'source-map';
6
6
 
@@ -1,7 +1,8 @@
1
- import { g as globalApis } from './constants-9cfa4d7b.js';
1
+ import { g as globalApis } from './constants-e78c749a.js';
2
2
  import { i as index } from './index-368448f4.js';
3
- import 'path';
4
3
  import 'url';
4
+ import './index-1488b423.js';
5
+ import 'path';
5
6
  import './suite-b8c6cb53.js';
6
7
  import './index-9e71c815.js';
7
8
  import 'chai';
@@ -1,13 +1,14 @@
1
- import path$2, { isAbsolute, relative, dirname, basename, resolve } from 'path';
1
+ import { i as isAbsolute, r as relative, d as dirname, b as basename, a as resolve } from './index-1488b423.js';
2
2
  import { createServer, mergeConfig } from 'vite';
3
+ import path$2 from 'path';
3
4
  import process$1 from 'process';
4
5
  import { promises } from 'fs';
5
6
  import fg from 'fast-glob';
6
7
  import require$$0 from 'util';
7
- import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-9cfa4d7b.js';
8
+ import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-e78c749a.js';
8
9
  import { c, g as getNames, s as slash, a as getTests, b as getSuites, n as noop, t as toArray, h as hasFailed } from './utils-70b78878.js';
9
10
  import { performance } from 'perf_hooks';
10
- import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, F as F_POINTER, d as F_DOWN, e as F_LONG_DASH, f as F_DOWN_RIGHT, g as F_DOT, h as F_CHECK, i as F_CROSS, j as cliTruncate, k as F_RIGHT, p as printError } from './error-7405ce56.js';
11
+ import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, F as F_POINTER, d as F_DOWN, e as F_LONG_DASH, f as F_DOWN_RIGHT, g as F_DOT, h as F_CHECK, i as F_CROSS, j as cliTruncate, k as F_RIGHT, p as printError } from './error-2437ee7f.js';
11
12
  import { o as onetime, s as signalExit } from './index-5cc247ff.js';
12
13
  import { MessageChannel } from 'worker_threads';
13
14
  import { pathToFileURL } from 'url';
@@ -5184,6 +5185,7 @@ function resolveConfig(options, viteConfig) {
5184
5185
  resolved.interpretDefault = resolved.interpretDefault ?? true;
5185
5186
  resolved.include = resolved.include ?? defaultInclude;
5186
5187
  resolved.exclude = resolved.exclude ?? defaultExclude;
5188
+ resolved.watchIgnore = resolved.watchIgnore ?? [/\/node_modules\//, /\/dist\//];
5187
5189
  const CI = !!process.env.CI;
5188
5190
  const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT;
5189
5191
  resolved.snapshotOptions = {
@@ -5450,7 +5452,7 @@ class Vitest {
5450
5452
  };
5451
5453
  }
5452
5454
  handleFileChanged(id) {
5453
- if (this.changedTests.has(id) || this.invalidates.has(id) || id.includes("/node_modules/") || id.includes("/vitest/dist/"))
5455
+ if (this.changedTests.has(id) || this.invalidates.has(id) || this.config.watchIgnore.some((i) => id.match(i)))
5454
5456
  return;
5455
5457
  this.invalidates.add(id);
5456
5458
  if (id in this.state.filesMap) {
@@ -5514,7 +5516,7 @@ async function createVitest(options, viteOverrides = {}) {
5514
5516
  ctx.setServer(options, server2);
5515
5517
  haveStarted = true;
5516
5518
  if (options.api)
5517
- server2.middlewares.use((await import('./middleware-bf0f818d.js')).default(ctx));
5519
+ server2.middlewares.use((await import('./middleware-8b68d8d7.js')).default(ctx));
5518
5520
  }
5519
5521
  }
5520
5522
  ],
@@ -0,0 +1,186 @@
1
+ import path from 'path';
2
+
3
+ function normalizeWindowsPath(input = "") {
4
+ if (!input.includes("\\")) {
5
+ return input;
6
+ }
7
+ return input.replace(/\\/g, "/");
8
+ }
9
+
10
+ const _UNC_REGEX = /^[/][/]/;
11
+ const _UNC_DRIVE_REGEX = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
12
+ const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
13
+ const sep = "/";
14
+ const delimiter = ":";
15
+ const normalize = function(path2) {
16
+ if (path2.length === 0) {
17
+ return ".";
18
+ }
19
+ path2 = normalizeWindowsPath(path2);
20
+ const isUNCPath = path2.match(_UNC_REGEX);
21
+ const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX);
22
+ const isPathAbsolute = isAbsolute(path2);
23
+ const trailingSeparator = path2[path2.length - 1] === "/";
24
+ path2 = normalizeString(path2, !isPathAbsolute);
25
+ if (path2.length === 0) {
26
+ if (isPathAbsolute) {
27
+ return "/";
28
+ }
29
+ return trailingSeparator ? "./" : ".";
30
+ }
31
+ if (trailingSeparator) {
32
+ path2 += "/";
33
+ }
34
+ if (isUNCPath) {
35
+ if (hasUNCDrive) {
36
+ return `//./${path2}`;
37
+ }
38
+ return `//${path2}`;
39
+ }
40
+ return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
41
+ };
42
+ const join = function(...args) {
43
+ if (args.length === 0) {
44
+ return ".";
45
+ }
46
+ let joined;
47
+ for (let i = 0; i < args.length; ++i) {
48
+ const arg = args[i];
49
+ if (arg.length > 0) {
50
+ if (joined === void 0) {
51
+ joined = arg;
52
+ } else {
53
+ joined += `/${arg}`;
54
+ }
55
+ }
56
+ }
57
+ if (joined === void 0) {
58
+ return ".";
59
+ }
60
+ return normalize(joined);
61
+ };
62
+ const resolve = function(...args) {
63
+ args = args.map((arg) => normalizeWindowsPath(arg));
64
+ let resolvedPath = "";
65
+ let resolvedAbsolute = false;
66
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
67
+ const path2 = i >= 0 ? args[i] : process.cwd();
68
+ if (path2.length === 0) {
69
+ continue;
70
+ }
71
+ resolvedPath = `${path2}/${resolvedPath}`;
72
+ resolvedAbsolute = isAbsolute(path2);
73
+ }
74
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
75
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
76
+ return `/${resolvedPath}`;
77
+ }
78
+ return resolvedPath.length > 0 ? resolvedPath : ".";
79
+ };
80
+ function normalizeString(path2, allowAboveRoot) {
81
+ let res = "";
82
+ let lastSegmentLength = 0;
83
+ let lastSlash = -1;
84
+ let dots = 0;
85
+ let char = null;
86
+ for (let i = 0; i <= path2.length; ++i) {
87
+ if (i < path2.length) {
88
+ char = path2[i];
89
+ } else if (char === "/") {
90
+ break;
91
+ } else {
92
+ char = "/";
93
+ }
94
+ if (char === "/") {
95
+ if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
96
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
97
+ if (res.length > 2) {
98
+ const lastSlashIndex = res.lastIndexOf("/");
99
+ if (lastSlashIndex === -1) {
100
+ res = "";
101
+ lastSegmentLength = 0;
102
+ } else {
103
+ res = res.slice(0, lastSlashIndex);
104
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
105
+ }
106
+ lastSlash = i;
107
+ dots = 0;
108
+ continue;
109
+ } else if (res.length !== 0) {
110
+ res = "";
111
+ lastSegmentLength = 0;
112
+ lastSlash = i;
113
+ dots = 0;
114
+ continue;
115
+ }
116
+ }
117
+ if (allowAboveRoot) {
118
+ res += res.length > 0 ? "/.." : "..";
119
+ lastSegmentLength = 2;
120
+ }
121
+ } else {
122
+ if (res.length > 0) {
123
+ res += `/${path2.slice(lastSlash + 1, i)}`;
124
+ } else {
125
+ res = path2.slice(lastSlash + 1, i);
126
+ }
127
+ lastSegmentLength = i - lastSlash - 1;
128
+ }
129
+ lastSlash = i;
130
+ dots = 0;
131
+ } else if (char === "." && dots !== -1) {
132
+ ++dots;
133
+ } else {
134
+ dots = -1;
135
+ }
136
+ }
137
+ return res;
138
+ }
139
+ const isAbsolute = function(p) {
140
+ return _IS_ABSOLUTE_RE.test(p);
141
+ };
142
+ const toNamespacedPath = function(p) {
143
+ return normalizeWindowsPath(p);
144
+ };
145
+ const extname = function(p) {
146
+ return path.posix.extname(normalizeWindowsPath(p));
147
+ };
148
+ const relative = function(from, to) {
149
+ return path.posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to));
150
+ };
151
+ const dirname = function(p) {
152
+ return path.posix.dirname(normalizeWindowsPath(p));
153
+ };
154
+ const format = function(p) {
155
+ return normalizeWindowsPath(path.posix.format(p));
156
+ };
157
+ const basename = function(p, ext) {
158
+ return path.posix.basename(normalizeWindowsPath(p), ext);
159
+ };
160
+ const parse = function(p) {
161
+ return path.posix.parse(normalizeWindowsPath(p));
162
+ };
163
+
164
+ const _path = /*#__PURE__*/Object.freeze({
165
+ __proto__: null,
166
+ sep: sep,
167
+ delimiter: delimiter,
168
+ normalize: normalize,
169
+ join: join,
170
+ resolve: resolve,
171
+ normalizeString: normalizeString,
172
+ isAbsolute: isAbsolute,
173
+ toNamespacedPath: toNamespacedPath,
174
+ extname: extname,
175
+ relative: relative,
176
+ dirname: dirname,
177
+ format: format,
178
+ basename: basename,
179
+ parse: parse
180
+ });
181
+
182
+ const index = {
183
+ ..._path
184
+ };
185
+
186
+ export { resolve as a, basename as b, index as c, dirname as d, isAbsolute as i, relative as r };
package/dist/index.d.ts CHANGED
@@ -420,6 +420,12 @@ interface InlineConfig {
420
420
  * Path to setup files
421
421
  */
422
422
  setupFiles?: string | string[];
423
+ /**
424
+ * Pattern of file paths to be ignore from triggering watch rerun
425
+ *
426
+ * @default ['**\/node_modules\/**', '**\/dist/**']
427
+ */
428
+ watchIgnore?: (string | RegExp)[];
423
429
  /**
424
430
  * Open Vitest UI
425
431
  * @internal WIP
@@ -1,6 +1,7 @@
1
- import { A as API_PATH } from './constants-9cfa4d7b.js';
2
- import 'path';
1
+ import { A as API_PATH } from './constants-e78c749a.js';
3
2
  import 'url';
3
+ import './index-1488b423.js';
4
+ import 'path';
4
5
 
5
6
  /*! (c) 2020 Andrea Giammarchi */
6
7
 
package/dist/node.js CHANGED
@@ -1,17 +1,18 @@
1
- export { c as createVitest } from './index-ca1a0bda.js';
1
+ export { c as createVitest } from './index-0697046c.js';
2
+ import './index-1488b423.js';
2
3
  import 'path';
3
4
  import 'vite';
4
5
  import 'process';
5
6
  import 'fs';
6
7
  import 'fast-glob';
7
8
  import 'util';
8
- import './constants-9cfa4d7b.js';
9
+ import './constants-e78c749a.js';
9
10
  import 'url';
10
11
  import './utils-70b78878.js';
11
12
  import 'tty';
12
13
  import 'local-pkg';
13
14
  import 'perf_hooks';
14
- import './error-7405ce56.js';
15
+ import './error-2437ee7f.js';
15
16
  import 'source-map';
16
17
  import './index-5cc247ff.js';
17
18
  import 'assert';
package/dist/worker.js CHANGED
@@ -1,9 +1,10 @@
1
- import path, { resolve, dirname as dirname$2 } from 'path';
1
+ import { a as resolve, d as dirname$2 } from './index-1488b423.js';
2
2
  import { n as nanoid } from './index-9e71c815.js';
3
- import { c as distDir } from './constants-9cfa4d7b.js';
3
+ import { c as distDir } from './constants-e78c749a.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
6
6
  import vm from 'vm';
7
+ import path from 'path';
7
8
  import fs, { promises, realpathSync, statSync, Stats } from 'fs';
8
9
  import assert from 'assert';
9
10
  import { format as format$2, inspect } from 'util';
@@ -9314,7 +9315,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
9314
9315
  var _a, _b;
9315
9316
  const id = normalizeId(rawId);
9316
9317
  if (externalCache.get(id))
9317
- return interpretedImport(id, options.interpretDefault);
9318
+ return interpretedImport(patchWindowsImportPath(id), options.interpretDefault);
9318
9319
  const fsPath = toFilePath(id, root);
9319
9320
  const importPath = patchWindowsImportPath(fsPath);
9320
9321
  if (!externalCache.has(importPath))
@@ -9379,6 +9380,8 @@ function matchExternalizePattern(id, patterns) {
9379
9380
  function patchWindowsImportPath(path) {
9380
9381
  if (path.match(/^\w:\\/))
9381
9382
  return `file:///${slash(path)}`;
9383
+ else if (path.match(/^\w:\//))
9384
+ return `file:///${path}`;
9382
9385
  else
9383
9386
  return path;
9384
9387
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.97",
3
+ "version": "0.0.98",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",