vitest 0.11.0 → 0.12.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.
@@ -1,5 +1,5 @@
1
1
  import { g as globalApis } from './chunk-constants.0567483c.js';
2
- import { i as index } from './vendor-entry.1b0b46f1.js';
2
+ import { i as index } from './vendor-entry.b20b007c.js';
3
3
  import 'url';
4
4
  import './chunk-utils-global.a5a8641f.js';
5
5
  import 'tty';
@@ -8,7 +8,7 @@ import 'path';
8
8
  import 'fs';
9
9
  import 'console';
10
10
  import 'stream';
11
- import './chunk-runtime-chain.8a313ffb.js';
11
+ import './chunk-runtime-chain.37b69607.js';
12
12
  import 'chai';
13
13
  import './vendor-_commonjsHelpers.addc3445.js';
14
14
  import './chunk-runtime-rpc.63398738.js';
@@ -1058,15 +1058,15 @@ if (!Object.prototype.hasOwnProperty.call(global, MATCHERS_OBJECT)) {
1058
1058
  expectedAssertionsNumber: null,
1059
1059
  expectedAssertionsNumberErrorGen: null
1060
1060
  };
1061
- Object.defineProperty(global, MATCHERS_OBJECT, {
1061
+ Object.defineProperty(globalThis, MATCHERS_OBJECT, {
1062
1062
  value: {
1063
1063
  state: defaultState
1064
1064
  }
1065
1065
  });
1066
1066
  }
1067
- const getState = () => global[MATCHERS_OBJECT].state;
1067
+ const getState = () => globalThis[MATCHERS_OBJECT].state;
1068
1068
  const setState = (state) => {
1069
- Object.assign(global[MATCHERS_OBJECT].state, state);
1069
+ Object.assign(globalThis[MATCHERS_OBJECT].state, state);
1070
1070
  };
1071
1071
  const JestChaiExpect = (chai, utils) => {
1072
1072
  function def(name, fn) {
@@ -23,7 +23,7 @@ import { e as stripAnsi, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as
23
23
  import MagicString from './chunk-magic-string.d5e0e473.js';
24
24
  import { p as prompts } from './vendor-index.405e58ef.js';
25
25
 
26
- var version = "0.11.0";
26
+ var version = "0.12.0";
27
27
 
28
28
  function stripFinalNewline(input) {
29
29
  const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { p as picocolors } from './chunk-utils-global.a5a8641f.js';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.d6642729.js';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.25eaf4e5.js';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
package/dist/entry.js CHANGED
@@ -1,4 +1,4 @@
1
- export { r as run } from './vendor-entry.1b0b46f1.js';
1
+ export { r as run } from './vendor-entry.b20b007c.js';
2
2
  import 'fs';
3
3
  import './chunk-utils-global.a5a8641f.js';
4
4
  import 'tty';
@@ -6,7 +6,7 @@ import 'local-pkg';
6
6
  import 'path';
7
7
  import 'console';
8
8
  import 'stream';
9
- import './chunk-runtime-chain.8a313ffb.js';
9
+ import './chunk-runtime-chain.37b69607.js';
10
10
  import 'chai';
11
11
  import './vendor-_commonjsHelpers.addc3445.js';
12
12
  import './chunk-runtime-rpc.63398738.js';
package/dist/index.d.ts CHANGED
@@ -1154,6 +1154,14 @@ interface InlineConfig {
1154
1154
  * Resolve custom snapshot path
1155
1155
  */
1156
1156
  resolveSnapshotPath?: (path: string, extension: string) => string;
1157
+ /**
1158
+ * Pass with no tests
1159
+ */
1160
+ passWithNoTests?: boolean;
1161
+ /**
1162
+ * Allow tests and suites that are marked as only
1163
+ */
1164
+ allowOnly?: boolean;
1157
1165
  /**
1158
1166
  * Show heap usage after each test. Usefull for debugging memory leaks.
1159
1167
  */
@@ -1174,14 +1182,6 @@ interface UserConfig extends InlineConfig {
1174
1182
  * Use happy-dom
1175
1183
  */
1176
1184
  dom?: boolean;
1177
- /**
1178
- * Pass with no tests
1179
- */
1180
- passWithNoTests?: boolean;
1181
- /**
1182
- * Allow tests and suites that are marked as only
1183
- */
1184
- allowOnly?: boolean;
1185
1185
  /**
1186
1186
  * Run tests that cover a list of source files
1187
1187
  */
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { c as afterAll, f as afterEach, b as beforeAll, e as beforeEach, g as createExpect, d as describe, h as expect, k as getRunningMode, a as isFirstRun, l as isWatchMode, i as it, r as runOnce, s as suite, t as test, j as vi, v as vitest, w as withCallback } from './chunk-runtime-chain.8a313ffb.js';
1
+ export { c as afterAll, f as afterEach, b as beforeAll, e as beforeEach, g as createExpect, d as describe, h as expect, k as getRunningMode, a as isFirstRun, l as isWatchMode, i as it, r as runOnce, s as suite, t as test, j as vi, v as vitest, w as withCallback } from './chunk-runtime-chain.37b69607.js';
2
2
  export { assert, default as chai, should } from 'chai';
3
3
  import './vendor-_commonjsHelpers.addc3445.js';
4
4
  import './chunk-runtime-rpc.63398738.js';
package/dist/node.d.ts CHANGED
@@ -855,6 +855,14 @@ interface InlineConfig {
855
855
  * Resolve custom snapshot path
856
856
  */
857
857
  resolveSnapshotPath?: (path: string, extension: string) => string;
858
+ /**
859
+ * Pass with no tests
860
+ */
861
+ passWithNoTests?: boolean;
862
+ /**
863
+ * Allow tests and suites that are marked as only
864
+ */
865
+ allowOnly?: boolean;
858
866
  /**
859
867
  * Show heap usage after each test. Usefull for debugging memory leaks.
860
868
  */
@@ -875,14 +883,6 @@ interface UserConfig extends InlineConfig {
875
883
  * Use happy-dom
876
884
  */
877
885
  dom?: boolean;
878
- /**
879
- * Pass with no tests
880
- */
881
- passWithNoTests?: boolean;
882
- /**
883
- * Allow tests and suites that are marked as only
884
- */
885
- allowOnly?: boolean;
886
886
  /**
887
887
  * Run tests that cover a list of source files
888
888
  */
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.d6642729.js';
1
+ export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.25eaf4e5.js';
2
2
  export { V as VitestRunner } from './chunk-runtime-mocker.ee72d19a.js';
3
3
  import 'buffer';
4
4
  import 'path';
@@ -3,7 +3,7 @@ import { a as getWorkerState, t as toArray, G as clone, E as getType, l as relat
3
3
  import { Console } from 'console';
4
4
  import { Writable } from 'stream';
5
5
  import { importModule } from 'local-pkg';
6
- import { s as suite, t as test, d as describe, i as it, r as runOnce, a as isFirstRun, b as beforeAll, c as afterAll, e as beforeEach, f as afterEach, w as withCallback, g as createExpect, h as expect, v as vitest, j as vi, k as getRunningMode, l as isWatchMode, m as resetRunOnceCounter, R as RealDate, n as clearCollectorContext, o as defaultSuite, p as setHooks, q as getHooks, u as collectorContext, x as getSnapshotClient, y as setState, z as getFn, A as getState } from './chunk-runtime-chain.8a313ffb.js';
6
+ import { s as suite, t as test, d as describe, i as it, r as runOnce, a as isFirstRun, b as beforeAll, c as afterAll, e as beforeEach, f as afterEach, w as withCallback, g as createExpect, h as expect, v as vitest, j as vi, k as getRunningMode, l as isWatchMode, m as resetRunOnceCounter, R as RealDate, n as clearCollectorContext, o as defaultSuite, p as setHooks, q as getHooks, u as collectorContext, x as getSnapshotClient, y as setState, z as getFn, A as getState } from './chunk-runtime-chain.37b69607.js';
7
7
  import chai, { assert, should, util } from 'chai';
8
8
  import { r as rpc } from './chunk-runtime-rpc.63398738.js';
9
9
  import { d as clearTimeout, c as setTimeout, s as stringify } from './chunk-utils-timers.f25e8f44.js';
@@ -270,7 +270,9 @@ const allowRewrite = [
270
270
  ];
271
271
  const skipKeys = [
272
272
  "window",
273
- "self"
273
+ "self",
274
+ "top",
275
+ "parent"
274
276
  ];
275
277
  function getWindowKeys(global, win) {
276
278
  const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
@@ -282,14 +284,18 @@ function getWindowKeys(global, win) {
282
284
  }));
283
285
  return keys;
284
286
  }
285
- function populateGlobal(global, win) {
287
+ function populateGlobal(global, win, options = {}) {
288
+ const { bindFunctions = false } = options;
286
289
  const keys = getWindowKeys(global, win);
287
290
  const overrideObject = /* @__PURE__ */ new Map();
288
291
  for (const key of keys) {
292
+ const shouldBind = bindFunctions && typeof win[key] === "function";
289
293
  Object.defineProperty(global, key, {
290
294
  get() {
291
295
  if (overrideObject.has(key))
292
296
  return overrideObject.get(key);
297
+ if (shouldBind)
298
+ return win[key].bind(win);
293
299
  return win[key];
294
300
  },
295
301
  set(v) {
@@ -298,50 +304,50 @@ function populateGlobal(global, win) {
298
304
  configurable: true
299
305
  });
300
306
  }
301
- const globalKeys = /* @__PURE__ */ new Set(["window", "self", "GLOBAL", "global"]);
307
+ const globalKeys = /* @__PURE__ */ new Set(["window", "self", "top", "parent"]);
308
+ const globalProxy = new Proxy(win.window, {
309
+ get(target, p, receiver) {
310
+ if (overrideObject.has(p))
311
+ return overrideObject.get(p);
312
+ return Reflect.get(target, p, receiver);
313
+ },
314
+ set(target, p, value, receiver) {
315
+ try {
316
+ Object.defineProperty(global, p, {
317
+ get: () => overrideObject.get(p),
318
+ set: (value2) => overrideObject.set(p, value2),
319
+ configurable: true
320
+ });
321
+ overrideObject.set(p, value);
322
+ Reflect.set(target, p, value, receiver);
323
+ } catch {
324
+ }
325
+ return true;
326
+ },
327
+ deleteProperty(target, p) {
328
+ Reflect.deleteProperty(global, p);
329
+ overrideObject.delete(p);
330
+ return Reflect.deleteProperty(target, p);
331
+ },
332
+ defineProperty(target, p, attributes) {
333
+ if (attributes.writable && "value" in attributes) ; else if (attributes.get) {
334
+ overrideObject.delete(p);
335
+ Reflect.defineProperty(global, p, attributes);
336
+ }
337
+ return Reflect.defineProperty(target, p, attributes);
338
+ }
339
+ });
302
340
  globalKeys.forEach((key) => {
303
341
  if (!win[key])
304
342
  return;
305
- const proxy = new Proxy(win[key], {
306
- get(target, p, receiver) {
307
- if (overrideObject.has(p))
308
- return overrideObject.get(p);
309
- return Reflect.get(target, p, receiver);
310
- },
311
- set(target, p, value, receiver) {
312
- try {
313
- Object.defineProperty(global, p, {
314
- get: () => overrideObject.get(p),
315
- set: (value2) => overrideObject.set(p, value2),
316
- configurable: true
317
- });
318
- overrideObject.set(p, value);
319
- Reflect.set(target, p, value, receiver);
320
- } catch {
321
- }
322
- return true;
323
- },
324
- deleteProperty(target, p) {
325
- Reflect.deleteProperty(global, p);
326
- overrideObject.delete(p);
327
- return Reflect.deleteProperty(target, p);
328
- },
329
- defineProperty(target, p, attributes) {
330
- if (attributes.writable && "value" in attributes) ; else if (attributes.get) {
331
- overrideObject.delete(p);
332
- Reflect.defineProperty(global, p, attributes);
333
- }
334
- return Reflect.defineProperty(target, p, attributes);
335
- }
336
- });
337
343
  Object.defineProperty(global, key, {
338
344
  get() {
339
- return proxy;
345
+ return globalProxy;
340
346
  },
341
347
  configurable: true
342
348
  });
343
349
  });
344
- global.globalThis = new Proxy(global.globalThis, {
350
+ const globalThisProxy = new Proxy(global.globalThis, {
345
351
  set(target, key, value, receiver) {
346
352
  overrideObject.set(key, value);
347
353
  return Reflect.set(target, key, value, receiver);
@@ -360,6 +366,9 @@ function populateGlobal(global, win) {
360
366
  return Reflect.defineProperty(target, p, attributes);
361
367
  }
362
368
  });
369
+ global.globalThis = globalThisProxy;
370
+ if (global.global)
371
+ global.global = globalThisProxy;
363
372
  skipKeys.forEach((k) => keys.add(k));
364
373
  return {
365
374
  keys,
@@ -455,7 +464,7 @@ var happy = {
455
464
  async setup(global) {
456
465
  const { Window, GlobalWindow } = await importModule("happy-dom");
457
466
  const win = new (GlobalWindow || Window)();
458
- const { keys, allowRewrite } = populateGlobal(global, win);
467
+ const { keys, allowRewrite } = populateGlobal(global, win, { bindFunctions: true });
459
468
  const originals = new Map(allowRewrite.map(([key]) => [key, global[key]]));
460
469
  return {
461
470
  teardown(global2) {
@@ -486,7 +495,7 @@ async function setupGlobalEnv(config) {
486
495
  globalSetup = true;
487
496
  setupConsoleLogSpy();
488
497
  if (config.globals)
489
- (await import('./chunk-integrations-globals.1ce15dfd.js')).registerApiGlobally();
498
+ (await import('./chunk-integrations-globals.a37b2801.js')).registerApiGlobally();
490
499
  }
491
500
  function setupDefines(defines) {
492
501
  for (const key in defines)
@@ -1037,21 +1046,39 @@ function clearModuleMocks() {
1037
1046
  }
1038
1047
 
1039
1048
  async function run(files, config) {
1040
- var _a;
1041
1049
  await setupGlobalEnv(config);
1042
1050
  const workerState = getWorkerState();
1043
- for (const file of files) {
1044
- workerState.mockMap.clear();
1045
- resetModules();
1051
+ const envs = ["node", "jsdom", "happy-dom"];
1052
+ const filesWithEnv = await Promise.all(files.map(async (file) => {
1053
+ var _a;
1046
1054
  const code = await promises.readFile(file, "utf-8");
1047
1055
  const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
1048
- if (!["node", "jsdom", "happy-dom"].includes(env))
1049
- throw new Error(`Unsupported environment: ${env}`);
1050
- workerState.filepath = file;
1051
- await withEnv(env, config.environmentOptions || {}, async () => {
1052
- await startTests([file], config);
1056
+ if (!envs.includes(env))
1057
+ throw new Error(`Unsupported environment: "${env}" in ${file}`);
1058
+ return {
1059
+ file,
1060
+ env
1061
+ };
1062
+ }));
1063
+ const filesByEnv = filesWithEnv.reduce((acc, { file, env }) => {
1064
+ acc[env] || (acc[env] = []);
1065
+ acc[env].push(file);
1066
+ return acc;
1067
+ }, {});
1068
+ for (const env of envs) {
1069
+ const environment = env;
1070
+ const files2 = filesByEnv[environment];
1071
+ if (!files2 || !files2.length)
1072
+ continue;
1073
+ await withEnv(environment, config.environmentOptions || {}, async () => {
1074
+ for (const file of files2) {
1075
+ workerState.mockMap.clear();
1076
+ resetModules();
1077
+ workerState.filepath = file;
1078
+ await startTests([file], config);
1079
+ workerState.filepath = void 0;
1080
+ }
1053
1081
  });
1054
- workerState.filepath = void 0;
1055
1082
  }
1056
1083
  }
1057
1084
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.11.0",
4
+ "version": "0.12.0",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "keywords": [
7
7
  "vite",
@@ -93,7 +93,7 @@
93
93
  "@types/node": "^17.0.31",
94
94
  "@types/prompts": "^2.4.0",
95
95
  "@types/sinonjs__fake-timers": "^8.1.2",
96
- "@vitest/ui": "0.11.0",
96
+ "@vitest/ui": "0.12.0",
97
97
  "birpc": "^0.2.2",
98
98
  "c8": "^7.11.2",
99
99
  "cac": "^6.7.12",
@@ -120,7 +120,7 @@
120
120
  "source-map-js": "^1.0.2",
121
121
  "strip-ansi": "^7.0.1",
122
122
  "typescript": "^4.6.4",
123
- "vite-node": "0.11.0",
123
+ "vite-node": "0.12.0",
124
124
  "ws": "^8.6.0"
125
125
  },
126
126
  "engines": {