vitest 0.0.112 → 0.0.116

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/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-bf29f0e6.js';
2
+ import 'url';
3
3
  import 'tty';
4
+ import 'local-pkg';
4
5
  import 'path';
@@ -1,6 +1,6 @@
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-bf29f0e6.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
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defProps = Object.defineProperties;
@@ -134,7 +134,7 @@ function createSuiteCollector(name, factory = () => {
134
134
  const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
135
135
  const computeMode = this.concurrent ? "concurrent" : void 0;
136
136
  const test3 = {
137
- id: nanoid(),
137
+ id: "",
138
138
  type: "test",
139
139
  name: name2,
140
140
  mode: mode2,
@@ -160,7 +160,7 @@ function createSuiteCollector(name, factory = () => {
160
160
  }
161
161
  function initSuite() {
162
162
  suite2 = {
163
- id: nanoid(),
163
+ id: "",
164
164
  type: "suite",
165
165
  computeMode: "serial",
166
166
  name,
@@ -199,7 +199,6 @@ function createSuite() {
199
199
  });
200
200
  }
201
201
 
202
- const isObject = (val) => toString.call(val) === "[object Object]";
203
202
  function equals(a, b, customTesters, strictCheck) {
204
203
  customTesters = customTesters || [];
205
204
  return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
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-bf29f0e6.js';
2
+ import { c as createBirpc } from './index-e909c175.js';
3
+ import { c as distDir } from './constants-080f26e8.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", "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.112",
3
+ "version": "0.0.116",
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",
@@ -77,7 +79,6 @@
77
79
  "micromatch": "^4.0.4",
78
80
  "mlly": "^0.3.16",
79
81
  "mockdate": "^3.0.5",
80
- "nanoid": "^3.1.30",
81
82
  "natural-compare": "^1.4.0",
82
83
  "pathe": "^0.2.0",
83
84
  "picocolors": "^1.0.0",
@@ -87,7 +88,8 @@
87
88
  "rollup": "^2.62.0",
88
89
  "source-map-js": "^1.0.1",
89
90
  "strip-ansi": "^7.0.1",
90
- "typescript": "^4.5.4"
91
+ "typescript": "^4.5.4",
92
+ "ws": "^8.4.0"
91
93
  },
92
94
  "peerDependencies": {
93
95
  "c8": "*",
@@ -111,8 +113,7 @@
111
113
  },
112
114
  "scripts": {
113
115
  "build": "rimraf dist && rollup -c",
114
- "dev": "rollup -c --watch src",
115
- "typecheck": "tsc --noEmit"
116
+ "dev": "rollup -c --watch src"
116
117
  },
117
118
  "readme": "# vitest\n\n[![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)\n\nA blazing fast unit test framework powered by Vite.\n\n> **This project is currently in closed beta exclusively for Sponsors.**<br>\n> Become a Sponsor of [@patak-dev](https://github.com/sponsors/patak-dev) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.\n> Learn more at [vitest.dev](https://vitest.dev)\n"
118
119
  }
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,81 +0,0 @@
1
- import { A as API_PATH } from './constants-2b0310b7.js';
2
- import 'url';
3
- import './utils-cb6b1266.js';
4
- import 'tty';
5
- import 'local-pkg';
6
- import 'path';
7
-
8
- /*! (c) 2020 Andrea Giammarchi */
9
-
10
- const {parse: $parse, stringify: $stringify} = JSON;
11
-
12
- const Primitive = String; // it could be Number
13
- const primitive = 'string'; // it could be 'number'
14
- const object = 'object';
15
-
16
- const noop = (_, value) => value;
17
-
18
- const set = (known, input, value) => {
19
- const index = Primitive(input.push(value) - 1);
20
- known.set(value, index);
21
- return index;
22
- };
23
-
24
- const stringify = (value, replacer, space) => {
25
- const $ = replacer && typeof replacer === object ?
26
- (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
27
- (replacer || noop);
28
- const known = new Map;
29
- const input = [];
30
- const output = [];
31
- let i = +set(known, input, $.call({'': value}, '', value));
32
- let firstRun = !i;
33
- while (i < input.length) {
34
- firstRun = true;
35
- output[i] = $stringify(input[i++], replace, space);
36
- }
37
- return '[' + output.join(',') + ']';
38
- function replace(key, value) {
39
- if (firstRun) {
40
- firstRun = !firstRun;
41
- return value;
42
- }
43
- const after = $.call(this, key, value);
44
- switch (typeof after) {
45
- case object:
46
- if (after === null) return after;
47
- case primitive:
48
- return known.get(after) || set(known, input, after);
49
- }
50
- return after;
51
- }
52
- };
53
-
54
- function sendFlatted(res, data) {
55
- res.setHeader("Content-Type", "application/json");
56
- res.write(stringify(data));
57
- res.statusCode = 200;
58
- res.end();
59
- }
60
- function middlewareAPI(ctx) {
61
- return (req, res, next) => {
62
- var _a;
63
- if (!((_a = req.url) == null ? void 0 : _a.startsWith(API_PATH)))
64
- return next();
65
- const url = req.url.slice(API_PATH.length);
66
- if (url === "/") {
67
- return sendFlatted(res, {
68
- files: ctx.state.filesMap
69
- });
70
- }
71
- if (url === "/files") {
72
- return sendFlatted(res, {
73
- files: Object.keys(ctx.state.filesMap)
74
- });
75
- }
76
- res.statusCode = 404;
77
- res.end();
78
- };
79
- }
80
-
81
- export { middlewareAPI as default, sendFlatted };
@@ -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 };