vitest 0.25.7 → 0.26.0

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.
Files changed (36) hide show
  1. package/LICENSE.md +29 -171
  2. package/dist/browser.d.ts +6 -3
  3. package/dist/browser.js +9 -10
  4. package/dist/{chunk-api-setup.5669c9a4.js → chunk-api-setup.08f3b356.js} +39 -42
  5. package/dist/{chunk-integrations-globals.57158eb5.js → chunk-integrations-globals.cab94a09.js} +5 -5
  6. package/dist/{chunk-magic-string.ffe2b171.js → chunk-magic-string.3a794426.js} +75 -39
  7. package/dist/{chunk-runtime-chain.dd978482.js → chunk-runtime-chain.e655f6cc.js} +5 -6
  8. package/dist/{chunk-runtime-error.616e92ca.js → chunk-runtime-error.dfbbf9be.js} +5 -5
  9. package/dist/{chunk-runtime-mocker.bf08ae09.js → chunk-runtime-mocker.35fabb8b.js} +65 -64
  10. package/dist/{chunk-runtime-rpc.42aebbb9.js → chunk-runtime-rpc.7959fc79.js} +1 -1
  11. package/dist/{chunk-runtime-setup.bd2deed4.js → chunk-runtime-setup.4c1b529e.js} +16 -29
  12. package/dist/{chunk-vite-node-externalize.5a3e0bdc.js → chunk-snapshot-manager.7d978f79.js} +41 -326
  13. package/dist/{chunk-typecheck-constants.ed987901.js → chunk-typecheck-constants.3f865d14.js} +5 -4
  14. package/dist/{chunk-runtime-test-state.0037e2e0.js → chunk-utils-import.ca62c9d7.js} +49 -18
  15. package/dist/{chunk-utils-source-map.29ff1088.js → chunk-utils-source-map.5bbb50cd.js} +6 -4
  16. package/dist/cli.js +13 -14
  17. package/dist/config.cjs +1 -1
  18. package/dist/config.d.ts +6 -3
  19. package/dist/config.js +1 -1
  20. package/dist/entry.js +9 -9
  21. package/dist/environments.d.ts +4 -1
  22. package/dist/{index-fde81ec3.d.ts → index-c3f83a58.d.ts} +20 -20
  23. package/dist/index.d.ts +28 -10
  24. package/dist/index.js +6 -6
  25. package/dist/loader.js +7 -6
  26. package/dist/node.d.ts +19 -19
  27. package/dist/node.js +15 -15
  28. package/dist/suite.js +4 -4
  29. package/dist/{types-c441ef31.d.ts → types-56bcd6c3.d.ts} +71 -328
  30. package/dist/vendor-index.783e7f3e.js +71 -0
  31. package/dist/vendor-index.96e022fd.js +211 -0
  32. package/dist/worker.js +12 -14
  33. package/package.json +15 -15
  34. package/dist/chunk-vite-node-source-map.2b1f492a.js +0 -445
  35. package/dist/chunk-vite-node-utils.0e4a6a88.js +0 -1385
  36. package/dist/vendor-source-map-support.1ce17397.js +0 -707
@@ -0,0 +1,71 @@
1
+ const DEFAULT_TIMEOUT = 6e4;
2
+ function createBirpc(functions, options) {
3
+ const {
4
+ post,
5
+ on,
6
+ eventNames = [],
7
+ serialize = (i) => i,
8
+ deserialize = (i) => i,
9
+ timeout = DEFAULT_TIMEOUT
10
+ } = options;
11
+ const rpcPromiseMap = /* @__PURE__ */ new Map();
12
+ const rpc = new Proxy({}, {
13
+ get(_, method) {
14
+ const sendEvent = (...args) => {
15
+ post(serialize({ m: method, a: args, t: "q" }));
16
+ };
17
+ if (eventNames.includes(method)) {
18
+ sendEvent.asEvent = sendEvent;
19
+ return sendEvent;
20
+ }
21
+ const sendCall = (...args) => {
22
+ return new Promise((resolve, reject) => {
23
+ const id = nanoid();
24
+ rpcPromiseMap.set(id, { resolve, reject });
25
+ post(serialize({ m: method, a: args, i: id, t: "q" }));
26
+ if (timeout >= 0) {
27
+ setTimeout(() => {
28
+ reject(new Error(`[birpc] timeout on calling "${method}"`));
29
+ rpcPromiseMap.delete(id);
30
+ }, timeout);
31
+ }
32
+ });
33
+ };
34
+ sendCall.asEvent = sendEvent;
35
+ return sendCall;
36
+ }
37
+ });
38
+ on(async (data, ...extra) => {
39
+ const msg = deserialize(data);
40
+ if (msg.t === "q") {
41
+ const { m: method, a: args } = msg;
42
+ let result, error;
43
+ try {
44
+ result = await functions[method].apply(rpc, args);
45
+ } catch (e) {
46
+ error = e;
47
+ }
48
+ if (msg.i)
49
+ post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
50
+ } else {
51
+ const { i: ack, r: result, e: error } = msg;
52
+ const promise = rpcPromiseMap.get(ack);
53
+ if (error)
54
+ promise?.reject(error);
55
+ else
56
+ promise?.resolve(result);
57
+ rpcPromiseMap.delete(ack);
58
+ }
59
+ });
60
+ return rpc;
61
+ }
62
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
63
+ function nanoid(size = 21) {
64
+ let id = "";
65
+ let i = size;
66
+ while (i--)
67
+ id += urlAlphabet[Math.random() * 64 | 0];
68
+ return id;
69
+ }
70
+
71
+ export { createBirpc as c };
@@ -0,0 +1,211 @@
1
+ import 'acorn';
2
+ import { builtinModules } from 'module';
3
+ import 'fs';
4
+ import { pathToFileURL } from 'url';
5
+ import 'path';
6
+ import assert from 'assert';
7
+ import { format, inspect } from 'util';
8
+
9
+ const BUILTIN_MODULES = new Set(builtinModules);
10
+
11
+ const isWindows = process.platform === "win32";
12
+ const own$1 = {}.hasOwnProperty;
13
+ const messages = /* @__PURE__ */ new Map();
14
+ const nodeInternalPrefix = "__node_internal_";
15
+ let userStackTraceLimit;
16
+ createError(
17
+ "ERR_INVALID_MODULE_SPECIFIER",
18
+ (request, reason, base = void 0) => {
19
+ return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
20
+ },
21
+ TypeError
22
+ );
23
+ createError(
24
+ "ERR_INVALID_PACKAGE_CONFIG",
25
+ (path, base, message) => {
26
+ return `Invalid package config ${path}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
27
+ },
28
+ Error
29
+ );
30
+ createError(
31
+ "ERR_INVALID_PACKAGE_TARGET",
32
+ (pkgPath, key, target, isImport = false, base = void 0) => {
33
+ const relError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
34
+ if (key === ".") {
35
+ assert(isImport === false);
36
+ return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ""}${relError ? '; targets must start with "./"' : ""}`;
37
+ }
38
+ return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
39
+ target
40
+ )} defined for '${key}' in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ""}${relError ? '; targets must start with "./"' : ""}`;
41
+ },
42
+ Error
43
+ );
44
+ createError(
45
+ "ERR_MODULE_NOT_FOUND",
46
+ (path, base, type = "package") => {
47
+ return `Cannot find ${type} '${path}' imported from ${base}`;
48
+ },
49
+ Error
50
+ );
51
+ createError(
52
+ "ERR_PACKAGE_IMPORT_NOT_DEFINED",
53
+ (specifier, packagePath, base) => {
54
+ return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
55
+ },
56
+ TypeError
57
+ );
58
+ createError(
59
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
60
+ (pkgPath, subpath, base = void 0) => {
61
+ if (subpath === ".") {
62
+ return `No "exports" main defined in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`;
63
+ }
64
+ return `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`;
65
+ },
66
+ Error
67
+ );
68
+ createError(
69
+ "ERR_UNSUPPORTED_DIR_IMPORT",
70
+ "Directory import '%s' is not supported resolving ES modules imported from %s",
71
+ Error
72
+ );
73
+ createError(
74
+ "ERR_UNKNOWN_FILE_EXTENSION",
75
+ 'Unknown file extension "%s" for %s',
76
+ TypeError
77
+ );
78
+ createError(
79
+ "ERR_INVALID_ARG_VALUE",
80
+ (name, value, reason = "is invalid") => {
81
+ let inspected = inspect(value);
82
+ if (inspected.length > 128) {
83
+ inspected = `${inspected.slice(0, 128)}...`;
84
+ }
85
+ const type = name.includes(".") ? "property" : "argument";
86
+ return `The ${type} '${name}' ${reason}. Received ${inspected}`;
87
+ },
88
+ TypeError
89
+ );
90
+ createError(
91
+ "ERR_UNSUPPORTED_ESM_URL_SCHEME",
92
+ (url) => {
93
+ let message = "Only file and data URLs are supported by the default ESM loader";
94
+ if (isWindows && url.protocol.length === 2) {
95
+ message += ". On Windows, absolute paths must be valid file:// URLs";
96
+ }
97
+ message += `. Received protocol '${url.protocol}'`;
98
+ return message;
99
+ },
100
+ Error
101
+ );
102
+ function createError(sym, value, def) {
103
+ messages.set(sym, value);
104
+ return makeNodeErrorWithCode(def, sym);
105
+ }
106
+ function makeNodeErrorWithCode(Base, key) {
107
+ return NodeError;
108
+ function NodeError(...args) {
109
+ const limit = Error.stackTraceLimit;
110
+ if (isErrorStackTraceLimitWritable()) {
111
+ Error.stackTraceLimit = 0;
112
+ }
113
+ const error = new Base();
114
+ if (isErrorStackTraceLimitWritable()) {
115
+ Error.stackTraceLimit = limit;
116
+ }
117
+ const message = getMessage(key, args, error);
118
+ Object.defineProperty(error, "message", {
119
+ value: message,
120
+ enumerable: false,
121
+ writable: true,
122
+ configurable: true
123
+ });
124
+ Object.defineProperty(error, "toString", {
125
+ value() {
126
+ return `${this.name} [${key}]: ${this.message}`;
127
+ },
128
+ enumerable: false,
129
+ writable: true,
130
+ configurable: true
131
+ });
132
+ addCodeToName(error, Base.name, key);
133
+ error.code = key;
134
+ return error;
135
+ }
136
+ }
137
+ const addCodeToName = hideStackFrames(
138
+ function(error, name, code) {
139
+ error = captureLargerStackTrace(error);
140
+ error.name = `${name} [${code}]`;
141
+ error.stack;
142
+ if (name === "SystemError") {
143
+ Object.defineProperty(error, "name", {
144
+ value: name,
145
+ enumerable: false,
146
+ writable: true,
147
+ configurable: true
148
+ });
149
+ } else {
150
+ delete error.name;
151
+ }
152
+ }
153
+ );
154
+ function isErrorStackTraceLimitWritable() {
155
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
156
+ if (desc === void 0) {
157
+ return Object.isExtensible(Error);
158
+ }
159
+ return own$1.call(desc, "writable") ? desc.writable : desc.set !== void 0;
160
+ }
161
+ function hideStackFrames(fn) {
162
+ const hidden = nodeInternalPrefix + fn.name;
163
+ Object.defineProperty(fn, "name", { value: hidden });
164
+ return fn;
165
+ }
166
+ const captureLargerStackTrace = hideStackFrames(
167
+ function(error) {
168
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
169
+ if (stackTraceLimitIsWritable) {
170
+ userStackTraceLimit = Error.stackTraceLimit;
171
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY;
172
+ }
173
+ Error.captureStackTrace(error);
174
+ if (stackTraceLimitIsWritable) {
175
+ Error.stackTraceLimit = userStackTraceLimit;
176
+ }
177
+ return error;
178
+ }
179
+ );
180
+ function getMessage(key, args, self) {
181
+ const message = messages.get(key);
182
+ if (typeof message === "function") {
183
+ assert(
184
+ message.length <= args.length,
185
+ `Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${message.length}).`
186
+ );
187
+ return Reflect.apply(message, self, args);
188
+ }
189
+ const expectedLength = (message.match(/%[dfijoOs]/g) || []).length;
190
+ assert(
191
+ expectedLength === args.length,
192
+ `Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${expectedLength}).`
193
+ );
194
+ if (args.length === 0) {
195
+ return message;
196
+ }
197
+ args.unshift(message);
198
+ return Reflect.apply(format, null, args);
199
+ }
200
+ Object.freeze(["node", "import"]);
201
+ function isNodeBuiltin(id = "") {
202
+ id = id.replace(/^node:/, "").split("/")[0];
203
+ return BUILTIN_MODULES.has(id);
204
+ }
205
+ pathToFileURL(process.cwd());
206
+ const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
207
+ function hasCJSSyntax(code) {
208
+ return CJS_RE.test(code);
209
+ }
210
+
211
+ export { hasCJSSyntax as h, isNodeBuiltin as i };
package/dist/worker.js CHANGED
@@ -1,25 +1,22 @@
1
1
  import { b as resolve, e as distDir } from './chunk-utils-env.03f840f2.js';
2
- import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-source-map.2b1f492a.js';
2
+ import { c as createBirpc } from './vendor-index.783e7f3e.js';
3
3
  import { workerId } from 'tinypool';
4
- import { g as getWorkerState } from './chunk-typecheck-constants.ed987901.js';
5
- import { e as executeInViteNode } from './chunk-runtime-mocker.bf08ae09.js';
6
- import { r as rpc } from './chunk-runtime-rpc.42aebbb9.js';
7
- import { p as processError } from './chunk-runtime-error.616e92ca.js';
4
+ import { ModuleCacheMap } from 'vite-node/client';
5
+ import { g as getWorkerState } from './chunk-typecheck-constants.3f865d14.js';
6
+ import { e as executeInViteNode } from './chunk-runtime-mocker.35fabb8b.js';
7
+ import { r as rpc } from './chunk-runtime-rpc.7959fc79.js';
8
+ import { p as processError } from './chunk-runtime-error.dfbbf9be.js';
8
9
  import 'tty';
9
10
  import 'url';
10
11
  import 'path';
11
- import 'module';
12
- import 'vm';
13
- import './chunk-vite-node-utils.0e4a6a88.js';
12
+ import 'local-pkg';
13
+ import 'vite';
14
14
  import 'fs';
15
+ import './vendor-index.96e022fd.js';
15
16
  import 'acorn';
17
+ import 'module';
16
18
  import 'assert';
17
19
  import 'util';
18
- import 'debug';
19
- import './vendor-source-map-support.1ce17397.js';
20
- import 'source-map';
21
- import 'local-pkg';
22
- import 'vite';
23
20
  import './chunk-utils-timers.793fd179.js';
24
21
  import 'chai';
25
22
 
@@ -53,7 +50,7 @@ async function startViteNode(ctx) {
53
50
  },
54
51
  moduleCache,
55
52
  mockMap,
56
- interopDefault: config.deps.interopDefault ?? true,
53
+ interopDefault: config.deps.interopDefault,
57
54
  root: config.root,
58
55
  base: config.base
59
56
  }))[0];
@@ -66,6 +63,7 @@ function init(ctx) {
66
63
  const { config, port, workerId: workerId$1 } = ctx;
67
64
  process.env.VITEST_WORKER_ID = String(workerId$1);
68
65
  process.env.VITEST_POOL_ID = String(workerId);
66
+ globalThis.__vitest_environment__ = config.environment;
69
67
  globalThis.__vitest_worker__ = {
70
68
  ctx,
71
69
  moduleCache,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.25.7",
4
+ "version": "0.26.0",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -100,12 +100,12 @@
100
100
  }
101
101
  },
102
102
  "dependencies": {
103
- "@types/chai": "^4.3.3",
103
+ "@types/chai": "^4.3.4",
104
104
  "@types/chai-subset": "^1.3.3",
105
105
  "@types/node": "*",
106
- "acorn": "^8.8.0",
106
+ "acorn": "^8.8.1",
107
107
  "acorn-walk": "^8.2.0",
108
- "chai": "^4.3.6",
108
+ "chai": "^4.3.7",
109
109
  "debug": "^4.3.4",
110
110
  "local-pkg": "^0.4.2",
111
111
  "source-map": "^0.6.1",
@@ -113,19 +113,19 @@
113
113
  "tinybench": "^2.3.1",
114
114
  "tinypool": "^0.3.0",
115
115
  "tinyspy": "^1.0.2",
116
- "vite": "^3.0.0 || ^4.0.0"
116
+ "vite": "^3.0.0 || ^4.0.0",
117
+ "vite-node": "0.26.0"
117
118
  },
118
119
  "devDependencies": {
119
120
  "@antfu/install-pkg": "^0.1.1",
120
- "@edge-runtime/vm": "2.0.1",
121
+ "@edge-runtime/vm": "2.0.2",
121
122
  "@sinonjs/fake-timers": "^10.0.0",
122
123
  "@types/diff": "^5.0.2",
123
- "@types/jsdom": "^20.0.0",
124
+ "@types/jsdom": "^20.0.1",
124
125
  "@types/micromatch": "^4.0.2",
125
126
  "@types/natural-compare": "^1.4.1",
126
- "@types/prompts": "^2.4.1",
127
+ "@types/prompts": "^2.4.2",
127
128
  "@types/sinonjs__fake-timers": "^8.1.2",
128
- "@vitest/ui": "0.25.7",
129
129
  "birpc": "^0.2.3",
130
130
  "cac": "^6.7.14",
131
131
  "chai-subset": "^1.6.0",
@@ -138,10 +138,10 @@
138
138
  "find-up": "^6.3.0",
139
139
  "flatted": "^3.2.7",
140
140
  "get-tsconfig": "^4.2.0",
141
- "happy-dom": "^7.6.6",
142
- "jsdom": "^20.0.2",
141
+ "happy-dom": "^7.8.1",
142
+ "jsdom": "^20.0.3",
143
143
  "log-update": "^5.0.1",
144
- "magic-string": "^0.26.7",
144
+ "magic-string": "^0.27.0",
145
145
  "micromatch": "^4.0.5",
146
146
  "mlly": "^1.0.0",
147
147
  "natural-compare": "^1.4.0",
@@ -153,9 +153,9 @@
153
153
  "prompts": "^2.4.2",
154
154
  "rollup": "^2.79.1",
155
155
  "strip-ansi": "^7.0.1",
156
- "typescript": "^4.8.4",
157
- "vite-node": "0.25.7",
158
- "ws": "^8.11.0"
156
+ "typescript": "^4.9.4",
157
+ "ws": "^8.11.0",
158
+ "@vitest/ui": "0.26.0"
159
159
  },
160
160
  "scripts": {
161
161
  "build": "rimraf dist && rollup -c",