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
@@ -1,31 +0,0 @@
1
- import { getSafeTimers } from '@vitest/utils';
2
- import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
3
-
4
- const safeRandom = Math.random;
5
- function withSafeTimers(fn) {
6
- const { setTimeout: safeSetTimeout } = getSafeTimers();
7
- const currentSetTimeout = globalThis.setTimeout;
8
- const currentRandom = globalThis.Math.random;
9
- try {
10
- globalThis.setTimeout = safeSetTimeout;
11
- globalThis.Math.random = safeRandom;
12
- const result = fn();
13
- return result;
14
- } finally {
15
- globalThis.setTimeout = currentSetTimeout;
16
- globalThis.Math.random = currentRandom;
17
- }
18
- }
19
- const rpc = () => {
20
- const { rpc: rpc2 } = getWorkerState();
21
- return new Proxy(rpc2, {
22
- get(target, p, handler) {
23
- const sendCall = Reflect.get(target, p, handler);
24
- const safeSendCall = (...args) => withSafeTimers(() => sendCall(...args));
25
- safeSendCall.asEvent = sendCall.asEvent;
26
- return safeSendCall;
27
- }
28
- });
29
- };
30
-
31
- export { rpc as r };
@@ -1,215 +0,0 @@
1
- import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
2
- import { d as getSnapshotClient, c as createExpect, a as vi, e as getBenchOptions, f as getBenchFn } from './chunk-utils-import.0402c9db.js';
3
- import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
4
- import { g as getFullName } from './chunk-utils-tasks.a9a8d8e1.js';
5
- import { updateTask } from '@vitest/runner';
6
- import { createDefer, getSafeTimers } from '@vitest/utils';
7
-
8
- class VitestTestRunner {
9
- constructor(config) {
10
- this.config = config;
11
- this.snapshotClient = getSnapshotClient();
12
- this.workerState = getWorkerState();
13
- }
14
- importFile(filepath, source) {
15
- if (source === "setup")
16
- this.workerState.moduleCache.delete(filepath);
17
- return import(filepath);
18
- }
19
- onBeforeRun() {
20
- this.snapshotClient.clear();
21
- }
22
- async onAfterRun() {
23
- await this.snapshotClient.saveCurrent();
24
- }
25
- onAfterRunSuite(suite) {
26
- if (this.config.logHeapUsage && typeof process !== "undefined")
27
- suite.result.heap = process.memoryUsage().heapUsed;
28
- }
29
- onAfterRunTest(test) {
30
- this.snapshotClient.clearTest();
31
- if (this.config.logHeapUsage && typeof process !== "undefined")
32
- test.result.heap = process.memoryUsage().heapUsed;
33
- this.workerState.current = void 0;
34
- }
35
- async onBeforeRunTest(test) {
36
- if (test.mode !== "run") {
37
- this.snapshotClient.skipTestSnapshots(test);
38
- return;
39
- }
40
- clearModuleMocks(this.config);
41
- await this.snapshotClient.setTest(test);
42
- this.workerState.current = test;
43
- }
44
- onBeforeTryTest(test) {
45
- var _a;
46
- setState({
47
- assertionCalls: 0,
48
- isExpectingAssertions: false,
49
- isExpectingAssertionsError: null,
50
- expectedAssertionsNumber: null,
51
- expectedAssertionsNumberErrorGen: null,
52
- testPath: (_a = test.suite.file) == null ? void 0 : _a.filepath,
53
- currentTestName: getFullName(test),
54
- snapshotState: this.snapshotClient.snapshotState
55
- }, globalThis[GLOBAL_EXPECT]);
56
- }
57
- onAfterTryTest(test) {
58
- const {
59
- assertionCalls,
60
- expectedAssertionsNumber,
61
- expectedAssertionsNumberErrorGen,
62
- isExpectingAssertions,
63
- isExpectingAssertionsError
64
- } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
65
- if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
66
- throw expectedAssertionsNumberErrorGen();
67
- if (isExpectingAssertions === true && assertionCalls === 0)
68
- throw isExpectingAssertionsError;
69
- }
70
- extendTestContext(context) {
71
- let _expect;
72
- Object.defineProperty(context, "expect", {
73
- get() {
74
- if (!_expect)
75
- _expect = createExpect(context.meta);
76
- return _expect;
77
- }
78
- });
79
- Object.defineProperty(context, "_local", {
80
- get() {
81
- return _expect != null;
82
- }
83
- });
84
- return context;
85
- }
86
- }
87
- function clearModuleMocks(config) {
88
- const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
89
- if (restoreMocks)
90
- vi.restoreAllMocks();
91
- else if (mockReset)
92
- vi.resetAllMocks();
93
- else if (clearMocks)
94
- vi.clearAllMocks();
95
- if (unstubEnvs)
96
- vi.unstubAllEnvs();
97
- if (unstubGlobals)
98
- vi.unstubAllGlobals();
99
- }
100
-
101
- async function importTinybench() {
102
- if (!globalThis.EventTarget)
103
- await import('./vendor-index.534e612c.js').then(function (n) { return n.i; });
104
- return await import('tinybench');
105
- }
106
- function createBenchmarkResult(name) {
107
- return {
108
- name,
109
- rank: 0,
110
- rme: 0,
111
- samples: []
112
- };
113
- }
114
- async function runBenchmarkSuite(suite, runner) {
115
- var _a;
116
- const { Task, Bench } = await importTinybench();
117
- const start = performance.now();
118
- const benchmarkGroup = [];
119
- const benchmarkSuiteGroup = [];
120
- for (const task of suite.tasks) {
121
- if (task.mode !== "run")
122
- continue;
123
- if ((_a = task.meta) == null ? void 0 : _a.benchmark)
124
- benchmarkGroup.push(task);
125
- else if (task.type === "suite")
126
- benchmarkSuiteGroup.push(task);
127
- }
128
- if (benchmarkSuiteGroup.length)
129
- await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuite(subSuite, runner)));
130
- if (benchmarkGroup.length) {
131
- const defer = createDefer();
132
- const benchmarkMap = {};
133
- suite.result = {
134
- state: "run",
135
- startTime: start,
136
- benchmark: createBenchmarkResult(suite.name)
137
- };
138
- updateTask$1(suite);
139
- benchmarkGroup.forEach((benchmark, idx) => {
140
- const options = getBenchOptions(benchmark);
141
- const benchmarkInstance = new Bench(options);
142
- const benchmarkFn = getBenchFn(benchmark);
143
- benchmark.result = {
144
- state: "run",
145
- startTime: start,
146
- benchmark: createBenchmarkResult(benchmark.name)
147
- };
148
- const id = idx.toString();
149
- benchmarkMap[id] = benchmark;
150
- const task = new Task(benchmarkInstance, id, benchmarkFn);
151
- benchmark.meta.task = task;
152
- updateTask$1(benchmark);
153
- });
154
- benchmarkGroup.forEach((benchmark) => {
155
- benchmark.meta.task.addEventListener("complete", (e) => {
156
- const task = e.task;
157
- const _benchmark = benchmarkMap[task.name || ""];
158
- if (_benchmark) {
159
- const taskRes = task.result;
160
- const result = _benchmark.result.benchmark;
161
- Object.assign(result, taskRes);
162
- updateTask$1(_benchmark);
163
- }
164
- });
165
- benchmark.meta.task.addEventListener("error", (e) => {
166
- const task = e.task;
167
- const _benchmark = benchmarkMap[task.name || ""];
168
- defer.reject(_benchmark ? task.result.error : e);
169
- });
170
- });
171
- Promise.all(benchmarkGroup.map(async (benchmark) => {
172
- await benchmark.meta.task.warmup();
173
- const { setTimeout } = getSafeTimers();
174
- return await new Promise((resolve) => setTimeout(async () => {
175
- resolve(await benchmark.meta.task.run());
176
- }));
177
- })).then((tasks) => {
178
- suite.result.duration = performance.now() - start;
179
- suite.result.state = "pass";
180
- tasks.sort((a, b) => a.result.mean - b.result.mean).forEach((cycle, idx) => {
181
- const benchmark = benchmarkMap[cycle.name || ""];
182
- benchmark.result.state = "pass";
183
- if (benchmark) {
184
- const result = benchmark.result.benchmark;
185
- result.rank = Number(idx) + 1;
186
- updateTask$1(benchmark);
187
- }
188
- });
189
- updateTask$1(suite);
190
- defer.resolve(null);
191
- });
192
- await defer;
193
- }
194
- function updateTask$1(task) {
195
- updateTask(task, runner);
196
- }
197
- }
198
- class NodeBenchmarkRunner {
199
- constructor(config) {
200
- this.config = config;
201
- }
202
- importFile(filepath, source) {
203
- if (source === "setup")
204
- getWorkerState().moduleCache.delete(filepath);
205
- return import(filepath);
206
- }
207
- async runSuite(suite) {
208
- await runBenchmarkSuite(suite, this);
209
- }
210
- async runTest() {
211
- throw new Error("`test()` and `it()` is only available in test mode.");
212
- }
213
- }
214
-
215
- export { NodeBenchmarkRunner as N, VitestTestRunner as V };