@rstest/core 0.9.3 → 0.9.5
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/LICENSE.md +0 -228
- package/dist/0~8843.js +33 -17
- package/dist/0~browserLoader.js +1 -1
- package/dist/0~browser~1.js +4 -4
- package/dist/0~checkThresholds.js +1 -1
- package/dist/0~console.js +1 -1
- package/dist/0~fake-timers.js +1483 -0
- package/dist/0~generate.js +4 -3
- package/dist/0~happyDom.js +1 -1
- package/dist/0~jsdom.js +1 -1
- package/dist/0~listTests.js +14 -10
- package/dist/0~loadEsModule.js +3 -1
- package/dist/0~loadModule.js +1 -1
- package/dist/0~runTests.js +17 -6
- package/dist/0~snapshot.js +2140 -0
- package/dist/0~snapshot.js.LICENSE.txt +7 -0
- package/dist/0~utils.js +1 -1
- package/dist/1949.js +2919 -9808
- package/dist/1949.js.LICENSE.txt +1 -49
- package/dist/3145.js +363 -63
- package/dist/4411.js +232 -47
- package/dist/6830.js +61 -9
- package/dist/7552.js +22 -4918
- package/dist/7704.js +1 -2
- package/dist/9743.js +1982 -0
- package/dist/9784.js +1343 -0
- package/dist/{7552.js.LICENSE.txt → 9784.js.LICENSE.txt} +19 -8
- package/dist/browser-runtime/2~fake-timers.js +1653 -0
- package/dist/browser-runtime/2~snapshot.js +2138 -0
- package/dist/browser-runtime/2~snapshot.js.LICENSE.txt +7 -0
- package/dist/browser-runtime/723.js +2055 -10605
- package/dist/browser-runtime/723.js.LICENSE.txt +0 -17
- package/dist/browser-runtime/index.d.ts +189 -11
- package/dist/browser-runtime/rslib-runtime.js +0 -7
- package/dist/browser.d.ts +39 -5
- package/dist/browser.js +2 -2
- package/dist/globalSetupWorker.js +1 -1
- package/dist/index.d.ts +39 -5
- package/dist/mockRuntimeCode.js +2 -0
- package/dist/worker.d.ts +31 -5
- package/dist/worker.js +32 -11
- package/package.json +21 -22
|
@@ -0,0 +1,1483 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import * as __rspack_external_node_util_1b29d436 from "node:util";
|
|
3
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
|
+
import "./4899.js";
|
|
5
|
+
__webpack_require__.add({
|
|
6
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/called-in-order.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
7
|
+
var every = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/array.js").every;
|
|
8
|
+
function hasCallsLeft(callMap, spy) {
|
|
9
|
+
if (void 0 === callMap[spy.id]) callMap[spy.id] = 0;
|
|
10
|
+
return callMap[spy.id] < spy.callCount;
|
|
11
|
+
}
|
|
12
|
+
function checkAdjacentCalls(callMap, spy, index, spies) {
|
|
13
|
+
var calledBeforeNext = true;
|
|
14
|
+
if (index !== spies.length - 1) calledBeforeNext = spy.calledBefore(spies[index + 1]);
|
|
15
|
+
if (hasCallsLeft(callMap, spy) && calledBeforeNext) {
|
|
16
|
+
callMap[spy.id] += 1;
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function calledInOrder(spies) {
|
|
22
|
+
var callMap = {};
|
|
23
|
+
var _spies = arguments.length > 1 ? arguments : spies;
|
|
24
|
+
return every(_spies, checkAdjacentCalls.bind(null, callMap));
|
|
25
|
+
}
|
|
26
|
+
module.exports = calledInOrder;
|
|
27
|
+
},
|
|
28
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/class-name.js" (module) {
|
|
29
|
+
function className(value) {
|
|
30
|
+
const name = value.constructor && value.constructor.name;
|
|
31
|
+
return name || null;
|
|
32
|
+
}
|
|
33
|
+
module.exports = className;
|
|
34
|
+
},
|
|
35
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/deprecated.js" (__unused_rspack_module, exports) {
|
|
36
|
+
exports.wrap = function(func, msg) {
|
|
37
|
+
var wrapped = function() {
|
|
38
|
+
exports.printWarning(msg);
|
|
39
|
+
return func.apply(this, arguments);
|
|
40
|
+
};
|
|
41
|
+
if (func.prototype) wrapped.prototype = func.prototype;
|
|
42
|
+
return wrapped;
|
|
43
|
+
};
|
|
44
|
+
exports.defaultMsg = function(packageName, funcName) {
|
|
45
|
+
return `${packageName}.${funcName} is deprecated and will be removed from the public API in a future version of ${packageName}.`;
|
|
46
|
+
};
|
|
47
|
+
exports.printWarning = function(msg) {
|
|
48
|
+
if ("object" == typeof process && process.emitWarning) process.emitWarning(msg);
|
|
49
|
+
else if (console.info) console.info(msg);
|
|
50
|
+
else console.log(msg);
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/every.js" (module) {
|
|
54
|
+
module.exports = function every(obj, fn) {
|
|
55
|
+
var pass = true;
|
|
56
|
+
try {
|
|
57
|
+
obj.forEach(function() {
|
|
58
|
+
if (!fn.apply(this, arguments)) throw new Error();
|
|
59
|
+
});
|
|
60
|
+
} catch (e) {
|
|
61
|
+
pass = false;
|
|
62
|
+
}
|
|
63
|
+
return pass;
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/function-name.js" (module) {
|
|
67
|
+
module.exports = function functionName(func) {
|
|
68
|
+
if (!func) return "";
|
|
69
|
+
try {
|
|
70
|
+
return func.displayName || func.name || (String(func).match(/function ([^\s(]+)/) || [])[1];
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/global.js" (module) {
|
|
77
|
+
var globalObject;
|
|
78
|
+
globalObject = "u" > typeof global ? global : "u" > typeof window ? window : self;
|
|
79
|
+
module.exports = globalObject;
|
|
80
|
+
},
|
|
81
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/index.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
82
|
+
module.exports = {
|
|
83
|
+
global: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/global.js"),
|
|
84
|
+
calledInOrder: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/called-in-order.js"),
|
|
85
|
+
className: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/class-name.js"),
|
|
86
|
+
deprecated: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/deprecated.js"),
|
|
87
|
+
every: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/every.js"),
|
|
88
|
+
functionName: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/function-name.js"),
|
|
89
|
+
orderByFirstCall: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/order-by-first-call.js"),
|
|
90
|
+
prototypes: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/index.js"),
|
|
91
|
+
typeOf: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/type-of.js"),
|
|
92
|
+
valueToString: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/value-to-string.js")
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/order-by-first-call.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
96
|
+
var sort = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/array.js").sort;
|
|
97
|
+
var slice = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/array.js").slice;
|
|
98
|
+
function comparator(a, b) {
|
|
99
|
+
var aCall = a.getCall(0);
|
|
100
|
+
var bCall = b.getCall(0);
|
|
101
|
+
var aId = aCall && aCall.callId || -1;
|
|
102
|
+
var bId = bCall && bCall.callId || -1;
|
|
103
|
+
return aId < bId ? -1 : 1;
|
|
104
|
+
}
|
|
105
|
+
function orderByFirstCall(spies) {
|
|
106
|
+
return sort(slice(spies), comparator);
|
|
107
|
+
}
|
|
108
|
+
module.exports = orderByFirstCall;
|
|
109
|
+
},
|
|
110
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/array.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
111
|
+
var copyPrototype = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/copy-prototype-methods.js");
|
|
112
|
+
module.exports = copyPrototype(Array.prototype);
|
|
113
|
+
},
|
|
114
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/copy-prototype-methods.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
115
|
+
var call = Function.call;
|
|
116
|
+
var throwsOnProto = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/throws-on-proto.js");
|
|
117
|
+
var disallowedProperties = [
|
|
118
|
+
"size",
|
|
119
|
+
"caller",
|
|
120
|
+
"callee",
|
|
121
|
+
"arguments"
|
|
122
|
+
];
|
|
123
|
+
if (throwsOnProto) disallowedProperties.push("__proto__");
|
|
124
|
+
module.exports = function copyPrototypeMethods(prototype) {
|
|
125
|
+
return Object.getOwnPropertyNames(prototype).reduce(function(result, name) {
|
|
126
|
+
if (disallowedProperties.includes(name)) return result;
|
|
127
|
+
if ("function" != typeof prototype[name]) return result;
|
|
128
|
+
result[name] = call.bind(prototype[name]);
|
|
129
|
+
return result;
|
|
130
|
+
}, Object.create(null));
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/function.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
134
|
+
var copyPrototype = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/copy-prototype-methods.js");
|
|
135
|
+
module.exports = copyPrototype(Function.prototype);
|
|
136
|
+
},
|
|
137
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/index.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
138
|
+
module.exports = {
|
|
139
|
+
array: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/array.js"),
|
|
140
|
+
function: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/function.js"),
|
|
141
|
+
map: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/map.js"),
|
|
142
|
+
object: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/object.js"),
|
|
143
|
+
set: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/set.js"),
|
|
144
|
+
string: __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/string.js")
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/map.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
148
|
+
var copyPrototype = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/copy-prototype-methods.js");
|
|
149
|
+
module.exports = copyPrototype(Map.prototype);
|
|
150
|
+
},
|
|
151
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/object.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
152
|
+
var copyPrototype = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/copy-prototype-methods.js");
|
|
153
|
+
module.exports = copyPrototype(Object.prototype);
|
|
154
|
+
},
|
|
155
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/set.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
156
|
+
var copyPrototype = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/copy-prototype-methods.js");
|
|
157
|
+
module.exports = copyPrototype(Set.prototype);
|
|
158
|
+
},
|
|
159
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/string.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
160
|
+
var copyPrototype = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/copy-prototype-methods.js");
|
|
161
|
+
module.exports = copyPrototype(String.prototype);
|
|
162
|
+
},
|
|
163
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/prototypes/throws-on-proto.js" (module) {
|
|
164
|
+
let throwsOnProto;
|
|
165
|
+
try {
|
|
166
|
+
const object = {};
|
|
167
|
+
object.__proto__;
|
|
168
|
+
throwsOnProto = false;
|
|
169
|
+
} catch (_) {
|
|
170
|
+
throwsOnProto = true;
|
|
171
|
+
}
|
|
172
|
+
module.exports = throwsOnProto;
|
|
173
|
+
},
|
|
174
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/type-of.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
175
|
+
var type = __webpack_require__("../../node_modules/.pnpm/type-detect@4.0.8/node_modules/type-detect/type-detect.js");
|
|
176
|
+
module.exports = function typeOf(value) {
|
|
177
|
+
return type(value).toLowerCase();
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
"../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/value-to-string.js" (module) {
|
|
181
|
+
function valueToString(value) {
|
|
182
|
+
if (value && value.toString) return value.toString();
|
|
183
|
+
return String(value);
|
|
184
|
+
}
|
|
185
|
+
module.exports = valueToString;
|
|
186
|
+
},
|
|
187
|
+
"../../node_modules/.pnpm/@sinonjs+fake-timers@15.1.1/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js" (__unused_rspack_module, exports, __webpack_require__) {
|
|
188
|
+
const globalObject = __webpack_require__("../../node_modules/.pnpm/@sinonjs+commons@3.0.1/node_modules/@sinonjs/commons/lib/index.js").global;
|
|
189
|
+
let timersModule, timersPromisesModule;
|
|
190
|
+
try {
|
|
191
|
+
timersModule = __webpack_require__("timers");
|
|
192
|
+
} catch (e) {}
|
|
193
|
+
try {
|
|
194
|
+
timersPromisesModule = __webpack_require__("timers/promises");
|
|
195
|
+
} catch (e) {}
|
|
196
|
+
function withGlobal(_global) {
|
|
197
|
+
const maxTimeout = Math.pow(2, 31) - 1;
|
|
198
|
+
const idCounterStart = 1e12;
|
|
199
|
+
const NOOP = function() {};
|
|
200
|
+
const NOOP_ARRAY = function() {
|
|
201
|
+
return [];
|
|
202
|
+
};
|
|
203
|
+
const isPresent = {};
|
|
204
|
+
let timeoutResult, addTimerReturnsObject = false;
|
|
205
|
+
if (_global.setTimeout) {
|
|
206
|
+
isPresent.setTimeout = true;
|
|
207
|
+
timeoutResult = _global.setTimeout(NOOP, 0);
|
|
208
|
+
addTimerReturnsObject = "object" == typeof timeoutResult;
|
|
209
|
+
}
|
|
210
|
+
isPresent.clearTimeout = Boolean(_global.clearTimeout);
|
|
211
|
+
isPresent.setInterval = Boolean(_global.setInterval);
|
|
212
|
+
isPresent.clearInterval = Boolean(_global.clearInterval);
|
|
213
|
+
isPresent.hrtime = _global.process && "function" == typeof _global.process.hrtime;
|
|
214
|
+
isPresent.hrtimeBigint = isPresent.hrtime && "function" == typeof _global.process.hrtime.bigint;
|
|
215
|
+
isPresent.nextTick = _global.process && "function" == typeof _global.process.nextTick;
|
|
216
|
+
const utilPromisify = _global.process && __webpack_require__("util").promisify;
|
|
217
|
+
isPresent.performance = _global.performance && "function" == typeof _global.performance.now;
|
|
218
|
+
const hasPerformancePrototype = _global.Performance && (typeof _global.Performance).match(/^(function|object)$/);
|
|
219
|
+
const hasPerformanceConstructorPrototype = _global.performance && _global.performance.constructor && _global.performance.constructor.prototype;
|
|
220
|
+
isPresent.queueMicrotask = _global.hasOwnProperty("queueMicrotask");
|
|
221
|
+
isPresent.requestAnimationFrame = _global.requestAnimationFrame && "function" == typeof _global.requestAnimationFrame;
|
|
222
|
+
isPresent.cancelAnimationFrame = _global.cancelAnimationFrame && "function" == typeof _global.cancelAnimationFrame;
|
|
223
|
+
isPresent.requestIdleCallback = _global.requestIdleCallback && "function" == typeof _global.requestIdleCallback;
|
|
224
|
+
isPresent.cancelIdleCallbackPresent = _global.cancelIdleCallback && "function" == typeof _global.cancelIdleCallback;
|
|
225
|
+
isPresent.setImmediate = _global.setImmediate && "function" == typeof _global.setImmediate;
|
|
226
|
+
isPresent.clearImmediate = _global.clearImmediate && "function" == typeof _global.clearImmediate;
|
|
227
|
+
isPresent.Intl = _global.Intl && "object" == typeof _global.Intl;
|
|
228
|
+
if (_global.clearTimeout) _global.clearTimeout(timeoutResult);
|
|
229
|
+
const NativeDate = _global.Date;
|
|
230
|
+
const NativeIntl = isPresent.Intl ? Object.defineProperties(Object.create(null), Object.getOwnPropertyDescriptors(_global.Intl)) : void 0;
|
|
231
|
+
let uniqueTimerId = idCounterStart;
|
|
232
|
+
if (void 0 === NativeDate) throw new Error("The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)");
|
|
233
|
+
isPresent.Date = true;
|
|
234
|
+
class FakePerformanceEntry {
|
|
235
|
+
constructor(name, entryType, startTime, duration){
|
|
236
|
+
this.name = name;
|
|
237
|
+
this.entryType = entryType;
|
|
238
|
+
this.startTime = startTime;
|
|
239
|
+
this.duration = duration;
|
|
240
|
+
}
|
|
241
|
+
toJSON() {
|
|
242
|
+
return JSON.stringify({
|
|
243
|
+
...this
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function isNumberFinite(num) {
|
|
248
|
+
if (Number.isFinite) return Number.isFinite(num);
|
|
249
|
+
return isFinite(num);
|
|
250
|
+
}
|
|
251
|
+
let isNearInfiniteLimit = false;
|
|
252
|
+
function checkIsNearInfiniteLimit(clock, i) {
|
|
253
|
+
if (clock.loopLimit && i === clock.loopLimit - 1) isNearInfiniteLimit = true;
|
|
254
|
+
}
|
|
255
|
+
function resetIsNearInfiniteLimit() {
|
|
256
|
+
isNearInfiniteLimit = false;
|
|
257
|
+
}
|
|
258
|
+
function parseTime(str) {
|
|
259
|
+
if (!str) return 0;
|
|
260
|
+
const strings = str.split(":");
|
|
261
|
+
const l = strings.length;
|
|
262
|
+
let i = l;
|
|
263
|
+
let ms = 0;
|
|
264
|
+
let parsed;
|
|
265
|
+
if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) throw new Error("tick only understands numbers, 'm:s' and 'h:m:s'. Each part must be two digits");
|
|
266
|
+
while(i--){
|
|
267
|
+
parsed = parseInt(strings[i], 10);
|
|
268
|
+
if (parsed >= 60) throw new Error(`Invalid time ${str}`);
|
|
269
|
+
ms += parsed * Math.pow(60, l - i - 1);
|
|
270
|
+
}
|
|
271
|
+
return 1000 * ms;
|
|
272
|
+
}
|
|
273
|
+
function nanoRemainder(msFloat) {
|
|
274
|
+
const modulo = 1e6;
|
|
275
|
+
const remainder = 1e6 * msFloat % modulo;
|
|
276
|
+
const positiveRemainder = remainder < 0 ? remainder + modulo : remainder;
|
|
277
|
+
return Math.floor(positiveRemainder);
|
|
278
|
+
}
|
|
279
|
+
function getEpoch(epoch) {
|
|
280
|
+
if (!epoch) return 0;
|
|
281
|
+
if ("function" == typeof epoch.getTime) return epoch.getTime();
|
|
282
|
+
if ("number" == typeof epoch) return epoch;
|
|
283
|
+
throw new TypeError("now should be milliseconds since UNIX epoch");
|
|
284
|
+
}
|
|
285
|
+
function inRange(from, to, timer) {
|
|
286
|
+
return timer && timer.callAt >= from && timer.callAt <= to;
|
|
287
|
+
}
|
|
288
|
+
function getInfiniteLoopError(clock, job) {
|
|
289
|
+
const infiniteLoopError = new Error(`Aborting after running ${clock.loopLimit} timers, assuming an infinite loop!`);
|
|
290
|
+
if (!job.error) return infiniteLoopError;
|
|
291
|
+
const computedTargetPattern = /target\.*[<|(|[].*?[>|\]|)]\s*/;
|
|
292
|
+
let clockMethodPattern = new RegExp(String(Object.keys(clock).join("|")));
|
|
293
|
+
if (addTimerReturnsObject) clockMethodPattern = new RegExp(`\\s+at (Object\\.)?(?:${Object.keys(clock).join("|")})\\s+`);
|
|
294
|
+
let matchedLineIndex = -1;
|
|
295
|
+
job.error.stack.split("\n").some(function(line, i) {
|
|
296
|
+
const matchedComputedTarget = line.match(computedTargetPattern);
|
|
297
|
+
if (matchedComputedTarget) {
|
|
298
|
+
matchedLineIndex = i;
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
const matchedClockMethod = line.match(clockMethodPattern);
|
|
302
|
+
if (matchedClockMethod) {
|
|
303
|
+
matchedLineIndex = i;
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
return matchedLineIndex >= 0;
|
|
307
|
+
});
|
|
308
|
+
const stack = `${infiniteLoopError}\n${job.type || "Microtask"} - ${job.func.name || "anonymous"}\n${job.error.stack.split("\n").slice(matchedLineIndex + 1).join("\n")}`;
|
|
309
|
+
try {
|
|
310
|
+
Object.defineProperty(infiniteLoopError, "stack", {
|
|
311
|
+
value: stack
|
|
312
|
+
});
|
|
313
|
+
} catch (e) {}
|
|
314
|
+
return infiniteLoopError;
|
|
315
|
+
}
|
|
316
|
+
function createDate() {
|
|
317
|
+
class ClockDate extends NativeDate {
|
|
318
|
+
constructor(year, month, date, hour, minute, second, ms){
|
|
319
|
+
if (0 === arguments.length) super(ClockDate.clock.now);
|
|
320
|
+
else super(...arguments);
|
|
321
|
+
Object.defineProperty(this, "constructor", {
|
|
322
|
+
value: NativeDate,
|
|
323
|
+
enumerable: false
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
static [Symbol.hasInstance](instance) {
|
|
327
|
+
return instance instanceof NativeDate;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
ClockDate.isFake = true;
|
|
331
|
+
if (NativeDate.now) ClockDate.now = function now() {
|
|
332
|
+
return ClockDate.clock.now;
|
|
333
|
+
};
|
|
334
|
+
if (NativeDate.toSource) ClockDate.toSource = function toSource() {
|
|
335
|
+
return NativeDate.toSource();
|
|
336
|
+
};
|
|
337
|
+
ClockDate.toString = function toString() {
|
|
338
|
+
return NativeDate.toString();
|
|
339
|
+
};
|
|
340
|
+
const ClockDateProxy = new Proxy(ClockDate, {
|
|
341
|
+
apply () {
|
|
342
|
+
if (this instanceof ClockDate) throw new TypeError("A Proxy should only capture `new` calls with the `construct` handler. This is not supposed to be possible, so check the logic.");
|
|
343
|
+
return new NativeDate(ClockDate.clock.now).toString();
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
return ClockDateProxy;
|
|
347
|
+
}
|
|
348
|
+
function createIntl() {
|
|
349
|
+
const ClockIntl = {};
|
|
350
|
+
Object.getOwnPropertyNames(NativeIntl).forEach((property)=>ClockIntl[property] = NativeIntl[property]);
|
|
351
|
+
ClockIntl.DateTimeFormat = function(...args) {
|
|
352
|
+
const realFormatter = new NativeIntl.DateTimeFormat(...args);
|
|
353
|
+
const formatter = {};
|
|
354
|
+
[
|
|
355
|
+
"formatRange",
|
|
356
|
+
"formatRangeToParts",
|
|
357
|
+
"resolvedOptions"
|
|
358
|
+
].forEach((method)=>{
|
|
359
|
+
formatter[method] = realFormatter[method].bind(realFormatter);
|
|
360
|
+
});
|
|
361
|
+
[
|
|
362
|
+
"format",
|
|
363
|
+
"formatToParts"
|
|
364
|
+
].forEach((method)=>{
|
|
365
|
+
formatter[method] = function(date) {
|
|
366
|
+
return realFormatter[method](date || ClockIntl.clock.now);
|
|
367
|
+
};
|
|
368
|
+
});
|
|
369
|
+
return formatter;
|
|
370
|
+
};
|
|
371
|
+
ClockIntl.DateTimeFormat.prototype = Object.create(NativeIntl.DateTimeFormat.prototype);
|
|
372
|
+
ClockIntl.DateTimeFormat.supportedLocalesOf = NativeIntl.DateTimeFormat.supportedLocalesOf;
|
|
373
|
+
return ClockIntl;
|
|
374
|
+
}
|
|
375
|
+
function enqueueJob(clock, job) {
|
|
376
|
+
if (!clock.jobs) clock.jobs = [];
|
|
377
|
+
clock.jobs.push(job);
|
|
378
|
+
}
|
|
379
|
+
function runJobs(clock) {
|
|
380
|
+
if (!clock.jobs) return;
|
|
381
|
+
for(let i = 0; i < clock.jobs.length; i++){
|
|
382
|
+
const job = clock.jobs[i];
|
|
383
|
+
job.func.apply(null, job.args);
|
|
384
|
+
checkIsNearInfiniteLimit(clock, i);
|
|
385
|
+
if (clock.loopLimit && i > clock.loopLimit) throw getInfiniteLoopError(clock, job);
|
|
386
|
+
}
|
|
387
|
+
resetIsNearInfiniteLimit();
|
|
388
|
+
clock.jobs = [];
|
|
389
|
+
}
|
|
390
|
+
function addTimer(clock, timer) {
|
|
391
|
+
if (void 0 === timer.func) throw new Error("Callback must be provided to timer calls");
|
|
392
|
+
if (addTimerReturnsObject) {
|
|
393
|
+
if ("function" != typeof timer.func) throw new TypeError(`[ERR_INVALID_CALLBACK]: Callback must be a function. Received ${timer.func} of type ${typeof timer.func}`);
|
|
394
|
+
}
|
|
395
|
+
if (isNearInfiniteLimit) timer.error = new Error();
|
|
396
|
+
timer.type = timer.immediate ? "Immediate" : "Timeout";
|
|
397
|
+
if (timer.hasOwnProperty("delay")) {
|
|
398
|
+
if ("number" != typeof timer.delay) timer.delay = parseInt(timer.delay, 10);
|
|
399
|
+
if (!isNumberFinite(timer.delay)) timer.delay = 0;
|
|
400
|
+
timer.delay = timer.delay > maxTimeout ? 1 : timer.delay;
|
|
401
|
+
timer.delay = Math.max(0, timer.delay);
|
|
402
|
+
}
|
|
403
|
+
if (timer.hasOwnProperty("interval")) {
|
|
404
|
+
timer.type = "Interval";
|
|
405
|
+
timer.interval = timer.interval > maxTimeout ? 1 : timer.interval;
|
|
406
|
+
}
|
|
407
|
+
if (timer.hasOwnProperty("animation")) {
|
|
408
|
+
timer.type = "AnimationFrame";
|
|
409
|
+
timer.animation = true;
|
|
410
|
+
}
|
|
411
|
+
if (timer.hasOwnProperty("idleCallback")) {
|
|
412
|
+
timer.type = "IdleCallback";
|
|
413
|
+
timer.idleCallback = true;
|
|
414
|
+
}
|
|
415
|
+
if (!clock.timers) clock.timers = {};
|
|
416
|
+
timer.id = uniqueTimerId++;
|
|
417
|
+
timer.createdAt = clock.now;
|
|
418
|
+
timer.callAt = clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));
|
|
419
|
+
clock.timers[timer.id] = timer;
|
|
420
|
+
if (addTimerReturnsObject) {
|
|
421
|
+
const res = {
|
|
422
|
+
refed: true,
|
|
423
|
+
ref: function() {
|
|
424
|
+
this.refed = true;
|
|
425
|
+
return res;
|
|
426
|
+
},
|
|
427
|
+
unref: function() {
|
|
428
|
+
this.refed = false;
|
|
429
|
+
return res;
|
|
430
|
+
},
|
|
431
|
+
hasRef: function() {
|
|
432
|
+
return this.refed;
|
|
433
|
+
},
|
|
434
|
+
refresh: function() {
|
|
435
|
+
timer.callAt = clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));
|
|
436
|
+
clock.timers[timer.id] = timer;
|
|
437
|
+
return res;
|
|
438
|
+
},
|
|
439
|
+
[Symbol.toPrimitive]: function() {
|
|
440
|
+
return timer.id;
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
return res;
|
|
444
|
+
}
|
|
445
|
+
return timer.id;
|
|
446
|
+
}
|
|
447
|
+
function compareTimers(a, b) {
|
|
448
|
+
if (a.callAt < b.callAt) return -1;
|
|
449
|
+
if (a.callAt > b.callAt) return 1;
|
|
450
|
+
if (a.immediate && !b.immediate) return -1;
|
|
451
|
+
if (!a.immediate && b.immediate) return 1;
|
|
452
|
+
if (a.createdAt < b.createdAt) return -1;
|
|
453
|
+
if (a.createdAt > b.createdAt) return 1;
|
|
454
|
+
if (a.id < b.id) return -1;
|
|
455
|
+
if (a.id > b.id) return 1;
|
|
456
|
+
}
|
|
457
|
+
function firstTimerInRange(clock, from, to) {
|
|
458
|
+
const timers = clock.timers;
|
|
459
|
+
let timer = null;
|
|
460
|
+
let id, isInRange;
|
|
461
|
+
for(id in timers)if (timers.hasOwnProperty(id)) {
|
|
462
|
+
isInRange = inRange(from, to, timers[id]);
|
|
463
|
+
if (isInRange && (!timer || 1 === compareTimers(timer, timers[id]))) timer = timers[id];
|
|
464
|
+
}
|
|
465
|
+
return timer;
|
|
466
|
+
}
|
|
467
|
+
function firstTimer(clock) {
|
|
468
|
+
const timers = clock.timers;
|
|
469
|
+
let timer = null;
|
|
470
|
+
let id;
|
|
471
|
+
for(id in timers)if (timers.hasOwnProperty(id)) {
|
|
472
|
+
if (!timer || 1 === compareTimers(timer, timers[id])) timer = timers[id];
|
|
473
|
+
}
|
|
474
|
+
return timer;
|
|
475
|
+
}
|
|
476
|
+
function lastTimer(clock) {
|
|
477
|
+
const timers = clock.timers;
|
|
478
|
+
let timer = null;
|
|
479
|
+
let id;
|
|
480
|
+
for(id in timers)if (timers.hasOwnProperty(id)) {
|
|
481
|
+
if (!timer || -1 === compareTimers(timer, timers[id])) timer = timers[id];
|
|
482
|
+
}
|
|
483
|
+
return timer;
|
|
484
|
+
}
|
|
485
|
+
function callTimer(clock, timer) {
|
|
486
|
+
if ("number" == typeof timer.interval) clock.timers[timer.id].callAt += timer.interval;
|
|
487
|
+
else delete clock.timers[timer.id];
|
|
488
|
+
if ("function" == typeof timer.func) timer.func.apply(null, timer.args);
|
|
489
|
+
else {
|
|
490
|
+
const eval2 = eval;
|
|
491
|
+
(function() {
|
|
492
|
+
eval2(timer.func);
|
|
493
|
+
})();
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function getClearHandler(ttype) {
|
|
497
|
+
if ("IdleCallback" === ttype || "AnimationFrame" === ttype) return `cancel${ttype}`;
|
|
498
|
+
return `clear${ttype}`;
|
|
499
|
+
}
|
|
500
|
+
function getScheduleHandler(ttype) {
|
|
501
|
+
if ("IdleCallback" === ttype || "AnimationFrame" === ttype) return `request${ttype}`;
|
|
502
|
+
return `set${ttype}`;
|
|
503
|
+
}
|
|
504
|
+
function createWarnOnce() {
|
|
505
|
+
let calls = 0;
|
|
506
|
+
return function(msg) {
|
|
507
|
+
calls++ || console.warn(msg);
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
const warnOnce = createWarnOnce();
|
|
511
|
+
function clearTimer(clock, timerId, ttype) {
|
|
512
|
+
if (!timerId) return;
|
|
513
|
+
if (!clock.timers) clock.timers = {};
|
|
514
|
+
const id = Number(timerId);
|
|
515
|
+
if (Number.isNaN(id) || id < idCounterStart) {
|
|
516
|
+
const handlerName = getClearHandler(ttype);
|
|
517
|
+
if (true === clock.shouldClearNativeTimers) {
|
|
518
|
+
const nativeHandler = clock[`_${handlerName}`];
|
|
519
|
+
return "function" == typeof nativeHandler ? nativeHandler(timerId) : void 0;
|
|
520
|
+
}
|
|
521
|
+
const stackTrace = new Error().stack.split("\n").slice(1).join("\n");
|
|
522
|
+
warnOnce(`FakeTimers: ${handlerName} was invoked to clear a native timer instead of one created by this library.\nTo automatically clean-up native timers, use \`shouldClearNativeTimers\`.\n${stackTrace}`);
|
|
523
|
+
}
|
|
524
|
+
if (clock.timers.hasOwnProperty(id)) {
|
|
525
|
+
const timer = clock.timers[id];
|
|
526
|
+
if (timer.type === ttype || "Timeout" === timer.type && "Interval" === ttype || "Interval" === timer.type && "Timeout" === ttype) delete clock.timers[id];
|
|
527
|
+
else {
|
|
528
|
+
const clear = getClearHandler(ttype);
|
|
529
|
+
const schedule = getScheduleHandler(timer.type);
|
|
530
|
+
throw new Error(`Cannot clear timer: timer created with ${schedule}() but cleared with ${clear}()`);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function uninstall(clock) {
|
|
535
|
+
let method, i, l;
|
|
536
|
+
const installedHrTime = "_hrtime";
|
|
537
|
+
const installedNextTick = "_nextTick";
|
|
538
|
+
for(i = 0, l = clock.methods.length; i < l; i++){
|
|
539
|
+
method = clock.methods[i];
|
|
540
|
+
if ("hrtime" === method && _global.process) _global.process.hrtime = clock[installedHrTime];
|
|
541
|
+
else if ("nextTick" === method && _global.process) _global.process.nextTick = clock[installedNextTick];
|
|
542
|
+
else if ("performance" === method) {
|
|
543
|
+
const originalPerfDescriptor = Object.getOwnPropertyDescriptor(clock, `_${method}`);
|
|
544
|
+
if (originalPerfDescriptor && originalPerfDescriptor.get && !originalPerfDescriptor.set) Object.defineProperty(_global, method, originalPerfDescriptor);
|
|
545
|
+
else if (originalPerfDescriptor.configurable) _global[method] = clock[`_${method}`];
|
|
546
|
+
} else if (_global[method] && _global[method].hadOwnProperty) _global[method] = clock[`_${method}`];
|
|
547
|
+
else try {
|
|
548
|
+
delete _global[method];
|
|
549
|
+
} catch (ignore) {}
|
|
550
|
+
if (void 0 !== clock.timersModuleMethods) for(let j = 0; j < clock.timersModuleMethods.length; j++){
|
|
551
|
+
const entry = clock.timersModuleMethods[j];
|
|
552
|
+
timersModule[entry.methodName] = entry.original;
|
|
553
|
+
}
|
|
554
|
+
if (void 0 !== clock.timersPromisesModuleMethods) for(let j = 0; j < clock.timersPromisesModuleMethods.length; j++){
|
|
555
|
+
const entry = clock.timersPromisesModuleMethods[j];
|
|
556
|
+
timersPromisesModule[entry.methodName] = entry.original;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
clock.setTickMode("manual");
|
|
560
|
+
clock.methods = [];
|
|
561
|
+
for (const [listener, signal] of clock.abortListenerMap.entries()){
|
|
562
|
+
signal.removeEventListener("abort", listener);
|
|
563
|
+
clock.abortListenerMap.delete(listener);
|
|
564
|
+
}
|
|
565
|
+
if (!clock.timers) return [];
|
|
566
|
+
return Object.keys(clock.timers).map(function mapper(key) {
|
|
567
|
+
return clock.timers[key];
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
function hijackMethod(target, method, clock) {
|
|
571
|
+
clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(target, method);
|
|
572
|
+
clock[`_${method}`] = target[method];
|
|
573
|
+
if ("Date" === method) target[method] = clock[method];
|
|
574
|
+
else if ("Intl" === method) target[method] = clock[method];
|
|
575
|
+
else if ("performance" === method) {
|
|
576
|
+
const originalPerfDescriptor = Object.getOwnPropertyDescriptor(target, method);
|
|
577
|
+
if (originalPerfDescriptor && originalPerfDescriptor.get && !originalPerfDescriptor.set) {
|
|
578
|
+
Object.defineProperty(clock, `_${method}`, originalPerfDescriptor);
|
|
579
|
+
const perfDescriptor = Object.getOwnPropertyDescriptor(clock, method);
|
|
580
|
+
Object.defineProperty(target, method, perfDescriptor);
|
|
581
|
+
} else target[method] = clock[method];
|
|
582
|
+
} else {
|
|
583
|
+
target[method] = function() {
|
|
584
|
+
return clock[method].apply(clock, arguments);
|
|
585
|
+
};
|
|
586
|
+
Object.defineProperties(target[method], Object.getOwnPropertyDescriptors(clock[method]));
|
|
587
|
+
}
|
|
588
|
+
target[method].clock = clock;
|
|
589
|
+
}
|
|
590
|
+
function doIntervalTick(clock, advanceTimeDelta) {
|
|
591
|
+
clock.tick(advanceTimeDelta);
|
|
592
|
+
}
|
|
593
|
+
const timers = {
|
|
594
|
+
setTimeout: _global.setTimeout,
|
|
595
|
+
clearTimeout: _global.clearTimeout,
|
|
596
|
+
setInterval: _global.setInterval,
|
|
597
|
+
clearInterval: _global.clearInterval,
|
|
598
|
+
Date: _global.Date
|
|
599
|
+
};
|
|
600
|
+
if (isPresent.setImmediate) timers.setImmediate = _global.setImmediate;
|
|
601
|
+
if (isPresent.clearImmediate) timers.clearImmediate = _global.clearImmediate;
|
|
602
|
+
if (isPresent.hrtime) timers.hrtime = _global.process.hrtime;
|
|
603
|
+
if (isPresent.nextTick) timers.nextTick = _global.process.nextTick;
|
|
604
|
+
if (isPresent.performance) timers.performance = _global.performance;
|
|
605
|
+
if (isPresent.requestAnimationFrame) timers.requestAnimationFrame = _global.requestAnimationFrame;
|
|
606
|
+
if (isPresent.queueMicrotask) timers.queueMicrotask = _global.queueMicrotask;
|
|
607
|
+
if (isPresent.cancelAnimationFrame) timers.cancelAnimationFrame = _global.cancelAnimationFrame;
|
|
608
|
+
if (isPresent.requestIdleCallback) timers.requestIdleCallback = _global.requestIdleCallback;
|
|
609
|
+
if (isPresent.cancelIdleCallback) timers.cancelIdleCallback = _global.cancelIdleCallback;
|
|
610
|
+
if (isPresent.Intl) timers.Intl = NativeIntl;
|
|
611
|
+
const originalSetTimeout = _global.setImmediate || _global.setTimeout;
|
|
612
|
+
const originalClearInterval = _global.clearInterval;
|
|
613
|
+
const originalSetInterval = _global.setInterval;
|
|
614
|
+
function createClock(start, loopLimit) {
|
|
615
|
+
start = Math.floor(getEpoch(start));
|
|
616
|
+
loopLimit = loopLimit || 1000;
|
|
617
|
+
let nanos = 0;
|
|
618
|
+
const adjustedSystemTime = [
|
|
619
|
+
0,
|
|
620
|
+
0
|
|
621
|
+
];
|
|
622
|
+
const clock = {
|
|
623
|
+
now: start,
|
|
624
|
+
Date: createDate(),
|
|
625
|
+
loopLimit: loopLimit,
|
|
626
|
+
tickMode: {
|
|
627
|
+
mode: "manual",
|
|
628
|
+
counter: 0,
|
|
629
|
+
delta: void 0
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
clock.Date.clock = clock;
|
|
633
|
+
function getTimeToNextFrame() {
|
|
634
|
+
return 16 - (clock.now - start) % 16;
|
|
635
|
+
}
|
|
636
|
+
function hrtime(prev) {
|
|
637
|
+
const millisSinceStart = clock.now - adjustedSystemTime[0] - start;
|
|
638
|
+
const secsSinceStart = Math.floor(millisSinceStart / 1000);
|
|
639
|
+
const remainderInNanos = (millisSinceStart - 1e3 * secsSinceStart) * 1e6 + nanos - adjustedSystemTime[1];
|
|
640
|
+
if (Array.isArray(prev)) {
|
|
641
|
+
if (prev[1] > 1e9) throw new TypeError("Number of nanoseconds can't exceed a billion");
|
|
642
|
+
const oldSecs = prev[0];
|
|
643
|
+
let nanoDiff = remainderInNanos - prev[1];
|
|
644
|
+
let secDiff = secsSinceStart - oldSecs;
|
|
645
|
+
if (nanoDiff < 0) {
|
|
646
|
+
nanoDiff += 1e9;
|
|
647
|
+
secDiff -= 1;
|
|
648
|
+
}
|
|
649
|
+
return [
|
|
650
|
+
secDiff,
|
|
651
|
+
nanoDiff
|
|
652
|
+
];
|
|
653
|
+
}
|
|
654
|
+
return [
|
|
655
|
+
secsSinceStart,
|
|
656
|
+
remainderInNanos
|
|
657
|
+
];
|
|
658
|
+
}
|
|
659
|
+
function fakePerformanceNow() {
|
|
660
|
+
const hrt = hrtime();
|
|
661
|
+
const millis = 1000 * hrt[0] + hrt[1] / 1e6;
|
|
662
|
+
return millis;
|
|
663
|
+
}
|
|
664
|
+
if (isPresent.hrtimeBigint) hrtime.bigint = function() {
|
|
665
|
+
const parts = hrtime();
|
|
666
|
+
return BigInt(parts[0]) * BigInt(1e9) + BigInt(parts[1]);
|
|
667
|
+
};
|
|
668
|
+
if (isPresent.Intl) {
|
|
669
|
+
clock.Intl = createIntl();
|
|
670
|
+
clock.Intl.clock = clock;
|
|
671
|
+
}
|
|
672
|
+
clock.setTickMode = function(tickModeConfig) {
|
|
673
|
+
const { mode: newMode, delta: newDelta } = tickModeConfig;
|
|
674
|
+
const { mode: oldMode, delta: oldDelta } = clock.tickMode;
|
|
675
|
+
if (newMode === oldMode && newDelta === oldDelta) return;
|
|
676
|
+
if ("interval" === oldMode) originalClearInterval(clock.attachedInterval);
|
|
677
|
+
clock.tickMode = {
|
|
678
|
+
counter: clock.tickMode.counter + 1,
|
|
679
|
+
mode: newMode,
|
|
680
|
+
delta: newDelta
|
|
681
|
+
};
|
|
682
|
+
if ("nextAsync" === newMode) advanceUntilModeChanges();
|
|
683
|
+
else if ("interval" === newMode) createIntervalTick(clock, newDelta || 20);
|
|
684
|
+
};
|
|
685
|
+
async function advanceUntilModeChanges() {
|
|
686
|
+
async function newMacrotask() {
|
|
687
|
+
const channel = new MessageChannel();
|
|
688
|
+
await new Promise((resolve)=>{
|
|
689
|
+
channel.port1.onmessage = ()=>{
|
|
690
|
+
resolve();
|
|
691
|
+
channel.port1.close();
|
|
692
|
+
};
|
|
693
|
+
channel.port2.postMessage(void 0);
|
|
694
|
+
});
|
|
695
|
+
channel.port1.close();
|
|
696
|
+
channel.port2.close();
|
|
697
|
+
await new Promise((resolve)=>{
|
|
698
|
+
originalSetTimeout(resolve);
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
const { counter } = clock.tickMode;
|
|
702
|
+
while(clock.tickMode.counter === counter){
|
|
703
|
+
await newMacrotask();
|
|
704
|
+
if (clock.tickMode.counter !== counter) return;
|
|
705
|
+
clock.next();
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
function pauseAutoTickUntilFinished(promise) {
|
|
709
|
+
if ("nextAsync" !== clock.tickMode.mode) return promise;
|
|
710
|
+
clock.setTickMode({
|
|
711
|
+
mode: "manual"
|
|
712
|
+
});
|
|
713
|
+
return promise.finally(()=>{
|
|
714
|
+
clock.setTickMode({
|
|
715
|
+
mode: "nextAsync"
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
clock.requestIdleCallback = function requestIdleCallback(func, timeout) {
|
|
720
|
+
let timeToNextIdlePeriod = 0;
|
|
721
|
+
if (clock.countTimers() > 0) timeToNextIdlePeriod = 50;
|
|
722
|
+
const result = addTimer(clock, {
|
|
723
|
+
func: func,
|
|
724
|
+
args: Array.prototype.slice.call(arguments, 2),
|
|
725
|
+
delay: void 0 === timeout ? timeToNextIdlePeriod : Math.min(timeout, timeToNextIdlePeriod),
|
|
726
|
+
idleCallback: true
|
|
727
|
+
});
|
|
728
|
+
return Number(result);
|
|
729
|
+
};
|
|
730
|
+
clock.cancelIdleCallback = function cancelIdleCallback(timerId) {
|
|
731
|
+
return clearTimer(clock, timerId, "IdleCallback");
|
|
732
|
+
};
|
|
733
|
+
clock.setTimeout = function setTimeout(func, timeout) {
|
|
734
|
+
return addTimer(clock, {
|
|
735
|
+
func: func,
|
|
736
|
+
args: Array.prototype.slice.call(arguments, 2),
|
|
737
|
+
delay: timeout
|
|
738
|
+
});
|
|
739
|
+
};
|
|
740
|
+
if (void 0 !== _global.Promise && utilPromisify) clock.setTimeout[utilPromisify.custom] = function promisifiedSetTimeout(timeout, arg) {
|
|
741
|
+
return new _global.Promise(function setTimeoutExecutor(resolve) {
|
|
742
|
+
addTimer(clock, {
|
|
743
|
+
func: resolve,
|
|
744
|
+
args: [
|
|
745
|
+
arg
|
|
746
|
+
],
|
|
747
|
+
delay: timeout
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
};
|
|
751
|
+
clock.clearTimeout = function clearTimeout(timerId) {
|
|
752
|
+
return clearTimer(clock, timerId, "Timeout");
|
|
753
|
+
};
|
|
754
|
+
clock.nextTick = function nextTick(func) {
|
|
755
|
+
return enqueueJob(clock, {
|
|
756
|
+
func: func,
|
|
757
|
+
args: Array.prototype.slice.call(arguments, 1),
|
|
758
|
+
error: isNearInfiniteLimit ? new Error() : null
|
|
759
|
+
});
|
|
760
|
+
};
|
|
761
|
+
clock.queueMicrotask = function queueMicrotask(func) {
|
|
762
|
+
return clock.nextTick(func);
|
|
763
|
+
};
|
|
764
|
+
clock.setInterval = function setInterval(func, timeout) {
|
|
765
|
+
timeout = parseInt(timeout, 10);
|
|
766
|
+
return addTimer(clock, {
|
|
767
|
+
func: func,
|
|
768
|
+
args: Array.prototype.slice.call(arguments, 2),
|
|
769
|
+
delay: timeout,
|
|
770
|
+
interval: timeout
|
|
771
|
+
});
|
|
772
|
+
};
|
|
773
|
+
clock.clearInterval = function clearInterval(timerId) {
|
|
774
|
+
return clearTimer(clock, timerId, "Interval");
|
|
775
|
+
};
|
|
776
|
+
if (isPresent.setImmediate) {
|
|
777
|
+
clock.setImmediate = function setImmediate(func) {
|
|
778
|
+
return addTimer(clock, {
|
|
779
|
+
func: func,
|
|
780
|
+
args: Array.prototype.slice.call(arguments, 1),
|
|
781
|
+
immediate: true
|
|
782
|
+
});
|
|
783
|
+
};
|
|
784
|
+
if (void 0 !== _global.Promise && utilPromisify) clock.setImmediate[utilPromisify.custom] = function promisifiedSetImmediate(arg) {
|
|
785
|
+
return new _global.Promise(function setImmediateExecutor(resolve) {
|
|
786
|
+
addTimer(clock, {
|
|
787
|
+
func: resolve,
|
|
788
|
+
args: [
|
|
789
|
+
arg
|
|
790
|
+
],
|
|
791
|
+
immediate: true
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
};
|
|
795
|
+
clock.clearImmediate = function clearImmediate(timerId) {
|
|
796
|
+
return clearTimer(clock, timerId, "Immediate");
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
clock.countTimers = function countTimers() {
|
|
800
|
+
return Object.keys(clock.timers || {}).length + (clock.jobs || []).length;
|
|
801
|
+
};
|
|
802
|
+
clock.requestAnimationFrame = function requestAnimationFrame(func) {
|
|
803
|
+
const result = addTimer(clock, {
|
|
804
|
+
func: func,
|
|
805
|
+
delay: getTimeToNextFrame(),
|
|
806
|
+
get args () {
|
|
807
|
+
return [
|
|
808
|
+
fakePerformanceNow()
|
|
809
|
+
];
|
|
810
|
+
},
|
|
811
|
+
animation: true
|
|
812
|
+
});
|
|
813
|
+
return Number(result);
|
|
814
|
+
};
|
|
815
|
+
clock.cancelAnimationFrame = function cancelAnimationFrame(timerId) {
|
|
816
|
+
return clearTimer(clock, timerId, "AnimationFrame");
|
|
817
|
+
};
|
|
818
|
+
clock.runMicrotasks = function runMicrotasks() {
|
|
819
|
+
runJobs(clock);
|
|
820
|
+
};
|
|
821
|
+
function doTick(tickValue, isAsync, resolve, reject) {
|
|
822
|
+
const msFloat = "number" == typeof tickValue ? tickValue : parseTime(tickValue);
|
|
823
|
+
const ms = Math.floor(msFloat);
|
|
824
|
+
const remainder = nanoRemainder(msFloat);
|
|
825
|
+
let nanosTotal = nanos + remainder;
|
|
826
|
+
let tickTo = clock.now + ms;
|
|
827
|
+
if (msFloat < 0) throw new TypeError("Negative ticks are not supported");
|
|
828
|
+
if (nanosTotal >= 1e6) {
|
|
829
|
+
tickTo += 1;
|
|
830
|
+
nanosTotal -= 1e6;
|
|
831
|
+
}
|
|
832
|
+
nanos = nanosTotal;
|
|
833
|
+
let tickFrom = clock.now;
|
|
834
|
+
let previous = clock.now;
|
|
835
|
+
let timer, firstException, oldNow, nextPromiseTick, compensationCheck, postTimerCall;
|
|
836
|
+
clock.duringTick = true;
|
|
837
|
+
oldNow = clock.now;
|
|
838
|
+
runJobs(clock);
|
|
839
|
+
if (oldNow !== clock.now) {
|
|
840
|
+
tickFrom += clock.now - oldNow;
|
|
841
|
+
tickTo += clock.now - oldNow;
|
|
842
|
+
}
|
|
843
|
+
function doTickInner() {
|
|
844
|
+
timer = firstTimerInRange(clock, tickFrom, tickTo);
|
|
845
|
+
while(timer && tickFrom <= tickTo){
|
|
846
|
+
if (clock.timers[timer.id]) {
|
|
847
|
+
tickFrom = timer.callAt;
|
|
848
|
+
clock.now = timer.callAt;
|
|
849
|
+
oldNow = clock.now;
|
|
850
|
+
try {
|
|
851
|
+
runJobs(clock);
|
|
852
|
+
callTimer(clock, timer);
|
|
853
|
+
} catch (e) {
|
|
854
|
+
firstException = firstException || e;
|
|
855
|
+
}
|
|
856
|
+
if (isAsync) return void originalSetTimeout(nextPromiseTick);
|
|
857
|
+
compensationCheck();
|
|
858
|
+
}
|
|
859
|
+
postTimerCall();
|
|
860
|
+
}
|
|
861
|
+
oldNow = clock.now;
|
|
862
|
+
runJobs(clock);
|
|
863
|
+
if (oldNow !== clock.now) {
|
|
864
|
+
tickFrom += clock.now - oldNow;
|
|
865
|
+
tickTo += clock.now - oldNow;
|
|
866
|
+
}
|
|
867
|
+
clock.duringTick = false;
|
|
868
|
+
timer = firstTimerInRange(clock, tickFrom, tickTo);
|
|
869
|
+
if (timer) try {
|
|
870
|
+
clock.tick(tickTo - clock.now);
|
|
871
|
+
} catch (e) {
|
|
872
|
+
firstException = firstException || e;
|
|
873
|
+
}
|
|
874
|
+
else {
|
|
875
|
+
clock.now = tickTo;
|
|
876
|
+
nanos = nanosTotal;
|
|
877
|
+
}
|
|
878
|
+
if (firstException) throw firstException;
|
|
879
|
+
if (!isAsync) return clock.now;
|
|
880
|
+
resolve(clock.now);
|
|
881
|
+
}
|
|
882
|
+
nextPromiseTick = isAsync && function() {
|
|
883
|
+
try {
|
|
884
|
+
compensationCheck();
|
|
885
|
+
postTimerCall();
|
|
886
|
+
doTickInner();
|
|
887
|
+
} catch (e) {
|
|
888
|
+
reject(e);
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
compensationCheck = function() {
|
|
892
|
+
if (oldNow !== clock.now) {
|
|
893
|
+
tickFrom += clock.now - oldNow;
|
|
894
|
+
tickTo += clock.now - oldNow;
|
|
895
|
+
previous += clock.now - oldNow;
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
postTimerCall = function() {
|
|
899
|
+
timer = firstTimerInRange(clock, previous, tickTo);
|
|
900
|
+
previous = tickFrom;
|
|
901
|
+
};
|
|
902
|
+
return doTickInner();
|
|
903
|
+
}
|
|
904
|
+
clock.tick = function tick(tickValue) {
|
|
905
|
+
return doTick(tickValue, false);
|
|
906
|
+
};
|
|
907
|
+
if (void 0 !== _global.Promise) clock.tickAsync = function tickAsync(tickValue) {
|
|
908
|
+
return pauseAutoTickUntilFinished(new _global.Promise(function(resolve, reject) {
|
|
909
|
+
originalSetTimeout(function() {
|
|
910
|
+
try {
|
|
911
|
+
doTick(tickValue, true, resolve, reject);
|
|
912
|
+
} catch (e) {
|
|
913
|
+
reject(e);
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
}));
|
|
917
|
+
};
|
|
918
|
+
clock.next = function next() {
|
|
919
|
+
runJobs(clock);
|
|
920
|
+
const timer = firstTimer(clock);
|
|
921
|
+
if (!timer) return clock.now;
|
|
922
|
+
clock.duringTick = true;
|
|
923
|
+
try {
|
|
924
|
+
clock.now = timer.callAt;
|
|
925
|
+
callTimer(clock, timer);
|
|
926
|
+
runJobs(clock);
|
|
927
|
+
return clock.now;
|
|
928
|
+
} finally{
|
|
929
|
+
clock.duringTick = false;
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
if (void 0 !== _global.Promise) clock.nextAsync = function nextAsync() {
|
|
933
|
+
return pauseAutoTickUntilFinished(new _global.Promise(function(resolve, reject) {
|
|
934
|
+
originalSetTimeout(function() {
|
|
935
|
+
try {
|
|
936
|
+
const timer = firstTimer(clock);
|
|
937
|
+
if (!timer) return void resolve(clock.now);
|
|
938
|
+
let err;
|
|
939
|
+
clock.duringTick = true;
|
|
940
|
+
clock.now = timer.callAt;
|
|
941
|
+
try {
|
|
942
|
+
callTimer(clock, timer);
|
|
943
|
+
} catch (e) {
|
|
944
|
+
err = e;
|
|
945
|
+
}
|
|
946
|
+
clock.duringTick = false;
|
|
947
|
+
originalSetTimeout(function() {
|
|
948
|
+
if (err) reject(err);
|
|
949
|
+
else resolve(clock.now);
|
|
950
|
+
});
|
|
951
|
+
} catch (e) {
|
|
952
|
+
reject(e);
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
}));
|
|
956
|
+
};
|
|
957
|
+
clock.runAll = function runAll() {
|
|
958
|
+
let numTimers, i;
|
|
959
|
+
runJobs(clock);
|
|
960
|
+
for(i = 0; i < clock.loopLimit; i++){
|
|
961
|
+
if (!clock.timers) {
|
|
962
|
+
resetIsNearInfiniteLimit();
|
|
963
|
+
return clock.now;
|
|
964
|
+
}
|
|
965
|
+
numTimers = Object.keys(clock.timers).length;
|
|
966
|
+
if (0 === numTimers) {
|
|
967
|
+
resetIsNearInfiniteLimit();
|
|
968
|
+
return clock.now;
|
|
969
|
+
}
|
|
970
|
+
clock.next();
|
|
971
|
+
checkIsNearInfiniteLimit(clock, i);
|
|
972
|
+
}
|
|
973
|
+
const excessJob = firstTimer(clock);
|
|
974
|
+
throw getInfiniteLoopError(clock, excessJob);
|
|
975
|
+
};
|
|
976
|
+
clock.runToFrame = function runToFrame() {
|
|
977
|
+
return clock.tick(getTimeToNextFrame());
|
|
978
|
+
};
|
|
979
|
+
if (void 0 !== _global.Promise) clock.runAllAsync = function runAllAsync() {
|
|
980
|
+
return pauseAutoTickUntilFinished(new _global.Promise(function(resolve, reject) {
|
|
981
|
+
let i = 0;
|
|
982
|
+
function doRun() {
|
|
983
|
+
originalSetTimeout(function() {
|
|
984
|
+
try {
|
|
985
|
+
runJobs(clock);
|
|
986
|
+
let numTimers;
|
|
987
|
+
if (i < clock.loopLimit) {
|
|
988
|
+
if (!clock.timers) {
|
|
989
|
+
resetIsNearInfiniteLimit();
|
|
990
|
+
resolve(clock.now);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
numTimers = Object.keys(clock.timers).length;
|
|
994
|
+
if (0 === numTimers) {
|
|
995
|
+
resetIsNearInfiniteLimit();
|
|
996
|
+
resolve(clock.now);
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
clock.next();
|
|
1000
|
+
i++;
|
|
1001
|
+
doRun();
|
|
1002
|
+
checkIsNearInfiniteLimit(clock, i);
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
const excessJob = firstTimer(clock);
|
|
1006
|
+
reject(getInfiniteLoopError(clock, excessJob));
|
|
1007
|
+
} catch (e) {
|
|
1008
|
+
reject(e);
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
doRun();
|
|
1013
|
+
}));
|
|
1014
|
+
};
|
|
1015
|
+
clock.runToLast = function runToLast() {
|
|
1016
|
+
const timer = lastTimer(clock);
|
|
1017
|
+
if (!timer) {
|
|
1018
|
+
runJobs(clock);
|
|
1019
|
+
return clock.now;
|
|
1020
|
+
}
|
|
1021
|
+
return clock.tick(timer.callAt - clock.now);
|
|
1022
|
+
};
|
|
1023
|
+
if (void 0 !== _global.Promise) clock.runToLastAsync = function runToLastAsync() {
|
|
1024
|
+
return pauseAutoTickUntilFinished(new _global.Promise(function(resolve, reject) {
|
|
1025
|
+
originalSetTimeout(function() {
|
|
1026
|
+
try {
|
|
1027
|
+
const timer = lastTimer(clock);
|
|
1028
|
+
if (!timer) {
|
|
1029
|
+
runJobs(clock);
|
|
1030
|
+
resolve(clock.now);
|
|
1031
|
+
}
|
|
1032
|
+
resolve(clock.tickAsync(timer.callAt - clock.now));
|
|
1033
|
+
} catch (e) {
|
|
1034
|
+
reject(e);
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
}));
|
|
1038
|
+
};
|
|
1039
|
+
clock.reset = function reset() {
|
|
1040
|
+
nanos = 0;
|
|
1041
|
+
clock.timers = {};
|
|
1042
|
+
clock.jobs = [];
|
|
1043
|
+
clock.now = start;
|
|
1044
|
+
};
|
|
1045
|
+
clock.setSystemTime = function setSystemTime(systemTime) {
|
|
1046
|
+
const newNow = getEpoch(systemTime);
|
|
1047
|
+
const difference = newNow - clock.now;
|
|
1048
|
+
let id, timer;
|
|
1049
|
+
adjustedSystemTime[0] = adjustedSystemTime[0] + difference;
|
|
1050
|
+
adjustedSystemTime[1] = adjustedSystemTime[1] + nanos;
|
|
1051
|
+
clock.now = newNow;
|
|
1052
|
+
nanos = 0;
|
|
1053
|
+
for(id in clock.timers)if (clock.timers.hasOwnProperty(id)) {
|
|
1054
|
+
timer = clock.timers[id];
|
|
1055
|
+
timer.createdAt += difference;
|
|
1056
|
+
timer.callAt += difference;
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
clock.jump = function jump(tickValue) {
|
|
1060
|
+
const msFloat = "number" == typeof tickValue ? tickValue : parseTime(tickValue);
|
|
1061
|
+
const ms = Math.floor(msFloat);
|
|
1062
|
+
for (const timer of Object.values(clock.timers))if (clock.now + ms > timer.callAt) timer.callAt = clock.now + ms;
|
|
1063
|
+
clock.tick(ms);
|
|
1064
|
+
};
|
|
1065
|
+
if (isPresent.performance) {
|
|
1066
|
+
clock.performance = Object.create(null);
|
|
1067
|
+
clock.performance.now = fakePerformanceNow;
|
|
1068
|
+
}
|
|
1069
|
+
if (isPresent.hrtime) clock.hrtime = hrtime;
|
|
1070
|
+
return clock;
|
|
1071
|
+
}
|
|
1072
|
+
function createIntervalTick(clock, delta) {
|
|
1073
|
+
const intervalTick = doIntervalTick.bind(null, clock, delta);
|
|
1074
|
+
const intervalId = originalSetInterval(intervalTick, delta);
|
|
1075
|
+
clock.attachedInterval = intervalId;
|
|
1076
|
+
}
|
|
1077
|
+
function install(config) {
|
|
1078
|
+
if (arguments.length > 1 || config instanceof Date || Array.isArray(config) || "number" == typeof config) throw new TypeError(`FakeTimers.install called with ${String(config)} install requires an object parameter`);
|
|
1079
|
+
if (true === _global.Date.isFake) throw new TypeError("Can't install fake timers twice on the same global object.");
|
|
1080
|
+
config = void 0 !== config ? config : {};
|
|
1081
|
+
config.shouldAdvanceTime = config.shouldAdvanceTime || false;
|
|
1082
|
+
config.advanceTimeDelta = config.advanceTimeDelta || 20;
|
|
1083
|
+
config.shouldClearNativeTimers = config.shouldClearNativeTimers || false;
|
|
1084
|
+
if (config.target) throw new TypeError("config.target is no longer supported. Use `withGlobal(target)` instead.");
|
|
1085
|
+
function handleMissingTimer(timer) {
|
|
1086
|
+
if (config.ignoreMissingTimers) return;
|
|
1087
|
+
throw new ReferenceError(`non-existent timers and/or objects cannot be faked: '${timer}'`);
|
|
1088
|
+
}
|
|
1089
|
+
let i, l;
|
|
1090
|
+
const clock = createClock(config.now, config.loopLimit);
|
|
1091
|
+
clock.shouldClearNativeTimers = config.shouldClearNativeTimers;
|
|
1092
|
+
clock.uninstall = function() {
|
|
1093
|
+
return uninstall(clock);
|
|
1094
|
+
};
|
|
1095
|
+
clock.abortListenerMap = new Map();
|
|
1096
|
+
clock.methods = config.toFake || [];
|
|
1097
|
+
if (0 === clock.methods.length) clock.methods = Object.keys(timers);
|
|
1098
|
+
if (true === config.shouldAdvanceTime) clock.setTickMode({
|
|
1099
|
+
mode: "interval",
|
|
1100
|
+
delta: config.advanceTimeDelta
|
|
1101
|
+
});
|
|
1102
|
+
if (clock.methods.includes("performance")) {
|
|
1103
|
+
const proto = (()=>{
|
|
1104
|
+
if (hasPerformanceConstructorPrototype) return _global.performance.constructor.prototype;
|
|
1105
|
+
if (hasPerformancePrototype) return _global.Performance.prototype;
|
|
1106
|
+
})();
|
|
1107
|
+
if (proto) {
|
|
1108
|
+
Object.getOwnPropertyNames(proto).forEach(function(name) {
|
|
1109
|
+
if ("now" !== name) clock.performance[name] = 0 === name.indexOf("getEntries") ? NOOP_ARRAY : NOOP;
|
|
1110
|
+
});
|
|
1111
|
+
clock.performance.mark = (name)=>new FakePerformanceEntry(name, "mark", 0, 0);
|
|
1112
|
+
clock.performance.measure = (name)=>new FakePerformanceEntry(name, "measure", 0, 100);
|
|
1113
|
+
clock.performance.timeOrigin = getEpoch(config.now);
|
|
1114
|
+
} else if ((config.toFake || []).includes("performance")) return handleMissingTimer("performance");
|
|
1115
|
+
}
|
|
1116
|
+
if (_global === globalObject && timersModule) clock.timersModuleMethods = [];
|
|
1117
|
+
if (_global === globalObject && timersPromisesModule) clock.timersPromisesModuleMethods = [];
|
|
1118
|
+
for(i = 0, l = clock.methods.length; i < l; i++){
|
|
1119
|
+
const nameOfMethodToReplace = clock.methods[i];
|
|
1120
|
+
if (!isPresent[nameOfMethodToReplace]) {
|
|
1121
|
+
handleMissingTimer(nameOfMethodToReplace);
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1124
|
+
if ("hrtime" === nameOfMethodToReplace) {
|
|
1125
|
+
if (_global.process && "function" == typeof _global.process.hrtime) hijackMethod(_global.process, nameOfMethodToReplace, clock);
|
|
1126
|
+
} else if ("nextTick" === nameOfMethodToReplace) {
|
|
1127
|
+
if (_global.process && "function" == typeof _global.process.nextTick) hijackMethod(_global.process, nameOfMethodToReplace, clock);
|
|
1128
|
+
} else hijackMethod(_global, nameOfMethodToReplace, clock);
|
|
1129
|
+
if (void 0 !== clock.timersModuleMethods && timersModule[nameOfMethodToReplace]) {
|
|
1130
|
+
const original = timersModule[nameOfMethodToReplace];
|
|
1131
|
+
clock.timersModuleMethods.push({
|
|
1132
|
+
methodName: nameOfMethodToReplace,
|
|
1133
|
+
original: original
|
|
1134
|
+
});
|
|
1135
|
+
timersModule[nameOfMethodToReplace] = _global[nameOfMethodToReplace];
|
|
1136
|
+
}
|
|
1137
|
+
if (void 0 !== clock.timersPromisesModuleMethods) {
|
|
1138
|
+
if ("setTimeout" === nameOfMethodToReplace) {
|
|
1139
|
+
clock.timersPromisesModuleMethods.push({
|
|
1140
|
+
methodName: "setTimeout",
|
|
1141
|
+
original: timersPromisesModule.setTimeout
|
|
1142
|
+
});
|
|
1143
|
+
timersPromisesModule.setTimeout = (delay, value, options = {})=>new Promise((resolve, reject)=>{
|
|
1144
|
+
const abort = ()=>{
|
|
1145
|
+
options.signal.removeEventListener("abort", abort);
|
|
1146
|
+
clock.abortListenerMap.delete(abort);
|
|
1147
|
+
clock.clearTimeout(handle);
|
|
1148
|
+
reject(options.signal.reason);
|
|
1149
|
+
};
|
|
1150
|
+
const handle = clock.setTimeout(()=>{
|
|
1151
|
+
if (options.signal) {
|
|
1152
|
+
options.signal.removeEventListener("abort", abort);
|
|
1153
|
+
clock.abortListenerMap.delete(abort);
|
|
1154
|
+
}
|
|
1155
|
+
resolve(value);
|
|
1156
|
+
}, delay);
|
|
1157
|
+
if (options.signal) if (options.signal.aborted) abort();
|
|
1158
|
+
else {
|
|
1159
|
+
options.signal.addEventListener("abort", abort);
|
|
1160
|
+
clock.abortListenerMap.set(abort, options.signal);
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
} else if ("setImmediate" === nameOfMethodToReplace) {
|
|
1164
|
+
clock.timersPromisesModuleMethods.push({
|
|
1165
|
+
methodName: "setImmediate",
|
|
1166
|
+
original: timersPromisesModule.setImmediate
|
|
1167
|
+
});
|
|
1168
|
+
timersPromisesModule.setImmediate = (value, options = {})=>new Promise((resolve, reject)=>{
|
|
1169
|
+
const abort = ()=>{
|
|
1170
|
+
options.signal.removeEventListener("abort", abort);
|
|
1171
|
+
clock.abortListenerMap.delete(abort);
|
|
1172
|
+
clock.clearImmediate(handle);
|
|
1173
|
+
reject(options.signal.reason);
|
|
1174
|
+
};
|
|
1175
|
+
const handle = clock.setImmediate(()=>{
|
|
1176
|
+
if (options.signal) {
|
|
1177
|
+
options.signal.removeEventListener("abort", abort);
|
|
1178
|
+
clock.abortListenerMap.delete(abort);
|
|
1179
|
+
}
|
|
1180
|
+
resolve(value);
|
|
1181
|
+
});
|
|
1182
|
+
if (options.signal) if (options.signal.aborted) abort();
|
|
1183
|
+
else {
|
|
1184
|
+
options.signal.addEventListener("abort", abort);
|
|
1185
|
+
clock.abortListenerMap.set(abort, options.signal);
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
} else if ("setInterval" === nameOfMethodToReplace) {
|
|
1189
|
+
clock.timersPromisesModuleMethods.push({
|
|
1190
|
+
methodName: "setInterval",
|
|
1191
|
+
original: timersPromisesModule.setInterval
|
|
1192
|
+
});
|
|
1193
|
+
timersPromisesModule.setInterval = (delay, value, options = {})=>({
|
|
1194
|
+
[Symbol.asyncIterator]: ()=>{
|
|
1195
|
+
const createResolvable = ()=>{
|
|
1196
|
+
let resolve, reject;
|
|
1197
|
+
const promise = new Promise((res, rej)=>{
|
|
1198
|
+
resolve = res;
|
|
1199
|
+
reject = rej;
|
|
1200
|
+
});
|
|
1201
|
+
promise.resolve = resolve;
|
|
1202
|
+
promise.reject = reject;
|
|
1203
|
+
return promise;
|
|
1204
|
+
};
|
|
1205
|
+
let done = false;
|
|
1206
|
+
let hasThrown = false;
|
|
1207
|
+
let returnCall;
|
|
1208
|
+
let nextAvailable = 0;
|
|
1209
|
+
const nextQueue = [];
|
|
1210
|
+
const handle = clock.setInterval(()=>{
|
|
1211
|
+
if (nextQueue.length > 0) nextQueue.shift().resolve();
|
|
1212
|
+
else nextAvailable++;
|
|
1213
|
+
}, delay);
|
|
1214
|
+
const abort = ()=>{
|
|
1215
|
+
options.signal.removeEventListener("abort", abort);
|
|
1216
|
+
clock.abortListenerMap.delete(abort);
|
|
1217
|
+
clock.clearInterval(handle);
|
|
1218
|
+
done = true;
|
|
1219
|
+
for (const resolvable of nextQueue)resolvable.resolve();
|
|
1220
|
+
};
|
|
1221
|
+
if (options.signal) if (options.signal.aborted) done = true;
|
|
1222
|
+
else {
|
|
1223
|
+
options.signal.addEventListener("abort", abort);
|
|
1224
|
+
clock.abortListenerMap.set(abort, options.signal);
|
|
1225
|
+
}
|
|
1226
|
+
return {
|
|
1227
|
+
next: async ()=>{
|
|
1228
|
+
if (options.signal?.aborted && !hasThrown) {
|
|
1229
|
+
hasThrown = true;
|
|
1230
|
+
throw options.signal.reason;
|
|
1231
|
+
}
|
|
1232
|
+
if (done) return {
|
|
1233
|
+
done: true,
|
|
1234
|
+
value: void 0
|
|
1235
|
+
};
|
|
1236
|
+
if (nextAvailable > 0) {
|
|
1237
|
+
nextAvailable--;
|
|
1238
|
+
return {
|
|
1239
|
+
done: false,
|
|
1240
|
+
value: value
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
const resolvable = createResolvable();
|
|
1244
|
+
nextQueue.push(resolvable);
|
|
1245
|
+
await resolvable;
|
|
1246
|
+
if (returnCall && 0 === nextQueue.length) returnCall.resolve();
|
|
1247
|
+
if (options.signal?.aborted && !hasThrown) {
|
|
1248
|
+
hasThrown = true;
|
|
1249
|
+
throw options.signal.reason;
|
|
1250
|
+
}
|
|
1251
|
+
if (done) return {
|
|
1252
|
+
done: true,
|
|
1253
|
+
value: void 0
|
|
1254
|
+
};
|
|
1255
|
+
return {
|
|
1256
|
+
done: false,
|
|
1257
|
+
value: value
|
|
1258
|
+
};
|
|
1259
|
+
},
|
|
1260
|
+
return: async ()=>{
|
|
1261
|
+
if (done) return {
|
|
1262
|
+
done: true,
|
|
1263
|
+
value: void 0
|
|
1264
|
+
};
|
|
1265
|
+
if (nextQueue.length > 0) {
|
|
1266
|
+
returnCall = createResolvable();
|
|
1267
|
+
await returnCall;
|
|
1268
|
+
}
|
|
1269
|
+
clock.clearInterval(handle);
|
|
1270
|
+
done = true;
|
|
1271
|
+
if (options.signal) {
|
|
1272
|
+
options.signal.removeEventListener("abort", abort);
|
|
1273
|
+
clock.abortListenerMap.delete(abort);
|
|
1274
|
+
}
|
|
1275
|
+
return {
|
|
1276
|
+
done: true,
|
|
1277
|
+
value: void 0
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
return clock;
|
|
1287
|
+
}
|
|
1288
|
+
return {
|
|
1289
|
+
timers: timers,
|
|
1290
|
+
createClock: createClock,
|
|
1291
|
+
install: install,
|
|
1292
|
+
withGlobal: withGlobal
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
const defaultImplementation = withGlobal(globalObject);
|
|
1296
|
+
defaultImplementation.timers;
|
|
1297
|
+
defaultImplementation.createClock;
|
|
1298
|
+
defaultImplementation.install;
|
|
1299
|
+
exports.withGlobal = withGlobal;
|
|
1300
|
+
},
|
|
1301
|
+
"../../node_modules/.pnpm/type-detect@4.0.8/node_modules/type-detect/type-detect.js" (module) {
|
|
1302
|
+
(function(global1, factory) {
|
|
1303
|
+
module.exports = factory();
|
|
1304
|
+
})(0, function() {
|
|
1305
|
+
'use strict';
|
|
1306
|
+
var promiseExists = 'function' == typeof Promise;
|
|
1307
|
+
var globalObject = 'object' == typeof self ? self : global;
|
|
1308
|
+
var symbolExists = "u" > typeof Symbol;
|
|
1309
|
+
var mapExists = "u" > typeof Map;
|
|
1310
|
+
var setExists = "u" > typeof Set;
|
|
1311
|
+
var weakMapExists = "u" > typeof WeakMap;
|
|
1312
|
+
var weakSetExists = "u" > typeof WeakSet;
|
|
1313
|
+
var dataViewExists = "u" > typeof DataView;
|
|
1314
|
+
var symbolIteratorExists = symbolExists && void 0 !== Symbol.iterator;
|
|
1315
|
+
var symbolToStringTagExists = symbolExists && void 0 !== Symbol.toStringTag;
|
|
1316
|
+
var setEntriesExists = setExists && 'function' == typeof Set.prototype.entries;
|
|
1317
|
+
var mapEntriesExists = mapExists && 'function' == typeof Map.prototype.entries;
|
|
1318
|
+
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
|
|
1319
|
+
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
|
|
1320
|
+
var arrayIteratorExists = symbolIteratorExists && 'function' == typeof Array.prototype[Symbol.iterator];
|
|
1321
|
+
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
|
|
1322
|
+
var stringIteratorExists = symbolIteratorExists && 'function' == typeof String.prototype[Symbol.iterator];
|
|
1323
|
+
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
|
|
1324
|
+
var toStringLeftSliceLength = 8;
|
|
1325
|
+
var toStringRightSliceLength = -1;
|
|
1326
|
+
function typeDetect(obj) {
|
|
1327
|
+
var typeofObj = typeof obj;
|
|
1328
|
+
if ('object' !== typeofObj) return typeofObj;
|
|
1329
|
+
if (null === obj) return 'null';
|
|
1330
|
+
if (obj === globalObject) return 'global';
|
|
1331
|
+
if (Array.isArray(obj) && (false === symbolToStringTagExists || !(Symbol.toStringTag in obj))) return 'Array';
|
|
1332
|
+
if ('object' == typeof window && null !== window) {
|
|
1333
|
+
if ('object' == typeof window.location && obj === window.location) return 'Location';
|
|
1334
|
+
if ('object' == typeof window.document && obj === window.document) return 'Document';
|
|
1335
|
+
if ('object' == typeof window.navigator) {
|
|
1336
|
+
if ('object' == typeof window.navigator.mimeTypes && obj === window.navigator.mimeTypes) return 'MimeTypeArray';
|
|
1337
|
+
if ('object' == typeof window.navigator.plugins && obj === window.navigator.plugins) return 'PluginArray';
|
|
1338
|
+
}
|
|
1339
|
+
if (('function' == typeof window.HTMLElement || 'object' == typeof window.HTMLElement) && obj instanceof window.HTMLElement) {
|
|
1340
|
+
if ('BLOCKQUOTE' === obj.tagName) return 'HTMLQuoteElement';
|
|
1341
|
+
if ('TD' === obj.tagName) return 'HTMLTableDataCellElement';
|
|
1342
|
+
if ('TH' === obj.tagName) return 'HTMLTableHeaderCellElement';
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
var stringTag = symbolToStringTagExists && obj[Symbol.toStringTag];
|
|
1346
|
+
if ('string' == typeof stringTag) return stringTag;
|
|
1347
|
+
var objPrototype = Object.getPrototypeOf(obj);
|
|
1348
|
+
if (objPrototype === RegExp.prototype) return 'RegExp';
|
|
1349
|
+
if (objPrototype === Date.prototype) return 'Date';
|
|
1350
|
+
if (promiseExists && objPrototype === Promise.prototype) return 'Promise';
|
|
1351
|
+
if (setExists && objPrototype === Set.prototype) return 'Set';
|
|
1352
|
+
if (mapExists && objPrototype === Map.prototype) return 'Map';
|
|
1353
|
+
if (weakSetExists && objPrototype === WeakSet.prototype) return 'WeakSet';
|
|
1354
|
+
if (weakMapExists && objPrototype === WeakMap.prototype) return 'WeakMap';
|
|
1355
|
+
if (dataViewExists && objPrototype === DataView.prototype) return 'DataView';
|
|
1356
|
+
if (mapExists && objPrototype === mapIteratorPrototype) return 'Map Iterator';
|
|
1357
|
+
if (setExists && objPrototype === setIteratorPrototype) return 'Set Iterator';
|
|
1358
|
+
if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) return 'Array Iterator';
|
|
1359
|
+
if (stringIteratorExists && objPrototype === stringIteratorPrototype) return 'String Iterator';
|
|
1360
|
+
if (null === objPrototype) return 'Object';
|
|
1361
|
+
return Object.prototype.toString.call(obj).slice(toStringLeftSliceLength, toStringRightSliceLength);
|
|
1362
|
+
}
|
|
1363
|
+
return typeDetect;
|
|
1364
|
+
});
|
|
1365
|
+
},
|
|
1366
|
+
util (module) {
|
|
1367
|
+
module.exports = __rspack_external_node_util_1b29d436;
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
const RealDate = Date;
|
|
1371
|
+
const loadFakeTimersModule = ()=>{
|
|
1372
|
+
const loaded = __webpack_require__("../../node_modules/.pnpm/@sinonjs+fake-timers@15.1.1/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js");
|
|
1373
|
+
return {
|
|
1374
|
+
withGlobal: loaded.withGlobal
|
|
1375
|
+
};
|
|
1376
|
+
};
|
|
1377
|
+
class FakeTimers {
|
|
1378
|
+
_clock;
|
|
1379
|
+
_config;
|
|
1380
|
+
_fakingTime;
|
|
1381
|
+
_fakeTimers;
|
|
1382
|
+
constructor({ global: global1, config = {} }){
|
|
1383
|
+
this._config = config;
|
|
1384
|
+
this._fakingTime = false;
|
|
1385
|
+
this._fakeTimers = loadFakeTimersModule().withGlobal(global1);
|
|
1386
|
+
}
|
|
1387
|
+
clearAllTimers() {
|
|
1388
|
+
if (this._fakingTime) this._clock.reset();
|
|
1389
|
+
}
|
|
1390
|
+
dispose() {
|
|
1391
|
+
this.useRealTimers();
|
|
1392
|
+
}
|
|
1393
|
+
runAllTimers() {
|
|
1394
|
+
if (this._checkFakeTimers()) this._clock.runAll();
|
|
1395
|
+
}
|
|
1396
|
+
async runAllTimersAsync() {
|
|
1397
|
+
if (this._checkFakeTimers()) await this._clock.runAllAsync();
|
|
1398
|
+
}
|
|
1399
|
+
runOnlyPendingTimers() {
|
|
1400
|
+
if (this._checkFakeTimers()) this._clock.runToLast();
|
|
1401
|
+
}
|
|
1402
|
+
async runOnlyPendingTimersAsync() {
|
|
1403
|
+
if (this._checkFakeTimers()) await this._clock.runToLastAsync();
|
|
1404
|
+
}
|
|
1405
|
+
advanceTimersToNextTimer(steps = 1) {
|
|
1406
|
+
if (this._checkFakeTimers()) for(let i = steps; i > 0; i--){
|
|
1407
|
+
this._clock.next();
|
|
1408
|
+
this._clock.tick(0);
|
|
1409
|
+
if (0 === this._clock.countTimers()) break;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
async advanceTimersToNextTimerAsync(steps = 1) {
|
|
1413
|
+
if (this._checkFakeTimers()) for(let i = steps; i > 0; i--){
|
|
1414
|
+
await this._clock.nextAsync();
|
|
1415
|
+
await this._clock.tickAsync(0);
|
|
1416
|
+
if (0 === this._clock.countTimers()) break;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
advanceTimersByTime(msToRun) {
|
|
1420
|
+
if (this._checkFakeTimers()) this._clock.tick(msToRun);
|
|
1421
|
+
}
|
|
1422
|
+
async advanceTimersByTimeAsync(msToRun) {
|
|
1423
|
+
if (this._checkFakeTimers()) await this._clock.tickAsync(msToRun);
|
|
1424
|
+
}
|
|
1425
|
+
advanceTimersToNextFrame() {
|
|
1426
|
+
if (this._checkFakeTimers()) this._clock.runToFrame();
|
|
1427
|
+
}
|
|
1428
|
+
runAllTicks() {
|
|
1429
|
+
if (this._checkFakeTimers()) this._clock.runMicrotasks();
|
|
1430
|
+
}
|
|
1431
|
+
useRealTimers() {
|
|
1432
|
+
if (this._fakingTime) {
|
|
1433
|
+
this._clock.uninstall();
|
|
1434
|
+
this._fakingTime = false;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
useFakeTimers(fakeTimersConfig = {}) {
|
|
1438
|
+
if (this._fakingTime) this._clock.uninstall();
|
|
1439
|
+
const toFake = Object.keys(this._fakeTimers.timers).filter((timer)=>'nextTick' !== timer && 'queueMicrotask' !== timer);
|
|
1440
|
+
const isChildProcess = "u" > typeof process && !!process.send;
|
|
1441
|
+
if (this._config?.toFake?.includes('nextTick') && isChildProcess) throw new Error('process.nextTick cannot be mocked inside child_process');
|
|
1442
|
+
this._clock = this._fakeTimers.install({
|
|
1443
|
+
loopLimit: 10000,
|
|
1444
|
+
shouldClearNativeTimers: true,
|
|
1445
|
+
now: Date.now(),
|
|
1446
|
+
toFake: [
|
|
1447
|
+
...toFake
|
|
1448
|
+
],
|
|
1449
|
+
ignoreMissingTimers: true,
|
|
1450
|
+
...fakeTimersConfig
|
|
1451
|
+
});
|
|
1452
|
+
this._fakingTime = true;
|
|
1453
|
+
}
|
|
1454
|
+
reset() {
|
|
1455
|
+
if (this._checkFakeTimers()) {
|
|
1456
|
+
const { now } = this._clock;
|
|
1457
|
+
this._clock.reset();
|
|
1458
|
+
this._clock.setSystemTime(now);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
setSystemTime(now) {
|
|
1462
|
+
if (this._checkFakeTimers()) this._clock.setSystemTime(now);
|
|
1463
|
+
}
|
|
1464
|
+
getRealSystemTime() {
|
|
1465
|
+
return RealDate.now();
|
|
1466
|
+
}
|
|
1467
|
+
now() {
|
|
1468
|
+
if (this._fakingTime) return this._clock.now;
|
|
1469
|
+
return Date.now();
|
|
1470
|
+
}
|
|
1471
|
+
getTimerCount() {
|
|
1472
|
+
if (this._checkFakeTimers()) return this._clock.countTimers();
|
|
1473
|
+
return 0;
|
|
1474
|
+
}
|
|
1475
|
+
_checkFakeTimers() {
|
|
1476
|
+
if (!this._fakingTime) throw new Error('Timers are not mocked. Try calling "rstest.useFakeTimers()" first.');
|
|
1477
|
+
return this._fakingTime;
|
|
1478
|
+
}
|
|
1479
|
+
isFakeTimers() {
|
|
1480
|
+
return this._fakingTime;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
export { FakeTimers };
|