vitest 0.0.97 → 0.0.101

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,236 +0,0 @@
1
- import { n as nanoid } from './index-9e71c815.js';
2
-
3
- const context = {
4
- tasks: [],
5
- currentSuite: null
6
- };
7
- function collectTask(task) {
8
- var _a;
9
- (_a = context.currentSuite) == null ? void 0 : _a.tasks.push(task);
10
- }
11
- async function runWithSuite(suite, fn) {
12
- const prev = context.currentSuite;
13
- context.currentSuite = suite;
14
- await fn();
15
- context.currentSuite = prev;
16
- }
17
- function getDefaultTestTimeout() {
18
- var _a, _b;
19
- return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.testTimeout) ?? 5e3;
20
- }
21
- function getDefaultHookTimeout() {
22
- var _a, _b;
23
- return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.hookTimeout) ?? 5e3;
24
- }
25
- function withTimeout(fn, _timeout) {
26
- const timeout = _timeout ?? getDefaultTestTimeout();
27
- if (timeout <= 0 || timeout === Infinity)
28
- return fn;
29
- return (...args) => {
30
- return Promise.race([fn(...args), new Promise((resolve, reject) => {
31
- const timer = setTimeout(() => {
32
- clearTimeout(timer);
33
- reject(new Error(`Test timed out in ${timeout}ms.`));
34
- }, timeout);
35
- timer.unref();
36
- })]);
37
- };
38
- }
39
- function ensureAsyncTest(fn) {
40
- if (!fn.length)
41
- return fn;
42
- return () => new Promise((resolve, reject) => {
43
- const done = (...args) => args[0] ? reject(args[0]) : resolve();
44
- fn(done);
45
- });
46
- }
47
- function normalizeTest(fn, timeout) {
48
- return withTimeout(ensureAsyncTest(fn), timeout);
49
- }
50
-
51
- const fnMap = /* @__PURE__ */ new WeakMap();
52
- const hooksMap = /* @__PURE__ */ new WeakMap();
53
- function setFn(key, fn) {
54
- fnMap.set(key, fn);
55
- }
56
- function getFn(key) {
57
- return fnMap.get(key);
58
- }
59
- function setHooks(key, hooks) {
60
- hooksMap.set(key, hooks);
61
- }
62
- function getHooks(key) {
63
- return hooksMap.get(key);
64
- }
65
-
66
- const suite = createSuite();
67
- const defaultSuite = suite("");
68
- function clearContext() {
69
- context.tasks.length = 0;
70
- defaultSuite.clear();
71
- context.currentSuite = defaultSuite;
72
- }
73
- function getCurrentSuite() {
74
- return context.currentSuite || defaultSuite;
75
- }
76
- function createSuiteHooks() {
77
- return {
78
- beforeAll: [],
79
- afterAll: [],
80
- beforeEach: [],
81
- afterEach: []
82
- };
83
- }
84
- function createSuiteCollector(name, factory = () => {
85
- }, mode, suiteComputeMode) {
86
- const tasks = [];
87
- const factoryQueue = [];
88
- let suite2;
89
- initSuite();
90
- const test2 = createTestCollector((name2, fn, mode2, computeMode) => {
91
- const test3 = {
92
- id: nanoid(),
93
- type: "test",
94
- name: name2,
95
- mode: mode2,
96
- computeMode: computeMode ?? (suiteComputeMode ?? "serial"),
97
- suite: void 0
98
- };
99
- setFn(test3, fn);
100
- tasks.push(test3);
101
- });
102
- const collector = {
103
- type: "collector",
104
- name,
105
- mode,
106
- test: test2,
107
- tasks,
108
- collect,
109
- clear,
110
- on: addHook
111
- };
112
- function addHook(name2, ...fn) {
113
- getHooks(suite2)[name2].push(...fn);
114
- }
115
- function initSuite() {
116
- suite2 = {
117
- id: nanoid(),
118
- type: "suite",
119
- computeMode: "serial",
120
- name,
121
- mode,
122
- tasks: []
123
- };
124
- setHooks(suite2, createSuiteHooks());
125
- }
126
- function clear() {
127
- tasks.length = 0;
128
- factoryQueue.length = 0;
129
- initSuite();
130
- }
131
- async function collect(file) {
132
- factoryQueue.length = 0;
133
- if (factory)
134
- await runWithSuite(collector, () => factory(test2));
135
- const allChildren = await Promise.all([...factoryQueue, ...tasks].map((i) => i.type === "collector" ? i.collect(file) : i));
136
- suite2.file = file;
137
- suite2.tasks = allChildren;
138
- allChildren.forEach((task) => {
139
- task.suite = suite2;
140
- if (file)
141
- task.file = file;
142
- });
143
- return suite2;
144
- }
145
- collectTask(collector);
146
- return collector;
147
- }
148
- function createTestCollector(collectTest) {
149
- function test2(name, fn, timeout) {
150
- collectTest(name, normalizeTest(fn, timeout), "run");
151
- }
152
- test2.concurrent = concurrent;
153
- test2.skip = skip;
154
- test2.only = only;
155
- test2.todo = todo;
156
- function concurrent(name, fn, timeout) {
157
- collectTest(name, normalizeTest(fn, timeout), "run", "concurrent");
158
- }
159
- concurrent.skip = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "skip", "concurrent");
160
- concurrent.only = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "only", "concurrent");
161
- concurrent.todo = todo;
162
- function skip(name, fn, timeout) {
163
- collectTest(name, normalizeTest(fn, timeout), "skip");
164
- }
165
- skip.concurrent = concurrent.skip;
166
- function only(name, fn, timeout) {
167
- collectTest(name, normalizeTest(fn, timeout), "only");
168
- }
169
- only.concurrent = concurrent.only;
170
- function todo(name) {
171
- collectTest(name, () => {
172
- }, "todo");
173
- }
174
- todo.concurrent = todo;
175
- return test2;
176
- }
177
- const test = function() {
178
- function test2(name, fn, timeout) {
179
- return getCurrentSuite().test(name, fn, timeout);
180
- }
181
- function concurrent(name, fn, timeout) {
182
- return getCurrentSuite().test.concurrent(name, fn, timeout);
183
- }
184
- concurrent.skip = (name, fn, timeout) => getCurrentSuite().test.concurrent.skip(name, fn, timeout);
185
- concurrent.only = (name, fn, timeout) => getCurrentSuite().test.concurrent.only(name, fn, timeout);
186
- concurrent.todo = (name) => getCurrentSuite().test.concurrent.todo(name);
187
- function skip(name, fn, timeout) {
188
- return getCurrentSuite().test.skip(name, fn, timeout);
189
- }
190
- skip.concurrent = (name, fn, timeout) => getCurrentSuite().test.skip.concurrent(name, fn, timeout);
191
- function only(name, fn, timeout) {
192
- return getCurrentSuite().test.only(name, fn, timeout);
193
- }
194
- only.concurrent = (name, fn, timeout) => getCurrentSuite().test.only.concurrent(name, fn, timeout);
195
- function todo(name) {
196
- return getCurrentSuite().test.todo(name);
197
- }
198
- todo.concurrent = (name) => getCurrentSuite().test.todo.concurrent(name);
199
- test2.concurrent = concurrent;
200
- test2.skip = skip;
201
- test2.only = only;
202
- test2.todo = todo;
203
- return test2;
204
- }();
205
- function createSuite() {
206
- function suite2(suiteName, factory) {
207
- return createSuiteCollector(suiteName, factory, "run");
208
- }
209
- function concurrent(suiteName, factory) {
210
- return createSuiteCollector(suiteName, factory, "run", "concurrent");
211
- }
212
- concurrent.skip = (suiteName, factory) => createSuiteCollector(suiteName, factory, "skip", "concurrent");
213
- concurrent.only = (suiteName, factory) => createSuiteCollector(suiteName, factory, "only", "concurrent");
214
- concurrent.todo = (suiteName) => createSuiteCollector(suiteName, void 0, "todo");
215
- function skip(suiteName, factory) {
216
- return createSuiteCollector(suiteName, factory, "skip");
217
- }
218
- skip.concurrent = concurrent.skip;
219
- function only(suiteName, factory) {
220
- return createSuiteCollector(suiteName, factory, "only");
221
- }
222
- only.concurrent = concurrent.only;
223
- function todo(suiteName) {
224
- return createSuiteCollector(suiteName, void 0, "todo");
225
- }
226
- todo.concurrent = concurrent.todo;
227
- suite2.concurrent = concurrent;
228
- suite2.skip = skip;
229
- suite2.only = only;
230
- suite2.todo = todo;
231
- return suite2;
232
- }
233
- const describe = suite;
234
- const it = test;
235
-
236
- export { getDefaultHookTimeout as a, setHooks as b, createSuiteHooks as c, describe as d, clearContext as e, defaultSuite as f, getCurrentSuite as g, context as h, it as i, getHooks as j, getFn as k, suite as s, test as t, withTimeout as w };