vitest 0.0.105 → 0.0.109

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