vitest 0.28.4 → 0.29.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 (46) hide show
  1. package/LICENSE.md +1 -1
  2. package/coverage.d.ts +1 -0
  3. package/dist/browser.d.ts +2 -1
  4. package/dist/browser.js +4 -4
  5. package/dist/child.js +89 -0
  6. package/dist/{chunk-api-setup.ec61b167.js → chunk-api-setup.d9eccaeb.js} +5 -5
  7. package/dist/{chunk-env-node.ffd1183b.js → chunk-env-node.affdd278.js} +1 -2
  8. package/dist/{chunk-install-pkg.13d8e7be.js → chunk-install-pkg.ea1a5ef4.js} +9 -8
  9. package/dist/chunk-integrations-coverage.e0a6acd2.js +51 -0
  10. package/dist/{chunk-integrations-globals.aacbac4d.js → chunk-integrations-globals.b56fcb06.js} +8 -8
  11. package/dist/{chunk-integrations-run-once.38756e30.js → chunk-integrations-run-once.9012f759.js} +1 -1
  12. package/dist/{chunk-integrations-utils.dae69d89.js → chunk-integrations-utils.233d6a3b.js} +2 -2
  13. package/dist/{chunk-node-git.d9ad64ab.js → chunk-node-git.ed5bded8.js} +1 -2
  14. package/dist/{chunk-node-pkg.94145502.js → chunk-node-pkg.88e7e848.js} +4423 -270
  15. package/dist/{chunk-runtime-mocker.eb0c265c.js → chunk-runtime-mocker.a048e92d.js} +83 -47
  16. package/dist/chunk-runtime-rpc.971b3848.js +61 -0
  17. package/dist/{chunk-runtime-setup.7dfc1a6a.js → chunk-runtime-setup.992bb661.js} +2 -2
  18. package/dist/{chunk-snapshot-env.6457638e.js → chunk-snapshot-env.a347d647.js} +2 -2
  19. package/dist/{chunk-utils-base.904102a8.js → chunk-utils-base.81f83dbd.js} +15 -1
  20. package/dist/{chunk-utils-global.442d1d33.js → chunk-utils-global.727b6d25.js} +1 -7
  21. package/dist/{chunk-utils-import.0402c9db.js → chunk-utils-import.ec15dcad.js} +18 -29
  22. package/dist/{chunk-utils-tasks.a9a8d8e1.js → chunk-utils-tasks.b41c8284.js} +14 -10
  23. package/dist/cli-wrapper.js +1 -2
  24. package/dist/cli.js +12 -11
  25. package/dist/config.cjs +1 -1
  26. package/dist/config.d.ts +8 -7
  27. package/dist/config.js +1 -1
  28. package/dist/coverage.d.ts +142 -0
  29. package/dist/coverage.js +49 -0
  30. package/dist/entry.js +51 -84
  31. package/dist/environments.d.ts +2 -1
  32. package/dist/environments.js +1 -1
  33. package/dist/index.d.ts +4 -3
  34. package/dist/index.js +9 -9
  35. package/dist/loader.js +2 -2
  36. package/dist/node.d.ts +9 -10
  37. package/dist/node.js +14 -12
  38. package/dist/runners.d.ts +4 -1
  39. package/dist/runners.js +221 -13
  40. package/dist/{types-aac763a5.d.ts → types-7cd96283.d.ts} +164 -39
  41. package/dist/{vendor-index.618ca5a1.js → vendor-index.2cbcdd1e.js} +18 -13
  42. package/dist/worker.js +14 -56
  43. package/package.json +16 -10
  44. package/dist/chunk-integrations-coverage.48e6286b.js +0 -3993
  45. package/dist/chunk-runtime-rpc.9c0386cc.js +0 -31
  46. package/dist/runners-chunk.js +0 -215
@@ -7,8 +7,7 @@ import k from 'path';
7
7
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
8
8
  import require$$0 from 'fs';
9
9
  import url from 'node:url';
10
- import { constants } from 'os';
11
- import os from 'node:os';
10
+ import os, { constants } from 'node:os';
12
11
  import require$$0$2 from 'assert';
13
12
  import require$$2 from 'events';
14
13
  import require$$0$5 from 'buffer';
@@ -1135,16 +1134,21 @@ return {name,number,description,supported,action,forced,standard};
1135
1134
 
1136
1135
  const getSignalsByName=function(){
1137
1136
  const signals=getSignals();
1138
- return signals.reduce(getSignalByName,{});
1137
+ return Object.fromEntries(signals.map(getSignalByName));
1139
1138
  };
1140
1139
 
1141
- const getSignalByName=function(
1142
- signalByNameMemo,
1143
- {name,number,description,supported,action,forced,standard})
1140
+ const getSignalByName=function({
1141
+ name,
1142
+ number,
1143
+ description,
1144
+ supported,
1145
+ action,
1146
+ forced,
1147
+ standard})
1144
1148
  {
1145
- return {
1146
- ...signalByNameMemo,
1147
- [name]:{name,number,description,supported,action,forced,standard}};
1149
+ return [
1150
+ name,
1151
+ {name,number,description,supported,action,forced,standard}];
1148
1152
 
1149
1153
  };
1150
1154
 
@@ -1845,9 +1849,7 @@ var mergeStream = function (/*streams...*/) {
1845
1849
 
1846
1850
  // `input` option
1847
1851
  const handleInput = (spawned, input) => {
1848
- // Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
1849
- // @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
1850
- if (input === undefined || spawned.stdin === undefined) {
1852
+ if (input === undefined) {
1851
1853
  return;
1852
1854
  }
1853
1855
 
@@ -1879,7 +1881,8 @@ const makeAllStream = (spawned, {all}) => {
1879
1881
 
1880
1882
  // On failure, `result.stdout|stderr|all` should contain the currently buffered stream
1881
1883
  const getBufferedData = async (stream, streamPromise) => {
1882
- if (!stream) {
1884
+ // When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve
1885
+ if (!stream || streamPromise === undefined) {
1883
1886
  return;
1884
1887
  }
1885
1888
 
@@ -1922,7 +1925,9 @@ const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuf
1922
1925
  }
1923
1926
  };
1924
1927
 
1928
+ // eslint-disable-next-line unicorn/prefer-top-level-await
1925
1929
  const nativePromisePrototype = (async () => {})().constructor.prototype;
1930
+
1926
1931
  const descriptors = ['then', 'catch', 'finally'].map(property => [
1927
1932
  property,
1928
1933
  Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),
package/dist/worker.js CHANGED
@@ -1,17 +1,16 @@
1
- import { resolve, relative } from 'pathe';
2
1
  import { c as createBirpc } from './vendor-index.783e7f3e.js';
3
2
  import { workerId } from 'tinypool';
4
- import { processError } from '@vitest/runner/utils';
5
- import { ModuleCacheMap } from 'vite-node/client';
6
- import { isPrimitive } from 'vite-node/utils';
7
- import { d as distDir } from './chunk-constants.797d3ebf.js';
8
- import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
9
- import { e as executeInViteNode } from './chunk-runtime-mocker.eb0c265c.js';
10
- import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
11
- import 'node:url';
3
+ import { g as getWorkerState } from './chunk-utils-global.727b6d25.js';
4
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './chunk-runtime-mocker.a048e92d.js';
5
+ import { a as rpcDone } from './chunk-runtime-rpc.971b3848.js';
6
+ import 'pathe';
12
7
  import './chunk-utils-env.860d90c2.js';
13
8
  import 'std-env';
9
+ import '@vitest/runner/utils';
14
10
  import '@vitest/utils';
11
+ import 'node:url';
12
+ import 'vite-node/client';
13
+ import 'vite-node/utils';
15
14
  import './vendor-index.bdee400f.js';
16
15
  import 'acorn';
17
16
  import 'node:module';
@@ -21,52 +20,10 @@ import 'node:process';
21
20
  import 'node:path';
22
21
  import 'node:v8';
23
22
  import 'node:util';
24
- import './chunk-utils-base.904102a8.js';
23
+ import './chunk-constants.797d3ebf.js';
24
+ import './chunk-utils-base.81f83dbd.js';
25
+ import '@vitest/spy';
25
26
 
26
- let _viteNode;
27
- const moduleCache = new ModuleCacheMap();
28
- const mockMap = /* @__PURE__ */ new Map();
29
- async function startViteNode(ctx) {
30
- if (_viteNode)
31
- return _viteNode;
32
- const { config } = ctx;
33
- const processExit = process.exit;
34
- process.exit = (code = process.exitCode || 0) => {
35
- const error = new Error(`process.exit called with "${code}"`);
36
- rpc().onWorkerExit(error, code);
37
- return processExit(code);
38
- };
39
- function catchError(err, type) {
40
- var _a;
41
- const worker = getWorkerState();
42
- const error = processError(err);
43
- if (worker.filepath && !isPrimitive(error)) {
44
- error.VITEST_TEST_NAME = (_a = worker.current) == null ? void 0 : _a.name;
45
- error.VITEST_TEST_PATH = relative(config.root, worker.filepath);
46
- }
47
- rpc().onUnhandledError(error, type);
48
- }
49
- process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
50
- process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
51
- const { run: run2 } = (await executeInViteNode({
52
- files: [
53
- resolve(distDir, "entry.js")
54
- ],
55
- fetchModule(id) {
56
- return rpc().fetch(id);
57
- },
58
- resolveId(id, importer) {
59
- return rpc().resolveId(id, importer);
60
- },
61
- moduleCache,
62
- mockMap,
63
- interopDefault: config.deps.interopDefault,
64
- root: config.root,
65
- base: config.base
66
- }))[0];
67
- _viteNode = { run: run2 };
68
- return _viteNode;
69
- }
70
27
  function init(ctx) {
71
28
  if (typeof __vitest_worker__ !== "undefined" && ctx.config.threads && ctx.config.isolate)
72
29
  throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${getWorkerState().ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
@@ -102,8 +59,9 @@ function init(ctx) {
102
59
  }
103
60
  async function run(ctx) {
104
61
  init(ctx);
105
- const { run: run2 } = await startViteNode(ctx);
106
- return run2(ctx.files, ctx.config);
62
+ const { run: run2, executor } = await startViteNode(ctx);
63
+ await run2(ctx.files, ctx.config, ctx.environment, executor);
64
+ await rpcDone();
107
65
  }
108
66
 
109
67
  export { run };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.28.4",
4
+ "version": "0.29.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",
@@ -65,6 +65,10 @@
65
65
  "types": "./config.d.ts",
66
66
  "require": "./dist/config.cjs",
67
67
  "import": "./dist/config.js"
68
+ },
69
+ "./coverage": {
70
+ "types": "./coverage.d.ts",
71
+ "import": "./dist/coverage.js"
68
72
  }
69
73
  },
70
74
  "main": "./dist/index.js",
@@ -128,18 +132,20 @@
128
132
  "tinyspy": "^1.0.2",
129
133
  "vite": "^3.0.0 || ^4.0.0",
130
134
  "why-is-node-running": "^2.2.2",
131
- "vite-node": "0.28.4",
132
- "@vitest/utils": "0.28.4",
133
- "@vitest/expect": "0.28.4",
134
- "@vitest/runner": "0.28.4",
135
- "@vitest/spy": "0.28.4"
135
+ "@vitest/expect": "0.29.0",
136
+ "@vitest/runner": "0.29.0",
137
+ "@vitest/spy": "0.29.0",
138
+ "vite-node": "0.29.0",
139
+ "@vitest/utils": "0.29.0"
136
140
  },
137
141
  "devDependencies": {
138
142
  "@antfu/install-pkg": "^0.1.1",
139
143
  "@edge-runtime/vm": "2.0.2",
140
144
  "@sinonjs/fake-timers": "^10.0.2",
141
145
  "@types/diff": "^5.0.2",
142
- "@types/jsdom": "^20.0.1",
146
+ "@types/istanbul-lib-coverage": "^2.0.4",
147
+ "@types/istanbul-reports": "^3.0.1",
148
+ "@types/jsdom": "^21.1.0",
143
149
  "@types/micromatch": "^4.0.2",
144
150
  "@types/natural-compare": "^1.4.1",
145
151
  "@types/prompts": "^2.4.2",
@@ -149,14 +155,14 @@
149
155
  "cli-truncate": "^3.1.0",
150
156
  "diff": "^5.1.0",
151
157
  "event-target-polyfill": "^0.0.3",
152
- "execa": "^6.1.0",
158
+ "execa": "^7.0.0",
153
159
  "expect-type": "^0.15.0",
154
160
  "fast-glob": "^3.2.12",
155
161
  "find-up": "^6.3.0",
156
162
  "flatted": "^3.2.7",
157
163
  "get-tsconfig": "^4.3.0",
158
- "happy-dom": "^7.8.1",
159
- "jsdom": "^20.0.3",
164
+ "happy-dom": "^8.3.2",
165
+ "jsdom": "^21.1.0",
160
166
  "log-update": "^5.0.1",
161
167
  "magic-string": "^0.27.0",
162
168
  "micromatch": "^4.0.5",