vitest 0.0.90 → 0.0.94
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.
- package/bin/vitest.mjs +6 -2
- package/dist/cli.js +19 -12
- package/dist/{constants-adef7ffb.js → constants-9cfa4d7b.js} +1 -2
- package/dist/entry.js +151 -20
- package/dist/{error-309196c9.js → error-81292c96.js} +11 -11
- package/dist/{global-f3eab75a.js → global-473089f7.js} +2 -2
- package/dist/index-368448f4.js +352 -0
- package/dist/index-5cc247ff.js +331 -0
- package/dist/index-de606d4a.js +5539 -0
- package/dist/index-e7a421bb.js +2409 -0
- package/dist/index-fa899e66.js +5707 -0
- package/dist/index.d.ts +72 -5
- package/dist/index.js +2 -2
- package/dist/middleware-bf0f818d.js +78 -0
- package/dist/node.js +8 -7
- package/dist/{utils-385e2d09.js → utils-576876dc.js} +35 -16
- package/dist/utils.js +2 -2
- package/dist/worker.js +8 -16
- package/global.d.ts +1 -2
- package/package.json +8 -5
- package/dist/index-722fb5a5.js +0 -122
- package/dist/index-733e7378.js +0 -1896
- package/dist/middleware-650c5fa0.js +0 -34
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-b8c6cb53.js';
|
|
2
|
+
import chai, { util, assert, should, expect } from 'chai';
|
|
3
|
+
import * as tinyspy from 'tinyspy';
|
|
4
|
+
import { spies } from 'tinyspy';
|
|
5
|
+
|
|
6
|
+
const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
7
|
+
const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
8
|
+
const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
9
|
+
const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
10
|
+
|
|
11
|
+
function spyOn(obj, method, accessType) {
|
|
12
|
+
const dictionary = {
|
|
13
|
+
get: "getter",
|
|
14
|
+
set: "setter"
|
|
15
|
+
};
|
|
16
|
+
const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
|
|
17
|
+
const stub = tinyspy.spyOn(obj, objMethod);
|
|
18
|
+
return enhanceSpy(stub);
|
|
19
|
+
}
|
|
20
|
+
function enhanceSpy(spy) {
|
|
21
|
+
const stub = spy;
|
|
22
|
+
let implementation;
|
|
23
|
+
const instances = [];
|
|
24
|
+
const mockContext = {
|
|
25
|
+
get calls() {
|
|
26
|
+
return stub.calls;
|
|
27
|
+
},
|
|
28
|
+
get instances() {
|
|
29
|
+
return instances;
|
|
30
|
+
},
|
|
31
|
+
get invocationCallOrder() {
|
|
32
|
+
return [];
|
|
33
|
+
},
|
|
34
|
+
get results() {
|
|
35
|
+
return stub.results.map(([callType, value]) => {
|
|
36
|
+
const type = callType === "error" ? "throw" : "return";
|
|
37
|
+
return { type, value };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
let onceImplementations = [];
|
|
42
|
+
let name = "";
|
|
43
|
+
Object.defineProperty(stub, "name", {
|
|
44
|
+
get: () => name
|
|
45
|
+
});
|
|
46
|
+
stub.getMockName = () => name || "vi.fn()";
|
|
47
|
+
stub.mockName = (n) => {
|
|
48
|
+
name = n;
|
|
49
|
+
return stub;
|
|
50
|
+
};
|
|
51
|
+
stub.mockClear = () => {
|
|
52
|
+
stub.reset();
|
|
53
|
+
return stub;
|
|
54
|
+
};
|
|
55
|
+
stub.mockReset = () => {
|
|
56
|
+
stub.reset();
|
|
57
|
+
return stub;
|
|
58
|
+
};
|
|
59
|
+
stub.mockRestore = () => {
|
|
60
|
+
implementation = void 0;
|
|
61
|
+
onceImplementations = [];
|
|
62
|
+
stub.reset();
|
|
63
|
+
stub.restore();
|
|
64
|
+
return stub;
|
|
65
|
+
};
|
|
66
|
+
stub.getMockImplementation = () => implementation;
|
|
67
|
+
stub.mockImplementation = (fn2) => {
|
|
68
|
+
implementation = fn2;
|
|
69
|
+
return stub;
|
|
70
|
+
};
|
|
71
|
+
stub.mockImplementationOnce = (fn2) => {
|
|
72
|
+
onceImplementations.push(fn2);
|
|
73
|
+
return stub;
|
|
74
|
+
};
|
|
75
|
+
stub.mockReturnThis = () => stub.mockImplementation(function() {
|
|
76
|
+
return this;
|
|
77
|
+
});
|
|
78
|
+
stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
|
|
79
|
+
stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
|
|
80
|
+
stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
|
|
81
|
+
stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
|
|
82
|
+
stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
|
|
83
|
+
stub.mockRejectedValueOnce = (val) => stub.mockImplementation(() => Promise.reject(val));
|
|
84
|
+
util.addProperty(stub, "mock", () => mockContext);
|
|
85
|
+
stub.willCall(function(...args) {
|
|
86
|
+
instances.push(this);
|
|
87
|
+
const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
|
|
88
|
+
});
|
|
89
|
+
return impl.apply(this, args);
|
|
90
|
+
});
|
|
91
|
+
return stub;
|
|
92
|
+
}
|
|
93
|
+
function fn(implementation) {
|
|
94
|
+
return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
|
|
95
|
+
}) }, "fn"));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const originalSetTimeout = global.setTimeout;
|
|
99
|
+
const originalSetInterval = global.setInterval;
|
|
100
|
+
const originalClearTimeout = global.clearTimeout;
|
|
101
|
+
const originalClearInterval = global.clearInterval;
|
|
102
|
+
const MAX_LOOPS = 1e4;
|
|
103
|
+
const assertEvery = (assertions, message) => {
|
|
104
|
+
if (assertions.some((a) => !a))
|
|
105
|
+
throw new Error(message);
|
|
106
|
+
};
|
|
107
|
+
const assertMaxLoop = (times) => {
|
|
108
|
+
if (times >= MAX_LOOPS)
|
|
109
|
+
throw new Error("setTimeout/setInterval called 10 000 times. It's possible it stuck in an infinite loop.");
|
|
110
|
+
};
|
|
111
|
+
const getNodeTimeout = (id) => {
|
|
112
|
+
const timer = {
|
|
113
|
+
ref: () => timer,
|
|
114
|
+
unref: () => timer,
|
|
115
|
+
hasRef: () => true,
|
|
116
|
+
refresh: () => timer,
|
|
117
|
+
[Symbol.toPrimitive]: () => id
|
|
118
|
+
};
|
|
119
|
+
return timer;
|
|
120
|
+
};
|
|
121
|
+
class FakeTimers {
|
|
122
|
+
constructor() {
|
|
123
|
+
this._advancedTime = 0;
|
|
124
|
+
this._nestedTime = {};
|
|
125
|
+
this._scopeId = 0;
|
|
126
|
+
this._isNested = false;
|
|
127
|
+
this._isOnlyPending = false;
|
|
128
|
+
this._spyid = 0;
|
|
129
|
+
this._isMocked = false;
|
|
130
|
+
this._tasksQueue = [];
|
|
131
|
+
this._queueCount = 0;
|
|
132
|
+
}
|
|
133
|
+
useFakeTimers() {
|
|
134
|
+
this._isMocked = true;
|
|
135
|
+
this.reset();
|
|
136
|
+
const spyFactory = (spyType, resultBuilder) => {
|
|
137
|
+
return (cb, ms = 0) => {
|
|
138
|
+
const id = ++this._spyid;
|
|
139
|
+
const nestedTo = Object.entries(this._nestedTime).filter(([key]) => Number(key) <= this._scopeId);
|
|
140
|
+
const nestedMs = nestedTo.reduce((total, [, ms2]) => total + ms2, ms);
|
|
141
|
+
const call = { id, cb, ms, nestedMs, scopeId: this._scopeId };
|
|
142
|
+
const task = { type: spyType, call, nested: this._isNested };
|
|
143
|
+
this.pushTask(task);
|
|
144
|
+
return resultBuilder(id, cb);
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory("timeout" /* Timeout */, getNodeTimeout));
|
|
148
|
+
this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory("interval" /* Interval */, getNodeTimeout));
|
|
149
|
+
const clearTimerFactory = (spyType) => (id) => {
|
|
150
|
+
if (id === void 0)
|
|
151
|
+
return;
|
|
152
|
+
const index = this._tasksQueue.findIndex(({ call, type }) => type === spyType && call.id === Number(id));
|
|
153
|
+
if (index !== -1)
|
|
154
|
+
this._tasksQueue.splice(index, 1);
|
|
155
|
+
};
|
|
156
|
+
this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory("timeout" /* Timeout */));
|
|
157
|
+
this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory("interval" /* Interval */));
|
|
158
|
+
}
|
|
159
|
+
useRealTimers() {
|
|
160
|
+
this._isMocked = false;
|
|
161
|
+
this.reset();
|
|
162
|
+
global.setTimeout = originalSetTimeout;
|
|
163
|
+
global.setInterval = originalSetInterval;
|
|
164
|
+
global.clearTimeout = originalClearTimeout;
|
|
165
|
+
global.clearInterval = originalClearInterval;
|
|
166
|
+
}
|
|
167
|
+
runOnlyPendingTimers() {
|
|
168
|
+
this.assertMocked();
|
|
169
|
+
this._isOnlyPending = true;
|
|
170
|
+
this.runQueue();
|
|
171
|
+
}
|
|
172
|
+
runAllTimers() {
|
|
173
|
+
this.assertMocked();
|
|
174
|
+
this.runQueue();
|
|
175
|
+
}
|
|
176
|
+
advanceTimersByTime(ms) {
|
|
177
|
+
this.assertMocked();
|
|
178
|
+
this._advancedTime += ms;
|
|
179
|
+
this.runQueue();
|
|
180
|
+
}
|
|
181
|
+
advanceTimersToNextTimer() {
|
|
182
|
+
throw new Error("advanceTimersToNextTimer is not implemented");
|
|
183
|
+
}
|
|
184
|
+
runAllTicks() {
|
|
185
|
+
throw new Error("runAllTicks is not implemented");
|
|
186
|
+
}
|
|
187
|
+
setSystemTime(now) {
|
|
188
|
+
throw new Error("setSystemTime is not implemented");
|
|
189
|
+
}
|
|
190
|
+
getRealSystemTime() {
|
|
191
|
+
return Date.now();
|
|
192
|
+
}
|
|
193
|
+
getTimerCount() {
|
|
194
|
+
this.assertMocked();
|
|
195
|
+
return this._tasksQueue.length;
|
|
196
|
+
}
|
|
197
|
+
reset() {
|
|
198
|
+
var _a, _b, _c, _d;
|
|
199
|
+
this._advancedTime = 0;
|
|
200
|
+
this._nestedTime = {};
|
|
201
|
+
this._isNested = false;
|
|
202
|
+
this._isOnlyPending = false;
|
|
203
|
+
this._spyid = 0;
|
|
204
|
+
this._queueCount = 0;
|
|
205
|
+
this._tasksQueue = [];
|
|
206
|
+
(_a = this._clearInterval) == null ? void 0 : _a.mockRestore();
|
|
207
|
+
(_b = this._clearTimeout) == null ? void 0 : _b.mockRestore();
|
|
208
|
+
(_c = this._setInterval) == null ? void 0 : _c.mockRestore();
|
|
209
|
+
(_d = this._setTimeout) == null ? void 0 : _d.mockRestore();
|
|
210
|
+
}
|
|
211
|
+
runQueue() {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
let index = 0;
|
|
214
|
+
while (this._tasksQueue[index]) {
|
|
215
|
+
assertMaxLoop(this._queueCount);
|
|
216
|
+
const task = this._tasksQueue[index];
|
|
217
|
+
const { call, nested, type } = task;
|
|
218
|
+
if (this._advancedTime && call.nestedMs > this._advancedTime)
|
|
219
|
+
break;
|
|
220
|
+
if (this._isOnlyPending && nested) {
|
|
221
|
+
index++;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
this._scopeId = call.id;
|
|
225
|
+
this._isNested = true;
|
|
226
|
+
(_a = this._nestedTime)[_b = call.id] ?? (_a[_b] = 0);
|
|
227
|
+
this._nestedTime[call.id] += call.ms;
|
|
228
|
+
if (type === "timeout") {
|
|
229
|
+
this.removeTask(index);
|
|
230
|
+
} else if (type === "interval") {
|
|
231
|
+
call.nestedMs += call.ms;
|
|
232
|
+
const nestedMs = call.nestedMs;
|
|
233
|
+
const closestTask = this._tasksQueue.findIndex(({ type: type2, call: call2 }) => type2 === "interval" && call2.nestedMs < nestedMs);
|
|
234
|
+
if (closestTask !== -1 && closestTask !== index)
|
|
235
|
+
this.ensureQueueOrder();
|
|
236
|
+
}
|
|
237
|
+
call.cb();
|
|
238
|
+
this._queueCount++;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
removeTask(index) {
|
|
242
|
+
if (index === 0)
|
|
243
|
+
this._tasksQueue.shift();
|
|
244
|
+
else
|
|
245
|
+
this._tasksQueue.splice(index, 1);
|
|
246
|
+
}
|
|
247
|
+
pushTask(task) {
|
|
248
|
+
this._tasksQueue.push(task);
|
|
249
|
+
this.ensureQueueOrder();
|
|
250
|
+
}
|
|
251
|
+
ensureQueueOrder() {
|
|
252
|
+
this._tasksQueue.sort((t1, t2) => {
|
|
253
|
+
const diff = t1.call.nestedMs - t2.call.nestedMs;
|
|
254
|
+
if (diff === 0) {
|
|
255
|
+
if (t1.type === "immediate" /* Immediate */ && t2.type !== "immediate" /* Immediate */)
|
|
256
|
+
return 1;
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
259
|
+
return diff;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
assertMocked() {
|
|
263
|
+
assertEvery([
|
|
264
|
+
this._isMocked,
|
|
265
|
+
this._setTimeout,
|
|
266
|
+
this._setInterval,
|
|
267
|
+
this._clearTimeout,
|
|
268
|
+
this._clearInterval
|
|
269
|
+
], 'timers are not mocked. try calling "vitest.useFakeTimers()" first');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
class VitestUtils {
|
|
274
|
+
constructor() {
|
|
275
|
+
this.spyOn = spyOn;
|
|
276
|
+
this.fn = fn;
|
|
277
|
+
this.mock = (path) => path;
|
|
278
|
+
this._timers = new FakeTimers();
|
|
279
|
+
}
|
|
280
|
+
useFakeTimers() {
|
|
281
|
+
return this._timers.useFakeTimers();
|
|
282
|
+
}
|
|
283
|
+
useRealTimers() {
|
|
284
|
+
return this._timers.useRealTimers();
|
|
285
|
+
}
|
|
286
|
+
runOnlyPendingTimers() {
|
|
287
|
+
return this._timers.runOnlyPendingTimers();
|
|
288
|
+
}
|
|
289
|
+
runAllTimers() {
|
|
290
|
+
return this._timers.runAllTimers();
|
|
291
|
+
}
|
|
292
|
+
advanceTimersByTime(ms) {
|
|
293
|
+
return this._timers.advanceTimersByTime(ms);
|
|
294
|
+
}
|
|
295
|
+
advanceTimersToNextTimer() {
|
|
296
|
+
return this._timers.advanceTimersToNextTimer();
|
|
297
|
+
}
|
|
298
|
+
runAllTicks() {
|
|
299
|
+
return this._timers.runAllTicks();
|
|
300
|
+
}
|
|
301
|
+
setSystemTime(time) {
|
|
302
|
+
return this._timers.setSystemTime(time);
|
|
303
|
+
}
|
|
304
|
+
getRealSystemTime() {
|
|
305
|
+
return this._timers.getRealSystemTime();
|
|
306
|
+
}
|
|
307
|
+
getTimerCount() {
|
|
308
|
+
return this._timers.getTimerCount();
|
|
309
|
+
}
|
|
310
|
+
isMockFunction(fn2) {
|
|
311
|
+
return typeof fn2 === "function" && "__isSpy" in fn2 && fn2.__isSpy;
|
|
312
|
+
}
|
|
313
|
+
clearAllMocks() {
|
|
314
|
+
spies.forEach((spy) => {
|
|
315
|
+
spy.reset();
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
resetAllMocks() {
|
|
319
|
+
spies.forEach((spy) => {
|
|
320
|
+
spy.reset();
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
restoreAllMocks() {
|
|
324
|
+
spies.forEach((spy) => {
|
|
325
|
+
spy.restore();
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const vitest = new VitestUtils();
|
|
330
|
+
const vi = vitest;
|
|
331
|
+
|
|
332
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
333
|
+
__proto__: null,
|
|
334
|
+
suite: suite,
|
|
335
|
+
test: test,
|
|
336
|
+
describe: describe,
|
|
337
|
+
it: it,
|
|
338
|
+
beforeAll: beforeAll,
|
|
339
|
+
afterAll: afterAll,
|
|
340
|
+
beforeEach: beforeEach,
|
|
341
|
+
afterEach: afterEach,
|
|
342
|
+
assert: assert,
|
|
343
|
+
should: should,
|
|
344
|
+
expect: expect,
|
|
345
|
+
chai: chai,
|
|
346
|
+
spyOn: spyOn,
|
|
347
|
+
fn: fn,
|
|
348
|
+
vitest: vitest,
|
|
349
|
+
vi: vi
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, vi as e, fn as f, index as i, spyOn as s, vitest as v };
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import assert$1 from 'assert';
|
|
2
|
+
import require$$2 from 'events';
|
|
3
|
+
|
|
4
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
5
|
+
|
|
6
|
+
var onetime$2 = {exports: {}};
|
|
7
|
+
|
|
8
|
+
var mimicFn$2 = {exports: {}};
|
|
9
|
+
|
|
10
|
+
const mimicFn$1 = (to, from) => {
|
|
11
|
+
for (const prop of Reflect.ownKeys(from)) {
|
|
12
|
+
Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
mimicFn$2.exports = mimicFn$1;
|
|
19
|
+
// TODO: Remove this for the next major release
|
|
20
|
+
mimicFn$2.exports.default = mimicFn$1;
|
|
21
|
+
|
|
22
|
+
const mimicFn = mimicFn$2.exports;
|
|
23
|
+
|
|
24
|
+
const calledFunctions = new WeakMap();
|
|
25
|
+
|
|
26
|
+
const onetime = (function_, options = {}) => {
|
|
27
|
+
if (typeof function_ !== 'function') {
|
|
28
|
+
throw new TypeError('Expected a function');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let returnValue;
|
|
32
|
+
let callCount = 0;
|
|
33
|
+
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
34
|
+
|
|
35
|
+
const onetime = function (...arguments_) {
|
|
36
|
+
calledFunctions.set(onetime, ++callCount);
|
|
37
|
+
|
|
38
|
+
if (callCount === 1) {
|
|
39
|
+
returnValue = function_.apply(this, arguments_);
|
|
40
|
+
function_ = null;
|
|
41
|
+
} else if (options.throw === true) {
|
|
42
|
+
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return returnValue;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
mimicFn(onetime, function_);
|
|
49
|
+
calledFunctions.set(onetime, callCount);
|
|
50
|
+
|
|
51
|
+
return onetime;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
onetime$2.exports = onetime;
|
|
55
|
+
// TODO: Remove this for the next major release
|
|
56
|
+
onetime$2.exports.default = onetime;
|
|
57
|
+
|
|
58
|
+
onetime$2.exports.callCount = function_ => {
|
|
59
|
+
if (!calledFunctions.has(function_)) {
|
|
60
|
+
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return calledFunctions.get(function_);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
var onetime$1 = onetime$2.exports;
|
|
67
|
+
|
|
68
|
+
var signalExit$1 = {exports: {}};
|
|
69
|
+
|
|
70
|
+
var signals$1 = {exports: {}};
|
|
71
|
+
|
|
72
|
+
(function (module) {
|
|
73
|
+
// This is not the set of all possible signals.
|
|
74
|
+
//
|
|
75
|
+
// It IS, however, the set of all signals that trigger
|
|
76
|
+
// an exit on either Linux or BSD systems. Linux is a
|
|
77
|
+
// superset of the signal names supported on BSD, and
|
|
78
|
+
// the unknown signals just fail to register, so we can
|
|
79
|
+
// catch that easily enough.
|
|
80
|
+
//
|
|
81
|
+
// Don't bother with SIGKILL. It's uncatchable, which
|
|
82
|
+
// means that we can't fire any callbacks anyway.
|
|
83
|
+
//
|
|
84
|
+
// If a user does happen to register a handler on a non-
|
|
85
|
+
// fatal signal like SIGWINCH or something, and then
|
|
86
|
+
// exit, it'll end up firing `process.emit('exit')`, so
|
|
87
|
+
// the handler will be fired anyway.
|
|
88
|
+
//
|
|
89
|
+
// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
|
90
|
+
// artificially, inherently leave the process in a
|
|
91
|
+
// state from which it is not safe to try and enter JS
|
|
92
|
+
// listeners.
|
|
93
|
+
module.exports = [
|
|
94
|
+
'SIGABRT',
|
|
95
|
+
'SIGALRM',
|
|
96
|
+
'SIGHUP',
|
|
97
|
+
'SIGINT',
|
|
98
|
+
'SIGTERM'
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
if (process.platform !== 'win32') {
|
|
102
|
+
module.exports.push(
|
|
103
|
+
'SIGVTALRM',
|
|
104
|
+
'SIGXCPU',
|
|
105
|
+
'SIGXFSZ',
|
|
106
|
+
'SIGUSR2',
|
|
107
|
+
'SIGTRAP',
|
|
108
|
+
'SIGSYS',
|
|
109
|
+
'SIGQUIT',
|
|
110
|
+
'SIGIOT'
|
|
111
|
+
// should detect profiler and enable/disable accordingly.
|
|
112
|
+
// see #21
|
|
113
|
+
// 'SIGPROF'
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (process.platform === 'linux') {
|
|
118
|
+
module.exports.push(
|
|
119
|
+
'SIGIO',
|
|
120
|
+
'SIGPOLL',
|
|
121
|
+
'SIGPWR',
|
|
122
|
+
'SIGSTKFLT',
|
|
123
|
+
'SIGUNUSED'
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}(signals$1));
|
|
127
|
+
|
|
128
|
+
// Note: since nyc uses this module to output coverage, any lines
|
|
129
|
+
// that are in the direct sync flow of nyc's outputCoverage are
|
|
130
|
+
// ignored, since we can never get coverage for them.
|
|
131
|
+
// grab a reference to node's real process object right away
|
|
132
|
+
var process$1 = commonjsGlobal.process;
|
|
133
|
+
|
|
134
|
+
const processOk = function (process) {
|
|
135
|
+
return process &&
|
|
136
|
+
typeof process === 'object' &&
|
|
137
|
+
typeof process.removeListener === 'function' &&
|
|
138
|
+
typeof process.emit === 'function' &&
|
|
139
|
+
typeof process.reallyExit === 'function' &&
|
|
140
|
+
typeof process.listeners === 'function' &&
|
|
141
|
+
typeof process.kill === 'function' &&
|
|
142
|
+
typeof process.pid === 'number' &&
|
|
143
|
+
typeof process.on === 'function'
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// some kind of non-node environment, just no-op
|
|
147
|
+
/* istanbul ignore if */
|
|
148
|
+
if (!processOk(process$1)) {
|
|
149
|
+
signalExit$1.exports = function () {};
|
|
150
|
+
} else {
|
|
151
|
+
var assert = assert$1;
|
|
152
|
+
var signals = signals$1.exports;
|
|
153
|
+
var isWin = /^win/i.test(process$1.platform);
|
|
154
|
+
|
|
155
|
+
var EE = require$$2;
|
|
156
|
+
/* istanbul ignore if */
|
|
157
|
+
if (typeof EE !== 'function') {
|
|
158
|
+
EE = EE.EventEmitter;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var emitter;
|
|
162
|
+
if (process$1.__signal_exit_emitter__) {
|
|
163
|
+
emitter = process$1.__signal_exit_emitter__;
|
|
164
|
+
} else {
|
|
165
|
+
emitter = process$1.__signal_exit_emitter__ = new EE();
|
|
166
|
+
emitter.count = 0;
|
|
167
|
+
emitter.emitted = {};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Because this emitter is a global, we have to check to see if a
|
|
171
|
+
// previous version of this library failed to enable infinite listeners.
|
|
172
|
+
// I know what you're about to say. But literally everything about
|
|
173
|
+
// signal-exit is a compromise with evil. Get used to it.
|
|
174
|
+
if (!emitter.infinite) {
|
|
175
|
+
emitter.setMaxListeners(Infinity);
|
|
176
|
+
emitter.infinite = true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
signalExit$1.exports = function (cb, opts) {
|
|
180
|
+
/* istanbul ignore if */
|
|
181
|
+
if (!processOk(commonjsGlobal.process)) {
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
|
|
185
|
+
|
|
186
|
+
if (loaded === false) {
|
|
187
|
+
load();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var ev = 'exit';
|
|
191
|
+
if (opts && opts.alwaysLast) {
|
|
192
|
+
ev = 'afterexit';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
var remove = function () {
|
|
196
|
+
emitter.removeListener(ev, cb);
|
|
197
|
+
if (emitter.listeners('exit').length === 0 &&
|
|
198
|
+
emitter.listeners('afterexit').length === 0) {
|
|
199
|
+
unload();
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
emitter.on(ev, cb);
|
|
203
|
+
|
|
204
|
+
return remove
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
var unload = function unload () {
|
|
208
|
+
if (!loaded || !processOk(commonjsGlobal.process)) {
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
loaded = false;
|
|
212
|
+
|
|
213
|
+
signals.forEach(function (sig) {
|
|
214
|
+
try {
|
|
215
|
+
process$1.removeListener(sig, sigListeners[sig]);
|
|
216
|
+
} catch (er) {}
|
|
217
|
+
});
|
|
218
|
+
process$1.emit = originalProcessEmit;
|
|
219
|
+
process$1.reallyExit = originalProcessReallyExit;
|
|
220
|
+
emitter.count -= 1;
|
|
221
|
+
};
|
|
222
|
+
signalExit$1.exports.unload = unload;
|
|
223
|
+
|
|
224
|
+
var emit = function emit (event, code, signal) {
|
|
225
|
+
/* istanbul ignore if */
|
|
226
|
+
if (emitter.emitted[event]) {
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
emitter.emitted[event] = true;
|
|
230
|
+
emitter.emit(event, code, signal);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// { <signal>: <listener fn>, ... }
|
|
234
|
+
var sigListeners = {};
|
|
235
|
+
signals.forEach(function (sig) {
|
|
236
|
+
sigListeners[sig] = function listener () {
|
|
237
|
+
/* istanbul ignore if */
|
|
238
|
+
if (!processOk(commonjsGlobal.process)) {
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
// If there are no other listeners, an exit is coming!
|
|
242
|
+
// Simplest way: remove us and then re-send the signal.
|
|
243
|
+
// We know that this will kill the process, so we can
|
|
244
|
+
// safely emit now.
|
|
245
|
+
var listeners = process$1.listeners(sig);
|
|
246
|
+
if (listeners.length === emitter.count) {
|
|
247
|
+
unload();
|
|
248
|
+
emit('exit', null, sig);
|
|
249
|
+
/* istanbul ignore next */
|
|
250
|
+
emit('afterexit', null, sig);
|
|
251
|
+
/* istanbul ignore next */
|
|
252
|
+
if (isWin && sig === 'SIGHUP') {
|
|
253
|
+
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
|
254
|
+
// so use a supported signal instead
|
|
255
|
+
sig = 'SIGINT';
|
|
256
|
+
}
|
|
257
|
+
/* istanbul ignore next */
|
|
258
|
+
process$1.kill(process$1.pid, sig);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
signalExit$1.exports.signals = function () {
|
|
264
|
+
return signals
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
var loaded = false;
|
|
268
|
+
|
|
269
|
+
var load = function load () {
|
|
270
|
+
if (loaded || !processOk(commonjsGlobal.process)) {
|
|
271
|
+
return
|
|
272
|
+
}
|
|
273
|
+
loaded = true;
|
|
274
|
+
|
|
275
|
+
// This is the number of onSignalExit's that are in play.
|
|
276
|
+
// It's important so that we can count the correct number of
|
|
277
|
+
// listeners on signals, and don't wait for the other one to
|
|
278
|
+
// handle it instead of us.
|
|
279
|
+
emitter.count += 1;
|
|
280
|
+
|
|
281
|
+
signals = signals.filter(function (sig) {
|
|
282
|
+
try {
|
|
283
|
+
process$1.on(sig, sigListeners[sig]);
|
|
284
|
+
return true
|
|
285
|
+
} catch (er) {
|
|
286
|
+
return false
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
process$1.emit = processEmit;
|
|
291
|
+
process$1.reallyExit = processReallyExit;
|
|
292
|
+
};
|
|
293
|
+
signalExit$1.exports.load = load;
|
|
294
|
+
|
|
295
|
+
var originalProcessReallyExit = process$1.reallyExit;
|
|
296
|
+
var processReallyExit = function processReallyExit (code) {
|
|
297
|
+
/* istanbul ignore if */
|
|
298
|
+
if (!processOk(commonjsGlobal.process)) {
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
process$1.exitCode = code || /* istanbul ignore next */ 0;
|
|
302
|
+
emit('exit', process$1.exitCode, null);
|
|
303
|
+
/* istanbul ignore next */
|
|
304
|
+
emit('afterexit', process$1.exitCode, null);
|
|
305
|
+
/* istanbul ignore next */
|
|
306
|
+
originalProcessReallyExit.call(process$1, process$1.exitCode);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
var originalProcessEmit = process$1.emit;
|
|
310
|
+
var processEmit = function processEmit (ev, arg) {
|
|
311
|
+
if (ev === 'exit' && processOk(commonjsGlobal.process)) {
|
|
312
|
+
/* istanbul ignore else */
|
|
313
|
+
if (arg !== undefined) {
|
|
314
|
+
process$1.exitCode = arg;
|
|
315
|
+
}
|
|
316
|
+
var ret = originalProcessEmit.apply(this, arguments);
|
|
317
|
+
/* istanbul ignore next */
|
|
318
|
+
emit('exit', process$1.exitCode, null);
|
|
319
|
+
/* istanbul ignore next */
|
|
320
|
+
emit('afterexit', process$1.exitCode, null);
|
|
321
|
+
/* istanbul ignore next */
|
|
322
|
+
return ret
|
|
323
|
+
} else {
|
|
324
|
+
return originalProcessEmit.apply(this, arguments)
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
var signalExit = signalExit$1.exports;
|
|
330
|
+
|
|
331
|
+
export { signalExit$1 as a, onetime$2 as b, commonjsGlobal as c, onetime$1 as o, signalExit as s };
|