vitest 0.0.96 → 0.0.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import require$$0 from 'readline';
2
2
  import { EventEmitter } from 'events';
3
- import { c, e as ensurePackageInstalled } from './utils-576876dc.js';
4
- import { c as createVitest } from './index-ece64e3c.js';
3
+ import { c, e as ensurePackageInstalled } from './utils-70b78878.js';
4
+ import { c as createVitest } from './index-ca1a0bda.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
@@ -13,7 +13,7 @@ import 'util';
13
13
  import './constants-9cfa4d7b.js';
14
14
  import 'url';
15
15
  import 'perf_hooks';
16
- import './error-81292c96.js';
16
+ import './error-7405ce56.js';
17
17
  import 'source-map';
18
18
  import './index-5cc247ff.js';
19
19
  import 'assert';
@@ -633,7 +633,7 @@ class CAC extends EventEmitter {
633
633
 
634
634
  const cac = (name = "") => new CAC(name);
635
635
 
636
- var version = "0.0.96";
636
+ var version = "0.0.97";
637
637
 
638
638
  const cli = cac("vitest");
639
639
  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", {
@@ -644,6 +644,7 @@ cli.command("watch [...filters]").action(dev);
644
644
  cli.command("dev [...filters]").action(dev);
645
645
  cli.command("[...filters]").action(dev);
646
646
  cli.parse();
647
+ const PROCESS_EXIT_TIMEOUT = 5e3;
647
648
  async function dev(cliFilters, argv) {
648
649
  if (argv.watch == null)
649
650
  argv.watch = !process.env.CI && !process.env.NODE_V8_COVERAGE;
@@ -675,6 +676,13 @@ async function run(cliFilters, options) {
675
676
  if (!ctx.config.watch)
676
677
  await ctx.close();
677
678
  }
679
+ if (!ctx.config.watch) {
680
+ const timer = setTimeout(() => {
681
+ console.error(c.red("Process hanging for 5 seconds after all tests are done. Exiting..."));
682
+ process.exit(1);
683
+ }, PROCESS_EXIT_TIMEOUT);
684
+ timer.unref();
685
+ }
678
686
  }
679
687
  function registerConsoleShortcuts(ctx) {
680
688
  if (process.stdin.isTTY) {
package/dist/entry.js CHANGED
@@ -6,8 +6,8 @@ import chai, { expect, util } from 'chai';
6
6
  import Subset from 'chai-subset';
7
7
  import path, { basename } from 'path';
8
8
  import { r as rpc, s as send } from './rpc-7de86f29.js';
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-576876dc.js';
10
- import { u as unifiedDiff } from './error-81292c96.js';
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';
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';
@@ -2675,19 +2675,19 @@ let PLUGINS$1 = [
2675
2675
  ];
2676
2676
  const getSerializers = () => PLUGINS$1;
2677
2677
 
2678
- var __defProp$1 = Object.defineProperty;
2679
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2680
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2681
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2682
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2683
- var __spreadValues$1 = (a, b) => {
2678
+ var __defProp$2 = Object.defineProperty;
2679
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
2680
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
2681
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
2682
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2683
+ var __spreadValues$2 = (a, b) => {
2684
2684
  for (var prop in b || (b = {}))
2685
- if (__hasOwnProp$1.call(b, prop))
2686
- __defNormalProp$1(a, prop, b[prop]);
2687
- if (__getOwnPropSymbols$1)
2688
- for (var prop of __getOwnPropSymbols$1(b)) {
2689
- if (__propIsEnum$1.call(b, prop))
2690
- __defNormalProp$1(a, prop, b[prop]);
2685
+ if (__hasOwnProp$2.call(b, prop))
2686
+ __defNormalProp$2(a, prop, b[prop]);
2687
+ if (__getOwnPropSymbols$2)
2688
+ for (var prop of __getOwnPropSymbols$2(b)) {
2689
+ if (__propIsEnum$2.call(b, prop))
2690
+ __defNormalProp$2(a, prop, b[prop]);
2691
2691
  }
2692
2692
  return a;
2693
2693
  };
@@ -2723,7 +2723,7 @@ const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith
2723
2723
  const escapeRegex = true;
2724
2724
  const printFunctionName = false;
2725
2725
  function serialize(val, indent = 2, formatOverrides = {}) {
2726
- return normalizeNewlines(format_1(val, __spreadValues$1({
2726
+ return normalizeNewlines(format_1(val, __spreadValues$2({
2727
2727
  escapeRegex,
2728
2728
  indent,
2729
2729
  plugins: getSerializers(),
@@ -2754,6 +2754,22 @@ ${snapshots.join("\n\n")}
2754
2754
  `);
2755
2755
  }
2756
2756
 
2757
+ var __defProp$1 = Object.defineProperty;
2758
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2759
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2760
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2761
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2762
+ var __spreadValues$1 = (a, b) => {
2763
+ for (var prop in b || (b = {}))
2764
+ if (__hasOwnProp$1.call(b, prop))
2765
+ __defNormalProp$1(a, prop, b[prop]);
2766
+ if (__getOwnPropSymbols$1)
2767
+ for (var prop of __getOwnPropSymbols$1(b)) {
2768
+ if (__propIsEnum$1.call(b, prop))
2769
+ __defNormalProp$1(a, prop, b[prop]);
2770
+ }
2771
+ return a;
2772
+ };
2757
2773
  class SnapshotState {
2758
2774
  constructor(snapshotPath, options) {
2759
2775
  this._snapshotPath = snapshotPath;
@@ -2770,7 +2786,9 @@ class SnapshotState {
2770
2786
  this.unmatched = 0;
2771
2787
  this._updateSnapshot = options.updateSnapshot;
2772
2788
  this.updated = 0;
2773
- this._snapshotFormat = options.snapshotFormat || {};
2789
+ this._snapshotFormat = __spreadValues$1({
2790
+ printBasicPrototype: false
2791
+ }, options.snapshotFormat);
2774
2792
  }
2775
2793
  markSnapshotsAsCheckedForTest(testName) {
2776
2794
  this._uncheckedKeys.forEach((uncheckedKey) => {
@@ -2919,7 +2937,10 @@ class SnapshotClient {
2919
2937
  assert(received, message, inlineSnapshot) {
2920
2938
  if (!this.test)
2921
2939
  throw new Error("Snapshot cannot be used outside of test");
2922
- const testName = getNames(this.test).slice(1).join(" > ");
2940
+ const testName = [
2941
+ ...getNames(this.test).slice(1),
2942
+ ...message ? [message] : []
2943
+ ].join(" > ");
2923
2944
  const { actual, expected, key, pass } = this.snapshotState.match({
2924
2945
  testName,
2925
2946
  received,
@@ -1,7 +1,7 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { relative } from 'path';
3
3
  import { format } from 'util';
4
- import { d as notNullish, c } from './utils-576876dc.js';
4
+ import { d as notNullish, c } from './utils-70b78878.js';
5
5
  import { SourceMapConsumer } from 'source-map';
6
6
 
7
7
  function Diff() {}
@@ -1267,12 +1267,14 @@ async function printStack(ctx, stack, highlight, onStack) {
1267
1267
  const pos = await getSourcePos(ctx, frame) || frame;
1268
1268
  const color = frame === highlight ? c.yellow : c.gray;
1269
1269
  const path = relative(ctx.config.root, frame.file);
1270
- ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
1270
+ if (!ctx.config.silent)
1271
+ ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
1271
1272
  await (onStack == null ? void 0 : onStack(frame, pos));
1272
1273
  if (frame.file in ctx.state.filesMap)
1273
1274
  break;
1274
1275
  }
1275
- ctx.console.log();
1276
+ if (!ctx.config.silent)
1277
+ ctx.console.log();
1276
1278
  }
1277
1279
  function getOriginalPos(map, { line, column }) {
1278
1280
  return new Promise((resolve) => {
@@ -5,9 +5,9 @@ import { promises } from 'fs';
5
5
  import fg from 'fast-glob';
6
6
  import require$$0 from 'util';
7
7
  import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-9cfa4d7b.js';
8
- 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-576876dc.js';
8
+ 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
9
  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-81292c96.js';
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
11
  import { o as onetime, s as signalExit } from './index-5cc247ff.js';
12
12
  import { MessageChannel } from 'worker_threads';
13
13
  import { pathToFileURL } from 'url';
@@ -4968,7 +4968,6 @@ class ConsoleReporter {
4968
4968
  this.ctx = ctx;
4969
4969
  this.start = 0;
4970
4970
  this.end = 0;
4971
- this.console = globalThis.console;
4972
4971
  this.isFirstWatchRun = true;
4973
4972
  const mode = ctx.config.watch ? c.yellow(" DEV ") : c.cyan(" RUN ");
4974
4973
  this.log(`
@@ -4979,12 +4978,12 @@ ${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
4979
4978
  log(...args) {
4980
4979
  if (this.ctx.config.silent)
4981
4980
  return;
4982
- this.console.log(...args);
4981
+ this.ctx.console.log(...args);
4983
4982
  }
4984
4983
  error(...args) {
4985
4984
  if (this.ctx.config.silent)
4986
4985
  return;
4987
- this.console.error(...args);
4986
+ this.ctx.console.error(...args);
4988
4987
  }
4989
4988
  relative(path) {
4990
4989
  return relative(this.ctx.config.root, path);
@@ -5092,9 +5091,11 @@ ${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")
5092
5091
  async onWatcherRerun(files, trigger) {
5093
5092
  await this.stopListRender();
5094
5093
  this.watchFilters = files;
5095
- this.console.clear();
5096
- this.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
5094
+ if (!this.ctx.config.silent) {
5095
+ this.ctx.console.clear();
5096
+ this.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
5097
5097
  `));
5098
+ }
5098
5099
  }
5099
5100
  async stopListRender() {
5100
5101
  var _a;
@@ -5230,7 +5231,7 @@ function createPool(ctx) {
5230
5231
  else
5231
5232
  return createFakePool(ctx);
5232
5233
  }
5233
- const workerPath = new URL("./dist/worker.js", pathToFileURL(distDir)).href;
5234
+ const workerPath = pathToFileURL(resolve(distDir, "./worker.js")).href;
5234
5235
  function createFakePool(ctx) {
5235
5236
  const runWithFiles = (name) => {
5236
5237
  return async (files, invalidates) => {
package/dist/index.d.ts CHANGED
@@ -469,8 +469,6 @@ interface RpcMap {
469
469
  onCollected: [[files: File[]], void];
470
470
  onFinished: [[], void];
471
471
  onTaskUpdate: [[pack: TaskResultPack], void];
472
- onWatcherStart: [[], void];
473
- onWatcherRerun: [[files: string[], trigger: string], void];
474
472
  snapshotSaved: [[snapshot: SnapshotResult], void];
475
473
  }
476
474
  declare type RpcCall = <T extends keyof RpcMap>(method: T, ...args: RpcMap[T][0]) => Promise<RpcMap[T][1]>;
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- export { c as createVitest } from './index-ece64e3c.js';
1
+ export { c as createVitest } from './index-ca1a0bda.js';
2
2
  import 'path';
3
3
  import 'vite';
4
4
  import 'process';
@@ -7,11 +7,11 @@ import 'fast-glob';
7
7
  import 'util';
8
8
  import './constants-9cfa4d7b.js';
9
9
  import 'url';
10
- import './utils-576876dc.js';
10
+ import './utils-70b78878.js';
11
11
  import 'tty';
12
12
  import 'local-pkg';
13
13
  import 'perf_hooks';
14
- import './error-81292c96.js';
14
+ import './error-7405ce56.js';
15
15
  import 'source-map';
16
16
  import './index-5cc247ff.js';
17
17
  import 'assert';
@@ -153,7 +153,7 @@ async function ensurePackageInstalled(dependency, promptInstall = !process.env.C
153
153
  message: c.reset(`Do you want to install ${c.green(dependency)}?`)
154
154
  });
155
155
  if (install) {
156
- await (await import('./index-e7a421bb.js')).installPackage(dependency);
156
+ await (await import('./index-e7a421bb.js')).installPackage(dependency, { dev: true });
157
157
  return true;
158
158
  }
159
159
  return false;
package/dist/utils.js CHANGED
@@ -1,3 +1,3 @@
1
- export { e as ensurePackageInstalled, g as getNames, b as getSuites, j as getTasks, a as getTests, h as hasFailed, f as hasTests, i as interpretOnlyMode, n as noop, d as notNullish, p as partitionSuiteChildren, s as slash, t as toArray } from './utils-576876dc.js';
1
+ export { e as ensurePackageInstalled, g as getNames, b as getSuites, j as getTasks, a as getTests, h as hasFailed, f as hasTests, i as interpretOnlyMode, n as noop, d as notNullish, p as partitionSuiteChildren, s as slash, t as toArray } from './utils-70b78878.js';
2
2
  import 'local-pkg';
3
3
  import 'tty';
package/dist/worker.js CHANGED
@@ -7,7 +7,7 @@ import vm from 'vm';
7
7
  import fs, { promises, realpathSync, statSync, Stats } from 'fs';
8
8
  import assert from 'assert';
9
9
  import { format as format$2, inspect } from 'util';
10
- import { s as slash } from './utils-576876dc.js';
10
+ import { s as slash } from './utils-70b78878.js';
11
11
  import { s as send } from './rpc-7de86f29.js';
12
12
  import 'tty';
13
13
  import 'local-pkg';
@@ -9226,18 +9226,21 @@ const stubRequests = {
9226
9226
  };
9227
9227
  async function interpretedImport(path, interpretDefault) {
9228
9228
  const mod = await import(path);
9229
- if (interpretDefault && "__esModule" in mod && "default" in mod) {
9230
- const defaultExport = mod.default;
9231
- if (!("default" in defaultExport)) {
9232
- Object.defineProperty(defaultExport, "default", {
9233
- enumerable: true,
9234
- configurable: true,
9235
- get() {
9236
- return defaultExport;
9237
- }
9238
- });
9239
- }
9240
- return defaultExport;
9229
+ if (interpretDefault && "default" in mod) {
9230
+ return new Proxy(mod, {
9231
+ get(target, key, receiver) {
9232
+ return Reflect.get(target, key, receiver) || Reflect.get(target.default, key, receiver);
9233
+ },
9234
+ set(target, key, value, receiver) {
9235
+ return Reflect.set(target, key, value, receiver) || Reflect.set(target.default, key, value, receiver);
9236
+ },
9237
+ has(target, key) {
9238
+ return Reflect.has(target, key) || Reflect.has(target.default, key);
9239
+ },
9240
+ deleteProperty(target, key) {
9241
+ return Reflect.deleteProperty(target, key) || Reflect.deleteProperty(target.default, key);
9242
+ }
9243
+ });
9241
9244
  }
9242
9245
  return mod;
9243
9246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.96",
3
+ "version": "0.0.97",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",