vitest 0.0.111 → 0.0.115

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.
@@ -1,6 +1,6 @@
1
- import { A as API_PATH } from './constants-2b0310b7.js';
1
+ import { A as API_PATH } from './constants-5968a78c.js';
2
2
  import 'url';
3
- import './utils-cb6b1266.js';
3
+ import './index-7c024e16.js';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
package/dist/node.d.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  import { ViteDevServer, UserConfig as UserConfig$1 } from 'vite';
2
+ import { RawSourceMap } from 'source-map-js';
3
+ import { Arrayable as Arrayable$1 } from 'vitest';
2
4
  import { OptionsReceived } from 'pretty-format';
3
5
 
4
6
  declare abstract class BaseReporter implements Reporter {
5
- ctx: Vitest;
6
7
  start: number;
7
8
  end: number;
8
9
  watchFilters?: string[];
9
10
  isTTY: boolean;
10
- constructor(ctx: Vitest);
11
+ ctx: Vitest;
12
+ onInit(ctx: Vitest): void;
11
13
  relative(path: string): string;
12
14
  onFinished(files?: File[]): Promise<void>;
13
15
  onTaskUpdate(pack: TaskResultPack): void;
@@ -17,12 +19,14 @@ declare abstract class BaseReporter implements Reporter {
17
19
  onUserConsoleLog(log: UserConsoleLog): void;
18
20
  onServerRestart(): void;
19
21
  reportSummary(files: File[]): Promise<void>;
22
+ private printTaskErrors;
20
23
  }
21
24
 
22
25
  interface ListRendererOptions {
23
26
  renderSucceed?: boolean;
27
+ outputStream: NodeJS.WritableStream;
24
28
  }
25
- declare const createListRenderer: (_tasks: Task[], options?: ListRendererOptions) => {
29
+ declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
26
30
  start(): any;
27
31
  update(_tasks: Task[]): any;
28
32
  stop(): Promise<any>;
@@ -51,7 +55,7 @@ declare class DotReporter extends BaseReporter {
51
55
  }
52
56
 
53
57
  declare class VerboseReporter extends DefaultReporter {
54
- constructor(ctx: Vitest);
58
+ constructor();
55
59
  }
56
60
 
57
61
  declare const ReportersMap: {
@@ -61,6 +65,56 @@ declare const ReportersMap: {
61
65
  };
62
66
  declare type BuiltinReporters = keyof typeof ReportersMap;
63
67
 
68
+ declare type Reporter$1 = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
69
+ interface C8Options {
70
+ /**
71
+ * Enable coverage, pass `--coverage` to enable
72
+ *
73
+ * @default false
74
+ */
75
+ enabled?: boolean;
76
+ /**
77
+ * Directory to write coverage report to
78
+ */
79
+ reportsDirectory?: string;
80
+ /**
81
+ * Clean coverage before running tests
82
+ *
83
+ * @default true
84
+ */
85
+ clean?: boolean;
86
+ /**
87
+ * Clean coverage report on watch rerun
88
+ *
89
+ * @default false
90
+ */
91
+ cleanOnRerun?: boolean;
92
+ /**
93
+ * Allow files from outside of your cwd.
94
+ *
95
+ * @default false
96
+ */
97
+ allowExternal?: any;
98
+ /**
99
+ * Reporters
100
+ *
101
+ * @default 'text'
102
+ */
103
+ reporter?: Arrayable$1<Reporter$1>;
104
+ /**
105
+ * Exclude coverage under /node_modules/
106
+ *
107
+ * @default true
108
+ */
109
+ excludeNodeModules?: boolean;
110
+ exclude?: string[];
111
+ include?: string[];
112
+ skipFull?: boolean;
113
+ }
114
+ interface ResolvedC8Options extends Required<C8Options> {
115
+ tempDirectory: string;
116
+ }
117
+
64
118
  declare type Awaitable<T> = T | PromiseLike<T>;
65
119
  declare type Arrayable<T> = T | Array<T>;
66
120
  declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
@@ -105,6 +159,7 @@ interface Test extends TaskBase {
105
159
  declare type Task = Test | Suite | File;
106
160
 
107
161
  interface Reporter {
162
+ onInit(ctx: Vitest): void;
108
163
  onStart?: (files?: string[]) => Awaitable<void>;
109
164
  onFinished?: (files?: File[]) => Awaitable<void>;
110
165
  onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
@@ -265,6 +320,16 @@ interface InlineConfig {
265
320
  * @default ['**\/node_modules\/**', '**\/dist/**']
266
321
  */
267
322
  watchIgnore?: (string | RegExp)[];
323
+ /**
324
+ * Isolate environment for each test file
325
+ *
326
+ * @default true
327
+ */
328
+ isolate?: boolean;
329
+ /**
330
+ * Coverage options
331
+ */
332
+ coverage?: C8Options;
268
333
  /**
269
334
  * Open Vitest UI
270
335
  * @internal WIP
@@ -319,11 +384,12 @@ interface UserConfig extends InlineConfig {
319
384
  */
320
385
  passWithNoTests?: boolean;
321
386
  }
322
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'> {
387
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage'> {
323
388
  config?: string;
324
389
  filters?: string[];
325
390
  depsInline: (string | RegExp)[];
326
391
  depsExternal: (string | RegExp)[];
392
+ coverage: ResolvedC8Options;
327
393
  snapshotOptions: SnapshotStateOptions;
328
394
  }
329
395
 
@@ -360,14 +426,21 @@ declare class Vitest {
360
426
  reporters: Reporter[];
361
427
  console: Console;
362
428
  pool: WorkerPool | undefined;
429
+ outputStream: NodeJS.WriteStream & {
430
+ fd: 1;
431
+ };
432
+ errorStream: NodeJS.WriteStream & {
433
+ fd: 2;
434
+ };
363
435
  invalidates: Set<string>;
364
436
  changedTests: Set<string>;
437
+ visitedFilesMap: Map<string, RawSourceMap>;
365
438
  runningPromise?: Promise<void>;
366
439
  isFirstRun: boolean;
367
440
  restartsCount: number;
368
441
  private _onRestartListeners;
369
442
  constructor();
370
- setServer(options: UserConfig, server: ViteDevServer): void;
443
+ setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
371
444
  start(filters?: string[]): Promise<void>;
372
445
  runFiles(files: string[]): Promise<void>;
373
446
  log(...args: any[]): void;
package/dist/node.js CHANGED
@@ -1,5 +1,6 @@
1
- export { c as createVitest } from './index-8ab26d25.js';
2
- import './utils-cb6b1266.js';
1
+ export { c as createVitest } from './index-b4f86684.js';
2
+ import './index-7c024e16.js';
3
+ import 'url';
3
4
  import 'tty';
4
5
  import 'local-pkg';
5
6
  import 'path';
@@ -10,12 +11,14 @@ import 'os';
10
11
  import 'util';
11
12
  import 'stream';
12
13
  import 'events';
13
- import './constants-2b0310b7.js';
14
- import 'url';
14
+ import './constants-5968a78c.js';
15
+ import './magic-string.es-94000aea.js';
15
16
  import 'perf_hooks';
16
- import './diff-66d6bb83.js';
17
- import './index-61c8686f.js';
17
+ import './diff-67678e1f.js';
18
+ import './index-648e7ab2.js';
18
19
  import './_commonjsHelpers-c9e3b764.js';
19
20
  import 'assert';
21
+ import 'module';
20
22
  import 'worker_threads';
21
23
  import 'tinypool';
24
+ import './index-e909c175.js';
@@ -0,0 +1,5 @@
1
+ const rpc = () => {
2
+ return process.__vitest_worker__.rpc;
3
+ };
4
+
5
+ export { rpc as r };
package/dist/utils.js CHANGED
@@ -1,4 +1,5 @@
1
- export { e as ensurePackageInstalled, g as getFullName, o as getNames, f as getSuites, v as getTasks, a as getTests, j as hasFailed, u as hasTests, p as interpretOnlyMode, m as mergeSlashes, n as noop, k as notNullish, q as partitionSuiteChildren, h as resolvePath, s as slash, t as toArray } from './utils-cb6b1266.js';
2
- import 'local-pkg';
1
+ export { l as deepMerge, e as ensurePackageInstalled, g as getFullName, u as getNames, f as getSuites, z as getTasks, j as getTests, h as hasFailed, x as hasTests, v as interpretOnlyMode, i as isObject, y as isWindows, p as mergeSlashes, n as noop, o as notNullish, w as partitionSuiteChildren, k as resolvePath, s as slash, t as toArray, m as toFilePath } from './index-7c024e16.js';
2
+ import 'url';
3
3
  import 'tty';
4
+ import 'local-pkg';
4
5
  import 'path';
@@ -1,6 +1,17 @@
1
- import { n as nanoid, a as spyOn, f as fn, s as spies } from './jest-mock-a57b745c.js';
2
- import { n as noop } from './utils-cb6b1266.js';
1
+ import { n as noop, i as isObject } from './index-7c024e16.js';
3
2
  import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-c9e3b764.js';
3
+ import { a as spyOn, f as fn, s as spies } from './jest-mock-4a754991.js';
4
+
5
+ let urlAlphabet =
6
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
7
+ let nanoid = (size = 21) => {
8
+ let id = '';
9
+ let i = size;
10
+ while (i--) {
11
+ id += urlAlphabet[(Math.random() * 64) | 0];
12
+ }
13
+ return id
14
+ };
4
15
 
5
16
  var __defProp = Object.defineProperty;
6
17
  var __defProps = Object.defineProperties;
@@ -199,7 +210,6 @@ function createSuite() {
199
210
  });
200
211
  }
201
212
 
202
- const isObject = (val) => toString.call(val) === "[object Object]";
203
213
  function equals(a, b, customTesters, strictCheck) {
204
214
  customTesters = customTesters || [];
205
215
  return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
@@ -1015,4 +1025,4 @@ class VitestUtils {
1015
1025
  const vitest = new VitestUtils();
1016
1026
  const vi = vitest;
1017
1027
 
1018
- export { JestChaiExpect as J, getDefaultHookTimeout as a, getState as b, suite as c, describe as d, vi as e, equals as f, getCurrentSuite as g, iterableEquality as h, it as i, subsetEquality as j, isA as k, clearContext as l, defaultSuite as m, setHooks as n, getHooks as o, context as p, getFn as q, setState as s, test as t, vitest as v, withTimeout as w };
1028
+ export { JestChaiExpect as J, getDefaultHookTimeout as a, getState as b, suite as c, describe as d, vi as e, equals as f, getCurrentSuite as g, iterableEquality as h, it as i, subsetEquality as j, isA as k, clearContext as l, defaultSuite as m, nanoid as n, setHooks as o, getHooks as p, context as q, getFn as r, setState as s, test as t, vitest as v, withTimeout as w };
package/dist/worker.js CHANGED
@@ -1,14 +1,15 @@
1
- import { h as resolve, d as dirname$2, b as basename$2, m as mergeSlashes, s as slash } from './utils-cb6b1266.js';
2
- import { a as spyOn, s as spies, n as nanoid } from './jest-mock-a57b745c.js';
3
- import { c as distDir } from './constants-2b0310b7.js';
1
+ import { k as resolve, d as dirname$2, b as basename$2, p as mergeSlashes, s as slash, m as toFilePath } from './index-7c024e16.js';
2
+ import { c as createBirpc } from './index-e909c175.js';
3
+ import { c as distDir } from './constants-5968a78c.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
7
  import path from 'path';
8
- import fs, { promises, realpathSync, statSync, Stats, readdirSync, existsSync } from 'fs';
8
+ import fs, { promises, realpathSync, statSync, Stats, existsSync, readdirSync } from 'fs';
9
9
  import assert from 'assert';
10
10
  import { format as format$2, inspect } from 'util';
11
- import { s as send } from './rpc-7de86f29.js';
11
+ import { a as spyOn, s as spies } from './jest-mock-4a754991.js';
12
+ import { r as rpc } from './rpc-8c7cc374.js';
12
13
  import 'tty';
13
14
  import 'local-pkg';
14
15
  import 'chai';
@@ -7663,7 +7664,7 @@ function find(dir) {
7663
7664
 
7664
7665
  // Manually “tree shaken” from:
7665
7666
 
7666
- const isWindows$2 = process.platform === 'win32';
7667
+ const isWindows = process.platform === 'win32';
7667
7668
 
7668
7669
  const own$1 = {}.hasOwnProperty;
7669
7670
 
@@ -7837,7 +7838,7 @@ codes.ERR_UNSUPPORTED_ESM_URL_SCHEME = createError(
7837
7838
  let message =
7838
7839
  'Only file and data URLs are supported by the default ESM loader';
7839
7840
 
7840
- if (isWindows$2 && url.protocol.length === 2) {
7841
+ if (isWindows && url.protocol.length === 2) {
7841
7842
  message += '. On Windows, absolute paths must be valid file:// URLs';
7842
7843
  }
7843
7844
 
@@ -9218,6 +9219,8 @@ var __spreadValues = (a, b) => {
9218
9219
  function resolveMockPath(mockPath, root, nmName) {
9219
9220
  if (nmName) {
9220
9221
  const mockFolder = resolve(root, "__mocks__");
9222
+ if (!existsSync(mockFolder))
9223
+ return null;
9221
9224
  const files = readdirSync(mockFolder);
9222
9225
  for (const file of files) {
9223
9226
  const [basename2] = file.split(".");
@@ -9325,7 +9328,6 @@ const depsExternal = [
9325
9328
  /\.cjs.js$/,
9326
9329
  /\.mjs$/
9327
9330
  ];
9328
- const isWindows = process.platform === "win32";
9329
9331
  const stubRequests = {
9330
9332
  "/@vite/client": {
9331
9333
  injectQuery: (id) => id,
@@ -9530,12 +9532,6 @@ async function shouldExternalize(id, config) {
9530
9532
  return false;
9531
9533
  return id.includes("/node_modules/") && await isValidNodeImport(id);
9532
9534
  }
9533
- function toFilePath(id, root) {
9534
- let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$2(root)) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
9535
- if (absolute.startsWith("//"))
9536
- absolute = absolute.slice(1);
9537
- return isWindows && absolute.startsWith("/") ? fileURLToPath$2(pathToFileURL(absolute.slice(1)).href) : absolute;
9538
- }
9539
9535
  function matchExternalizePattern(id, patterns) {
9540
9536
  for (const ex of patterns) {
9541
9537
  if (typeof ex === "string") {
@@ -9565,10 +9561,10 @@ async function startViteNode(ctx) {
9565
9561
  return _viteNode;
9566
9562
  const processExit = process.exit;
9567
9563
  process.on("beforeExit", (code) => {
9568
- send("processExit", code);
9564
+ rpc().onWorkerExit(code);
9569
9565
  });
9570
9566
  process.exit = (code = process.exitCode || 0) => {
9571
- send("processExit", code);
9567
+ rpc().onWorkerExit(code);
9572
9568
  return processExit(code);
9573
9569
  };
9574
9570
  const { config } = ctx;
@@ -9578,7 +9574,7 @@ async function startViteNode(ctx) {
9578
9574
  resolve(distDir, "entry.js")
9579
9575
  ],
9580
9576
  fetch(id) {
9581
- return process.__vitest_worker__.rpc("fetch", id);
9577
+ return rpc().fetch(id);
9582
9578
  },
9583
9579
  inline: config.depsInline,
9584
9580
  external: config.depsExternal,
@@ -9594,31 +9590,21 @@ function init(ctx) {
9594
9590
  throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${process.__vitest_worker__.ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
9595
9591
  process.stdout.write("\0");
9596
9592
  const { config, port } = ctx;
9597
- const rpcPromiseMap = /* @__PURE__ */ new Map();
9598
9593
  process.__vitest_worker__ = {
9599
9594
  ctx,
9600
9595
  moduleCache,
9601
9596
  config,
9602
- rpc: (method, ...args) => {
9603
- return new Promise((resolve2, reject) => {
9604
- const id = nanoid();
9605
- rpcPromiseMap.set(id, { resolve: resolve2, reject });
9606
- port.postMessage({ method, args, id });
9607
- });
9608
- },
9609
- send(method, ...args) {
9610
- port.postMessage({ method, args });
9611
- }
9597
+ rpc: createBirpc({
9598
+ functions: {},
9599
+ eventNames: ["onUserLog", "onCollected", "onTaskUpdate", "onWorkerExit"],
9600
+ post(v) {
9601
+ port.postMessage(v);
9602
+ },
9603
+ on(fn) {
9604
+ port.addListener("message", fn);
9605
+ }
9606
+ })
9612
9607
  };
9613
- port.addListener("message", async (data) => {
9614
- const api = rpcPromiseMap.get(data.id);
9615
- if (api) {
9616
- if (data.error)
9617
- api.reject(data.error);
9618
- else
9619
- api.resolve(data.result);
9620
- }
9621
- });
9622
9608
  if (ctx.invalidates)
9623
9609
  ctx.invalidates.forEach((i) => moduleCache.delete(i));
9624
9610
  ctx.files.forEach((i) => moduleCache.delete(i));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.111",
3
+ "version": "0.0.115",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -62,11 +62,13 @@
62
62
  "@types/natural-compare": "^1.4.1",
63
63
  "@types/node": "^17.0.4",
64
64
  "@types/prompts": "^2.4.0",
65
+ "birpc": "^0.0.2",
65
66
  "c8": "^7.10.0",
66
67
  "cac": "^6.7.12",
67
68
  "chai-subset": "^1.6.0",
68
69
  "cli-truncate": "^3.1.0",
69
70
  "diff": "^5.0.0",
71
+ "execa": "^6.0.0",
70
72
  "fast-glob": "^3.2.7",
71
73
  "find-up": "^6.2.0",
72
74
  "flatted": "^3.2.4",
package/vitest.mjs CHANGED
@@ -1,21 +1,2 @@
1
1
  #!/usr/bin/env node
2
-
3
- import { fileURLToPath } from 'url'
4
- import { ensurePackageInstalled, resolvePath } from './dist/utils.js'
5
-
6
- const argv = process.argv.slice(2)
7
-
8
- if (!await ensurePackageInstalled('vite'))
9
- process.exit(1)
10
-
11
- if (argv.includes('--coverage')) {
12
- if (!await ensurePackageInstalled('c8'))
13
- process.exit(1)
14
- const filename = fileURLToPath(import.meta.url)
15
- const entry = resolvePath(filename, '../dist/cli.js')
16
- process.argv.splice(2, 0, process.argv[0], entry)
17
- await import('c8/bin/c8.js')
18
- }
19
- else {
20
- await import('./dist/cli.js')
21
- }
2
+ import('./dist/cli.js')
@@ -1,10 +0,0 @@
1
- const rpc = async (method, ...args) => {
2
- var _a;
3
- return (_a = process.__vitest_worker__) == null ? void 0 : _a.rpc(method, ...args);
4
- };
5
- const send = async (method, ...args) => {
6
- var _a;
7
- return (_a = process.__vitest_worker__) == null ? void 0 : _a.send(method, ...args);
8
- };
9
-
10
- export { rpc as r, send as s };