vitest 0.27.2 → 0.28.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 (64) hide show
  1. package/LICENSE.md +4 -93
  2. package/browser.d.ts +1 -1
  3. package/dist/browser.d.ts +11 -13
  4. package/dist/browser.js +10 -34
  5. package/dist/{chunk-api-setup.029198e3.js → chunk-api-setup.52751a38.js} +27 -12
  6. package/dist/chunk-constants.797d3ebf.js +42 -0
  7. package/dist/{chunk-env-node.787e9561.js → chunk-env-node.ffd1183b.js} +26 -0
  8. package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.cfd23146.js} +51 -11
  9. package/dist/chunk-integrations-coverage.48e6286b.js +3993 -0
  10. package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
  11. package/dist/chunk-integrations-run-once.38756e30.js +27 -0
  12. package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
  13. package/dist/{chunk-node-git.125c9008.js → chunk-node-git.d9ad64ab.js} +6 -7
  14. package/dist/{chunk-snapshot-manager.ce714e21.js → chunk-node-pkg.dcdf4369.js} +12653 -9324
  15. package/dist/{chunk-runtime-mocker.58511c38.js → chunk-runtime-mocker.03017e8c.js} +14 -13
  16. package/dist/{chunk-runtime-rpc.d709e91b.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
  17. package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
  18. package/dist/chunk-snapshot-env.6457638e.js +11 -0
  19. package/dist/chunk-utils-base.977ae74f.js +77 -0
  20. package/dist/chunk-utils-env.860d90c2.js +6 -0
  21. package/dist/chunk-utils-global.442d1d33.js +73 -0
  22. package/dist/{chunk-utils-import.054ab315.js → chunk-utils-import.9911c99d.js} +3289 -169
  23. package/dist/chunk-utils-tasks.1b603032.js +103 -0
  24. package/dist/cli-wrapper.js +8 -6
  25. package/dist/cli.js +18 -15
  26. package/dist/config.cjs +10 -7
  27. package/dist/config.d.ts +22 -4
  28. package/dist/config.js +10 -8
  29. package/dist/entry.js +244 -28
  30. package/dist/env-afee91f0.d.ts +10 -0
  31. package/dist/environments.d.ts +7 -2
  32. package/dist/environments.js +1 -1
  33. package/dist/index.d.ts +160 -11
  34. package/dist/index.js +18 -18
  35. package/dist/loader.js +9 -8
  36. package/dist/node.d.ts +9 -7
  37. package/dist/node.js +20 -17
  38. package/dist/runners-chunk.js +215 -0
  39. package/dist/runners.d.ts +39 -0
  40. package/dist/runners.js +18 -0
  41. package/dist/spy.js +1 -2
  42. package/dist/suite.d.ts +2 -0
  43. package/dist/suite.js +2 -18
  44. package/dist/{types-d97c72c7.d.ts → types-c800444e.d.ts} +196 -437
  45. package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
  46. package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
  47. package/dist/worker.js +17 -16
  48. package/package.json +22 -12
  49. package/runners.d.ts +1 -0
  50. package/suite.d.ts +1 -0
  51. package/dist/chunk-integrations-coverage.44413252.js +0 -240
  52. package/dist/chunk-integrations-globals.0024ce21.js +0 -27
  53. package/dist/chunk-mock-date.c543fa3e.js +0 -349
  54. package/dist/chunk-runtime-chain.2da9e75c.js +0 -2595
  55. package/dist/chunk-runtime-error.de671af0.js +0 -144
  56. package/dist/chunk-runtime-setup.35da9209.js +0 -649
  57. package/dist/chunk-utils-env.f4a39d2c.js +0 -228
  58. package/dist/chunk-utils-source-map.5f5d12cf.js +0 -408
  59. package/dist/chunk-utils-timers.52534f96.js +0 -3573
  60. package/dist/index-50755efe.d.ts +0 -258
  61. package/dist/vendor-index.451e37bc.js +0 -1071
  62. package/dist/vendor-index.723a074f.js +0 -102
  63. package/dist/vendor-index.9c919048.js +0 -61
  64. package/dist/vendor-index.9f20a9be.js +0 -6291
@@ -2,6 +2,7 @@ import 'acorn';
2
2
  import { builtinModules } from 'node:module';
3
3
  import 'node:fs';
4
4
  import { pathToFileURL } from 'node:url';
5
+ import 'pathe';
5
6
  import assert from 'node:assert';
6
7
  import process$1 from 'node:process';
7
8
  import 'node:path';
package/dist/worker.js CHANGED
@@ -1,29 +1,28 @@
1
- import { r as relative, b as resolve, f as distDir } from './chunk-utils-env.f4a39d2c.js';
1
+ import { resolve, relative } from 'pathe';
2
2
  import { c as createBirpc } from './vendor-index.783e7f3e.js';
3
3
  import { workerId } from 'tinypool';
4
+ import { processError } from '@vitest/runner/utils';
4
5
  import { ModuleCacheMap } from 'vite-node/client';
5
6
  import { isPrimitive } from 'vite-node/utils';
6
- import { g as getWorkerState } from './chunk-mock-date.c543fa3e.js';
7
- import { e as executeInViteNode } from './chunk-runtime-mocker.58511c38.js';
8
- import { r as rpc } from './chunk-runtime-rpc.d709e91b.js';
9
- import { p as processError } from './chunk-runtime-error.de671af0.js';
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.03017e8c.js';
10
+ import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
10
11
  import 'node:url';
11
- import 'path';
12
- import 'node:path';
13
- import 'picocolors';
14
- import 'local-pkg';
12
+ import './chunk-utils-env.860d90c2.js';
13
+ import 'std-env';
14
+ import '@vitest/utils';
15
15
  import 'vite';
16
- import './vendor-index.b0346fe4.js';
16
+ import './vendor-index.bdee400f.js';
17
17
  import 'acorn';
18
18
  import 'node:module';
19
19
  import 'node:fs';
20
20
  import 'node:assert';
21
21
  import 'node:process';
22
+ import 'node:path';
22
23
  import 'node:v8';
23
24
  import 'node:util';
24
- import './chunk-utils-timers.52534f96.js';
25
- import 'util';
26
- import 'chai';
25
+ import './chunk-utils-base.977ae74f.js';
27
26
 
28
27
  let _viteNode;
29
28
  const moduleCache = new ModuleCacheMap();
@@ -38,7 +37,7 @@ async function startViteNode(ctx) {
38
37
  rpc().onWorkerExit(error, code);
39
38
  return processExit(code);
40
39
  };
41
- process.on("unhandledRejection", (err) => {
40
+ function catchError(err, type) {
42
41
  var _a;
43
42
  const worker = getWorkerState();
44
43
  const error = processError(err);
@@ -46,8 +45,10 @@ async function startViteNode(ctx) {
46
45
  error.VITEST_TEST_NAME = (_a = worker.current) == null ? void 0 : _a.name;
47
46
  error.VITEST_TEST_PATH = relative(config.root, worker.filepath);
48
47
  }
49
- rpc().onUnhandledRejection(error);
50
- });
48
+ rpc().onUnhandledError(error, type);
49
+ }
50
+ process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
51
+ process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
51
52
  const { run: run2 } = (await executeInViteNode({
52
53
  files: [
53
54
  resolve(distDir, "entry.js")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.27.2",
4
+ "version": "0.28.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",
@@ -45,14 +45,22 @@
45
45
  "types": "./dist/node.d.ts",
46
46
  "import": "./dist/node.js"
47
47
  },
48
- "./environments": {
49
- "types": "./dist/environments.d.ts",
50
- "import": "./dist/environments.js"
51
- },
52
48
  "./browser": {
53
49
  "types": "./dist/browser.d.ts",
54
50
  "import": "./dist/browser.js"
55
51
  },
52
+ "./runners": {
53
+ "types": "./dist/runners.d.ts",
54
+ "import": "./dist/runners.js"
55
+ },
56
+ "./suite": {
57
+ "types": "./dist/suite.d.ts",
58
+ "import": "./dist/suite.js"
59
+ },
60
+ "./environments": {
61
+ "types": "./dist/environments.d.ts",
62
+ "import": "./dist/environments.js"
63
+ },
56
64
  "./config": {
57
65
  "types": "./config.d.ts",
58
66
  "require": "./dist/config.cjs",
@@ -110,15 +118,22 @@
110
118
  "chai": "^4.3.7",
111
119
  "debug": "^4.3.4",
112
120
  "local-pkg": "^0.4.2",
121
+ "pathe": "^1.1.0",
113
122
  "picocolors": "^1.0.0",
114
123
  "source-map": "^0.6.1",
124
+ "std-env": "^3.3.1",
115
125
  "strip-literal": "^1.0.0",
116
126
  "tinybench": "^2.3.1",
117
127
  "tinypool": "^0.3.0",
118
128
  "tinyspy": "^1.0.2",
119
129
  "vite": "^3.0.0 || ^4.0.0",
120
130
  "why-is-node-running": "^2.2.2",
121
- "vite-node": "0.27.2"
131
+ "@vitest/runner": "0.28.0",
132
+ "@vitest/expect": "0.28.0",
133
+ "@vitest/utils": "0.28.0",
134
+ "@vitest/ui": "0.28.0",
135
+ "@vitest/spy": "0.28.0",
136
+ "vite-node": "0.28.0"
122
137
  },
123
138
  "devDependencies": {
124
139
  "@antfu/install-pkg": "^0.1.1",
@@ -149,18 +164,13 @@
149
164
  "mlly": "^1.1.0",
150
165
  "natural-compare": "^1.4.0",
151
166
  "p-limit": "^4.0.0",
152
- "pathe": "^0.2.0",
153
167
  "pkg-types": "^1.0.1",
154
168
  "pretty-format": "^27.5.1",
155
169
  "prompts": "^2.4.2",
156
170
  "rollup": "^2.79.1",
157
171
  "strip-ansi": "^7.0.1",
158
172
  "typescript": "^4.9.4",
159
- "ws": "^8.12.0",
160
- "@vitest/expect": "0.27.2",
161
- "@vitest/spy": "0.27.2",
162
- "@vitest/utils": "0.27.2",
163
- "@vitest/ui": "0.27.2"
173
+ "ws": "^8.12.0"
164
174
  },
165
175
  "scripts": {
166
176
  "build": "rimraf dist && rollup -c",
package/runners.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/runners.js'
package/suite.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/suite.js'
@@ -1,240 +0,0 @@
1
- import { importModule } from 'local-pkg';
2
-
3
- /*
4
- How it works:
5
- `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
6
- */
7
-
8
- class Node {
9
- value;
10
- next;
11
-
12
- constructor(value) {
13
- this.value = value;
14
- }
15
- }
16
-
17
- class Queue {
18
- #head;
19
- #tail;
20
- #size;
21
-
22
- constructor() {
23
- this.clear();
24
- }
25
-
26
- enqueue(value) {
27
- const node = new Node(value);
28
-
29
- if (this.#head) {
30
- this.#tail.next = node;
31
- this.#tail = node;
32
- } else {
33
- this.#head = node;
34
- this.#tail = node;
35
- }
36
-
37
- this.#size++;
38
- }
39
-
40
- dequeue() {
41
- const current = this.#head;
42
- if (!current) {
43
- return;
44
- }
45
-
46
- this.#head = this.#head.next;
47
- this.#size--;
48
- return current.value;
49
- }
50
-
51
- clear() {
52
- this.#head = undefined;
53
- this.#tail = undefined;
54
- this.#size = 0;
55
- }
56
-
57
- get size() {
58
- return this.#size;
59
- }
60
-
61
- * [Symbol.iterator]() {
62
- let current = this.#head;
63
-
64
- while (current) {
65
- yield current.value;
66
- current = current.next;
67
- }
68
- }
69
- }
70
-
71
- function pLimit(concurrency) {
72
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
73
- throw new TypeError('Expected `concurrency` to be a number from 1 and up');
74
- }
75
-
76
- const queue = new Queue();
77
- let activeCount = 0;
78
-
79
- const next = () => {
80
- activeCount--;
81
-
82
- if (queue.size > 0) {
83
- queue.dequeue()();
84
- }
85
- };
86
-
87
- const run = async (fn, resolve, args) => {
88
- activeCount++;
89
-
90
- const result = (async () => fn(...args))();
91
-
92
- resolve(result);
93
-
94
- try {
95
- await result;
96
- } catch {}
97
-
98
- next();
99
- };
100
-
101
- const enqueue = (fn, resolve, args) => {
102
- queue.enqueue(run.bind(undefined, fn, resolve, args));
103
-
104
- (async () => {
105
- // This function needs to wait until the next microtask before comparing
106
- // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
107
- // when the run function is dequeued and called. The comparison in the if-statement
108
- // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
109
- await Promise.resolve();
110
-
111
- if (activeCount < concurrency && queue.size > 0) {
112
- queue.dequeue()();
113
- }
114
- })();
115
- };
116
-
117
- const generator = (fn, ...args) => new Promise(resolve => {
118
- enqueue(fn, resolve, args);
119
- });
120
-
121
- Object.defineProperties(generator, {
122
- activeCount: {
123
- get: () => activeCount,
124
- },
125
- pendingCount: {
126
- get: () => queue.size,
127
- },
128
- clearQueue: {
129
- value: () => {
130
- queue.clear();
131
- },
132
- },
133
- });
134
-
135
- return generator;
136
- }
137
-
138
- const CoverageProviderMap = {
139
- c8: "@vitest/coverage-c8",
140
- istanbul: "@vitest/coverage-istanbul"
141
- };
142
- async function resolveCoverageProvider(provider) {
143
- if (typeof provider === "string") {
144
- const pkg = CoverageProviderMap[provider];
145
- if (!pkg)
146
- throw new Error(`Unknown coverage provider: ${provider}`);
147
- return await importModule(pkg);
148
- } else {
149
- return provider;
150
- }
151
- }
152
- async function getCoverageProvider(options) {
153
- if ((options == null ? void 0 : options.enabled) && (options == null ? void 0 : options.provider)) {
154
- const { getProvider } = await resolveCoverageProvider(options.provider);
155
- return await getProvider();
156
- }
157
- return null;
158
- }
159
- async function takeCoverageInsideWorker(options) {
160
- if (options.enabled && options.provider) {
161
- const { takeCoverage } = await resolveCoverageProvider(options.provider);
162
- return await (takeCoverage == null ? void 0 : takeCoverage());
163
- }
164
- }
165
-
166
- function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
167
- const suiteIsOnly = parentIsOnly || suite.mode === "only";
168
- suite.tasks.forEach((t) => {
169
- const includeTask = suiteIsOnly || t.mode === "only";
170
- if (onlyMode) {
171
- if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
172
- if (t.mode === "only") {
173
- checkAllowOnly(t, allowOnly);
174
- t.mode = "run";
175
- }
176
- } else if (t.mode === "run" && !includeTask) {
177
- t.mode = "skip";
178
- } else if (t.mode === "only") {
179
- checkAllowOnly(t, allowOnly);
180
- t.mode = "run";
181
- }
182
- }
183
- if (t.type === "test") {
184
- if (namePattern && !getTaskFullName(t).match(namePattern))
185
- t.mode = "skip";
186
- } else if (t.type === "suite") {
187
- if (t.mode === "skip")
188
- skipAllTasks(t);
189
- else
190
- interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly);
191
- }
192
- });
193
- if (suite.mode === "run") {
194
- if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run"))
195
- suite.mode = "skip";
196
- }
197
- }
198
- function getTaskFullName(task) {
199
- return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
200
- }
201
- function someTasksAreOnly(suite) {
202
- return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
203
- }
204
- function skipAllTasks(suite) {
205
- suite.tasks.forEach((t) => {
206
- if (t.mode === "run") {
207
- t.mode = "skip";
208
- if (t.type === "suite")
209
- skipAllTasks(t);
210
- }
211
- });
212
- }
213
- function checkAllowOnly(task, allowOnly) {
214
- if (allowOnly)
215
- return;
216
- task.result = {
217
- state: "fail",
218
- error: new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error")
219
- };
220
- }
221
- function generateHash(str) {
222
- let hash = 0;
223
- if (str.length === 0)
224
- return `${hash}`;
225
- for (let i = 0; i < str.length; i++) {
226
- const char = str.charCodeAt(i);
227
- hash = (hash << 5) - hash + char;
228
- hash = hash & hash;
229
- }
230
- return `${hash}`;
231
- }
232
- function calculateSuiteHash(parent) {
233
- parent.tasks.forEach((t, idx) => {
234
- t.id = `${parent.id}_${idx}`;
235
- if (t.type === "suite")
236
- calculateSuiteHash(t);
237
- });
238
- }
239
-
240
- export { CoverageProviderMap as C, getCoverageProvider as a, calculateSuiteHash as c, generateHash as g, interpretTaskModes as i, pLimit as p, someTasksAreOnly as s, takeCoverageInsideWorker as t };
@@ -1,27 +0,0 @@
1
- import { m as globalApis } from './chunk-utils-env.f4a39d2c.js';
2
- import { i as index } from './chunk-utils-import.054ab315.js';
3
- import 'node:url';
4
- import 'path';
5
- import './chunk-runtime-chain.2da9e75c.js';
6
- import 'util';
7
- import 'chai';
8
- import './chunk-mock-date.c543fa3e.js';
9
- import 'node:path';
10
- import 'picocolors';
11
- import 'local-pkg';
12
- import './vendor-_commonjsHelpers.addc3445.js';
13
- import './chunk-utils-timers.52534f96.js';
14
- import './vendor-index.723a074f.js';
15
- import 'tinyspy';
16
- import './chunk-utils-source-map.5f5d12cf.js';
17
- import './chunk-runtime-rpc.d709e91b.js';
18
- import 'node:fs';
19
- import 'fs';
20
-
21
- function registerApiGlobally() {
22
- globalApis.forEach((api) => {
23
- globalThis[api] = index[api];
24
- });
25
- }
26
-
27
- export { registerApiGlobally };