vitest 0.0.95 → 0.0.99

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.
@@ -0,0 +1,7 @@
1
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
+
3
+ function commonjsRequire (path) {
4
+ 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.');
5
+ }
6
+
7
+ export { commonjsRequire as a, commonjsGlobal as c };
package/dist/cli.js CHANGED
@@ -1,21 +1,22 @@
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 { e as ensurePackageInstalled } from './utils-b780070b.js';
4
+ import { c as createVitest } from './index-d5bb350e.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
8
  import 'vite';
9
9
  import 'process';
10
10
  import 'fs';
11
- import 'fast-glob';
11
+ import 'os';
12
12
  import 'util';
13
- import './constants-9cfa4d7b.js';
13
+ import 'stream';
14
+ import './constants-3cbd9066.js';
14
15
  import 'url';
15
16
  import 'perf_hooks';
16
- import './error-81292c96.js';
17
- import 'source-map';
18
- import './index-5cc247ff.js';
17
+ import './error-34c1d9e5.js';
18
+ import './index-825cb54c.js';
19
+ import './_commonjsHelpers-bdec4bbd.js';
19
20
  import 'assert';
20
21
  import 'worker_threads';
21
22
  import 'tinypool';
@@ -633,10 +634,10 @@ class CAC extends EventEmitter {
633
634
 
634
635
  const cac = (name = "") => new CAC(name);
635
636
 
636
- var version = "0.0.95";
637
+ var version = "0.0.99";
637
638
 
638
639
  const cli = cac("vitest");
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", {
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", {
640
641
  default: "node"
641
642
  }).help();
642
643
  cli.command("run [...filters]").action(run);
@@ -646,16 +647,12 @@ cli.command("[...filters]").action(dev);
646
647
  cli.parse();
647
648
  async function dev(cliFilters, argv) {
648
649
  if (argv.watch == null)
649
- argv.watch = !process.env.CI && !process.env.NODE_V8_COVERAGE;
650
+ argv.watch = !process.env.CI && !process.env.NODE_V8_COVERAGE && !argv.silent && !argv.run;
650
651
  await run(cliFilters, argv);
651
652
  }
652
653
  async function run(cliFilters, options) {
653
654
  process.env.VITEST = "true";
654
655
  process.env.NODE_ENV = "test";
655
- if (!options.silent) {
656
- console.log(c.magenta(c.bold("\nVitest is in closed beta exclusively for Sponsors")));
657
- console.log(c.yellow("Learn more at https://vitest.dev"));
658
- }
659
656
  const ctx = await createVitest(options);
660
657
  process.chdir(ctx.config.root);
661
658
  registerConsoleShortcuts(ctx);
@@ -675,6 +672,8 @@ async function run(cliFilters, options) {
675
672
  if (!ctx.config.watch)
676
673
  await ctx.close();
677
674
  }
675
+ if (!ctx.config.watch)
676
+ process.exit();
678
677
  }
679
678
  function registerConsoleShortcuts(ctx) {
680
679
  if (process.stdin.isTTY) {
@@ -1,5 +1,5 @@
1
- import { resolve } from 'path';
2
1
  import { fileURLToPath } from 'url';
2
+ import { h as resolve } from './utils-b780070b.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
@@ -2,18 +2,16 @@ import fs, { promises } from 'fs';
2
2
  import { Console } from 'console';
3
3
  import { Writable } from 'stream';
4
4
  import { importModule } from 'local-pkg';
5
- import chai, { expect, util } from 'chai';
6
- import Subset from 'chai-subset';
7
- import path, { basename } from 'path';
5
+ import { e as expect, f as chai$1, u as util, h as setHooks, j as createSuiteHooks, k as clearContext, l as defaultSuite, m as context, n as getHooks, o as getFn } from './index-aa25bceb.js';
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-b780070b.js';
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 { u as unifiedDiff } from './error-34c1d9e5.js';
11
10
  import { performance } from 'perf_hooks';
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
11
  import { n as nanoid } from './index-9e71c815.js';
14
12
  import { format as format$1 } from 'util';
15
13
  import 'tty';
16
- import 'source-map';
14
+ import 'path';
17
15
 
18
16
  var node = {
19
17
  name: "node",
@@ -297,6 +295,91 @@ const environments = {
297
295
  "happy-dom": happy
298
296
  };
299
297
 
298
+ var chaiSubset = {exports: {}};
299
+
300
+ (function (module, exports) {
301
+ (function() {
302
+ (function(chaiSubset) {
303
+ if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
304
+ return module.exports = chaiSubset;
305
+ } else {
306
+ return chai.use(chaiSubset);
307
+ }
308
+ })(function(chai, utils) {
309
+ var Assertion = chai.Assertion;
310
+ var assertionPrototype = Assertion.prototype;
311
+
312
+ Assertion.addMethod('containSubset', function (expected) {
313
+ var actual = utils.flag(this, 'object');
314
+ var showDiff = chai.config.showDiff;
315
+
316
+ assertionPrototype.assert.call(this,
317
+ compare(expected, actual),
318
+ 'expected #{act} to contain subset #{exp}',
319
+ 'expected #{act} to not contain subset #{exp}',
320
+ expected,
321
+ actual,
322
+ showDiff
323
+ );
324
+ });
325
+
326
+ chai.assert.containSubset = function(val, exp, msg) {
327
+ new chai.Assertion(val, msg).to.be.containSubset(exp);
328
+ };
329
+
330
+ function compare(expected, actual) {
331
+ if (expected === actual) {
332
+ return true;
333
+ }
334
+ if (typeof(actual) !== typeof(expected)) {
335
+ return false;
336
+ }
337
+ if (typeof(expected) !== 'object' || expected === null) {
338
+ return expected === actual;
339
+ }
340
+ if (!!expected && !actual) {
341
+ return false;
342
+ }
343
+
344
+ if (Array.isArray(expected)) {
345
+ if (typeof(actual.length) !== 'number') {
346
+ return false;
347
+ }
348
+ var aa = Array.prototype.slice.call(actual);
349
+ return expected.every(function (exp) {
350
+ return aa.some(function (act) {
351
+ return compare(exp, act);
352
+ });
353
+ });
354
+ }
355
+
356
+ if (expected instanceof Date) {
357
+ if (actual instanceof Date) {
358
+ return expected.getTime() === actual.getTime();
359
+ } else {
360
+ return false;
361
+ }
362
+ }
363
+
364
+ return Object.keys(expected).every(function (key) {
365
+ var eo = expected[key];
366
+ var ao = actual[key];
367
+ if (typeof(eo) === 'object' && eo !== null && ao !== null) {
368
+ return compare(eo, ao);
369
+ }
370
+ if (typeof(eo) === 'function') {
371
+ return eo(ao);
372
+ }
373
+ return ao === eo;
374
+ });
375
+ }
376
+ });
377
+
378
+ }).call(commonjsGlobal);
379
+ }(chaiSubset));
380
+
381
+ var Subset = chaiSubset.exports;
382
+
300
383
  var naturalCompare$2 = {exports: {}};
301
384
 
302
385
  /*
@@ -2675,19 +2758,19 @@ let PLUGINS$1 = [
2675
2758
  ];
2676
2759
  const getSerializers = () => PLUGINS$1;
2677
2760
 
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) => {
2761
+ var __defProp$2 = Object.defineProperty;
2762
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
2763
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
2764
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
2765
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2766
+ var __spreadValues$2 = (a, b) => {
2684
2767
  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]);
2768
+ if (__hasOwnProp$2.call(b, prop))
2769
+ __defNormalProp$2(a, prop, b[prop]);
2770
+ if (__getOwnPropSymbols$2)
2771
+ for (var prop of __getOwnPropSymbols$2(b)) {
2772
+ if (__propIsEnum$2.call(b, prop))
2773
+ __defNormalProp$2(a, prop, b[prop]);
2691
2774
  }
2692
2775
  return a;
2693
2776
  };
@@ -2723,7 +2806,7 @@ const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith
2723
2806
  const escapeRegex = true;
2724
2807
  const printFunctionName = false;
2725
2808
  function serialize(val, indent = 2, formatOverrides = {}) {
2726
- return normalizeNewlines(format_1(val, __spreadValues$1({
2809
+ return normalizeNewlines(format_1(val, __spreadValues$2({
2727
2810
  escapeRegex,
2728
2811
  indent,
2729
2812
  plugins: getSerializers(),
@@ -2738,7 +2821,7 @@ function printBacktickString(str) {
2738
2821
  }
2739
2822
  function ensureDirectoryExists(filePath) {
2740
2823
  try {
2741
- fs.mkdirSync(path.join(path.dirname(filePath)), { recursive: true });
2824
+ fs.mkdirSync(index.join(index.dirname(filePath)), { recursive: true });
2742
2825
  } catch {
2743
2826
  }
2744
2827
  }
@@ -2754,6 +2837,22 @@ ${snapshots.join("\n\n")}
2754
2837
  `);
2755
2838
  }
2756
2839
 
2840
+ var __defProp$1 = Object.defineProperty;
2841
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2842
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2843
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2844
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2845
+ var __spreadValues$1 = (a, b) => {
2846
+ for (var prop in b || (b = {}))
2847
+ if (__hasOwnProp$1.call(b, prop))
2848
+ __defNormalProp$1(a, prop, b[prop]);
2849
+ if (__getOwnPropSymbols$1)
2850
+ for (var prop of __getOwnPropSymbols$1(b)) {
2851
+ if (__propIsEnum$1.call(b, prop))
2852
+ __defNormalProp$1(a, prop, b[prop]);
2853
+ }
2854
+ return a;
2855
+ };
2757
2856
  class SnapshotState {
2758
2857
  constructor(snapshotPath, options) {
2759
2858
  this._snapshotPath = snapshotPath;
@@ -2770,7 +2869,9 @@ class SnapshotState {
2770
2869
  this.unmatched = 0;
2771
2870
  this._updateSnapshot = options.updateSnapshot;
2772
2871
  this.updated = 0;
2773
- this._snapshotFormat = options.snapshotFormat || {};
2872
+ this._snapshotFormat = __spreadValues$1({
2873
+ printBasicPrototype: false
2874
+ }, options.snapshotFormat);
2774
2875
  }
2775
2876
  markSnapshotsAsCheckedForTest(testName) {
2776
2877
  this._uncheckedKeys.forEach((uncheckedKey) => {
@@ -2899,7 +3000,7 @@ class SnapshotState {
2899
3000
  }
2900
3001
  }
2901
3002
 
2902
- const resolveSnapshotPath = (testPath) => path.join(path.join(path.dirname(testPath), "__snapshots__"), `${path.basename(testPath)}.snap`);
3003
+ const resolveSnapshotPath = (testPath) => index.join(index.join(index.dirname(testPath), "__snapshots__"), `${index.basename(testPath)}.snap`);
2903
3004
  class SnapshotClient {
2904
3005
  constructor() {
2905
3006
  this.testFile = "";
@@ -2919,7 +3020,10 @@ class SnapshotClient {
2919
3020
  assert(received, message, inlineSnapshot) {
2920
3021
  if (!this.test)
2921
3022
  throw new Error("Snapshot cannot be used outside of test");
2922
- const testName = getNames(this.test).slice(1).join(" > ");
3023
+ const testName = [
3024
+ ...getNames(this.test).slice(1),
3025
+ ...message ? [message] : []
3026
+ ].join(" > ");
2923
3027
  const { actual, expected, key, pass } = this.snapshotState.match({
2924
3028
  testName,
2925
3029
  received,
@@ -3385,7 +3489,7 @@ function JestExtendPlugin(expects) {
3385
3489
  c.expect.fail(message());
3386
3490
  }
3387
3491
  const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
3388
- utils.addMethod(chai.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
3492
+ utils.addMethod(chai$1.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
3389
3493
  });
3390
3494
  };
3391
3495
  }
@@ -3555,7 +3659,7 @@ const JestChaiExpect = (chai, utils) => {
3555
3659
  });
3556
3660
  def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
3557
3661
  const spy = getSpy(this);
3558
- const lastCall = spy.calls.at(-1);
3662
+ const lastCall = spy.calls[spy.calls.length - 1];
3559
3663
  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);
3560
3664
  });
3561
3665
  def(["toThrow", "toThrowError"], function(expected) {
@@ -3582,7 +3686,7 @@ const JestChaiExpect = (chai, utils) => {
3582
3686
  });
3583
3687
  def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
3584
3688
  const spy = getSpy(this);
3585
- const lastResult = spy.returns.at(-1);
3689
+ const lastResult = spy.returns[spy.returns.length - 1];
3586
3690
  const pass = equals(lastResult, value);
3587
3691
  this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
3588
3692
  });
@@ -3766,11 +3870,11 @@ let installed = false;
3766
3870
  async function setupChai() {
3767
3871
  if (installed)
3768
3872
  return;
3769
- chai.use(JestExtend);
3770
- chai.use(JestChaiExpect);
3771
- chai.use(Subset);
3772
- chai.use(SnapshotPlugin);
3773
- chai.use(JestAsymmetricMatchers);
3873
+ chai$1.use(JestExtend);
3874
+ chai$1.use(JestChaiExpect);
3875
+ chai$1.use(Subset);
3876
+ chai$1.use(SnapshotPlugin);
3877
+ chai$1.use(JestAsymmetricMatchers);
3774
3878
  installed = true;
3775
3879
  }
3776
3880
 
@@ -3782,7 +3886,7 @@ async function setupGlobalEnv(config) {
3782
3886
  setupConsoleLogSpy();
3783
3887
  await setupChai();
3784
3888
  if (config.global)
3785
- (await import('./global-473089f7.js')).registerApiGlobally();
3889
+ (await import('./global-0be1f687.js')).registerApiGlobally();
3786
3890
  }
3787
3891
  function setupConsoleLogSpy() {
3788
3892
  const stdout = new Writable({
@@ -3937,6 +4041,15 @@ async function runTest(test) {
3937
4041
  test.result.state = "fail";
3938
4042
  test.result.error = processError(e);
3939
4043
  }
4044
+ if (test.fails) {
4045
+ if (test.result.state === "pass") {
4046
+ test.result.state = "fail";
4047
+ test.result.error = processError(new Error("Expect test to fail"));
4048
+ } else {
4049
+ test.result.state = "pass";
4050
+ test.result.error = void 0;
4051
+ }
4052
+ }
3940
4053
  getSnapshotClient().clearTest();
3941
4054
  test.result.end = performance.now();
3942
4055
  process.__vitest_worker__.current = void 0;