vitest 0.0.97 → 0.0.101

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-70b78878.js';
4
- import { c as createVitest } from './index-ca1a0bda.js';
3
+ import { e as ensurePackageInstalled } from './utils-c8e62373.js';
4
+ import { c as createVitest } from './index-37755855.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-a1417084.js';
14
15
  import 'url';
15
16
  import 'perf_hooks';
16
- import './error-7405ce56.js';
17
- import 'source-map';
18
- import './index-5cc247ff.js';
17
+ import './error-d97062cd.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.97";
637
+ var version = "0.0.101";
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);
@@ -644,19 +645,14 @@ cli.command("watch [...filters]").action(dev);
644
645
  cli.command("dev [...filters]").action(dev);
645
646
  cli.command("[...filters]").action(dev);
646
647
  cli.parse();
647
- const PROCESS_EXIT_TIMEOUT = 5e3;
648
648
  async function dev(cliFilters, argv) {
649
649
  if (argv.watch == null)
650
- 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;
651
651
  await run(cliFilters, argv);
652
652
  }
653
653
  async function run(cliFilters, options) {
654
654
  process.env.VITEST = "true";
655
655
  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
656
  const ctx = await createVitest(options);
661
657
  process.chdir(ctx.config.root);
662
658
  registerConsoleShortcuts(ctx);
@@ -676,13 +672,8 @@ async function run(cliFilters, options) {
676
672
  if (!ctx.config.watch)
677
673
  await ctx.close();
678
674
  }
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
- }
675
+ if (!ctx.config.watch)
676
+ process.exit();
686
677
  }
687
678
  function registerConsoleShortcuts(ctx) {
688
679
  if (process.stdin.isTTY) {
@@ -1,9 +1,9 @@
1
- import { resolve } from 'path';
2
1
  import { fileURLToPath } from 'url';
2
+ import { h as resolve } from './utils-c8e62373.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}"];
6
- const defaultExclude = ["**/node_modules/**", "**/dist/**"];
6
+ const defaultExclude = ["node_modules", "dist", ".idea", ".git", ".cache"];
7
7
  const defaultPort = 51204;
8
8
  const API_PATH = "/__vitest_api__";
9
9
  const configFiles = [
package/dist/entry.js CHANGED
@@ -2,18 +2,17 @@ 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 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
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-70b78878.js';
10
- import { u as unifiedDiff } from './error-7405ce56.js';
9
+ import { u as unifiedDiff } from './error-d97062cd.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';
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';
13
12
  import { n as nanoid } from './index-9e71c815.js';
14
13
  import { format as format$1 } from 'util';
15
14
  import 'tty';
16
- import 'source-map';
15
+ import 'path';
17
16
 
18
17
  var node = {
19
18
  name: "node",
@@ -297,6 +296,91 @@ const environments = {
297
296
  "happy-dom": happy
298
297
  };
299
298
 
299
+ var chaiSubset = {exports: {}};
300
+
301
+ (function (module, exports) {
302
+ (function() {
303
+ (function(chaiSubset) {
304
+ if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
305
+ return module.exports = chaiSubset;
306
+ } else {
307
+ return chai.use(chaiSubset);
308
+ }
309
+ })(function(chai, utils) {
310
+ var Assertion = chai.Assertion;
311
+ var assertionPrototype = Assertion.prototype;
312
+
313
+ Assertion.addMethod('containSubset', function (expected) {
314
+ var actual = utils.flag(this, 'object');
315
+ var showDiff = chai.config.showDiff;
316
+
317
+ assertionPrototype.assert.call(this,
318
+ compare(expected, actual),
319
+ 'expected #{act} to contain subset #{exp}',
320
+ 'expected #{act} to not contain subset #{exp}',
321
+ expected,
322
+ actual,
323
+ showDiff
324
+ );
325
+ });
326
+
327
+ chai.assert.containSubset = function(val, exp, msg) {
328
+ new chai.Assertion(val, msg).to.be.containSubset(exp);
329
+ };
330
+
331
+ function compare(expected, actual) {
332
+ if (expected === actual) {
333
+ return true;
334
+ }
335
+ if (typeof(actual) !== typeof(expected)) {
336
+ return false;
337
+ }
338
+ if (typeof(expected) !== 'object' || expected === null) {
339
+ return expected === actual;
340
+ }
341
+ if (!!expected && !actual) {
342
+ return false;
343
+ }
344
+
345
+ if (Array.isArray(expected)) {
346
+ if (typeof(actual.length) !== 'number') {
347
+ return false;
348
+ }
349
+ var aa = Array.prototype.slice.call(actual);
350
+ return expected.every(function (exp) {
351
+ return aa.some(function (act) {
352
+ return compare(exp, act);
353
+ });
354
+ });
355
+ }
356
+
357
+ if (expected instanceof Date) {
358
+ if (actual instanceof Date) {
359
+ return expected.getTime() === actual.getTime();
360
+ } else {
361
+ return false;
362
+ }
363
+ }
364
+
365
+ return Object.keys(expected).every(function (key) {
366
+ var eo = expected[key];
367
+ var ao = actual[key];
368
+ if (typeof(eo) === 'object' && eo !== null && ao !== null) {
369
+ return compare(eo, ao);
370
+ }
371
+ if (typeof(eo) === 'function') {
372
+ return eo(ao);
373
+ }
374
+ return ao === eo;
375
+ });
376
+ }
377
+ });
378
+
379
+ }).call(commonjsGlobal);
380
+ }(chaiSubset));
381
+
382
+ var Subset = chaiSubset.exports;
383
+
300
384
  var naturalCompare$2 = {exports: {}};
301
385
 
302
386
  /*
@@ -2738,7 +2822,7 @@ function printBacktickString(str) {
2738
2822
  }
2739
2823
  function ensureDirectoryExists(filePath) {
2740
2824
  try {
2741
- fs.mkdirSync(path.join(path.dirname(filePath)), { recursive: true });
2825
+ fs.mkdirSync(index.join(index.dirname(filePath)), { recursive: true });
2742
2826
  } catch {
2743
2827
  }
2744
2828
  }
@@ -2917,7 +3001,7 @@ class SnapshotState {
2917
3001
  }
2918
3002
  }
2919
3003
 
2920
- const resolveSnapshotPath = (testPath) => path.join(path.join(path.dirname(testPath), "__snapshots__"), `${path.basename(testPath)}.snap`);
3004
+ const resolveSnapshotPath = (testPath) => index.join(index.join(index.dirname(testPath), "__snapshots__"), `${index.basename(testPath)}.snap`);
2921
3005
  class SnapshotClient {
2922
3006
  constructor() {
2923
3007
  this.testFile = "";
@@ -3406,7 +3490,7 @@ function JestExtendPlugin(expects) {
3406
3490
  c.expect.fail(message());
3407
3491
  }
3408
3492
  const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
3409
- utils.addMethod(chai.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
3493
+ utils.addMethod(chai$1.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
3410
3494
  });
3411
3495
  };
3412
3496
  }
@@ -3576,7 +3660,7 @@ const JestChaiExpect = (chai, utils) => {
3576
3660
  });
3577
3661
  def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
3578
3662
  const spy = getSpy(this);
3579
- const lastCall = spy.calls.at(-1);
3663
+ const lastCall = spy.calls[spy.calls.length - 1];
3580
3664
  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
3665
  });
3582
3666
  def(["toThrow", "toThrowError"], function(expected) {
@@ -3603,7 +3687,7 @@ const JestChaiExpect = (chai, utils) => {
3603
3687
  });
3604
3688
  def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
3605
3689
  const spy = getSpy(this);
3606
- const lastResult = spy.returns.at(-1);
3690
+ const lastResult = spy.returns[spy.returns.length - 1];
3607
3691
  const pass = equals(lastResult, value);
3608
3692
  this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
3609
3693
  });
@@ -3787,11 +3871,11 @@ let installed = false;
3787
3871
  async function setupChai() {
3788
3872
  if (installed)
3789
3873
  return;
3790
- chai.use(JestExtend);
3791
- chai.use(JestChaiExpect);
3792
- chai.use(Subset);
3793
- chai.use(SnapshotPlugin);
3794
- chai.use(JestAsymmetricMatchers);
3874
+ chai$1.use(JestExtend);
3875
+ chai$1.use(JestChaiExpect);
3876
+ chai$1.use(Subset);
3877
+ chai$1.use(SnapshotPlugin);
3878
+ chai$1.use(JestAsymmetricMatchers);
3795
3879
  installed = true;
3796
3880
  }
3797
3881
 
@@ -3803,7 +3887,7 @@ async function setupGlobalEnv(config) {
3803
3887
  setupConsoleLogSpy();
3804
3888
  await setupChai();
3805
3889
  if (config.global)
3806
- (await import('./global-473089f7.js')).registerApiGlobally();
3890
+ (await import('./global-5b58e48f.js')).registerApiGlobally();
3807
3891
  }
3808
3892
  function setupConsoleLogSpy() {
3809
3893
  const stdout = new Writable({
@@ -3958,6 +4042,15 @@ async function runTest(test) {
3958
4042
  test.result.state = "fail";
3959
4043
  test.result.error = processError(e);
3960
4044
  }
4045
+ if (test.fails) {
4046
+ if (test.result.state === "pass") {
4047
+ test.result.state = "fail";
4048
+ test.result.error = processError(new Error("Expect test to fail"));
4049
+ } else {
4050
+ test.result.state = "pass";
4051
+ test.result.error = void 0;
4052
+ }
4053
+ }
3961
4054
  getSnapshotClient().clearTest();
3962
4055
  test.result.end = performance.now();
3963
4056
  process.__vitest_worker__.current = void 0;