osra 0.2.0 → 0.2.1
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/README.md +284 -34
- package/build/extension/background.js +2 -0
- package/build/extension/background.js.map +1 -0
- package/build/extension/chunks/index.js +2 -0
- package/build/extension/chunks/index.js.map +1 -0
- package/build/extension/content.js +2 -0
- package/build/extension/content.js.map +1 -0
- package/build/extension/manifest.json +21 -0
- package/build/extension/popup.html +120 -0
- package/build/extension/popup.js +2 -0
- package/build/extension/popup.js.map +1 -0
- package/build/extension-test/background.js +753 -0
- package/build/extension-test/background.js.map +1 -0
- package/build/extension-test/content.js +4585 -0
- package/build/extension-test/content.js.map +1 -0
- package/build/extension-test/manifest.json +22 -0
- package/build/extension-test/popup.html +106 -0
- package/build/extension-test/popup.js +4610 -0
- package/build/extension-test/popup.js.map +1 -0
- package/build/extension-test-firefox/background.js +5464 -0
- package/build/extension-test-firefox/background.js.map +1 -0
- package/build/extension-test-firefox/content.js +5286 -0
- package/build/extension-test-firefox/content.js.map +1 -0
- package/build/extension-test-firefox/manifest.json +27 -0
- package/build/extension-test-firefox/popup.html +106 -0
- package/build/extension-test-firefox/popup.js +5213 -0
- package/build/extension-test-firefox/popup.js.map +1 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +30 -30
- package/build/index.js.map +1 -1
- package/build/test.js +24987 -0
- package/build/test.js.map +1 -0
- package/package.json +9 -4
|
@@ -0,0 +1,4585 @@
|
|
|
1
|
+
(async ()=>{
|
|
2
|
+
const OSRA_KEY = "__OSRA_KEY__";
|
|
3
|
+
const OSRA_DEFAULT_KEY = "__OSRA_DEFAULT_KEY__";
|
|
4
|
+
const OSRA_BOX = "__OSRA_BOX__";
|
|
5
|
+
const makeMessageChannelAllocator = ()=>{
|
|
6
|
+
const channels = new Map();
|
|
7
|
+
const result = {
|
|
8
|
+
getUniqueUuid: ()=>{
|
|
9
|
+
let uuid = globalThis.crypto.randomUUID();
|
|
10
|
+
while(channels.has(uuid)){
|
|
11
|
+
uuid = globalThis.crypto.randomUUID();
|
|
12
|
+
}
|
|
13
|
+
return uuid;
|
|
14
|
+
},
|
|
15
|
+
set: (uuid, messagePorts)=>{
|
|
16
|
+
channels.set(uuid, {
|
|
17
|
+
uuid,
|
|
18
|
+
...messagePorts
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
alloc: (uuid = result.getUniqueUuid(), messagePorts)=>{
|
|
22
|
+
if (messagePorts) {
|
|
23
|
+
channels.set(uuid, {
|
|
24
|
+
uuid,
|
|
25
|
+
...messagePorts
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
uuid,
|
|
29
|
+
...messagePorts
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const messageChannel = new MessageChannel();
|
|
33
|
+
const allocatedMessageChannel = {
|
|
34
|
+
uuid,
|
|
35
|
+
port1: messageChannel.port1,
|
|
36
|
+
port2: messageChannel.port2
|
|
37
|
+
};
|
|
38
|
+
channels.set(uuid, allocatedMessageChannel);
|
|
39
|
+
return allocatedMessageChannel;
|
|
40
|
+
},
|
|
41
|
+
has: (uuid)=>channels.has(uuid),
|
|
42
|
+
get: (uuid)=>channels.get(uuid),
|
|
43
|
+
free: (uuid)=>channels.delete(uuid),
|
|
44
|
+
getOrAlloc: (uuid = result.getUniqueUuid(), messagePorts)=>{
|
|
45
|
+
const existingChannel = result.get(uuid);
|
|
46
|
+
if (existingChannel) return existingChannel;
|
|
47
|
+
return result.alloc(uuid, messagePorts);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
const checkOsraMessageKey = (message, key)=>isOsraMessage(message) && message[OSRA_KEY] === key;
|
|
53
|
+
const registerOsraMessageListener = ({ listener, transport, remoteName, key = OSRA_KEY, unregisterSignal })=>{
|
|
54
|
+
const registerListenerOnReceiveTransport = (receiveTransport)=>{
|
|
55
|
+
if (typeof receiveTransport === "function") {
|
|
56
|
+
receiveTransport(listener);
|
|
57
|
+
} else if (isWebExtensionPort(receiveTransport) || isWebExtensionOnConnect(receiveTransport) || isWebExtensionOnMessage(receiveTransport)) {
|
|
58
|
+
const listenOnWebExtOnMessage = (onMessage, port)=>{
|
|
59
|
+
const _listener = (message, sender)=>{
|
|
60
|
+
if (!checkOsraMessageKey(message, key)) return;
|
|
61
|
+
if (remoteName && message.name !== remoteName) return;
|
|
62
|
+
listener(message, {
|
|
63
|
+
port,
|
|
64
|
+
sender
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
onMessage.addListener(_listener);
|
|
68
|
+
if (unregisterSignal) {
|
|
69
|
+
unregisterSignal.addEventListener("abort", ()=>onMessage.removeListener(_listener));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
if (isWebExtensionOnConnect(receiveTransport)) {
|
|
73
|
+
const _listener = (port)=>{
|
|
74
|
+
listenOnWebExtOnMessage(port.onMessage, port);
|
|
75
|
+
};
|
|
76
|
+
receiveTransport.addListener(_listener);
|
|
77
|
+
if (unregisterSignal) {
|
|
78
|
+
unregisterSignal.addEventListener("abort", ()=>receiveTransport.removeListener(_listener));
|
|
79
|
+
}
|
|
80
|
+
} else if (isWebExtensionOnMessage(receiveTransport)) {
|
|
81
|
+
listenOnWebExtOnMessage(receiveTransport);
|
|
82
|
+
} else {
|
|
83
|
+
listenOnWebExtOnMessage(receiveTransport.onMessage);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
const _listener = (event)=>{
|
|
87
|
+
if (!checkOsraMessageKey(event.data, key)) return;
|
|
88
|
+
if (remoteName && event.data.name !== remoteName) return;
|
|
89
|
+
listener(event.data, {
|
|
90
|
+
receiveTransport,
|
|
91
|
+
source: event.source
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
receiveTransport.addEventListener("message", _listener);
|
|
95
|
+
if (unregisterSignal) {
|
|
96
|
+
unregisterSignal.addEventListener("abort", ()=>receiveTransport.removeEventListener("message", _listener));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
if (isCustomTransport(transport)) {
|
|
101
|
+
registerListenerOnReceiveTransport(transport.receive);
|
|
102
|
+
} else {
|
|
103
|
+
registerListenerOnReceiveTransport(transport);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const sendOsraMessage = (transport, message, origin = "*", transferables = [])=>{
|
|
107
|
+
const sendToEmitTransport = (emitTransport)=>{
|
|
108
|
+
if (typeof emitTransport === "function") {
|
|
109
|
+
emitTransport(message, transferables);
|
|
110
|
+
} else if (isWebExtensionPort(emitTransport)) {
|
|
111
|
+
emitTransport.postMessage(message);
|
|
112
|
+
} else if (isWindow(emitTransport)) {
|
|
113
|
+
emitTransport.postMessage(message, origin, transferables);
|
|
114
|
+
} else if (isWebSocket(emitTransport)) {
|
|
115
|
+
emitTransport.send(JSON.stringify(message));
|
|
116
|
+
} else if (isSharedWorker(emitTransport)) {
|
|
117
|
+
emitTransport.port.postMessage(message, transferables);
|
|
118
|
+
} else {
|
|
119
|
+
emitTransport.postMessage(message, transferables);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
if (isCustomTransport(transport)) {
|
|
123
|
+
sendToEmitTransport(transport.emit);
|
|
124
|
+
} else {
|
|
125
|
+
sendToEmitTransport(transport);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const typedArrayConstructors = [
|
|
129
|
+
Int8Array,
|
|
130
|
+
Uint8Array,
|
|
131
|
+
Uint8ClampedArray,
|
|
132
|
+
Int16Array,
|
|
133
|
+
Uint16Array,
|
|
134
|
+
Int32Array,
|
|
135
|
+
Uint32Array,
|
|
136
|
+
Float16Array,
|
|
137
|
+
Float32Array,
|
|
138
|
+
Float64Array,
|
|
139
|
+
BigInt64Array,
|
|
140
|
+
BigUint64Array
|
|
141
|
+
];
|
|
142
|
+
[
|
|
143
|
+
new Int8Array(),
|
|
144
|
+
new Uint8Array(),
|
|
145
|
+
new Uint8ClampedArray(),
|
|
146
|
+
new Int16Array(),
|
|
147
|
+
new Uint16Array(),
|
|
148
|
+
new Int32Array(),
|
|
149
|
+
new Uint32Array(),
|
|
150
|
+
new Float16Array(),
|
|
151
|
+
new Float32Array(),
|
|
152
|
+
new Float64Array(),
|
|
153
|
+
new BigInt64Array(),
|
|
154
|
+
new BigUint64Array()
|
|
155
|
+
];
|
|
156
|
+
const typedArrayToType = (value)=>{
|
|
157
|
+
const type = value instanceof Int8Array ? "Int8Array" : value instanceof Uint8Array ? "Uint8Array" : value instanceof Uint8ClampedArray ? "Uint8ClampedArray" : value instanceof Int16Array ? "Int16Array" : value instanceof Uint16Array ? "Uint16Array" : value instanceof Int32Array ? "Int32Array" : value instanceof Uint32Array ? "Uint32Array" : value instanceof Float16Array ? "Float16Array" : value instanceof Float32Array ? "Float32Array" : value instanceof Float64Array ? "Float64Array" : value instanceof BigInt64Array ? "BigInt64Array" : value instanceof BigUint64Array ? "BigUint64Array" : void 0;
|
|
158
|
+
if (type === void 0) throw new Error("Unknown typed array type");
|
|
159
|
+
return type;
|
|
160
|
+
};
|
|
161
|
+
const typedArrayTypeToTypedArrayConstructor = (value)=>{
|
|
162
|
+
const typedArray = value === "Int8Array" ? Int8Array : value === "Uint8Array" ? Uint8Array : value === "Uint8ClampedArray" ? Uint8ClampedArray : value === "Int16Array" ? Int16Array : value === "Uint16Array" ? Uint16Array : value === "Int32Array" ? Int32Array : value === "Uint32Array" ? Uint32Array : value === "Float16Array" ? Float16Array : value === "Float32Array" ? Float32Array : value === "Float64Array" ? Float64Array : value === "BigInt64Array" ? BigInt64Array : value === "BigUint64Array" ? BigUint64Array : void 0;
|
|
163
|
+
if (typedArray === void 0) throw new Error("Unknown typed array type");
|
|
164
|
+
return typedArray;
|
|
165
|
+
};
|
|
166
|
+
const isTypedArray = (value)=>typedArrayConstructors.some((typedArray)=>value instanceof typedArray);
|
|
167
|
+
const isWebSocket = (value)=>value instanceof WebSocket;
|
|
168
|
+
const isServiceWorkerContainer = (value)=>globalThis.ServiceWorkerContainer && value instanceof ServiceWorkerContainer;
|
|
169
|
+
const isWorker = (value)=>globalThis.Worker && value instanceof Worker;
|
|
170
|
+
const isDedicatedWorker = (value)=>globalThis.DedicatedWorkerGlobalScope && value instanceof DedicatedWorkerGlobalScope;
|
|
171
|
+
const isSharedWorker = (value)=>globalThis.SharedWorker && value instanceof SharedWorker;
|
|
172
|
+
const isMessagePort = (value)=>value instanceof MessagePort;
|
|
173
|
+
const isPromise = (value)=>value instanceof Promise;
|
|
174
|
+
const isFunction = (value)=>typeof value === "function";
|
|
175
|
+
const isArrayBuffer = (value)=>value instanceof ArrayBuffer;
|
|
176
|
+
const isReadableStream = (value)=>value instanceof ReadableStream;
|
|
177
|
+
const isDate = (value)=>value instanceof Date;
|
|
178
|
+
const isError = (value)=>value instanceof Error;
|
|
179
|
+
const isAlwaysBox = (value)=>isFunction(value) || isPromise(value) || isTypedArray(value) || isDate(value) || isError(value);
|
|
180
|
+
const isOsraMessage = (value)=>Boolean(value && typeof value === "object" && value[OSRA_KEY]);
|
|
181
|
+
const isClonable = (value)=>globalThis.SharedArrayBuffer && value instanceof globalThis.SharedArrayBuffer ? true : false;
|
|
182
|
+
const isTransferable = (value)=>globalThis.ArrayBuffer && value instanceof globalThis.ArrayBuffer ? true : globalThis.MessagePort && value instanceof globalThis.MessagePort ? true : globalThis.ReadableStream && value instanceof globalThis.ReadableStream ? true : globalThis.WritableStream && value instanceof globalThis.WritableStream ? true : globalThis.TransformStream && value instanceof globalThis.TransformStream ? true : globalThis.ImageBitmap && value instanceof globalThis.ImageBitmap ? true : false;
|
|
183
|
+
const isWebExtensionPort = (value, connectPort = false)=>{
|
|
184
|
+
return Boolean(value && typeof value === "object" && value.name && value.disconnect && value.postMessage && (connectPort ? value.sender && value.onMessage && value.onDisconnect : true));
|
|
185
|
+
};
|
|
186
|
+
const isWebExtensionOnConnect = (value)=>Boolean(value && typeof value === "object" && value.addListener && value.hasListener && value.removeListener);
|
|
187
|
+
const isWebExtensionOnMessage = (value)=>Boolean(value && typeof value === "object" && value.addListener && value.hasListener && value.removeListener);
|
|
188
|
+
const isWindow = (value)=>{
|
|
189
|
+
return Boolean(value && typeof value === "object" && value.document && value.location && value.navigator && value.screen && value.history);
|
|
190
|
+
};
|
|
191
|
+
const isEmitJsonOnlyTransport = (value)=>isWebSocket(value) || isWebExtensionPort(value);
|
|
192
|
+
const isReceiveJsonOnlyTransport = (value)=>isWebSocket(value) || isWebExtensionPort(value) || isWebExtensionOnConnect(value) || isWebExtensionOnMessage(value);
|
|
193
|
+
const isJsonOnlyTransport = (value)=>isEmitJsonOnlyTransport(value) || isReceiveJsonOnlyTransport(value);
|
|
194
|
+
const isEmitTransport = (value)=>isEmitJsonOnlyTransport(value) || isWindow(value) || isServiceWorkerContainer(value) || isWorker(value) || isDedicatedWorker(value) || isSharedWorker(value) || isMessagePort(value) || isCustomEmitTransport(value);
|
|
195
|
+
const isReceiveTransport = (value)=>isReceiveJsonOnlyTransport(value) || isWindow(value) || isServiceWorkerContainer(value) || isWorker(value) || isDedicatedWorker(value) || isSharedWorker(value) || isMessagePort(value) || isCustomReceiveTransport(value);
|
|
196
|
+
const isCustomEmitTransport = (value)=>Boolean(value && typeof value === "object" && ("emit" in value && (isEmitTransport(value.emit) || typeof value.emit === "function")));
|
|
197
|
+
const isCustomReceiveTransport = (value)=>Boolean(value && typeof value === "object" && ("receive" in value && (isReceiveTransport(value.receive) || typeof value.receive === "function")));
|
|
198
|
+
const isCustomTransport = (value)=>isCustomEmitTransport(value) || isCustomReceiveTransport(value);
|
|
199
|
+
const isRevivable = (value)=>isMessagePort(value) || isFunction(value) || isPromise(value) || isTypedArray(value) || isArrayBuffer(value) || isReadableStream(value) || isDate(value) || isError(value);
|
|
200
|
+
const isRevivableBox = (value)=>value && typeof value === "object" && OSRA_BOX in value && value[OSRA_BOX] === "revivable";
|
|
201
|
+
const isRevivableMessagePortBox = (value)=>isRevivableBox(value) && value.type === "messagePort";
|
|
202
|
+
const isRevivablePromiseBox = (value)=>isRevivableBox(value) && value.type === "promise";
|
|
203
|
+
const isRevivableFunctionBox = (value)=>isRevivableBox(value) && value.type === "function";
|
|
204
|
+
const isRevivableTypedArrayBox = (value)=>isRevivableBox(value) && value.type === "typedArray";
|
|
205
|
+
const isRevivableArrayBufferBox = (value)=>isRevivableBox(value) && value.type === "arrayBuffer";
|
|
206
|
+
const isRevivableReadableStreamBox = (value)=>isRevivableBox(value) && value.type === "readableStream";
|
|
207
|
+
const isRevivableErrorBox = (value)=>isRevivableBox(value) && value.type === "error";
|
|
208
|
+
const isRevivableDateBox = (value)=>isRevivableBox(value) && value.type === "date";
|
|
209
|
+
const getTransferableObjects = (value)=>{
|
|
210
|
+
const transferables = [];
|
|
211
|
+
const recurse = (value2)=>isClonable(value2) ? void 0 : isTransferable(value2) ? transferables.push(value2) : Array.isArray(value2) ? value2.map(recurse) : value2 && typeof value2 === "object" ? Object.values(value2).map(recurse) : void 0;
|
|
212
|
+
recurse(value);
|
|
213
|
+
return transferables;
|
|
214
|
+
};
|
|
215
|
+
const probePlatformCapabilityUtil = (value, transfer = false)=>{
|
|
216
|
+
const { port1, port2 } = new MessageChannel();
|
|
217
|
+
const result = new Promise((resolve)=>port1.addEventListener("message", (message)=>resolve(message.data)));
|
|
218
|
+
port1.start();
|
|
219
|
+
port2.postMessage(value, transfer ? getTransferableObjects(value) : []);
|
|
220
|
+
return result;
|
|
221
|
+
};
|
|
222
|
+
const probeMessagePortTransfer = async ()=>{
|
|
223
|
+
const { port1 } = new MessageChannel();
|
|
224
|
+
const port = await probePlatformCapabilityUtil(port1, true);
|
|
225
|
+
return port instanceof MessagePort;
|
|
226
|
+
};
|
|
227
|
+
const probeArrayBufferClone = async ()=>{
|
|
228
|
+
const buffer = new ArrayBuffer(1);
|
|
229
|
+
const arrayBuffer = await probePlatformCapabilityUtil(buffer);
|
|
230
|
+
return arrayBuffer instanceof ArrayBuffer;
|
|
231
|
+
};
|
|
232
|
+
const probeArrayBufferTransfer = async ()=>{
|
|
233
|
+
const buffer = new ArrayBuffer(1);
|
|
234
|
+
const arrayBuffer = await probePlatformCapabilityUtil(buffer, true);
|
|
235
|
+
return arrayBuffer instanceof ArrayBuffer;
|
|
236
|
+
};
|
|
237
|
+
const probeTransferableStream = async ()=>{
|
|
238
|
+
const stream = new ReadableStream({
|
|
239
|
+
start (controller) {
|
|
240
|
+
controller.enqueue(new Uint8Array(1));
|
|
241
|
+
controller.close();
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
const transferableStream = await probePlatformCapabilityUtil(stream, true);
|
|
245
|
+
return transferableStream instanceof ReadableStream;
|
|
246
|
+
};
|
|
247
|
+
const probePlatformCapabilities = async ()=>{
|
|
248
|
+
const [messagePort, arrayBuffer, transferable, transferableStream] = await Promise.all([
|
|
249
|
+
probeMessagePortTransfer().catch(()=>false),
|
|
250
|
+
probeArrayBufferClone().catch(()=>false),
|
|
251
|
+
probeArrayBufferTransfer().catch(()=>false),
|
|
252
|
+
probeTransferableStream().catch(()=>false)
|
|
253
|
+
]);
|
|
254
|
+
return {
|
|
255
|
+
jsonOnly: !messagePort && !arrayBuffer && !transferable && !transferableStream,
|
|
256
|
+
messagePort,
|
|
257
|
+
arrayBuffer,
|
|
258
|
+
transferable,
|
|
259
|
+
transferableStream
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
const boxMessagePort = (value, context)=>{
|
|
263
|
+
const messagePort = value;
|
|
264
|
+
const { uuid: portId } = context.messageChannels.alloc(void 0, {
|
|
265
|
+
port1: messagePort
|
|
266
|
+
});
|
|
267
|
+
messagePort.addEventListener("message", ({ data })=>{
|
|
268
|
+
context.sendMessage({
|
|
269
|
+
type: "message",
|
|
270
|
+
remoteUuid: context.remoteUuid,
|
|
271
|
+
data: isRevivableBox(data) ? data : recursiveBox(data, context),
|
|
272
|
+
portId
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
messagePort.start();
|
|
276
|
+
context.eventTarget.addEventListener("message", function listener({ detail: message }) {
|
|
277
|
+
if (message.type === "message-port-close") {
|
|
278
|
+
if (message.portId !== portId) return;
|
|
279
|
+
context.eventTarget.removeEventListener("message", listener);
|
|
280
|
+
messagePort.close();
|
|
281
|
+
context.messageChannels.free(portId);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (message.type !== "message" || message.portId !== portId) return;
|
|
285
|
+
messagePort.postMessage(message.data, getTransferableObjects(message.data));
|
|
286
|
+
});
|
|
287
|
+
return {
|
|
288
|
+
type: "messagePort",
|
|
289
|
+
portId
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
const reviveMessagePort = (value, context)=>{
|
|
293
|
+
const { port1: userPort, port2: internalPort } = new MessageChannel();
|
|
294
|
+
internalPort.addEventListener("message", ({ data })=>{
|
|
295
|
+
context.sendMessage({
|
|
296
|
+
type: "message",
|
|
297
|
+
remoteUuid: context.remoteUuid,
|
|
298
|
+
data: isRevivableBox(data) ? data : recursiveBox(data, context),
|
|
299
|
+
portId: value.portId
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
internalPort.start();
|
|
303
|
+
const existingChannel = context.messageChannels.get(value.portId);
|
|
304
|
+
const { port1 } = existingChannel ? existingChannel : context.messageChannels.alloc(value.portId);
|
|
305
|
+
port1.addEventListener("message", function listener({ data: message }) {
|
|
306
|
+
if (message.type === "message-port-close") {
|
|
307
|
+
if (message.portId !== value.portId) return;
|
|
308
|
+
port1.removeEventListener("message", listener);
|
|
309
|
+
internalPort.close();
|
|
310
|
+
context.messageChannels.free(value.portId);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (message.type !== "message" || message.portId !== value.portId) return;
|
|
314
|
+
if (context.messagePorts.has(userPort)) {
|
|
315
|
+
internalPort.postMessage(message.data);
|
|
316
|
+
} else {
|
|
317
|
+
const revivedData = recursiveRevive(message.data, context);
|
|
318
|
+
internalPort.postMessage(revivedData, getTransferableObjects(revivedData));
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
port1.start();
|
|
322
|
+
return userPort;
|
|
323
|
+
};
|
|
324
|
+
const boxPromise = (value, context)=>{
|
|
325
|
+
const { port1: localPort, port2: remotePort } = new MessageChannel();
|
|
326
|
+
context.messagePorts.add(remotePort);
|
|
327
|
+
const sendResult = (result)=>{
|
|
328
|
+
const boxedResult = recursiveBox(result, context);
|
|
329
|
+
localPort.postMessage(boxedResult, getTransferableObjects(boxedResult));
|
|
330
|
+
localPort.close();
|
|
331
|
+
};
|
|
332
|
+
value.then((data)=>sendResult({
|
|
333
|
+
type: "resolve",
|
|
334
|
+
data
|
|
335
|
+
})).catch((error)=>sendResult({
|
|
336
|
+
type: "reject",
|
|
337
|
+
error: error.stack
|
|
338
|
+
}));
|
|
339
|
+
return {
|
|
340
|
+
type: "promise",
|
|
341
|
+
port: remotePort
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
const revivePromise = (value, context)=>{
|
|
345
|
+
context.messagePorts.add(value.port);
|
|
346
|
+
return new Promise((resolve, reject)=>{
|
|
347
|
+
value.port.addEventListener("message", ({ data })=>{
|
|
348
|
+
const result = recursiveRevive(data, context);
|
|
349
|
+
if (result.type === "resolve") {
|
|
350
|
+
resolve(result.data);
|
|
351
|
+
} else {
|
|
352
|
+
reject(result.error);
|
|
353
|
+
}
|
|
354
|
+
value.port.close();
|
|
355
|
+
}, {
|
|
356
|
+
once: true
|
|
357
|
+
});
|
|
358
|
+
value.port.start();
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
const boxFunction = (value, context)=>{
|
|
362
|
+
const { port1: localPort, port2: remotePort } = new MessageChannel();
|
|
363
|
+
context.messagePorts.add(remotePort);
|
|
364
|
+
localPort.addEventListener("message", ({ data })=>{
|
|
365
|
+
const [returnValuePort, args] = recursiveRevive(data, context);
|
|
366
|
+
const result = (async ()=>value(...args))();
|
|
367
|
+
const boxedResult = recursiveBox(result, context);
|
|
368
|
+
returnValuePort.postMessage(boxedResult, getTransferableObjects(boxedResult));
|
|
369
|
+
});
|
|
370
|
+
localPort.start();
|
|
371
|
+
return {
|
|
372
|
+
type: "function",
|
|
373
|
+
port: remotePort
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
const reviveFunction = (value, context)=>{
|
|
377
|
+
const func = (...args)=>new Promise((resolve, reject)=>{
|
|
378
|
+
const { port1: returnValueLocalPort, port2: returnValueRemotePort } = new MessageChannel();
|
|
379
|
+
context.messagePorts.add(returnValueRemotePort);
|
|
380
|
+
const callContext = recursiveBox([
|
|
381
|
+
returnValueRemotePort,
|
|
382
|
+
args
|
|
383
|
+
], context);
|
|
384
|
+
value.port.postMessage(callContext, getTransferableObjects(callContext));
|
|
385
|
+
returnValueLocalPort.addEventListener("message", ({ data })=>{
|
|
386
|
+
if (!isRevivablePromiseBox(data)) throw new Error(`Proxied function did not return a promise`);
|
|
387
|
+
const result = recursiveRevive(data, context);
|
|
388
|
+
result.then(resolve).catch(reject).finally(()=>returnValueLocalPort.close());
|
|
389
|
+
});
|
|
390
|
+
returnValueLocalPort.start();
|
|
391
|
+
});
|
|
392
|
+
return func;
|
|
393
|
+
};
|
|
394
|
+
const boxTypedArray = (value, context)=>{
|
|
395
|
+
return {
|
|
396
|
+
type: "typedArray",
|
|
397
|
+
typedArrayType: typedArrayToType(value),
|
|
398
|
+
arrayBuffer: value.buffer
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
const reviveTypedArray = (value, context)=>{
|
|
402
|
+
const TypedArrayConstructor = typedArrayTypeToTypedArrayConstructor(value.typedArrayType);
|
|
403
|
+
const result = new TypedArrayConstructor(value.arrayBuffer);
|
|
404
|
+
return result;
|
|
405
|
+
};
|
|
406
|
+
const boxArrayBuffer = (value, context)=>{
|
|
407
|
+
return {
|
|
408
|
+
type: "arrayBuffer",
|
|
409
|
+
base64Buffer: new Uint8Array(value).toBase64()
|
|
410
|
+
};
|
|
411
|
+
};
|
|
412
|
+
const reviveArrayBuffer = (value, context)=>{
|
|
413
|
+
return Uint8Array.fromBase64(value.base64Buffer).buffer;
|
|
414
|
+
};
|
|
415
|
+
const boxError = (value, context)=>{
|
|
416
|
+
return {
|
|
417
|
+
type: "error",
|
|
418
|
+
message: value.message,
|
|
419
|
+
stack: value.stack || value.toString()
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
const reviveError = (value, context)=>{
|
|
423
|
+
return new Error(value.message, {
|
|
424
|
+
cause: value.stack
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
const boxReadableStream = (value, context)=>{
|
|
428
|
+
const { port1: localPort, port2: remotePort } = new MessageChannel();
|
|
429
|
+
context.messagePorts.add(remotePort);
|
|
430
|
+
const reader = value.getReader();
|
|
431
|
+
localPort.addEventListener("message", async ({ data })=>{
|
|
432
|
+
const { type } = recursiveRevive(data, context);
|
|
433
|
+
if (type === "pull") {
|
|
434
|
+
const pullResult = reader.read();
|
|
435
|
+
const boxedResult = recursiveBox(pullResult, context);
|
|
436
|
+
localPort.postMessage(boxedResult, getTransferableObjects(boxedResult));
|
|
437
|
+
} else {
|
|
438
|
+
reader.cancel();
|
|
439
|
+
localPort.close();
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
localPort.start();
|
|
443
|
+
return {
|
|
444
|
+
type: "readableStream",
|
|
445
|
+
port: remotePort
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
const reviveReadableStream = (value, context)=>{
|
|
449
|
+
context.messagePorts.add(value.port);
|
|
450
|
+
value.port.start();
|
|
451
|
+
return new ReadableStream({
|
|
452
|
+
start (controller) {},
|
|
453
|
+
pull (controller) {
|
|
454
|
+
return new Promise((resolve, reject)=>{
|
|
455
|
+
value.port.addEventListener("message", async ({ data })=>{
|
|
456
|
+
if (!isRevivablePromiseBox(data)) throw new Error(`Proxied function did not return a promise`);
|
|
457
|
+
const result = recursiveRevive(data, context);
|
|
458
|
+
result.then((result2)=>{
|
|
459
|
+
if (result2.done) controller.close();
|
|
460
|
+
else controller.enqueue(result2.value);
|
|
461
|
+
resolve();
|
|
462
|
+
}).catch(reject);
|
|
463
|
+
}, {
|
|
464
|
+
once: true
|
|
465
|
+
});
|
|
466
|
+
value.port.postMessage(recursiveBox({
|
|
467
|
+
type: "pull"
|
|
468
|
+
}, context));
|
|
469
|
+
});
|
|
470
|
+
},
|
|
471
|
+
cancel () {
|
|
472
|
+
value.port.postMessage(recursiveBox({
|
|
473
|
+
type: "cancel"
|
|
474
|
+
}, context));
|
|
475
|
+
value.port.close();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
};
|
|
479
|
+
const boxDate = (value, context)=>{
|
|
480
|
+
return {
|
|
481
|
+
type: "date",
|
|
482
|
+
ISOString: value.toISOString()
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
const reviveDate = (value, context)=>{
|
|
486
|
+
return new Date(value.ISOString);
|
|
487
|
+
};
|
|
488
|
+
const box = (value, context)=>{
|
|
489
|
+
if (isAlwaysBox(value) || isReadableStream(value) && !context.platformCapabilities.transferableStream) {
|
|
490
|
+
return {
|
|
491
|
+
[OSRA_BOX]: "revivable",
|
|
492
|
+
...isFunction(value) ? boxFunction(value, context) : isPromise(value) ? boxPromise(value, context) : isTypedArray(value) ? boxTypedArray(value) : isReadableStream(value) ? boxReadableStream(value, context) : isDate(value) ? boxDate(value) : isError(value) ? boxError(value) : value
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
[OSRA_BOX]: "revivable",
|
|
497
|
+
..."isJson" in context.transport && context.transport.isJson ? isMessagePort(value) ? boxMessagePort(value, context) : isArrayBuffer(value) ? boxArrayBuffer(value) : isReadableStream(value) ? boxReadableStream(value, context) : {
|
|
498
|
+
type: "unknown",
|
|
499
|
+
value
|
|
500
|
+
} : {
|
|
501
|
+
type: isMessagePort(value) ? "messagePort" : isArrayBuffer(value) ? "arrayBuffer" : isReadableStream(value) ? "readableStream" : "unknown",
|
|
502
|
+
value
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
};
|
|
506
|
+
const recursiveBox = (value, context)=>{
|
|
507
|
+
const boxedValue = isRevivable(value) ? box(value, context) : value;
|
|
508
|
+
return Array.isArray(boxedValue) ? boxedValue.map((value2)=>recursiveBox(value2, context)) : boxedValue && typeof boxedValue === "object" && Object.getPrototypeOf(boxedValue) === Object.prototype ? Object.fromEntries(Object.entries(boxedValue).map(([key, value2])=>[
|
|
509
|
+
key,
|
|
510
|
+
isRevivableBox(boxedValue) && boxedValue.type === "messagePort" && boxedValue.value instanceof MessagePort || isRevivableBox(boxedValue) && boxedValue.type === "arrayBuffer" && boxedValue.value instanceof ArrayBuffer || isRevivableBox(boxedValue) && boxedValue.type === "readableStream" && boxedValue.value instanceof ReadableStream ? value2 : recursiveBox(value2, context)
|
|
511
|
+
])) : boxedValue;
|
|
512
|
+
};
|
|
513
|
+
const revive = (box2, context)=>{
|
|
514
|
+
if (isRevivable(box2.value)) return box2.value;
|
|
515
|
+
return isRevivableMessagePortBox(box2) ? reviveMessagePort(box2, context) : isRevivableFunctionBox(box2) ? reviveFunction(box2, context) : isRevivablePromiseBox(box2) ? revivePromise(box2, context) : isRevivableErrorBox(box2) ? reviveError(box2) : isRevivableTypedArrayBox(box2) ? reviveTypedArray(box2) : isRevivableArrayBufferBox(box2) ? reviveArrayBuffer(box2) : isRevivableReadableStreamBox(box2) ? reviveReadableStream(box2, context) : isRevivableDateBox(box2) ? reviveDate(box2) : box2;
|
|
516
|
+
};
|
|
517
|
+
const recursiveRevive = (value, context)=>{
|
|
518
|
+
const recursedValue = isTransferable(value) ? value : Array.isArray(value) ? value.map((value2)=>recursiveRevive(value2, context)) : value && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([key, value2])=>[
|
|
519
|
+
key,
|
|
520
|
+
recursiveRevive(value2, context)
|
|
521
|
+
])) : value;
|
|
522
|
+
return isRevivableBox(recursedValue) ? revive(recursedValue, context) : recursedValue;
|
|
523
|
+
};
|
|
524
|
+
const startBidirectionalConnection = ({ transport, value, uuid, remoteUuid, platformCapabilities, eventTarget, send, close })=>{
|
|
525
|
+
const revivableContext = {
|
|
526
|
+
platformCapabilities,
|
|
527
|
+
transport,
|
|
528
|
+
remoteUuid,
|
|
529
|
+
messagePorts: new Set(),
|
|
530
|
+
messageChannels: makeMessageChannelAllocator(),
|
|
531
|
+
sendMessage: send,
|
|
532
|
+
eventTarget
|
|
533
|
+
};
|
|
534
|
+
let initResolve;
|
|
535
|
+
const initMessage = new Promise((resolve, reject)=>{
|
|
536
|
+
initResolve = resolve;
|
|
537
|
+
});
|
|
538
|
+
eventTarget.addEventListener("message", ({ detail })=>{
|
|
539
|
+
if (detail.type === "init") {
|
|
540
|
+
initResolve(detail);
|
|
541
|
+
return;
|
|
542
|
+
} else if (detail.type === "message") {
|
|
543
|
+
const messageChannel = revivableContext.messageChannels.getOrAlloc(detail.portId);
|
|
544
|
+
messageChannel.port2?.postMessage(detail);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
send({
|
|
548
|
+
type: "init",
|
|
549
|
+
remoteUuid,
|
|
550
|
+
data: recursiveBox(value, revivableContext)
|
|
551
|
+
});
|
|
552
|
+
return {
|
|
553
|
+
revivableContext,
|
|
554
|
+
close: ()=>{},
|
|
555
|
+
remoteValue: initMessage.then((initMessage2)=>recursiveRevive(initMessage2.data, revivableContext))
|
|
556
|
+
};
|
|
557
|
+
};
|
|
558
|
+
const startUnidirectionalEmittingConnection = ({ value, uuid, platformCapabilities, send, close })=>{
|
|
559
|
+
return {
|
|
560
|
+
close: ()=>{},
|
|
561
|
+
remoteValueProxy: new Proxy(new Function(), {
|
|
562
|
+
apply: (target, thisArg, args)=>{},
|
|
563
|
+
get: (target, prop)=>{}
|
|
564
|
+
})
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
var e = class extends EventTarget {
|
|
568
|
+
dispatchTypedEvent(s, t) {
|
|
569
|
+
return super.dispatchEvent(t);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
const expose = async (value, { transport: _transport, name, remoteName, key = OSRA_DEFAULT_KEY, origin = "*", unregisterSignal, platformCapabilities: _platformCapabilities, transferAll, logger })=>{
|
|
573
|
+
const transport = {
|
|
574
|
+
isJson: "isJson" in _transport && _transport.isJson !== void 0 ? _transport.isJson : isJsonOnlyTransport(_transport),
|
|
575
|
+
...isCustomTransport(_transport) ? _transport : {
|
|
576
|
+
emit: _transport,
|
|
577
|
+
receive: _transport
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
const platformCapabilities = _platformCapabilities ?? await probePlatformCapabilities();
|
|
581
|
+
const connectionContexts = new Map();
|
|
582
|
+
let resolveRemoteValue;
|
|
583
|
+
const remoteValuePromise = new Promise((resolve)=>{
|
|
584
|
+
resolveRemoteValue = resolve;
|
|
585
|
+
});
|
|
586
|
+
let uuid = globalThis.crypto.randomUUID();
|
|
587
|
+
const sendMessage = (transport2, message)=>{
|
|
588
|
+
const transferables = getTransferableObjects(message);
|
|
589
|
+
sendOsraMessage(transport2, {
|
|
590
|
+
[OSRA_KEY]: key,
|
|
591
|
+
name,
|
|
592
|
+
uuid,
|
|
593
|
+
...message
|
|
594
|
+
}, origin, transferables);
|
|
595
|
+
};
|
|
596
|
+
const listener = async (message, messageContext)=>{
|
|
597
|
+
if (message.uuid === uuid) return;
|
|
598
|
+
if (!isEmitTransport(transport)) {
|
|
599
|
+
throw new Error("Unidirectional receiving mode not implemented");
|
|
600
|
+
}
|
|
601
|
+
if (message.type === "announce") {
|
|
602
|
+
if (!message.remoteUuid) {
|
|
603
|
+
sendMessage(transport, {
|
|
604
|
+
type: "announce",
|
|
605
|
+
remoteUuid: message.uuid
|
|
606
|
+
});
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
if (message.remoteUuid !== uuid) return;
|
|
610
|
+
if (connectionContexts.has(message.uuid)) {
|
|
611
|
+
sendMessage(transport, {
|
|
612
|
+
type: "reject-uuid-taken",
|
|
613
|
+
remoteUuid: message.uuid
|
|
614
|
+
});
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const eventTarget = new e();
|
|
618
|
+
const connectionContext = {
|
|
619
|
+
type: "bidirectional",
|
|
620
|
+
eventTarget,
|
|
621
|
+
connection: startBidirectionalConnection({
|
|
622
|
+
transport,
|
|
623
|
+
value,
|
|
624
|
+
uuid,
|
|
625
|
+
remoteUuid: message.uuid,
|
|
626
|
+
platformCapabilities,
|
|
627
|
+
eventTarget,
|
|
628
|
+
send: (message2)=>sendMessage(transport, message2),
|
|
629
|
+
close: ()=>void connectionContexts.delete(message.uuid)
|
|
630
|
+
})
|
|
631
|
+
};
|
|
632
|
+
connectionContexts.set(message.uuid, connectionContext);
|
|
633
|
+
connectionContext.connection.remoteValue.then((remoteValue)=>resolveRemoteValue(remoteValue));
|
|
634
|
+
} else if (message.type === "reject-uuid-taken") {
|
|
635
|
+
if (message.remoteUuid !== uuid) return;
|
|
636
|
+
uuid = globalThis.crypto.randomUUID();
|
|
637
|
+
sendMessage(transport, {
|
|
638
|
+
type: "announce"
|
|
639
|
+
});
|
|
640
|
+
} else if (message.type === "close") {
|
|
641
|
+
if (message.remoteUuid !== uuid) return;
|
|
642
|
+
const connectionContext = connectionContexts.get(message.uuid);
|
|
643
|
+
if (!connectionContext) {
|
|
644
|
+
console.warn(`Connection not found for remoteUuid: ${message.uuid}`);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
connectionContext.connection.close();
|
|
648
|
+
connectionContexts.delete(message.uuid);
|
|
649
|
+
} else {
|
|
650
|
+
if (message.remoteUuid !== uuid) return;
|
|
651
|
+
const connection = connectionContexts.get(message.uuid);
|
|
652
|
+
if (!connection) {
|
|
653
|
+
console.warn(`Connection not found for remoteUuid: ${message.uuid}`);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (connection.type !== "unidirectional-emitting") {
|
|
657
|
+
connection.eventTarget.dispatchTypedEvent("message", new CustomEvent("message", {
|
|
658
|
+
detail: message
|
|
659
|
+
}));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
if (isReceiveTransport(transport)) {
|
|
664
|
+
registerOsraMessageListener({
|
|
665
|
+
listener,
|
|
666
|
+
transport,
|
|
667
|
+
remoteName,
|
|
668
|
+
key,
|
|
669
|
+
unregisterSignal
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
if (isEmitTransport(transport)) {
|
|
673
|
+
sendMessage(transport, {
|
|
674
|
+
type: "announce"
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
if (isEmitTransport(transport) && !isReceiveTransport(transport)) {
|
|
678
|
+
const { remoteValueProxy } = startUnidirectionalEmittingConnection({
|
|
679
|
+
value,
|
|
680
|
+
uuid,
|
|
681
|
+
platformCapabilities,
|
|
682
|
+
send: (message)=>sendMessage(transport, message),
|
|
683
|
+
close: ()=>connectionContexts.delete(uuid)
|
|
684
|
+
});
|
|
685
|
+
return remoteValueProxy;
|
|
686
|
+
}
|
|
687
|
+
return remoteValuePromise;
|
|
688
|
+
};
|
|
689
|
+
var __defProp = Object.defineProperty;
|
|
690
|
+
var __name = (target, value)=>__defProp(target, "name", {
|
|
691
|
+
value,
|
|
692
|
+
configurable: true
|
|
693
|
+
});
|
|
694
|
+
var __export = (target, all)=>{
|
|
695
|
+
for(var name in all)__defProp(target, name, {
|
|
696
|
+
get: all[name],
|
|
697
|
+
enumerable: true
|
|
698
|
+
});
|
|
699
|
+
};
|
|
700
|
+
var utils_exports = {};
|
|
701
|
+
__export(utils_exports, {
|
|
702
|
+
addChainableMethod: ()=>addChainableMethod,
|
|
703
|
+
addLengthGuard: ()=>addLengthGuard,
|
|
704
|
+
addMethod: ()=>addMethod,
|
|
705
|
+
addProperty: ()=>addProperty,
|
|
706
|
+
checkError: ()=>check_error_exports,
|
|
707
|
+
compareByInspect: ()=>compareByInspect,
|
|
708
|
+
eql: ()=>deep_eql_default,
|
|
709
|
+
expectTypes: ()=>expectTypes,
|
|
710
|
+
flag: ()=>flag,
|
|
711
|
+
getActual: ()=>getActual,
|
|
712
|
+
getMessage: ()=>getMessage2,
|
|
713
|
+
getName: ()=>getName,
|
|
714
|
+
getOperator: ()=>getOperator,
|
|
715
|
+
getOwnEnumerableProperties: ()=>getOwnEnumerableProperties,
|
|
716
|
+
getOwnEnumerablePropertySymbols: ()=>getOwnEnumerablePropertySymbols,
|
|
717
|
+
getPathInfo: ()=>getPathInfo,
|
|
718
|
+
hasProperty: ()=>hasProperty,
|
|
719
|
+
inspect: ()=>inspect2,
|
|
720
|
+
isNaN: ()=>isNaN2,
|
|
721
|
+
isNumeric: ()=>isNumeric,
|
|
722
|
+
isProxyEnabled: ()=>isProxyEnabled,
|
|
723
|
+
isRegExp: ()=>isRegExp2,
|
|
724
|
+
objDisplay: ()=>objDisplay,
|
|
725
|
+
overwriteChainableMethod: ()=>overwriteChainableMethod,
|
|
726
|
+
overwriteMethod: ()=>overwriteMethod,
|
|
727
|
+
overwriteProperty: ()=>overwriteProperty,
|
|
728
|
+
proxify: ()=>proxify,
|
|
729
|
+
test: ()=>test,
|
|
730
|
+
transferFlags: ()=>transferFlags,
|
|
731
|
+
type: ()=>type
|
|
732
|
+
});
|
|
733
|
+
var check_error_exports = {};
|
|
734
|
+
__export(check_error_exports, {
|
|
735
|
+
compatibleConstructor: ()=>compatibleConstructor$1,
|
|
736
|
+
compatibleInstance: ()=>compatibleInstance$1,
|
|
737
|
+
compatibleMessage: ()=>compatibleMessage$1,
|
|
738
|
+
getConstructorName: ()=>getConstructorName$1,
|
|
739
|
+
getMessage: ()=>getMessage$1
|
|
740
|
+
});
|
|
741
|
+
function isErrorInstance$1(obj) {
|
|
742
|
+
return obj instanceof Error || Object.prototype.toString.call(obj) === "[object Error]";
|
|
743
|
+
}
|
|
744
|
+
__name(isErrorInstance$1, "isErrorInstance");
|
|
745
|
+
function isRegExp$1(obj) {
|
|
746
|
+
return Object.prototype.toString.call(obj) === "[object RegExp]";
|
|
747
|
+
}
|
|
748
|
+
__name(isRegExp$1, "isRegExp");
|
|
749
|
+
function compatibleInstance$1(thrown, errorLike) {
|
|
750
|
+
return isErrorInstance$1(errorLike) && thrown === errorLike;
|
|
751
|
+
}
|
|
752
|
+
__name(compatibleInstance$1, "compatibleInstance");
|
|
753
|
+
function compatibleConstructor$1(thrown, errorLike) {
|
|
754
|
+
if (isErrorInstance$1(errorLike)) {
|
|
755
|
+
return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
|
|
756
|
+
} else if ((typeof errorLike === "object" || typeof errorLike === "function") && errorLike.prototype) {
|
|
757
|
+
return thrown.constructor === errorLike || thrown instanceof errorLike;
|
|
758
|
+
}
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
__name(compatibleConstructor$1, "compatibleConstructor");
|
|
762
|
+
function compatibleMessage$1(thrown, errMatcher) {
|
|
763
|
+
const comparisonString = typeof thrown === "string" ? thrown : thrown.message;
|
|
764
|
+
if (isRegExp$1(errMatcher)) {
|
|
765
|
+
return errMatcher.test(comparisonString);
|
|
766
|
+
} else if (typeof errMatcher === "string") {
|
|
767
|
+
return comparisonString.indexOf(errMatcher) !== -1;
|
|
768
|
+
}
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
__name(compatibleMessage$1, "compatibleMessage");
|
|
772
|
+
function getConstructorName$1(errorLike) {
|
|
773
|
+
let constructorName = errorLike;
|
|
774
|
+
if (isErrorInstance$1(errorLike)) {
|
|
775
|
+
constructorName = errorLike.constructor.name;
|
|
776
|
+
} else if (typeof errorLike === "function") {
|
|
777
|
+
constructorName = errorLike.name;
|
|
778
|
+
if (constructorName === "") {
|
|
779
|
+
const newConstructorName = new errorLike().name;
|
|
780
|
+
constructorName = newConstructorName || constructorName;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return constructorName;
|
|
784
|
+
}
|
|
785
|
+
__name(getConstructorName$1, "getConstructorName");
|
|
786
|
+
function getMessage$1(errorLike) {
|
|
787
|
+
let msg = "";
|
|
788
|
+
if (errorLike && errorLike.message) {
|
|
789
|
+
msg = errorLike.message;
|
|
790
|
+
} else if (typeof errorLike === "string") {
|
|
791
|
+
msg = errorLike;
|
|
792
|
+
}
|
|
793
|
+
return msg;
|
|
794
|
+
}
|
|
795
|
+
__name(getMessage$1, "getMessage");
|
|
796
|
+
function flag(obj, key, value) {
|
|
797
|
+
let flags = obj.__flags || (obj.__flags = Object.create(null));
|
|
798
|
+
if (arguments.length === 3) {
|
|
799
|
+
flags[key] = value;
|
|
800
|
+
} else {
|
|
801
|
+
return flags[key];
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
__name(flag, "flag");
|
|
805
|
+
function test(obj, args) {
|
|
806
|
+
let negate = flag(obj, "negate"), expr = args[0];
|
|
807
|
+
return negate ? !expr : expr;
|
|
808
|
+
}
|
|
809
|
+
__name(test, "test");
|
|
810
|
+
function type(obj) {
|
|
811
|
+
if (typeof obj === "undefined") {
|
|
812
|
+
return "undefined";
|
|
813
|
+
}
|
|
814
|
+
if (obj === null) {
|
|
815
|
+
return "null";
|
|
816
|
+
}
|
|
817
|
+
const stringTag = obj[Symbol.toStringTag];
|
|
818
|
+
if (typeof stringTag === "string") {
|
|
819
|
+
return stringTag;
|
|
820
|
+
}
|
|
821
|
+
const type3 = Object.prototype.toString.call(obj).slice(8, -1);
|
|
822
|
+
return type3;
|
|
823
|
+
}
|
|
824
|
+
__name(type, "type");
|
|
825
|
+
var canElideFrames = "captureStackTrace" in Error;
|
|
826
|
+
var AssertionError = class _AssertionError extends Error {
|
|
827
|
+
static{
|
|
828
|
+
__name(this, "AssertionError");
|
|
829
|
+
}
|
|
830
|
+
message;
|
|
831
|
+
get name() {
|
|
832
|
+
return "AssertionError";
|
|
833
|
+
}
|
|
834
|
+
get ok() {
|
|
835
|
+
return false;
|
|
836
|
+
}
|
|
837
|
+
constructor(message = "Unspecified AssertionError", props, ssf){
|
|
838
|
+
super(message);
|
|
839
|
+
this.message = message;
|
|
840
|
+
if (canElideFrames) {
|
|
841
|
+
Error.captureStackTrace(this, ssf || _AssertionError);
|
|
842
|
+
}
|
|
843
|
+
for(const key in props){
|
|
844
|
+
if (!(key in this)) {
|
|
845
|
+
this[key] = props[key];
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
toJSON(stack) {
|
|
850
|
+
return {
|
|
851
|
+
...this,
|
|
852
|
+
name: this.name,
|
|
853
|
+
message: this.message,
|
|
854
|
+
ok: false,
|
|
855
|
+
stack: stack !== false ? this.stack : void 0
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
function expectTypes(obj, types) {
|
|
860
|
+
let flagMsg = flag(obj, "message");
|
|
861
|
+
let ssfi = flag(obj, "ssfi");
|
|
862
|
+
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
863
|
+
obj = flag(obj, "object");
|
|
864
|
+
types = types.map(function(t) {
|
|
865
|
+
return t.toLowerCase();
|
|
866
|
+
});
|
|
867
|
+
types.sort();
|
|
868
|
+
let str = types.map(function(t, index) {
|
|
869
|
+
let art = ~[
|
|
870
|
+
"a",
|
|
871
|
+
"e",
|
|
872
|
+
"i",
|
|
873
|
+
"o",
|
|
874
|
+
"u"
|
|
875
|
+
].indexOf(t.charAt(0)) ? "an" : "a";
|
|
876
|
+
let or = types.length > 1 && index === types.length - 1 ? "or " : "";
|
|
877
|
+
return or + art + " " + t;
|
|
878
|
+
}).join(", ");
|
|
879
|
+
let objType = type(obj).toLowerCase();
|
|
880
|
+
if (!types.some(function(expected) {
|
|
881
|
+
return objType === expected;
|
|
882
|
+
})) {
|
|
883
|
+
throw new AssertionError(flagMsg + "object tested must be " + str + ", but " + objType + " given", void 0, ssfi);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
__name(expectTypes, "expectTypes");
|
|
887
|
+
function getActual(obj, args) {
|
|
888
|
+
return args.length > 4 ? args[4] : obj._obj;
|
|
889
|
+
}
|
|
890
|
+
__name(getActual, "getActual");
|
|
891
|
+
var ansiColors = {
|
|
892
|
+
bold: [
|
|
893
|
+
"1",
|
|
894
|
+
"22"
|
|
895
|
+
],
|
|
896
|
+
dim: [
|
|
897
|
+
"2",
|
|
898
|
+
"22"
|
|
899
|
+
],
|
|
900
|
+
italic: [
|
|
901
|
+
"3",
|
|
902
|
+
"23"
|
|
903
|
+
],
|
|
904
|
+
underline: [
|
|
905
|
+
"4",
|
|
906
|
+
"24"
|
|
907
|
+
],
|
|
908
|
+
inverse: [
|
|
909
|
+
"7",
|
|
910
|
+
"27"
|
|
911
|
+
],
|
|
912
|
+
hidden: [
|
|
913
|
+
"8",
|
|
914
|
+
"28"
|
|
915
|
+
],
|
|
916
|
+
strike: [
|
|
917
|
+
"9",
|
|
918
|
+
"29"
|
|
919
|
+
],
|
|
920
|
+
black: [
|
|
921
|
+
"30",
|
|
922
|
+
"39"
|
|
923
|
+
],
|
|
924
|
+
red: [
|
|
925
|
+
"31",
|
|
926
|
+
"39"
|
|
927
|
+
],
|
|
928
|
+
green: [
|
|
929
|
+
"32",
|
|
930
|
+
"39"
|
|
931
|
+
],
|
|
932
|
+
yellow: [
|
|
933
|
+
"33",
|
|
934
|
+
"39"
|
|
935
|
+
],
|
|
936
|
+
blue: [
|
|
937
|
+
"34",
|
|
938
|
+
"39"
|
|
939
|
+
],
|
|
940
|
+
magenta: [
|
|
941
|
+
"35",
|
|
942
|
+
"39"
|
|
943
|
+
],
|
|
944
|
+
cyan: [
|
|
945
|
+
"36",
|
|
946
|
+
"39"
|
|
947
|
+
],
|
|
948
|
+
white: [
|
|
949
|
+
"37",
|
|
950
|
+
"39"
|
|
951
|
+
],
|
|
952
|
+
brightblack: [
|
|
953
|
+
"30;1",
|
|
954
|
+
"39"
|
|
955
|
+
],
|
|
956
|
+
brightred: [
|
|
957
|
+
"31;1",
|
|
958
|
+
"39"
|
|
959
|
+
],
|
|
960
|
+
brightgreen: [
|
|
961
|
+
"32;1",
|
|
962
|
+
"39"
|
|
963
|
+
],
|
|
964
|
+
brightyellow: [
|
|
965
|
+
"33;1",
|
|
966
|
+
"39"
|
|
967
|
+
],
|
|
968
|
+
brightblue: [
|
|
969
|
+
"34;1",
|
|
970
|
+
"39"
|
|
971
|
+
],
|
|
972
|
+
brightmagenta: [
|
|
973
|
+
"35;1",
|
|
974
|
+
"39"
|
|
975
|
+
],
|
|
976
|
+
brightcyan: [
|
|
977
|
+
"36;1",
|
|
978
|
+
"39"
|
|
979
|
+
],
|
|
980
|
+
brightwhite: [
|
|
981
|
+
"37;1",
|
|
982
|
+
"39"
|
|
983
|
+
],
|
|
984
|
+
grey: [
|
|
985
|
+
"90",
|
|
986
|
+
"39"
|
|
987
|
+
]
|
|
988
|
+
};
|
|
989
|
+
var styles = {
|
|
990
|
+
special: "cyan",
|
|
991
|
+
number: "yellow",
|
|
992
|
+
bigint: "yellow",
|
|
993
|
+
boolean: "yellow",
|
|
994
|
+
undefined: "grey",
|
|
995
|
+
null: "bold",
|
|
996
|
+
string: "green",
|
|
997
|
+
symbol: "green",
|
|
998
|
+
date: "magenta",
|
|
999
|
+
regexp: "red"
|
|
1000
|
+
};
|
|
1001
|
+
var truncator = "\u2026";
|
|
1002
|
+
function colorise(value, styleType) {
|
|
1003
|
+
const color = ansiColors[styles[styleType]] || ansiColors[styleType] || "";
|
|
1004
|
+
if (!color) {
|
|
1005
|
+
return String(value);
|
|
1006
|
+
}
|
|
1007
|
+
return `\x1B[${color[0]}m${String(value)}\x1B[${color[1]}m`;
|
|
1008
|
+
}
|
|
1009
|
+
__name(colorise, "colorise");
|
|
1010
|
+
function normaliseOptions({ showHidden = false, depth = 2, colors = false, customInspect = true, showProxy = false, maxArrayLength = Infinity, breakLength = Infinity, seen = [], truncate: truncate2 = Infinity, stylize = String } = {}, inspect3) {
|
|
1011
|
+
const options = {
|
|
1012
|
+
showHidden: Boolean(showHidden),
|
|
1013
|
+
depth: Number(depth),
|
|
1014
|
+
colors: Boolean(colors),
|
|
1015
|
+
customInspect: Boolean(customInspect),
|
|
1016
|
+
showProxy: Boolean(showProxy),
|
|
1017
|
+
maxArrayLength: Number(maxArrayLength),
|
|
1018
|
+
breakLength: Number(breakLength),
|
|
1019
|
+
truncate: Number(truncate2),
|
|
1020
|
+
seen,
|
|
1021
|
+
inspect: inspect3,
|
|
1022
|
+
stylize
|
|
1023
|
+
};
|
|
1024
|
+
if (options.colors) {
|
|
1025
|
+
options.stylize = colorise;
|
|
1026
|
+
}
|
|
1027
|
+
return options;
|
|
1028
|
+
}
|
|
1029
|
+
__name(normaliseOptions, "normaliseOptions");
|
|
1030
|
+
function isHighSurrogate(char) {
|
|
1031
|
+
return char >= "\uD800" && char <= "\uDBFF";
|
|
1032
|
+
}
|
|
1033
|
+
__name(isHighSurrogate, "isHighSurrogate");
|
|
1034
|
+
function truncate(string, length, tail = truncator) {
|
|
1035
|
+
string = String(string);
|
|
1036
|
+
const tailLength = tail.length;
|
|
1037
|
+
const stringLength = string.length;
|
|
1038
|
+
if (tailLength > length && stringLength > tailLength) {
|
|
1039
|
+
return tail;
|
|
1040
|
+
}
|
|
1041
|
+
if (stringLength > length && stringLength > tailLength) {
|
|
1042
|
+
let end = length - tailLength;
|
|
1043
|
+
if (end > 0 && isHighSurrogate(string[end - 1])) {
|
|
1044
|
+
end = end - 1;
|
|
1045
|
+
}
|
|
1046
|
+
return `${string.slice(0, end)}${tail}`;
|
|
1047
|
+
}
|
|
1048
|
+
return string;
|
|
1049
|
+
}
|
|
1050
|
+
__name(truncate, "truncate");
|
|
1051
|
+
function inspectList(list, options, inspectItem, separator = ", ") {
|
|
1052
|
+
inspectItem = inspectItem || options.inspect;
|
|
1053
|
+
const size = list.length;
|
|
1054
|
+
if (size === 0) return "";
|
|
1055
|
+
const originalLength = options.truncate;
|
|
1056
|
+
let output = "";
|
|
1057
|
+
let peek = "";
|
|
1058
|
+
let truncated = "";
|
|
1059
|
+
for(let i = 0; i < size; i += 1){
|
|
1060
|
+
const last = i + 1 === list.length;
|
|
1061
|
+
const secondToLast = i + 2 === list.length;
|
|
1062
|
+
truncated = `${truncator}(${list.length - i})`;
|
|
1063
|
+
const value = list[i];
|
|
1064
|
+
options.truncate = originalLength - output.length - (last ? 0 : separator.length);
|
|
1065
|
+
const string = peek || inspectItem(value, options) + (last ? "" : separator);
|
|
1066
|
+
const nextLength = output.length + string.length;
|
|
1067
|
+
const truncatedLength = nextLength + truncated.length;
|
|
1068
|
+
if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) {
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
if (!last && !secondToLast && truncatedLength > originalLength) {
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
peek = last ? "" : inspectItem(list[i + 1], options) + (secondToLast ? "" : separator);
|
|
1075
|
+
if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) {
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
output += string;
|
|
1079
|
+
if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
|
|
1080
|
+
truncated = `${truncator}(${list.length - i - 1})`;
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
truncated = "";
|
|
1084
|
+
}
|
|
1085
|
+
return `${output}${truncated}`;
|
|
1086
|
+
}
|
|
1087
|
+
__name(inspectList, "inspectList");
|
|
1088
|
+
function quoteComplexKey(key) {
|
|
1089
|
+
if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) {
|
|
1090
|
+
return key;
|
|
1091
|
+
}
|
|
1092
|
+
return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
|
|
1093
|
+
}
|
|
1094
|
+
__name(quoteComplexKey, "quoteComplexKey");
|
|
1095
|
+
function inspectProperty([key, value], options) {
|
|
1096
|
+
options.truncate -= 2;
|
|
1097
|
+
if (typeof key === "string") {
|
|
1098
|
+
key = quoteComplexKey(key);
|
|
1099
|
+
} else if (typeof key !== "number") {
|
|
1100
|
+
key = `[${options.inspect(key, options)}]`;
|
|
1101
|
+
}
|
|
1102
|
+
options.truncate -= key.length;
|
|
1103
|
+
value = options.inspect(value, options);
|
|
1104
|
+
return `${key}: ${value}`;
|
|
1105
|
+
}
|
|
1106
|
+
__name(inspectProperty, "inspectProperty");
|
|
1107
|
+
function inspectArray(array, options) {
|
|
1108
|
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
|
1109
|
+
if (!array.length && !nonIndexProperties.length) return "[]";
|
|
1110
|
+
options.truncate -= 4;
|
|
1111
|
+
const listContents = inspectList(array, options);
|
|
1112
|
+
options.truncate -= listContents.length;
|
|
1113
|
+
let propertyContents = "";
|
|
1114
|
+
if (nonIndexProperties.length) {
|
|
1115
|
+
propertyContents = inspectList(nonIndexProperties.map((key)=>[
|
|
1116
|
+
key,
|
|
1117
|
+
array[key]
|
|
1118
|
+
]), options, inspectProperty);
|
|
1119
|
+
}
|
|
1120
|
+
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ""} ]`;
|
|
1121
|
+
}
|
|
1122
|
+
__name(inspectArray, "inspectArray");
|
|
1123
|
+
var getArrayName = __name((array)=>{
|
|
1124
|
+
if (typeof Buffer === "function" && array instanceof Buffer) {
|
|
1125
|
+
return "Buffer";
|
|
1126
|
+
}
|
|
1127
|
+
if (array[Symbol.toStringTag]) {
|
|
1128
|
+
return array[Symbol.toStringTag];
|
|
1129
|
+
}
|
|
1130
|
+
return array.constructor.name;
|
|
1131
|
+
}, "getArrayName");
|
|
1132
|
+
function inspectTypedArray(array, options) {
|
|
1133
|
+
const name = getArrayName(array);
|
|
1134
|
+
options.truncate -= name.length + 4;
|
|
1135
|
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
|
1136
|
+
if (!array.length && !nonIndexProperties.length) return `${name}[]`;
|
|
1137
|
+
let output = "";
|
|
1138
|
+
for(let i = 0; i < array.length; i++){
|
|
1139
|
+
const string = `${options.stylize(truncate(array[i], options.truncate), "number")}${i === array.length - 1 ? "" : ", "}`;
|
|
1140
|
+
options.truncate -= string.length;
|
|
1141
|
+
if (array[i] !== array.length && options.truncate <= 3) {
|
|
1142
|
+
output += `${truncator}(${array.length - array[i] + 1})`;
|
|
1143
|
+
break;
|
|
1144
|
+
}
|
|
1145
|
+
output += string;
|
|
1146
|
+
}
|
|
1147
|
+
let propertyContents = "";
|
|
1148
|
+
if (nonIndexProperties.length) {
|
|
1149
|
+
propertyContents = inspectList(nonIndexProperties.map((key)=>[
|
|
1150
|
+
key,
|
|
1151
|
+
array[key]
|
|
1152
|
+
]), options, inspectProperty);
|
|
1153
|
+
}
|
|
1154
|
+
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`;
|
|
1155
|
+
}
|
|
1156
|
+
__name(inspectTypedArray, "inspectTypedArray");
|
|
1157
|
+
function inspectDate(dateObject, options) {
|
|
1158
|
+
const stringRepresentation = dateObject.toJSON();
|
|
1159
|
+
if (stringRepresentation === null) {
|
|
1160
|
+
return "Invalid Date";
|
|
1161
|
+
}
|
|
1162
|
+
const split = stringRepresentation.split("T");
|
|
1163
|
+
const date = split[0];
|
|
1164
|
+
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, "date");
|
|
1165
|
+
}
|
|
1166
|
+
__name(inspectDate, "inspectDate");
|
|
1167
|
+
function inspectFunction(func, options) {
|
|
1168
|
+
const functionType = func[Symbol.toStringTag] || "Function";
|
|
1169
|
+
const name = func.name;
|
|
1170
|
+
if (!name) {
|
|
1171
|
+
return options.stylize(`[${functionType}]`, "special");
|
|
1172
|
+
}
|
|
1173
|
+
return options.stylize(`[${functionType} ${truncate(name, options.truncate - 11)}]`, "special");
|
|
1174
|
+
}
|
|
1175
|
+
__name(inspectFunction, "inspectFunction");
|
|
1176
|
+
function inspectMapEntry([key, value], options) {
|
|
1177
|
+
options.truncate -= 4;
|
|
1178
|
+
key = options.inspect(key, options);
|
|
1179
|
+
options.truncate -= key.length;
|
|
1180
|
+
value = options.inspect(value, options);
|
|
1181
|
+
return `${key} => ${value}`;
|
|
1182
|
+
}
|
|
1183
|
+
__name(inspectMapEntry, "inspectMapEntry");
|
|
1184
|
+
function mapToEntries(map) {
|
|
1185
|
+
const entries = [];
|
|
1186
|
+
map.forEach((value, key)=>{
|
|
1187
|
+
entries.push([
|
|
1188
|
+
key,
|
|
1189
|
+
value
|
|
1190
|
+
]);
|
|
1191
|
+
});
|
|
1192
|
+
return entries;
|
|
1193
|
+
}
|
|
1194
|
+
__name(mapToEntries, "mapToEntries");
|
|
1195
|
+
function inspectMap(map, options) {
|
|
1196
|
+
if (map.size === 0) return "Map{}";
|
|
1197
|
+
options.truncate -= 7;
|
|
1198
|
+
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }`;
|
|
1199
|
+
}
|
|
1200
|
+
__name(inspectMap, "inspectMap");
|
|
1201
|
+
var isNaN = Number.isNaN || ((i)=>i !== i);
|
|
1202
|
+
function inspectNumber(number, options) {
|
|
1203
|
+
if (isNaN(number)) {
|
|
1204
|
+
return options.stylize("NaN", "number");
|
|
1205
|
+
}
|
|
1206
|
+
if (number === Infinity) {
|
|
1207
|
+
return options.stylize("Infinity", "number");
|
|
1208
|
+
}
|
|
1209
|
+
if (number === -Infinity) {
|
|
1210
|
+
return options.stylize("-Infinity", "number");
|
|
1211
|
+
}
|
|
1212
|
+
if (number === 0) {
|
|
1213
|
+
return options.stylize(1 / number === Infinity ? "+0" : "-0", "number");
|
|
1214
|
+
}
|
|
1215
|
+
return options.stylize(truncate(String(number), options.truncate), "number");
|
|
1216
|
+
}
|
|
1217
|
+
__name(inspectNumber, "inspectNumber");
|
|
1218
|
+
function inspectBigInt(number, options) {
|
|
1219
|
+
let nums = truncate(number.toString(), options.truncate - 1);
|
|
1220
|
+
if (nums !== truncator) nums += "n";
|
|
1221
|
+
return options.stylize(nums, "bigint");
|
|
1222
|
+
}
|
|
1223
|
+
__name(inspectBigInt, "inspectBigInt");
|
|
1224
|
+
function inspectRegExp(value, options) {
|
|
1225
|
+
const flags = value.toString().split("/")[2];
|
|
1226
|
+
const sourceLength = options.truncate - (2 + flags.length);
|
|
1227
|
+
const source = value.source;
|
|
1228
|
+
return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, "regexp");
|
|
1229
|
+
}
|
|
1230
|
+
__name(inspectRegExp, "inspectRegExp");
|
|
1231
|
+
function arrayFromSet(set2) {
|
|
1232
|
+
const values = [];
|
|
1233
|
+
set2.forEach((value)=>{
|
|
1234
|
+
values.push(value);
|
|
1235
|
+
});
|
|
1236
|
+
return values;
|
|
1237
|
+
}
|
|
1238
|
+
__name(arrayFromSet, "arrayFromSet");
|
|
1239
|
+
function inspectSet(set2, options) {
|
|
1240
|
+
if (set2.size === 0) return "Set{}";
|
|
1241
|
+
options.truncate -= 7;
|
|
1242
|
+
return `Set{ ${inspectList(arrayFromSet(set2), options)} }`;
|
|
1243
|
+
}
|
|
1244
|
+
__name(inspectSet, "inspectSet");
|
|
1245
|
+
var stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", "g");
|
|
1246
|
+
var escapeCharacters = {
|
|
1247
|
+
"\b": "\\b",
|
|
1248
|
+
" ": "\\t",
|
|
1249
|
+
"\n": "\\n",
|
|
1250
|
+
"\f": "\\f",
|
|
1251
|
+
"\r": "\\r",
|
|
1252
|
+
"'": "\\'",
|
|
1253
|
+
"\\": "\\\\"
|
|
1254
|
+
};
|
|
1255
|
+
var hex = 16;
|
|
1256
|
+
function escape(char) {
|
|
1257
|
+
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-4)}`;
|
|
1258
|
+
}
|
|
1259
|
+
__name(escape, "escape");
|
|
1260
|
+
function inspectString(string, options) {
|
|
1261
|
+
if (stringEscapeChars.test(string)) {
|
|
1262
|
+
string = string.replace(stringEscapeChars, escape);
|
|
1263
|
+
}
|
|
1264
|
+
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, "string");
|
|
1265
|
+
}
|
|
1266
|
+
__name(inspectString, "inspectString");
|
|
1267
|
+
function inspectSymbol(value) {
|
|
1268
|
+
if ("description" in Symbol.prototype) {
|
|
1269
|
+
return value.description ? `Symbol(${value.description})` : "Symbol()";
|
|
1270
|
+
}
|
|
1271
|
+
return value.toString();
|
|
1272
|
+
}
|
|
1273
|
+
__name(inspectSymbol, "inspectSymbol");
|
|
1274
|
+
var getPromiseValue = __name(()=>"Promise{\u2026}", "getPromiseValue");
|
|
1275
|
+
var promise_default = getPromiseValue;
|
|
1276
|
+
function inspectObject(object, options) {
|
|
1277
|
+
const properties = Object.getOwnPropertyNames(object);
|
|
1278
|
+
const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
|
|
1279
|
+
if (properties.length === 0 && symbols.length === 0) {
|
|
1280
|
+
return "{}";
|
|
1281
|
+
}
|
|
1282
|
+
options.truncate -= 4;
|
|
1283
|
+
options.seen = options.seen || [];
|
|
1284
|
+
if (options.seen.includes(object)) {
|
|
1285
|
+
return "[Circular]";
|
|
1286
|
+
}
|
|
1287
|
+
options.seen.push(object);
|
|
1288
|
+
const propertyContents = inspectList(properties.map((key)=>[
|
|
1289
|
+
key,
|
|
1290
|
+
object[key]
|
|
1291
|
+
]), options, inspectProperty);
|
|
1292
|
+
const symbolContents = inspectList(symbols.map((key)=>[
|
|
1293
|
+
key,
|
|
1294
|
+
object[key]
|
|
1295
|
+
]), options, inspectProperty);
|
|
1296
|
+
options.seen.pop();
|
|
1297
|
+
let sep = "";
|
|
1298
|
+
if (propertyContents && symbolContents) {
|
|
1299
|
+
sep = ", ";
|
|
1300
|
+
}
|
|
1301
|
+
return `{ ${propertyContents}${sep}${symbolContents} }`;
|
|
1302
|
+
}
|
|
1303
|
+
__name(inspectObject, "inspectObject");
|
|
1304
|
+
var toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag ? Symbol.toStringTag : false;
|
|
1305
|
+
function inspectClass(value, options) {
|
|
1306
|
+
let name = "";
|
|
1307
|
+
if (toStringTag && toStringTag in value) {
|
|
1308
|
+
name = value[toStringTag];
|
|
1309
|
+
}
|
|
1310
|
+
name = name || value.constructor.name;
|
|
1311
|
+
if (!name || name === "_class") {
|
|
1312
|
+
name = "<Anonymous Class>";
|
|
1313
|
+
}
|
|
1314
|
+
options.truncate -= name.length;
|
|
1315
|
+
return `${name}${inspectObject(value, options)}`;
|
|
1316
|
+
}
|
|
1317
|
+
__name(inspectClass, "inspectClass");
|
|
1318
|
+
function inspectArguments(args, options) {
|
|
1319
|
+
if (args.length === 0) return "Arguments[]";
|
|
1320
|
+
options.truncate -= 13;
|
|
1321
|
+
return `Arguments[ ${inspectList(args, options)} ]`;
|
|
1322
|
+
}
|
|
1323
|
+
__name(inspectArguments, "inspectArguments");
|
|
1324
|
+
var errorKeys = [
|
|
1325
|
+
"stack",
|
|
1326
|
+
"line",
|
|
1327
|
+
"column",
|
|
1328
|
+
"name",
|
|
1329
|
+
"message",
|
|
1330
|
+
"fileName",
|
|
1331
|
+
"lineNumber",
|
|
1332
|
+
"columnNumber",
|
|
1333
|
+
"number",
|
|
1334
|
+
"description",
|
|
1335
|
+
"cause"
|
|
1336
|
+
];
|
|
1337
|
+
function inspectObject2(error, options) {
|
|
1338
|
+
const properties = Object.getOwnPropertyNames(error).filter((key)=>errorKeys.indexOf(key) === -1);
|
|
1339
|
+
const name = error.name;
|
|
1340
|
+
options.truncate -= name.length;
|
|
1341
|
+
let message = "";
|
|
1342
|
+
if (typeof error.message === "string") {
|
|
1343
|
+
message = truncate(error.message, options.truncate);
|
|
1344
|
+
} else {
|
|
1345
|
+
properties.unshift("message");
|
|
1346
|
+
}
|
|
1347
|
+
message = message ? `: ${message}` : "";
|
|
1348
|
+
options.truncate -= message.length + 5;
|
|
1349
|
+
options.seen = options.seen || [];
|
|
1350
|
+
if (options.seen.includes(error)) {
|
|
1351
|
+
return "[Circular]";
|
|
1352
|
+
}
|
|
1353
|
+
options.seen.push(error);
|
|
1354
|
+
const propertyContents = inspectList(properties.map((key)=>[
|
|
1355
|
+
key,
|
|
1356
|
+
error[key]
|
|
1357
|
+
]), options, inspectProperty);
|
|
1358
|
+
return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ""}`;
|
|
1359
|
+
}
|
|
1360
|
+
__name(inspectObject2, "inspectObject");
|
|
1361
|
+
function inspectAttribute([key, value], options) {
|
|
1362
|
+
options.truncate -= 3;
|
|
1363
|
+
if (!value) {
|
|
1364
|
+
return `${options.stylize(String(key), "yellow")}`;
|
|
1365
|
+
}
|
|
1366
|
+
return `${options.stylize(String(key), "yellow")}=${options.stylize(`"${value}"`, "string")}`;
|
|
1367
|
+
}
|
|
1368
|
+
__name(inspectAttribute, "inspectAttribute");
|
|
1369
|
+
function inspectNodeCollection(collection, options) {
|
|
1370
|
+
return inspectList(collection, options, inspectNode, "\n");
|
|
1371
|
+
}
|
|
1372
|
+
__name(inspectNodeCollection, "inspectNodeCollection");
|
|
1373
|
+
function inspectNode(node, options) {
|
|
1374
|
+
switch(node.nodeType){
|
|
1375
|
+
case 1:
|
|
1376
|
+
return inspectHTML(node, options);
|
|
1377
|
+
case 3:
|
|
1378
|
+
return options.inspect(node.data, options);
|
|
1379
|
+
default:
|
|
1380
|
+
return options.inspect(node, options);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
__name(inspectNode, "inspectNode");
|
|
1384
|
+
function inspectHTML(element, options) {
|
|
1385
|
+
const properties = element.getAttributeNames();
|
|
1386
|
+
const name = element.tagName.toLowerCase();
|
|
1387
|
+
const head = options.stylize(`<${name}`, "special");
|
|
1388
|
+
const headClose = options.stylize(`>`, "special");
|
|
1389
|
+
const tail = options.stylize(`</${name}>`, "special");
|
|
1390
|
+
options.truncate -= name.length * 2 + 5;
|
|
1391
|
+
let propertyContents = "";
|
|
1392
|
+
if (properties.length > 0) {
|
|
1393
|
+
propertyContents += " ";
|
|
1394
|
+
propertyContents += inspectList(properties.map((key)=>[
|
|
1395
|
+
key,
|
|
1396
|
+
element.getAttribute(key)
|
|
1397
|
+
]), options, inspectAttribute, " ");
|
|
1398
|
+
}
|
|
1399
|
+
options.truncate -= propertyContents.length;
|
|
1400
|
+
const truncate2 = options.truncate;
|
|
1401
|
+
let children = inspectNodeCollection(element.children, options);
|
|
1402
|
+
if (children && children.length > truncate2) {
|
|
1403
|
+
children = `${truncator}(${element.children.length})`;
|
|
1404
|
+
}
|
|
1405
|
+
return `${head}${propertyContents}${headClose}${children}${tail}`;
|
|
1406
|
+
}
|
|
1407
|
+
__name(inspectHTML, "inspectHTML");
|
|
1408
|
+
var symbolsSupported = typeof Symbol === "function" && typeof Symbol.for === "function";
|
|
1409
|
+
var chaiInspect = symbolsSupported ? Symbol.for("chai/inspect") : "@@chai/inspect";
|
|
1410
|
+
var nodeInspect = Symbol.for("nodejs.util.inspect.custom");
|
|
1411
|
+
var constructorMap = new WeakMap();
|
|
1412
|
+
var stringTagMap = {};
|
|
1413
|
+
var baseTypesMap = {
|
|
1414
|
+
undefined: __name((value, options)=>options.stylize("undefined", "undefined"), "undefined"),
|
|
1415
|
+
null: __name((value, options)=>options.stylize("null", "null"), "null"),
|
|
1416
|
+
boolean: __name((value, options)=>options.stylize(String(value), "boolean"), "boolean"),
|
|
1417
|
+
Boolean: __name((value, options)=>options.stylize(String(value), "boolean"), "Boolean"),
|
|
1418
|
+
number: inspectNumber,
|
|
1419
|
+
Number: inspectNumber,
|
|
1420
|
+
bigint: inspectBigInt,
|
|
1421
|
+
BigInt: inspectBigInt,
|
|
1422
|
+
string: inspectString,
|
|
1423
|
+
String: inspectString,
|
|
1424
|
+
function: inspectFunction,
|
|
1425
|
+
Function: inspectFunction,
|
|
1426
|
+
symbol: inspectSymbol,
|
|
1427
|
+
Symbol: inspectSymbol,
|
|
1428
|
+
Array: inspectArray,
|
|
1429
|
+
Date: inspectDate,
|
|
1430
|
+
Map: inspectMap,
|
|
1431
|
+
Set: inspectSet,
|
|
1432
|
+
RegExp: inspectRegExp,
|
|
1433
|
+
Promise: promise_default,
|
|
1434
|
+
WeakSet: __name((value, options)=>options.stylize("WeakSet{\u2026}", "special"), "WeakSet"),
|
|
1435
|
+
WeakMap: __name((value, options)=>options.stylize("WeakMap{\u2026}", "special"), "WeakMap"),
|
|
1436
|
+
Arguments: inspectArguments,
|
|
1437
|
+
Int8Array: inspectTypedArray,
|
|
1438
|
+
Uint8Array: inspectTypedArray,
|
|
1439
|
+
Uint8ClampedArray: inspectTypedArray,
|
|
1440
|
+
Int16Array: inspectTypedArray,
|
|
1441
|
+
Uint16Array: inspectTypedArray,
|
|
1442
|
+
Int32Array: inspectTypedArray,
|
|
1443
|
+
Uint32Array: inspectTypedArray,
|
|
1444
|
+
Float32Array: inspectTypedArray,
|
|
1445
|
+
Float64Array: inspectTypedArray,
|
|
1446
|
+
Generator: __name(()=>"", "Generator"),
|
|
1447
|
+
DataView: __name(()=>"", "DataView"),
|
|
1448
|
+
ArrayBuffer: __name(()=>"", "ArrayBuffer"),
|
|
1449
|
+
Error: inspectObject2,
|
|
1450
|
+
HTMLCollection: inspectNodeCollection,
|
|
1451
|
+
NodeList: inspectNodeCollection
|
|
1452
|
+
};
|
|
1453
|
+
var inspectCustom = __name((value, options, type3)=>{
|
|
1454
|
+
if (chaiInspect in value && typeof value[chaiInspect] === "function") {
|
|
1455
|
+
return value[chaiInspect](options);
|
|
1456
|
+
}
|
|
1457
|
+
if (nodeInspect in value && typeof value[nodeInspect] === "function") {
|
|
1458
|
+
return value[nodeInspect](options.depth, options);
|
|
1459
|
+
}
|
|
1460
|
+
if ("inspect" in value && typeof value.inspect === "function") {
|
|
1461
|
+
return value.inspect(options.depth, options);
|
|
1462
|
+
}
|
|
1463
|
+
if ("constructor" in value && constructorMap.has(value.constructor)) {
|
|
1464
|
+
return constructorMap.get(value.constructor)(value, options);
|
|
1465
|
+
}
|
|
1466
|
+
if (stringTagMap[type3]) {
|
|
1467
|
+
return stringTagMap[type3](value, options);
|
|
1468
|
+
}
|
|
1469
|
+
return "";
|
|
1470
|
+
}, "inspectCustom");
|
|
1471
|
+
var toString = Object.prototype.toString;
|
|
1472
|
+
function inspect(value, opts = {}) {
|
|
1473
|
+
const options = normaliseOptions(opts, inspect);
|
|
1474
|
+
const { customInspect } = options;
|
|
1475
|
+
let type3 = value === null ? "null" : typeof value;
|
|
1476
|
+
if (type3 === "object") {
|
|
1477
|
+
type3 = toString.call(value).slice(8, -1);
|
|
1478
|
+
}
|
|
1479
|
+
if (type3 in baseTypesMap) {
|
|
1480
|
+
return baseTypesMap[type3](value, options);
|
|
1481
|
+
}
|
|
1482
|
+
if (customInspect && value) {
|
|
1483
|
+
const output = inspectCustom(value, options, type3);
|
|
1484
|
+
if (output) {
|
|
1485
|
+
if (typeof output === "string") return output;
|
|
1486
|
+
return inspect(output, options);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
const proto = value ? Object.getPrototypeOf(value) : false;
|
|
1490
|
+
if (proto === Object.prototype || proto === null) {
|
|
1491
|
+
return inspectObject(value, options);
|
|
1492
|
+
}
|
|
1493
|
+
if (value && typeof HTMLElement === "function" && value instanceof HTMLElement) {
|
|
1494
|
+
return inspectHTML(value, options);
|
|
1495
|
+
}
|
|
1496
|
+
if ("constructor" in value) {
|
|
1497
|
+
if (value.constructor !== Object) {
|
|
1498
|
+
return inspectClass(value, options);
|
|
1499
|
+
}
|
|
1500
|
+
return inspectObject(value, options);
|
|
1501
|
+
}
|
|
1502
|
+
if (value === Object(value)) {
|
|
1503
|
+
return inspectObject(value, options);
|
|
1504
|
+
}
|
|
1505
|
+
return options.stylize(String(value), type3);
|
|
1506
|
+
}
|
|
1507
|
+
__name(inspect, "inspect");
|
|
1508
|
+
var config = {
|
|
1509
|
+
includeStack: false,
|
|
1510
|
+
showDiff: true,
|
|
1511
|
+
truncateThreshold: 40,
|
|
1512
|
+
useProxy: true,
|
|
1513
|
+
proxyExcludedKeys: [
|
|
1514
|
+
"then",
|
|
1515
|
+
"catch",
|
|
1516
|
+
"inspect",
|
|
1517
|
+
"toJSON"
|
|
1518
|
+
],
|
|
1519
|
+
deepEqual: null
|
|
1520
|
+
};
|
|
1521
|
+
function inspect2(obj, showHidden, depth, colors) {
|
|
1522
|
+
let options = {
|
|
1523
|
+
colors,
|
|
1524
|
+
depth: typeof depth === "undefined" ? 2 : depth,
|
|
1525
|
+
showHidden,
|
|
1526
|
+
truncate: config.truncateThreshold ? config.truncateThreshold : Infinity
|
|
1527
|
+
};
|
|
1528
|
+
return inspect(obj, options);
|
|
1529
|
+
}
|
|
1530
|
+
__name(inspect2, "inspect");
|
|
1531
|
+
function objDisplay(obj) {
|
|
1532
|
+
let str = inspect2(obj), type3 = Object.prototype.toString.call(obj);
|
|
1533
|
+
if (config.truncateThreshold && str.length >= config.truncateThreshold) {
|
|
1534
|
+
if (type3 === "[object Function]") {
|
|
1535
|
+
return !obj.name || obj.name === "" ? "[Function]" : "[Function: " + obj.name + "]";
|
|
1536
|
+
} else if (type3 === "[object Array]") {
|
|
1537
|
+
return "[ Array(" + obj.length + ") ]";
|
|
1538
|
+
} else if (type3 === "[object Object]") {
|
|
1539
|
+
let keys = Object.keys(obj), kstr = keys.length > 2 ? keys.splice(0, 2).join(", ") + ", ..." : keys.join(", ");
|
|
1540
|
+
return "{ Object (" + kstr + ") }";
|
|
1541
|
+
} else {
|
|
1542
|
+
return str;
|
|
1543
|
+
}
|
|
1544
|
+
} else {
|
|
1545
|
+
return str;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
__name(objDisplay, "objDisplay");
|
|
1549
|
+
function getMessage2(obj, args) {
|
|
1550
|
+
let negate = flag(obj, "negate");
|
|
1551
|
+
let val = flag(obj, "object");
|
|
1552
|
+
let expected = args[3];
|
|
1553
|
+
let actual = getActual(obj, args);
|
|
1554
|
+
let msg = negate ? args[2] : args[1];
|
|
1555
|
+
let flagMsg = flag(obj, "message");
|
|
1556
|
+
if (typeof msg === "function") msg = msg();
|
|
1557
|
+
msg = msg || "";
|
|
1558
|
+
msg = msg.replace(/#\{this\}/g, function() {
|
|
1559
|
+
return objDisplay(val);
|
|
1560
|
+
}).replace(/#\{act\}/g, function() {
|
|
1561
|
+
return objDisplay(actual);
|
|
1562
|
+
}).replace(/#\{exp\}/g, function() {
|
|
1563
|
+
return objDisplay(expected);
|
|
1564
|
+
});
|
|
1565
|
+
return flagMsg ? flagMsg + ": " + msg : msg;
|
|
1566
|
+
}
|
|
1567
|
+
__name(getMessage2, "getMessage");
|
|
1568
|
+
function transferFlags(assertion, object, includeAll) {
|
|
1569
|
+
let flags = assertion.__flags || (assertion.__flags = Object.create(null));
|
|
1570
|
+
if (!object.__flags) {
|
|
1571
|
+
object.__flags = Object.create(null);
|
|
1572
|
+
}
|
|
1573
|
+
includeAll = arguments.length === 3 ? includeAll : true;
|
|
1574
|
+
for(let flag3 in flags){
|
|
1575
|
+
if (includeAll || flag3 !== "object" && flag3 !== "ssfi" && flag3 !== "lockSsfi" && flag3 != "message") {
|
|
1576
|
+
object.__flags[flag3] = flags[flag3];
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
__name(transferFlags, "transferFlags");
|
|
1581
|
+
function type2(obj) {
|
|
1582
|
+
if (typeof obj === "undefined") {
|
|
1583
|
+
return "undefined";
|
|
1584
|
+
}
|
|
1585
|
+
if (obj === null) {
|
|
1586
|
+
return "null";
|
|
1587
|
+
}
|
|
1588
|
+
const stringTag = obj[Symbol.toStringTag];
|
|
1589
|
+
if (typeof stringTag === "string") {
|
|
1590
|
+
return stringTag;
|
|
1591
|
+
}
|
|
1592
|
+
const sliceStart = 8;
|
|
1593
|
+
const sliceEnd = -1;
|
|
1594
|
+
return Object.prototype.toString.call(obj).slice(sliceStart, sliceEnd);
|
|
1595
|
+
}
|
|
1596
|
+
__name(type2, "type");
|
|
1597
|
+
function FakeMap() {
|
|
1598
|
+
this._key = "chai/deep-eql__" + Math.random() + Date.now();
|
|
1599
|
+
}
|
|
1600
|
+
__name(FakeMap, "FakeMap");
|
|
1601
|
+
FakeMap.prototype = {
|
|
1602
|
+
get: __name(function get(key) {
|
|
1603
|
+
return key[this._key];
|
|
1604
|
+
}, "get"),
|
|
1605
|
+
set: __name(function set(key, value) {
|
|
1606
|
+
if (Object.isExtensible(key)) {
|
|
1607
|
+
Object.defineProperty(key, this._key, {
|
|
1608
|
+
value,
|
|
1609
|
+
configurable: true
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
}, "set")
|
|
1613
|
+
};
|
|
1614
|
+
var MemoizeMap = typeof WeakMap === "function" ? WeakMap : FakeMap;
|
|
1615
|
+
function memoizeCompare(leftHandOperand, rightHandOperand, memoizeMap) {
|
|
1616
|
+
if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
|
|
1617
|
+
return null;
|
|
1618
|
+
}
|
|
1619
|
+
var leftHandMap = memoizeMap.get(leftHandOperand);
|
|
1620
|
+
if (leftHandMap) {
|
|
1621
|
+
var result = leftHandMap.get(rightHandOperand);
|
|
1622
|
+
if (typeof result === "boolean") {
|
|
1623
|
+
return result;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return null;
|
|
1627
|
+
}
|
|
1628
|
+
__name(memoizeCompare, "memoizeCompare");
|
|
1629
|
+
function memoizeSet(leftHandOperand, rightHandOperand, memoizeMap, result) {
|
|
1630
|
+
if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1633
|
+
var leftHandMap = memoizeMap.get(leftHandOperand);
|
|
1634
|
+
if (leftHandMap) {
|
|
1635
|
+
leftHandMap.set(rightHandOperand, result);
|
|
1636
|
+
} else {
|
|
1637
|
+
leftHandMap = new MemoizeMap();
|
|
1638
|
+
leftHandMap.set(rightHandOperand, result);
|
|
1639
|
+
memoizeMap.set(leftHandOperand, leftHandMap);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
__name(memoizeSet, "memoizeSet");
|
|
1643
|
+
var deep_eql_default = deepEqual;
|
|
1644
|
+
function deepEqual(leftHandOperand, rightHandOperand, options) {
|
|
1645
|
+
if (options && options.comparator) {
|
|
1646
|
+
return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
|
|
1647
|
+
}
|
|
1648
|
+
var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
|
|
1649
|
+
if (simpleResult !== null) {
|
|
1650
|
+
return simpleResult;
|
|
1651
|
+
}
|
|
1652
|
+
return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
|
|
1653
|
+
}
|
|
1654
|
+
__name(deepEqual, "deepEqual");
|
|
1655
|
+
function simpleEqual(leftHandOperand, rightHandOperand) {
|
|
1656
|
+
if (leftHandOperand === rightHandOperand) {
|
|
1657
|
+
return leftHandOperand !== 0 || 1 / leftHandOperand === 1 / rightHandOperand;
|
|
1658
|
+
}
|
|
1659
|
+
if (leftHandOperand !== leftHandOperand && rightHandOperand !== rightHandOperand) {
|
|
1660
|
+
return true;
|
|
1661
|
+
}
|
|
1662
|
+
if (isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
|
|
1663
|
+
return false;
|
|
1664
|
+
}
|
|
1665
|
+
return null;
|
|
1666
|
+
}
|
|
1667
|
+
__name(simpleEqual, "simpleEqual");
|
|
1668
|
+
function extensiveDeepEqual(leftHandOperand, rightHandOperand, options) {
|
|
1669
|
+
options = options || {};
|
|
1670
|
+
options.memoize = options.memoize === false ? false : options.memoize || new MemoizeMap();
|
|
1671
|
+
var comparator = options && options.comparator;
|
|
1672
|
+
var memoizeResultLeft = memoizeCompare(leftHandOperand, rightHandOperand, options.memoize);
|
|
1673
|
+
if (memoizeResultLeft !== null) {
|
|
1674
|
+
return memoizeResultLeft;
|
|
1675
|
+
}
|
|
1676
|
+
var memoizeResultRight = memoizeCompare(rightHandOperand, leftHandOperand, options.memoize);
|
|
1677
|
+
if (memoizeResultRight !== null) {
|
|
1678
|
+
return memoizeResultRight;
|
|
1679
|
+
}
|
|
1680
|
+
if (comparator) {
|
|
1681
|
+
var comparatorResult = comparator(leftHandOperand, rightHandOperand);
|
|
1682
|
+
if (comparatorResult === false || comparatorResult === true) {
|
|
1683
|
+
memoizeSet(leftHandOperand, rightHandOperand, options.memoize, comparatorResult);
|
|
1684
|
+
return comparatorResult;
|
|
1685
|
+
}
|
|
1686
|
+
var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
|
|
1687
|
+
if (simpleResult !== null) {
|
|
1688
|
+
return simpleResult;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
var leftHandType = type2(leftHandOperand);
|
|
1692
|
+
if (leftHandType !== type2(rightHandOperand)) {
|
|
1693
|
+
memoizeSet(leftHandOperand, rightHandOperand, options.memoize, false);
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
memoizeSet(leftHandOperand, rightHandOperand, options.memoize, true);
|
|
1697
|
+
var result = extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options);
|
|
1698
|
+
memoizeSet(leftHandOperand, rightHandOperand, options.memoize, result);
|
|
1699
|
+
return result;
|
|
1700
|
+
}
|
|
1701
|
+
__name(extensiveDeepEqual, "extensiveDeepEqual");
|
|
1702
|
+
function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options) {
|
|
1703
|
+
switch(leftHandType){
|
|
1704
|
+
case "String":
|
|
1705
|
+
case "Number":
|
|
1706
|
+
case "Boolean":
|
|
1707
|
+
case "Date":
|
|
1708
|
+
return deepEqual(leftHandOperand.valueOf(), rightHandOperand.valueOf());
|
|
1709
|
+
case "Promise":
|
|
1710
|
+
case "Symbol":
|
|
1711
|
+
case "function":
|
|
1712
|
+
case "WeakMap":
|
|
1713
|
+
case "WeakSet":
|
|
1714
|
+
return leftHandOperand === rightHandOperand;
|
|
1715
|
+
case "Error":
|
|
1716
|
+
return keysEqual(leftHandOperand, rightHandOperand, [
|
|
1717
|
+
"name",
|
|
1718
|
+
"message",
|
|
1719
|
+
"code"
|
|
1720
|
+
], options);
|
|
1721
|
+
case "Arguments":
|
|
1722
|
+
case "Int8Array":
|
|
1723
|
+
case "Uint8Array":
|
|
1724
|
+
case "Uint8ClampedArray":
|
|
1725
|
+
case "Int16Array":
|
|
1726
|
+
case "Uint16Array":
|
|
1727
|
+
case "Int32Array":
|
|
1728
|
+
case "Uint32Array":
|
|
1729
|
+
case "Float32Array":
|
|
1730
|
+
case "Float64Array":
|
|
1731
|
+
case "Array":
|
|
1732
|
+
return iterableEqual(leftHandOperand, rightHandOperand, options);
|
|
1733
|
+
case "RegExp":
|
|
1734
|
+
return regexpEqual(leftHandOperand, rightHandOperand);
|
|
1735
|
+
case "Generator":
|
|
1736
|
+
return generatorEqual(leftHandOperand, rightHandOperand, options);
|
|
1737
|
+
case "DataView":
|
|
1738
|
+
return iterableEqual(new Uint8Array(leftHandOperand.buffer), new Uint8Array(rightHandOperand.buffer), options);
|
|
1739
|
+
case "ArrayBuffer":
|
|
1740
|
+
return iterableEqual(new Uint8Array(leftHandOperand), new Uint8Array(rightHandOperand), options);
|
|
1741
|
+
case "Set":
|
|
1742
|
+
return entriesEqual(leftHandOperand, rightHandOperand, options);
|
|
1743
|
+
case "Map":
|
|
1744
|
+
return entriesEqual(leftHandOperand, rightHandOperand, options);
|
|
1745
|
+
case "Temporal.PlainDate":
|
|
1746
|
+
case "Temporal.PlainTime":
|
|
1747
|
+
case "Temporal.PlainDateTime":
|
|
1748
|
+
case "Temporal.Instant":
|
|
1749
|
+
case "Temporal.ZonedDateTime":
|
|
1750
|
+
case "Temporal.PlainYearMonth":
|
|
1751
|
+
case "Temporal.PlainMonthDay":
|
|
1752
|
+
return leftHandOperand.equals(rightHandOperand);
|
|
1753
|
+
case "Temporal.Duration":
|
|
1754
|
+
return leftHandOperand.total("nanoseconds") === rightHandOperand.total("nanoseconds");
|
|
1755
|
+
case "Temporal.TimeZone":
|
|
1756
|
+
case "Temporal.Calendar":
|
|
1757
|
+
return leftHandOperand.toString() === rightHandOperand.toString();
|
|
1758
|
+
default:
|
|
1759
|
+
return objectEqual(leftHandOperand, rightHandOperand, options);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
__name(extensiveDeepEqualByType, "extensiveDeepEqualByType");
|
|
1763
|
+
function regexpEqual(leftHandOperand, rightHandOperand) {
|
|
1764
|
+
return leftHandOperand.toString() === rightHandOperand.toString();
|
|
1765
|
+
}
|
|
1766
|
+
__name(regexpEqual, "regexpEqual");
|
|
1767
|
+
function entriesEqual(leftHandOperand, rightHandOperand, options) {
|
|
1768
|
+
try {
|
|
1769
|
+
if (leftHandOperand.size !== rightHandOperand.size) {
|
|
1770
|
+
return false;
|
|
1771
|
+
}
|
|
1772
|
+
if (leftHandOperand.size === 0) {
|
|
1773
|
+
return true;
|
|
1774
|
+
}
|
|
1775
|
+
} catch (sizeError) {
|
|
1776
|
+
return false;
|
|
1777
|
+
}
|
|
1778
|
+
var leftHandItems = [];
|
|
1779
|
+
var rightHandItems = [];
|
|
1780
|
+
leftHandOperand.forEach(__name(function gatherEntries(key, value) {
|
|
1781
|
+
leftHandItems.push([
|
|
1782
|
+
key,
|
|
1783
|
+
value
|
|
1784
|
+
]);
|
|
1785
|
+
}, "gatherEntries"));
|
|
1786
|
+
rightHandOperand.forEach(__name(function gatherEntries(key, value) {
|
|
1787
|
+
rightHandItems.push([
|
|
1788
|
+
key,
|
|
1789
|
+
value
|
|
1790
|
+
]);
|
|
1791
|
+
}, "gatherEntries"));
|
|
1792
|
+
return iterableEqual(leftHandItems.sort(), rightHandItems.sort(), options);
|
|
1793
|
+
}
|
|
1794
|
+
__name(entriesEqual, "entriesEqual");
|
|
1795
|
+
function iterableEqual(leftHandOperand, rightHandOperand, options) {
|
|
1796
|
+
var length = leftHandOperand.length;
|
|
1797
|
+
if (length !== rightHandOperand.length) {
|
|
1798
|
+
return false;
|
|
1799
|
+
}
|
|
1800
|
+
if (length === 0) {
|
|
1801
|
+
return true;
|
|
1802
|
+
}
|
|
1803
|
+
var index = -1;
|
|
1804
|
+
while(++index < length){
|
|
1805
|
+
if (deepEqual(leftHandOperand[index], rightHandOperand[index], options) === false) {
|
|
1806
|
+
return false;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
return true;
|
|
1810
|
+
}
|
|
1811
|
+
__name(iterableEqual, "iterableEqual");
|
|
1812
|
+
function generatorEqual(leftHandOperand, rightHandOperand, options) {
|
|
1813
|
+
return iterableEqual(getGeneratorEntries(leftHandOperand), getGeneratorEntries(rightHandOperand), options);
|
|
1814
|
+
}
|
|
1815
|
+
__name(generatorEqual, "generatorEqual");
|
|
1816
|
+
function hasIteratorFunction(target) {
|
|
1817
|
+
return typeof Symbol !== "undefined" && typeof target === "object" && typeof Symbol.iterator !== "undefined" && typeof target[Symbol.iterator] === "function";
|
|
1818
|
+
}
|
|
1819
|
+
__name(hasIteratorFunction, "hasIteratorFunction");
|
|
1820
|
+
function getIteratorEntries(target) {
|
|
1821
|
+
if (hasIteratorFunction(target)) {
|
|
1822
|
+
try {
|
|
1823
|
+
return getGeneratorEntries(target[Symbol.iterator]());
|
|
1824
|
+
} catch (iteratorError) {
|
|
1825
|
+
return [];
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
return [];
|
|
1829
|
+
}
|
|
1830
|
+
__name(getIteratorEntries, "getIteratorEntries");
|
|
1831
|
+
function getGeneratorEntries(generator) {
|
|
1832
|
+
var generatorResult = generator.next();
|
|
1833
|
+
var accumulator = [
|
|
1834
|
+
generatorResult.value
|
|
1835
|
+
];
|
|
1836
|
+
while(generatorResult.done === false){
|
|
1837
|
+
generatorResult = generator.next();
|
|
1838
|
+
accumulator.push(generatorResult.value);
|
|
1839
|
+
}
|
|
1840
|
+
return accumulator;
|
|
1841
|
+
}
|
|
1842
|
+
__name(getGeneratorEntries, "getGeneratorEntries");
|
|
1843
|
+
function getEnumerableKeys(target) {
|
|
1844
|
+
var keys = [];
|
|
1845
|
+
for(var key in target){
|
|
1846
|
+
keys.push(key);
|
|
1847
|
+
}
|
|
1848
|
+
return keys;
|
|
1849
|
+
}
|
|
1850
|
+
__name(getEnumerableKeys, "getEnumerableKeys");
|
|
1851
|
+
function getEnumerableSymbols(target) {
|
|
1852
|
+
var keys = [];
|
|
1853
|
+
var allKeys = Object.getOwnPropertySymbols(target);
|
|
1854
|
+
for(var i = 0; i < allKeys.length; i += 1){
|
|
1855
|
+
var key = allKeys[i];
|
|
1856
|
+
if (Object.getOwnPropertyDescriptor(target, key).enumerable) {
|
|
1857
|
+
keys.push(key);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
return keys;
|
|
1861
|
+
}
|
|
1862
|
+
__name(getEnumerableSymbols, "getEnumerableSymbols");
|
|
1863
|
+
function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
|
|
1864
|
+
var length = keys.length;
|
|
1865
|
+
if (length === 0) {
|
|
1866
|
+
return true;
|
|
1867
|
+
}
|
|
1868
|
+
for(var i = 0; i < length; i += 1){
|
|
1869
|
+
if (deepEqual(leftHandOperand[keys[i]], rightHandOperand[keys[i]], options) === false) {
|
|
1870
|
+
return false;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
return true;
|
|
1874
|
+
}
|
|
1875
|
+
__name(keysEqual, "keysEqual");
|
|
1876
|
+
function objectEqual(leftHandOperand, rightHandOperand, options) {
|
|
1877
|
+
var leftHandKeys = getEnumerableKeys(leftHandOperand);
|
|
1878
|
+
var rightHandKeys = getEnumerableKeys(rightHandOperand);
|
|
1879
|
+
var leftHandSymbols = getEnumerableSymbols(leftHandOperand);
|
|
1880
|
+
var rightHandSymbols = getEnumerableSymbols(rightHandOperand);
|
|
1881
|
+
leftHandKeys = leftHandKeys.concat(leftHandSymbols);
|
|
1882
|
+
rightHandKeys = rightHandKeys.concat(rightHandSymbols);
|
|
1883
|
+
if (leftHandKeys.length && leftHandKeys.length === rightHandKeys.length) {
|
|
1884
|
+
if (iterableEqual(mapSymbols(leftHandKeys).sort(), mapSymbols(rightHandKeys).sort()) === false) {
|
|
1885
|
+
return false;
|
|
1886
|
+
}
|
|
1887
|
+
return keysEqual(leftHandOperand, rightHandOperand, leftHandKeys, options);
|
|
1888
|
+
}
|
|
1889
|
+
var leftHandEntries = getIteratorEntries(leftHandOperand);
|
|
1890
|
+
var rightHandEntries = getIteratorEntries(rightHandOperand);
|
|
1891
|
+
if (leftHandEntries.length && leftHandEntries.length === rightHandEntries.length) {
|
|
1892
|
+
leftHandEntries.sort();
|
|
1893
|
+
rightHandEntries.sort();
|
|
1894
|
+
return iterableEqual(leftHandEntries, rightHandEntries, options);
|
|
1895
|
+
}
|
|
1896
|
+
if (leftHandKeys.length === 0 && leftHandEntries.length === 0 && rightHandKeys.length === 0 && rightHandEntries.length === 0) {
|
|
1897
|
+
return true;
|
|
1898
|
+
}
|
|
1899
|
+
return false;
|
|
1900
|
+
}
|
|
1901
|
+
__name(objectEqual, "objectEqual");
|
|
1902
|
+
function isPrimitive(value) {
|
|
1903
|
+
return value === null || typeof value !== "object";
|
|
1904
|
+
}
|
|
1905
|
+
__name(isPrimitive, "isPrimitive");
|
|
1906
|
+
function mapSymbols(arr) {
|
|
1907
|
+
return arr.map(__name(function mapSymbol(entry) {
|
|
1908
|
+
if (typeof entry === "symbol") {
|
|
1909
|
+
return entry.toString();
|
|
1910
|
+
}
|
|
1911
|
+
return entry;
|
|
1912
|
+
}, "mapSymbol"));
|
|
1913
|
+
}
|
|
1914
|
+
__name(mapSymbols, "mapSymbols");
|
|
1915
|
+
function hasProperty(obj, name) {
|
|
1916
|
+
if (typeof obj === "undefined" || obj === null) {
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1919
|
+
return name in Object(obj);
|
|
1920
|
+
}
|
|
1921
|
+
__name(hasProperty, "hasProperty");
|
|
1922
|
+
function parsePath(path) {
|
|
1923
|
+
const str = path.replace(/([^\\])\[/g, "$1.[");
|
|
1924
|
+
const parts = str.match(/(\\\.|[^.]+?)+/g);
|
|
1925
|
+
return parts.map((value)=>{
|
|
1926
|
+
if (value === "constructor" || value === "__proto__" || value === "prototype") {
|
|
1927
|
+
return {};
|
|
1928
|
+
}
|
|
1929
|
+
const regexp = /^\[(\d+)\]$/;
|
|
1930
|
+
const mArr = regexp.exec(value);
|
|
1931
|
+
let parsed = null;
|
|
1932
|
+
if (mArr) {
|
|
1933
|
+
parsed = {
|
|
1934
|
+
i: parseFloat(mArr[1])
|
|
1935
|
+
};
|
|
1936
|
+
} else {
|
|
1937
|
+
parsed = {
|
|
1938
|
+
p: value.replace(/\\([.[\]])/g, "$1")
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
return parsed;
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
__name(parsePath, "parsePath");
|
|
1945
|
+
function internalGetPathValue(obj, parsed, pathDepth) {
|
|
1946
|
+
let temporaryValue = obj;
|
|
1947
|
+
let res = null;
|
|
1948
|
+
pathDepth = typeof pathDepth === "undefined" ? parsed.length : pathDepth;
|
|
1949
|
+
for(let i = 0; i < pathDepth; i++){
|
|
1950
|
+
const part = parsed[i];
|
|
1951
|
+
if (temporaryValue) {
|
|
1952
|
+
if (typeof part.p === "undefined") {
|
|
1953
|
+
temporaryValue = temporaryValue[part.i];
|
|
1954
|
+
} else {
|
|
1955
|
+
temporaryValue = temporaryValue[part.p];
|
|
1956
|
+
}
|
|
1957
|
+
if (i === pathDepth - 1) {
|
|
1958
|
+
res = temporaryValue;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
return res;
|
|
1963
|
+
}
|
|
1964
|
+
__name(internalGetPathValue, "internalGetPathValue");
|
|
1965
|
+
function getPathInfo(obj, path) {
|
|
1966
|
+
const parsed = parsePath(path);
|
|
1967
|
+
const last = parsed[parsed.length - 1];
|
|
1968
|
+
const info = {
|
|
1969
|
+
parent: parsed.length > 1 ? internalGetPathValue(obj, parsed, parsed.length - 1) : obj,
|
|
1970
|
+
name: last.p || last.i,
|
|
1971
|
+
value: internalGetPathValue(obj, parsed)
|
|
1972
|
+
};
|
|
1973
|
+
info.exists = hasProperty(info.parent, info.name);
|
|
1974
|
+
return info;
|
|
1975
|
+
}
|
|
1976
|
+
__name(getPathInfo, "getPathInfo");
|
|
1977
|
+
var Assertion = class _Assertion {
|
|
1978
|
+
static{
|
|
1979
|
+
__name(this, "Assertion");
|
|
1980
|
+
}
|
|
1981
|
+
__flags = {};
|
|
1982
|
+
constructor(obj, msg, ssfi, lockSsfi){
|
|
1983
|
+
flag(this, "ssfi", ssfi || _Assertion);
|
|
1984
|
+
flag(this, "lockSsfi", lockSsfi);
|
|
1985
|
+
flag(this, "object", obj);
|
|
1986
|
+
flag(this, "message", msg);
|
|
1987
|
+
flag(this, "eql", config.deepEqual || deep_eql_default);
|
|
1988
|
+
return proxify(this);
|
|
1989
|
+
}
|
|
1990
|
+
static get includeStack() {
|
|
1991
|
+
console.warn("Assertion.includeStack is deprecated, use chai.config.includeStack instead.");
|
|
1992
|
+
return config.includeStack;
|
|
1993
|
+
}
|
|
1994
|
+
static set includeStack(value) {
|
|
1995
|
+
console.warn("Assertion.includeStack is deprecated, use chai.config.includeStack instead.");
|
|
1996
|
+
config.includeStack = value;
|
|
1997
|
+
}
|
|
1998
|
+
static get showDiff() {
|
|
1999
|
+
console.warn("Assertion.showDiff is deprecated, use chai.config.showDiff instead.");
|
|
2000
|
+
return config.showDiff;
|
|
2001
|
+
}
|
|
2002
|
+
static set showDiff(value) {
|
|
2003
|
+
console.warn("Assertion.showDiff is deprecated, use chai.config.showDiff instead.");
|
|
2004
|
+
config.showDiff = value;
|
|
2005
|
+
}
|
|
2006
|
+
static addProperty(name, fn) {
|
|
2007
|
+
addProperty(this.prototype, name, fn);
|
|
2008
|
+
}
|
|
2009
|
+
static addMethod(name, fn) {
|
|
2010
|
+
addMethod(this.prototype, name, fn);
|
|
2011
|
+
}
|
|
2012
|
+
static addChainableMethod(name, fn, chainingBehavior) {
|
|
2013
|
+
addChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
2014
|
+
}
|
|
2015
|
+
static overwriteProperty(name, fn) {
|
|
2016
|
+
overwriteProperty(this.prototype, name, fn);
|
|
2017
|
+
}
|
|
2018
|
+
static overwriteMethod(name, fn) {
|
|
2019
|
+
overwriteMethod(this.prototype, name, fn);
|
|
2020
|
+
}
|
|
2021
|
+
static overwriteChainableMethod(name, fn, chainingBehavior) {
|
|
2022
|
+
overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
2023
|
+
}
|
|
2024
|
+
assert(_expr, msg, _negateMsg, expected, _actual, showDiff) {
|
|
2025
|
+
const ok = test(this, arguments);
|
|
2026
|
+
if (false !== showDiff) showDiff = true;
|
|
2027
|
+
if (void 0 === expected && void 0 === _actual) showDiff = false;
|
|
2028
|
+
if (true !== config.showDiff) showDiff = false;
|
|
2029
|
+
if (!ok) {
|
|
2030
|
+
msg = getMessage2(this, arguments);
|
|
2031
|
+
const actual = getActual(this, arguments);
|
|
2032
|
+
const assertionErrorObjectProperties = {
|
|
2033
|
+
actual,
|
|
2034
|
+
expected,
|
|
2035
|
+
showDiff
|
|
2036
|
+
};
|
|
2037
|
+
const operator = getOperator(this, arguments);
|
|
2038
|
+
if (operator) {
|
|
2039
|
+
assertionErrorObjectProperties.operator = operator;
|
|
2040
|
+
}
|
|
2041
|
+
throw new AssertionError(msg, assertionErrorObjectProperties, config.includeStack ? this.assert : flag(this, "ssfi"));
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
get _obj() {
|
|
2045
|
+
return flag(this, "object");
|
|
2046
|
+
}
|
|
2047
|
+
set _obj(val) {
|
|
2048
|
+
flag(this, "object", val);
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
function isProxyEnabled() {
|
|
2052
|
+
return config.useProxy && typeof Proxy !== "undefined" && typeof Reflect !== "undefined";
|
|
2053
|
+
}
|
|
2054
|
+
__name(isProxyEnabled, "isProxyEnabled");
|
|
2055
|
+
function addProperty(ctx, name, getter) {
|
|
2056
|
+
getter = getter === void 0 ? function() {} : getter;
|
|
2057
|
+
Object.defineProperty(ctx, name, {
|
|
2058
|
+
get: __name(function propertyGetter() {
|
|
2059
|
+
if (!isProxyEnabled() && !flag(this, "lockSsfi")) {
|
|
2060
|
+
flag(this, "ssfi", propertyGetter);
|
|
2061
|
+
}
|
|
2062
|
+
let result = getter.call(this);
|
|
2063
|
+
if (result !== void 0) return result;
|
|
2064
|
+
let newAssertion = new Assertion();
|
|
2065
|
+
transferFlags(this, newAssertion);
|
|
2066
|
+
return newAssertion;
|
|
2067
|
+
}, "propertyGetter"),
|
|
2068
|
+
configurable: true
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
__name(addProperty, "addProperty");
|
|
2072
|
+
var fnLengthDesc = Object.getOwnPropertyDescriptor(function() {}, "length");
|
|
2073
|
+
function addLengthGuard(fn, assertionName, isChainable) {
|
|
2074
|
+
if (!fnLengthDesc.configurable) return fn;
|
|
2075
|
+
Object.defineProperty(fn, "length", {
|
|
2076
|
+
get: __name(function() {
|
|
2077
|
+
if (isChainable) {
|
|
2078
|
+
throw Error("Invalid Chai property: " + assertionName + '.length. Due to a compatibility issue, "length" cannot directly follow "' + assertionName + '". Use "' + assertionName + '.lengthOf" instead.');
|
|
2079
|
+
}
|
|
2080
|
+
throw Error("Invalid Chai property: " + assertionName + '.length. See docs for proper usage of "' + assertionName + '".');
|
|
2081
|
+
}, "get")
|
|
2082
|
+
});
|
|
2083
|
+
return fn;
|
|
2084
|
+
}
|
|
2085
|
+
__name(addLengthGuard, "addLengthGuard");
|
|
2086
|
+
function getProperties(object) {
|
|
2087
|
+
let result = Object.getOwnPropertyNames(object);
|
|
2088
|
+
function addProperty2(property) {
|
|
2089
|
+
if (result.indexOf(property) === -1) {
|
|
2090
|
+
result.push(property);
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
__name(addProperty2, "addProperty");
|
|
2094
|
+
let proto = Object.getPrototypeOf(object);
|
|
2095
|
+
while(proto !== null){
|
|
2096
|
+
Object.getOwnPropertyNames(proto).forEach(addProperty2);
|
|
2097
|
+
proto = Object.getPrototypeOf(proto);
|
|
2098
|
+
}
|
|
2099
|
+
return result;
|
|
2100
|
+
}
|
|
2101
|
+
__name(getProperties, "getProperties");
|
|
2102
|
+
var builtins = [
|
|
2103
|
+
"__flags",
|
|
2104
|
+
"__methods",
|
|
2105
|
+
"_obj",
|
|
2106
|
+
"assert"
|
|
2107
|
+
];
|
|
2108
|
+
function proxify(obj, nonChainableMethodName) {
|
|
2109
|
+
if (!isProxyEnabled()) return obj;
|
|
2110
|
+
return new Proxy(obj, {
|
|
2111
|
+
get: __name(function proxyGetter(target, property) {
|
|
2112
|
+
if (typeof property === "string" && config.proxyExcludedKeys.indexOf(property) === -1 && !Reflect.has(target, property)) {
|
|
2113
|
+
if (nonChainableMethodName) {
|
|
2114
|
+
throw Error("Invalid Chai property: " + nonChainableMethodName + "." + property + '. See docs for proper usage of "' + nonChainableMethodName + '".');
|
|
2115
|
+
}
|
|
2116
|
+
let suggestion = null;
|
|
2117
|
+
let suggestionDistance = 4;
|
|
2118
|
+
getProperties(target).forEach(function(prop) {
|
|
2119
|
+
if (!Object.prototype.hasOwnProperty(prop) && builtins.indexOf(prop) === -1) {
|
|
2120
|
+
let dist = stringDistanceCapped(property, prop, suggestionDistance);
|
|
2121
|
+
if (dist < suggestionDistance) {
|
|
2122
|
+
suggestion = prop;
|
|
2123
|
+
suggestionDistance = dist;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
if (suggestion !== null) {
|
|
2128
|
+
throw Error("Invalid Chai property: " + property + '. Did you mean "' + suggestion + '"?');
|
|
2129
|
+
} else {
|
|
2130
|
+
throw Error("Invalid Chai property: " + property);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
if (builtins.indexOf(property) === -1 && !flag(target, "lockSsfi")) {
|
|
2134
|
+
flag(target, "ssfi", proxyGetter);
|
|
2135
|
+
}
|
|
2136
|
+
return Reflect.get(target, property);
|
|
2137
|
+
}, "proxyGetter")
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
__name(proxify, "proxify");
|
|
2141
|
+
function stringDistanceCapped(strA, strB, cap) {
|
|
2142
|
+
if (Math.abs(strA.length - strB.length) >= cap) {
|
|
2143
|
+
return cap;
|
|
2144
|
+
}
|
|
2145
|
+
let memo = [];
|
|
2146
|
+
for(let i = 0; i <= strA.length; i++){
|
|
2147
|
+
memo[i] = Array(strB.length + 1).fill(0);
|
|
2148
|
+
memo[i][0] = i;
|
|
2149
|
+
}
|
|
2150
|
+
for(let j = 0; j < strB.length; j++){
|
|
2151
|
+
memo[0][j] = j;
|
|
2152
|
+
}
|
|
2153
|
+
for(let i = 1; i <= strA.length; i++){
|
|
2154
|
+
let ch = strA.charCodeAt(i - 1);
|
|
2155
|
+
for(let j = 1; j <= strB.length; j++){
|
|
2156
|
+
if (Math.abs(i - j) >= cap) {
|
|
2157
|
+
memo[i][j] = cap;
|
|
2158
|
+
continue;
|
|
2159
|
+
}
|
|
2160
|
+
memo[i][j] = Math.min(memo[i - 1][j] + 1, memo[i][j - 1] + 1, memo[i - 1][j - 1] + (ch === strB.charCodeAt(j - 1) ? 0 : 1));
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
return memo[strA.length][strB.length];
|
|
2164
|
+
}
|
|
2165
|
+
__name(stringDistanceCapped, "stringDistanceCapped");
|
|
2166
|
+
function addMethod(ctx, name, method) {
|
|
2167
|
+
let methodWrapper = __name(function() {
|
|
2168
|
+
if (!flag(this, "lockSsfi")) {
|
|
2169
|
+
flag(this, "ssfi", methodWrapper);
|
|
2170
|
+
}
|
|
2171
|
+
let result = method.apply(this, arguments);
|
|
2172
|
+
if (result !== void 0) return result;
|
|
2173
|
+
let newAssertion = new Assertion();
|
|
2174
|
+
transferFlags(this, newAssertion);
|
|
2175
|
+
return newAssertion;
|
|
2176
|
+
}, "methodWrapper");
|
|
2177
|
+
addLengthGuard(methodWrapper, name, false);
|
|
2178
|
+
ctx[name] = proxify(methodWrapper, name);
|
|
2179
|
+
}
|
|
2180
|
+
__name(addMethod, "addMethod");
|
|
2181
|
+
function overwriteProperty(ctx, name, getter) {
|
|
2182
|
+
let _get = Object.getOwnPropertyDescriptor(ctx, name), _super = __name(function() {}, "_super");
|
|
2183
|
+
if (_get && "function" === typeof _get.get) _super = _get.get;
|
|
2184
|
+
Object.defineProperty(ctx, name, {
|
|
2185
|
+
get: __name(function overwritingPropertyGetter() {
|
|
2186
|
+
if (!isProxyEnabled() && !flag(this, "lockSsfi")) {
|
|
2187
|
+
flag(this, "ssfi", overwritingPropertyGetter);
|
|
2188
|
+
}
|
|
2189
|
+
let origLockSsfi = flag(this, "lockSsfi");
|
|
2190
|
+
flag(this, "lockSsfi", true);
|
|
2191
|
+
let result = getter(_super).call(this);
|
|
2192
|
+
flag(this, "lockSsfi", origLockSsfi);
|
|
2193
|
+
if (result !== void 0) {
|
|
2194
|
+
return result;
|
|
2195
|
+
}
|
|
2196
|
+
let newAssertion = new Assertion();
|
|
2197
|
+
transferFlags(this, newAssertion);
|
|
2198
|
+
return newAssertion;
|
|
2199
|
+
}, "overwritingPropertyGetter"),
|
|
2200
|
+
configurable: true
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
__name(overwriteProperty, "overwriteProperty");
|
|
2204
|
+
function overwriteMethod(ctx, name, method) {
|
|
2205
|
+
let _method = ctx[name], _super = __name(function() {
|
|
2206
|
+
throw new Error(name + " is not a function");
|
|
2207
|
+
}, "_super");
|
|
2208
|
+
if (_method && "function" === typeof _method) _super = _method;
|
|
2209
|
+
let overwritingMethodWrapper = __name(function() {
|
|
2210
|
+
if (!flag(this, "lockSsfi")) {
|
|
2211
|
+
flag(this, "ssfi", overwritingMethodWrapper);
|
|
2212
|
+
}
|
|
2213
|
+
let origLockSsfi = flag(this, "lockSsfi");
|
|
2214
|
+
flag(this, "lockSsfi", true);
|
|
2215
|
+
let result = method(_super).apply(this, arguments);
|
|
2216
|
+
flag(this, "lockSsfi", origLockSsfi);
|
|
2217
|
+
if (result !== void 0) {
|
|
2218
|
+
return result;
|
|
2219
|
+
}
|
|
2220
|
+
let newAssertion = new Assertion();
|
|
2221
|
+
transferFlags(this, newAssertion);
|
|
2222
|
+
return newAssertion;
|
|
2223
|
+
}, "overwritingMethodWrapper");
|
|
2224
|
+
addLengthGuard(overwritingMethodWrapper, name, false);
|
|
2225
|
+
ctx[name] = proxify(overwritingMethodWrapper, name);
|
|
2226
|
+
}
|
|
2227
|
+
__name(overwriteMethod, "overwriteMethod");
|
|
2228
|
+
var canSetPrototype = typeof Object.setPrototypeOf === "function";
|
|
2229
|
+
var testFn = __name(function() {}, "testFn");
|
|
2230
|
+
var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) {
|
|
2231
|
+
let propDesc = Object.getOwnPropertyDescriptor(testFn, name);
|
|
2232
|
+
if (typeof propDesc !== "object") return true;
|
|
2233
|
+
return !propDesc.configurable;
|
|
2234
|
+
});
|
|
2235
|
+
var call = Function.prototype.call;
|
|
2236
|
+
var apply = Function.prototype.apply;
|
|
2237
|
+
function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
2238
|
+
if (typeof chainingBehavior !== "function") {
|
|
2239
|
+
chainingBehavior = __name(function() {}, "chainingBehavior");
|
|
2240
|
+
}
|
|
2241
|
+
let chainableBehavior = {
|
|
2242
|
+
method,
|
|
2243
|
+
chainingBehavior
|
|
2244
|
+
};
|
|
2245
|
+
if (!ctx.__methods) {
|
|
2246
|
+
ctx.__methods = {};
|
|
2247
|
+
}
|
|
2248
|
+
ctx.__methods[name] = chainableBehavior;
|
|
2249
|
+
Object.defineProperty(ctx, name, {
|
|
2250
|
+
get: __name(function chainableMethodGetter() {
|
|
2251
|
+
chainableBehavior.chainingBehavior.call(this);
|
|
2252
|
+
let chainableMethodWrapper = __name(function() {
|
|
2253
|
+
if (!flag(this, "lockSsfi")) {
|
|
2254
|
+
flag(this, "ssfi", chainableMethodWrapper);
|
|
2255
|
+
}
|
|
2256
|
+
let result = chainableBehavior.method.apply(this, arguments);
|
|
2257
|
+
if (result !== void 0) {
|
|
2258
|
+
return result;
|
|
2259
|
+
}
|
|
2260
|
+
let newAssertion = new Assertion();
|
|
2261
|
+
transferFlags(this, newAssertion);
|
|
2262
|
+
return newAssertion;
|
|
2263
|
+
}, "chainableMethodWrapper");
|
|
2264
|
+
addLengthGuard(chainableMethodWrapper, name, true);
|
|
2265
|
+
if (canSetPrototype) {
|
|
2266
|
+
let prototype = Object.create(this);
|
|
2267
|
+
prototype.call = call;
|
|
2268
|
+
prototype.apply = apply;
|
|
2269
|
+
Object.setPrototypeOf(chainableMethodWrapper, prototype);
|
|
2270
|
+
} else {
|
|
2271
|
+
let asserterNames = Object.getOwnPropertyNames(ctx);
|
|
2272
|
+
asserterNames.forEach(function(asserterName) {
|
|
2273
|
+
if (excludeNames.indexOf(asserterName) !== -1) {
|
|
2274
|
+
return;
|
|
2275
|
+
}
|
|
2276
|
+
let pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
|
|
2277
|
+
Object.defineProperty(chainableMethodWrapper, asserterName, pd);
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
transferFlags(this, chainableMethodWrapper);
|
|
2281
|
+
return proxify(chainableMethodWrapper);
|
|
2282
|
+
}, "chainableMethodGetter"),
|
|
2283
|
+
configurable: true
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
__name(addChainableMethod, "addChainableMethod");
|
|
2287
|
+
function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
|
|
2288
|
+
let chainableBehavior = ctx.__methods[name];
|
|
2289
|
+
let _chainingBehavior = chainableBehavior.chainingBehavior;
|
|
2290
|
+
chainableBehavior.chainingBehavior = __name(function overwritingChainableMethodGetter() {
|
|
2291
|
+
let result = chainingBehavior(_chainingBehavior).call(this);
|
|
2292
|
+
if (result !== void 0) {
|
|
2293
|
+
return result;
|
|
2294
|
+
}
|
|
2295
|
+
let newAssertion = new Assertion();
|
|
2296
|
+
transferFlags(this, newAssertion);
|
|
2297
|
+
return newAssertion;
|
|
2298
|
+
}, "overwritingChainableMethodGetter");
|
|
2299
|
+
let _method = chainableBehavior.method;
|
|
2300
|
+
chainableBehavior.method = __name(function overwritingChainableMethodWrapper() {
|
|
2301
|
+
let result = method(_method).apply(this, arguments);
|
|
2302
|
+
if (result !== void 0) {
|
|
2303
|
+
return result;
|
|
2304
|
+
}
|
|
2305
|
+
let newAssertion = new Assertion();
|
|
2306
|
+
transferFlags(this, newAssertion);
|
|
2307
|
+
return newAssertion;
|
|
2308
|
+
}, "overwritingChainableMethodWrapper");
|
|
2309
|
+
}
|
|
2310
|
+
__name(overwriteChainableMethod, "overwriteChainableMethod");
|
|
2311
|
+
function compareByInspect(a, b) {
|
|
2312
|
+
return inspect2(a) < inspect2(b) ? -1 : 1;
|
|
2313
|
+
}
|
|
2314
|
+
__name(compareByInspect, "compareByInspect");
|
|
2315
|
+
function getOwnEnumerablePropertySymbols(obj) {
|
|
2316
|
+
if (typeof Object.getOwnPropertySymbols !== "function") return [];
|
|
2317
|
+
return Object.getOwnPropertySymbols(obj).filter(function(sym) {
|
|
2318
|
+
return Object.getOwnPropertyDescriptor(obj, sym).enumerable;
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
__name(getOwnEnumerablePropertySymbols, "getOwnEnumerablePropertySymbols");
|
|
2322
|
+
function getOwnEnumerableProperties(obj) {
|
|
2323
|
+
return Object.keys(obj).concat(getOwnEnumerablePropertySymbols(obj));
|
|
2324
|
+
}
|
|
2325
|
+
__name(getOwnEnumerableProperties, "getOwnEnumerableProperties");
|
|
2326
|
+
var isNaN2 = Number.isNaN;
|
|
2327
|
+
function isObjectType(obj) {
|
|
2328
|
+
let objectType = type(obj);
|
|
2329
|
+
let objectTypes = [
|
|
2330
|
+
"Array",
|
|
2331
|
+
"Object",
|
|
2332
|
+
"Function"
|
|
2333
|
+
];
|
|
2334
|
+
return objectTypes.indexOf(objectType) !== -1;
|
|
2335
|
+
}
|
|
2336
|
+
__name(isObjectType, "isObjectType");
|
|
2337
|
+
function getOperator(obj, args) {
|
|
2338
|
+
let operator = flag(obj, "operator");
|
|
2339
|
+
let negate = flag(obj, "negate");
|
|
2340
|
+
let expected = args[3];
|
|
2341
|
+
let msg = negate ? args[2] : args[1];
|
|
2342
|
+
if (operator) {
|
|
2343
|
+
return operator;
|
|
2344
|
+
}
|
|
2345
|
+
if (typeof msg === "function") msg = msg();
|
|
2346
|
+
msg = msg || "";
|
|
2347
|
+
if (!msg) {
|
|
2348
|
+
return void 0;
|
|
2349
|
+
}
|
|
2350
|
+
if (/\shave\s/.test(msg)) {
|
|
2351
|
+
return void 0;
|
|
2352
|
+
}
|
|
2353
|
+
let isObject = isObjectType(expected);
|
|
2354
|
+
if (/\snot\s/.test(msg)) {
|
|
2355
|
+
return isObject ? "notDeepStrictEqual" : "notStrictEqual";
|
|
2356
|
+
}
|
|
2357
|
+
return isObject ? "deepStrictEqual" : "strictEqual";
|
|
2358
|
+
}
|
|
2359
|
+
__name(getOperator, "getOperator");
|
|
2360
|
+
function getName(fn) {
|
|
2361
|
+
return fn.name;
|
|
2362
|
+
}
|
|
2363
|
+
__name(getName, "getName");
|
|
2364
|
+
function isRegExp2(obj) {
|
|
2365
|
+
return Object.prototype.toString.call(obj) === "[object RegExp]";
|
|
2366
|
+
}
|
|
2367
|
+
__name(isRegExp2, "isRegExp");
|
|
2368
|
+
function isNumeric(obj) {
|
|
2369
|
+
return [
|
|
2370
|
+
"Number",
|
|
2371
|
+
"BigInt"
|
|
2372
|
+
].includes(type(obj));
|
|
2373
|
+
}
|
|
2374
|
+
__name(isNumeric, "isNumeric");
|
|
2375
|
+
var { flag: flag2 } = utils_exports;
|
|
2376
|
+
[
|
|
2377
|
+
"to",
|
|
2378
|
+
"be",
|
|
2379
|
+
"been",
|
|
2380
|
+
"is",
|
|
2381
|
+
"and",
|
|
2382
|
+
"has",
|
|
2383
|
+
"have",
|
|
2384
|
+
"with",
|
|
2385
|
+
"that",
|
|
2386
|
+
"which",
|
|
2387
|
+
"at",
|
|
2388
|
+
"of",
|
|
2389
|
+
"same",
|
|
2390
|
+
"but",
|
|
2391
|
+
"does",
|
|
2392
|
+
"still",
|
|
2393
|
+
"also"
|
|
2394
|
+
].forEach(function(chain) {
|
|
2395
|
+
Assertion.addProperty(chain);
|
|
2396
|
+
});
|
|
2397
|
+
Assertion.addProperty("not", function() {
|
|
2398
|
+
flag2(this, "negate", true);
|
|
2399
|
+
});
|
|
2400
|
+
Assertion.addProperty("deep", function() {
|
|
2401
|
+
flag2(this, "deep", true);
|
|
2402
|
+
});
|
|
2403
|
+
Assertion.addProperty("nested", function() {
|
|
2404
|
+
flag2(this, "nested", true);
|
|
2405
|
+
});
|
|
2406
|
+
Assertion.addProperty("own", function() {
|
|
2407
|
+
flag2(this, "own", true);
|
|
2408
|
+
});
|
|
2409
|
+
Assertion.addProperty("ordered", function() {
|
|
2410
|
+
flag2(this, "ordered", true);
|
|
2411
|
+
});
|
|
2412
|
+
Assertion.addProperty("any", function() {
|
|
2413
|
+
flag2(this, "any", true);
|
|
2414
|
+
flag2(this, "all", false);
|
|
2415
|
+
});
|
|
2416
|
+
Assertion.addProperty("all", function() {
|
|
2417
|
+
flag2(this, "all", true);
|
|
2418
|
+
flag2(this, "any", false);
|
|
2419
|
+
});
|
|
2420
|
+
var functionTypes = {
|
|
2421
|
+
function: [
|
|
2422
|
+
"function",
|
|
2423
|
+
"asyncfunction",
|
|
2424
|
+
"generatorfunction",
|
|
2425
|
+
"asyncgeneratorfunction"
|
|
2426
|
+
],
|
|
2427
|
+
asyncfunction: [
|
|
2428
|
+
"asyncfunction",
|
|
2429
|
+
"asyncgeneratorfunction"
|
|
2430
|
+
],
|
|
2431
|
+
generatorfunction: [
|
|
2432
|
+
"generatorfunction",
|
|
2433
|
+
"asyncgeneratorfunction"
|
|
2434
|
+
],
|
|
2435
|
+
asyncgeneratorfunction: [
|
|
2436
|
+
"asyncgeneratorfunction"
|
|
2437
|
+
]
|
|
2438
|
+
};
|
|
2439
|
+
function an(type3, msg) {
|
|
2440
|
+
if (msg) flag2(this, "message", msg);
|
|
2441
|
+
type3 = type3.toLowerCase();
|
|
2442
|
+
let obj = flag2(this, "object"), article = ~[
|
|
2443
|
+
"a",
|
|
2444
|
+
"e",
|
|
2445
|
+
"i",
|
|
2446
|
+
"o",
|
|
2447
|
+
"u"
|
|
2448
|
+
].indexOf(type3.charAt(0)) ? "an " : "a ";
|
|
2449
|
+
const detectedType = type(obj).toLowerCase();
|
|
2450
|
+
if (functionTypes["function"].includes(type3)) {
|
|
2451
|
+
this.assert(functionTypes[type3].includes(detectedType), "expected #{this} to be " + article + type3, "expected #{this} not to be " + article + type3);
|
|
2452
|
+
} else {
|
|
2453
|
+
this.assert(type3 === detectedType, "expected #{this} to be " + article + type3, "expected #{this} not to be " + article + type3);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
__name(an, "an");
|
|
2457
|
+
Assertion.addChainableMethod("an", an);
|
|
2458
|
+
Assertion.addChainableMethod("a", an);
|
|
2459
|
+
function SameValueZero(a, b) {
|
|
2460
|
+
return isNaN2(a) && isNaN2(b) || a === b;
|
|
2461
|
+
}
|
|
2462
|
+
__name(SameValueZero, "SameValueZero");
|
|
2463
|
+
function includeChainingBehavior() {
|
|
2464
|
+
flag2(this, "contains", true);
|
|
2465
|
+
}
|
|
2466
|
+
__name(includeChainingBehavior, "includeChainingBehavior");
|
|
2467
|
+
function include(val, msg) {
|
|
2468
|
+
if (msg) flag2(this, "message", msg);
|
|
2469
|
+
let obj = flag2(this, "object"), objType = type(obj).toLowerCase(), flagMsg = flag2(this, "message"), negate = flag2(this, "negate"), ssfi = flag2(this, "ssfi"), isDeep = flag2(this, "deep"), descriptor = isDeep ? "deep " : "", isEql = isDeep ? flag2(this, "eql") : SameValueZero;
|
|
2470
|
+
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
2471
|
+
let included = false;
|
|
2472
|
+
switch(objType){
|
|
2473
|
+
case "string":
|
|
2474
|
+
included = obj.indexOf(val) !== -1;
|
|
2475
|
+
break;
|
|
2476
|
+
case "weakset":
|
|
2477
|
+
if (isDeep) {
|
|
2478
|
+
throw new AssertionError(flagMsg + "unable to use .deep.include with WeakSet", void 0, ssfi);
|
|
2479
|
+
}
|
|
2480
|
+
included = obj.has(val);
|
|
2481
|
+
break;
|
|
2482
|
+
case "map":
|
|
2483
|
+
obj.forEach(function(item) {
|
|
2484
|
+
included = included || isEql(item, val);
|
|
2485
|
+
});
|
|
2486
|
+
break;
|
|
2487
|
+
case "set":
|
|
2488
|
+
if (isDeep) {
|
|
2489
|
+
obj.forEach(function(item) {
|
|
2490
|
+
included = included || isEql(item, val);
|
|
2491
|
+
});
|
|
2492
|
+
} else {
|
|
2493
|
+
included = obj.has(val);
|
|
2494
|
+
}
|
|
2495
|
+
break;
|
|
2496
|
+
case "array":
|
|
2497
|
+
if (isDeep) {
|
|
2498
|
+
included = obj.some(function(item) {
|
|
2499
|
+
return isEql(item, val);
|
|
2500
|
+
});
|
|
2501
|
+
} else {
|
|
2502
|
+
included = obj.indexOf(val) !== -1;
|
|
2503
|
+
}
|
|
2504
|
+
break;
|
|
2505
|
+
default:
|
|
2506
|
+
{
|
|
2507
|
+
if (val !== Object(val)) {
|
|
2508
|
+
throw new AssertionError(flagMsg + "the given combination of arguments (" + objType + " and " + type(val).toLowerCase() + ") is invalid for this assertion. You can use an array, a map, an object, a set, a string, or a weakset instead of a " + type(val).toLowerCase(), void 0, ssfi);
|
|
2509
|
+
}
|
|
2510
|
+
let props = Object.keys(val);
|
|
2511
|
+
let firstErr = null;
|
|
2512
|
+
let numErrs = 0;
|
|
2513
|
+
props.forEach(function(prop) {
|
|
2514
|
+
let propAssertion = new Assertion(obj);
|
|
2515
|
+
transferFlags(this, propAssertion, true);
|
|
2516
|
+
flag2(propAssertion, "lockSsfi", true);
|
|
2517
|
+
if (!negate || props.length === 1) {
|
|
2518
|
+
propAssertion.property(prop, val[prop]);
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
try {
|
|
2522
|
+
propAssertion.property(prop, val[prop]);
|
|
2523
|
+
} catch (err) {
|
|
2524
|
+
if (!check_error_exports.compatibleConstructor(err, AssertionError)) {
|
|
2525
|
+
throw err;
|
|
2526
|
+
}
|
|
2527
|
+
if (firstErr === null) firstErr = err;
|
|
2528
|
+
numErrs++;
|
|
2529
|
+
}
|
|
2530
|
+
}, this);
|
|
2531
|
+
if (negate && props.length > 1 && numErrs === props.length) {
|
|
2532
|
+
throw firstErr;
|
|
2533
|
+
}
|
|
2534
|
+
return;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
this.assert(included, "expected #{this} to " + descriptor + "include " + inspect2(val), "expected #{this} to not " + descriptor + "include " + inspect2(val));
|
|
2538
|
+
}
|
|
2539
|
+
__name(include, "include");
|
|
2540
|
+
Assertion.addChainableMethod("include", include, includeChainingBehavior);
|
|
2541
|
+
Assertion.addChainableMethod("contain", include, includeChainingBehavior);
|
|
2542
|
+
Assertion.addChainableMethod("contains", include, includeChainingBehavior);
|
|
2543
|
+
Assertion.addChainableMethod("includes", include, includeChainingBehavior);
|
|
2544
|
+
Assertion.addProperty("ok", function() {
|
|
2545
|
+
this.assert(flag2(this, "object"), "expected #{this} to be truthy", "expected #{this} to be falsy");
|
|
2546
|
+
});
|
|
2547
|
+
Assertion.addProperty("true", function() {
|
|
2548
|
+
this.assert(true === flag2(this, "object"), "expected #{this} to be true", "expected #{this} to be false", flag2(this, "negate") ? false : true);
|
|
2549
|
+
});
|
|
2550
|
+
Assertion.addProperty("numeric", function() {
|
|
2551
|
+
const object = flag2(this, "object");
|
|
2552
|
+
this.assert([
|
|
2553
|
+
"Number",
|
|
2554
|
+
"BigInt"
|
|
2555
|
+
].includes(type(object)), "expected #{this} to be numeric", "expected #{this} to not be numeric", flag2(this, "negate") ? false : true);
|
|
2556
|
+
});
|
|
2557
|
+
Assertion.addProperty("callable", function() {
|
|
2558
|
+
const val = flag2(this, "object");
|
|
2559
|
+
const ssfi = flag2(this, "ssfi");
|
|
2560
|
+
const message = flag2(this, "message");
|
|
2561
|
+
const msg = message ? `${message}: ` : "";
|
|
2562
|
+
const negate = flag2(this, "negate");
|
|
2563
|
+
const assertionMessage = negate ? `${msg}expected ${inspect2(val)} not to be a callable function` : `${msg}expected ${inspect2(val)} to be a callable function`;
|
|
2564
|
+
const isCallable = [
|
|
2565
|
+
"Function",
|
|
2566
|
+
"AsyncFunction",
|
|
2567
|
+
"GeneratorFunction",
|
|
2568
|
+
"AsyncGeneratorFunction"
|
|
2569
|
+
].includes(type(val));
|
|
2570
|
+
if (isCallable && negate || !isCallable && !negate) {
|
|
2571
|
+
throw new AssertionError(assertionMessage, void 0, ssfi);
|
|
2572
|
+
}
|
|
2573
|
+
});
|
|
2574
|
+
Assertion.addProperty("false", function() {
|
|
2575
|
+
this.assert(false === flag2(this, "object"), "expected #{this} to be false", "expected #{this} to be true", flag2(this, "negate") ? true : false);
|
|
2576
|
+
});
|
|
2577
|
+
Assertion.addProperty("null", function() {
|
|
2578
|
+
this.assert(null === flag2(this, "object"), "expected #{this} to be null", "expected #{this} not to be null");
|
|
2579
|
+
});
|
|
2580
|
+
Assertion.addProperty("undefined", function() {
|
|
2581
|
+
this.assert(void 0 === flag2(this, "object"), "expected #{this} to be undefined", "expected #{this} not to be undefined");
|
|
2582
|
+
});
|
|
2583
|
+
Assertion.addProperty("NaN", function() {
|
|
2584
|
+
this.assert(isNaN2(flag2(this, "object")), "expected #{this} to be NaN", "expected #{this} not to be NaN");
|
|
2585
|
+
});
|
|
2586
|
+
function assertExist() {
|
|
2587
|
+
let val = flag2(this, "object");
|
|
2588
|
+
this.assert(val !== null && val !== void 0, "expected #{this} to exist", "expected #{this} to not exist");
|
|
2589
|
+
}
|
|
2590
|
+
__name(assertExist, "assertExist");
|
|
2591
|
+
Assertion.addProperty("exist", assertExist);
|
|
2592
|
+
Assertion.addProperty("exists", assertExist);
|
|
2593
|
+
Assertion.addProperty("empty", function() {
|
|
2594
|
+
let val = flag2(this, "object"), ssfi = flag2(this, "ssfi"), flagMsg = flag2(this, "message"), itemsCount;
|
|
2595
|
+
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
2596
|
+
switch(type(val).toLowerCase()){
|
|
2597
|
+
case "array":
|
|
2598
|
+
case "string":
|
|
2599
|
+
itemsCount = val.length;
|
|
2600
|
+
break;
|
|
2601
|
+
case "map":
|
|
2602
|
+
case "set":
|
|
2603
|
+
itemsCount = val.size;
|
|
2604
|
+
break;
|
|
2605
|
+
case "weakmap":
|
|
2606
|
+
case "weakset":
|
|
2607
|
+
throw new AssertionError(flagMsg + ".empty was passed a weak collection", void 0, ssfi);
|
|
2608
|
+
case "function":
|
|
2609
|
+
{
|
|
2610
|
+
const msg = flagMsg + ".empty was passed a function " + getName(val);
|
|
2611
|
+
throw new AssertionError(msg.trim(), void 0, ssfi);
|
|
2612
|
+
}
|
|
2613
|
+
default:
|
|
2614
|
+
if (val !== Object(val)) {
|
|
2615
|
+
throw new AssertionError(flagMsg + ".empty was passed non-string primitive " + inspect2(val), void 0, ssfi);
|
|
2616
|
+
}
|
|
2617
|
+
itemsCount = Object.keys(val).length;
|
|
2618
|
+
}
|
|
2619
|
+
this.assert(0 === itemsCount, "expected #{this} to be empty", "expected #{this} not to be empty");
|
|
2620
|
+
});
|
|
2621
|
+
function checkArguments() {
|
|
2622
|
+
let obj = flag2(this, "object"), type3 = type(obj);
|
|
2623
|
+
this.assert("Arguments" === type3, "expected #{this} to be arguments but got " + type3, "expected #{this} to not be arguments");
|
|
2624
|
+
}
|
|
2625
|
+
__name(checkArguments, "checkArguments");
|
|
2626
|
+
Assertion.addProperty("arguments", checkArguments);
|
|
2627
|
+
Assertion.addProperty("Arguments", checkArguments);
|
|
2628
|
+
function assertEqual(val, msg) {
|
|
2629
|
+
if (msg) flag2(this, "message", msg);
|
|
2630
|
+
let obj = flag2(this, "object");
|
|
2631
|
+
if (flag2(this, "deep")) {
|
|
2632
|
+
let prevLockSsfi = flag2(this, "lockSsfi");
|
|
2633
|
+
flag2(this, "lockSsfi", true);
|
|
2634
|
+
this.eql(val);
|
|
2635
|
+
flag2(this, "lockSsfi", prevLockSsfi);
|
|
2636
|
+
} else {
|
|
2637
|
+
this.assert(val === obj, "expected #{this} to equal #{exp}", "expected #{this} to not equal #{exp}", val, this._obj, true);
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
__name(assertEqual, "assertEqual");
|
|
2641
|
+
Assertion.addMethod("equal", assertEqual);
|
|
2642
|
+
Assertion.addMethod("equals", assertEqual);
|
|
2643
|
+
Assertion.addMethod("eq", assertEqual);
|
|
2644
|
+
function assertEql(obj, msg) {
|
|
2645
|
+
if (msg) flag2(this, "message", msg);
|
|
2646
|
+
let eql = flag2(this, "eql");
|
|
2647
|
+
this.assert(eql(obj, flag2(this, "object")), "expected #{this} to deeply equal #{exp}", "expected #{this} to not deeply equal #{exp}", obj, this._obj, true);
|
|
2648
|
+
}
|
|
2649
|
+
__name(assertEql, "assertEql");
|
|
2650
|
+
Assertion.addMethod("eql", assertEql);
|
|
2651
|
+
Assertion.addMethod("eqls", assertEql);
|
|
2652
|
+
function assertAbove(n, msg) {
|
|
2653
|
+
if (msg) flag2(this, "message", msg);
|
|
2654
|
+
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase();
|
|
2655
|
+
if (doLength && objType !== "map" && objType !== "set") {
|
|
2656
|
+
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
2657
|
+
}
|
|
2658
|
+
if (!doLength && objType === "date" && nType !== "date") {
|
|
2659
|
+
throw new AssertionError(msgPrefix + "the argument to above must be a date", void 0, ssfi);
|
|
2660
|
+
} else if (!isNumeric(n) && (doLength || isNumeric(obj))) {
|
|
2661
|
+
throw new AssertionError(msgPrefix + "the argument to above must be a number", void 0, ssfi);
|
|
2662
|
+
} else if (!doLength && objType !== "date" && !isNumeric(obj)) {
|
|
2663
|
+
let printObj = objType === "string" ? "'" + obj + "'" : obj;
|
|
2664
|
+
throw new AssertionError(msgPrefix + "expected " + printObj + " to be a number or a date", void 0, ssfi);
|
|
2665
|
+
}
|
|
2666
|
+
if (doLength) {
|
|
2667
|
+
let descriptor = "length", itemsCount;
|
|
2668
|
+
if (objType === "map" || objType === "set") {
|
|
2669
|
+
descriptor = "size";
|
|
2670
|
+
itemsCount = obj.size;
|
|
2671
|
+
} else {
|
|
2672
|
+
itemsCount = obj.length;
|
|
2673
|
+
}
|
|
2674
|
+
this.assert(itemsCount > n, "expected #{this} to have a " + descriptor + " above #{exp} but got #{act}", "expected #{this} to not have a " + descriptor + " above #{exp}", n, itemsCount);
|
|
2675
|
+
} else {
|
|
2676
|
+
this.assert(obj > n, "expected #{this} to be above #{exp}", "expected #{this} to be at most #{exp}", n);
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
__name(assertAbove, "assertAbove");
|
|
2680
|
+
Assertion.addMethod("above", assertAbove);
|
|
2681
|
+
Assertion.addMethod("gt", assertAbove);
|
|
2682
|
+
Assertion.addMethod("greaterThan", assertAbove);
|
|
2683
|
+
function assertLeast(n, msg) {
|
|
2684
|
+
if (msg) flag2(this, "message", msg);
|
|
2685
|
+
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase(), errorMessage, shouldThrow = true;
|
|
2686
|
+
if (doLength && objType !== "map" && objType !== "set") {
|
|
2687
|
+
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
2688
|
+
}
|
|
2689
|
+
if (!doLength && objType === "date" && nType !== "date") {
|
|
2690
|
+
errorMessage = msgPrefix + "the argument to least must be a date";
|
|
2691
|
+
} else if (!isNumeric(n) && (doLength || isNumeric(obj))) {
|
|
2692
|
+
errorMessage = msgPrefix + "the argument to least must be a number";
|
|
2693
|
+
} else if (!doLength && objType !== "date" && !isNumeric(obj)) {
|
|
2694
|
+
let printObj = objType === "string" ? "'" + obj + "'" : obj;
|
|
2695
|
+
errorMessage = msgPrefix + "expected " + printObj + " to be a number or a date";
|
|
2696
|
+
} else {
|
|
2697
|
+
shouldThrow = false;
|
|
2698
|
+
}
|
|
2699
|
+
if (shouldThrow) {
|
|
2700
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
2701
|
+
}
|
|
2702
|
+
if (doLength) {
|
|
2703
|
+
let descriptor = "length", itemsCount;
|
|
2704
|
+
if (objType === "map" || objType === "set") {
|
|
2705
|
+
descriptor = "size";
|
|
2706
|
+
itemsCount = obj.size;
|
|
2707
|
+
} else {
|
|
2708
|
+
itemsCount = obj.length;
|
|
2709
|
+
}
|
|
2710
|
+
this.assert(itemsCount >= n, "expected #{this} to have a " + descriptor + " at least #{exp} but got #{act}", "expected #{this} to have a " + descriptor + " below #{exp}", n, itemsCount);
|
|
2711
|
+
} else {
|
|
2712
|
+
this.assert(obj >= n, "expected #{this} to be at least #{exp}", "expected #{this} to be below #{exp}", n);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
__name(assertLeast, "assertLeast");
|
|
2716
|
+
Assertion.addMethod("least", assertLeast);
|
|
2717
|
+
Assertion.addMethod("gte", assertLeast);
|
|
2718
|
+
Assertion.addMethod("greaterThanOrEqual", assertLeast);
|
|
2719
|
+
function assertBelow(n, msg) {
|
|
2720
|
+
if (msg) flag2(this, "message", msg);
|
|
2721
|
+
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase(), errorMessage, shouldThrow = true;
|
|
2722
|
+
if (doLength && objType !== "map" && objType !== "set") {
|
|
2723
|
+
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
2724
|
+
}
|
|
2725
|
+
if (!doLength && objType === "date" && nType !== "date") {
|
|
2726
|
+
errorMessage = msgPrefix + "the argument to below must be a date";
|
|
2727
|
+
} else if (!isNumeric(n) && (doLength || isNumeric(obj))) {
|
|
2728
|
+
errorMessage = msgPrefix + "the argument to below must be a number";
|
|
2729
|
+
} else if (!doLength && objType !== "date" && !isNumeric(obj)) {
|
|
2730
|
+
let printObj = objType === "string" ? "'" + obj + "'" : obj;
|
|
2731
|
+
errorMessage = msgPrefix + "expected " + printObj + " to be a number or a date";
|
|
2732
|
+
} else {
|
|
2733
|
+
shouldThrow = false;
|
|
2734
|
+
}
|
|
2735
|
+
if (shouldThrow) {
|
|
2736
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
2737
|
+
}
|
|
2738
|
+
if (doLength) {
|
|
2739
|
+
let descriptor = "length", itemsCount;
|
|
2740
|
+
if (objType === "map" || objType === "set") {
|
|
2741
|
+
descriptor = "size";
|
|
2742
|
+
itemsCount = obj.size;
|
|
2743
|
+
} else {
|
|
2744
|
+
itemsCount = obj.length;
|
|
2745
|
+
}
|
|
2746
|
+
this.assert(itemsCount < n, "expected #{this} to have a " + descriptor + " below #{exp} but got #{act}", "expected #{this} to not have a " + descriptor + " below #{exp}", n, itemsCount);
|
|
2747
|
+
} else {
|
|
2748
|
+
this.assert(obj < n, "expected #{this} to be below #{exp}", "expected #{this} to be at least #{exp}", n);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
__name(assertBelow, "assertBelow");
|
|
2752
|
+
Assertion.addMethod("below", assertBelow);
|
|
2753
|
+
Assertion.addMethod("lt", assertBelow);
|
|
2754
|
+
Assertion.addMethod("lessThan", assertBelow);
|
|
2755
|
+
function assertMost(n, msg) {
|
|
2756
|
+
if (msg) flag2(this, "message", msg);
|
|
2757
|
+
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase(), errorMessage, shouldThrow = true;
|
|
2758
|
+
if (doLength && objType !== "map" && objType !== "set") {
|
|
2759
|
+
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
2760
|
+
}
|
|
2761
|
+
if (!doLength && objType === "date" && nType !== "date") {
|
|
2762
|
+
errorMessage = msgPrefix + "the argument to most must be a date";
|
|
2763
|
+
} else if (!isNumeric(n) && (doLength || isNumeric(obj))) {
|
|
2764
|
+
errorMessage = msgPrefix + "the argument to most must be a number";
|
|
2765
|
+
} else if (!doLength && objType !== "date" && !isNumeric(obj)) {
|
|
2766
|
+
let printObj = objType === "string" ? "'" + obj + "'" : obj;
|
|
2767
|
+
errorMessage = msgPrefix + "expected " + printObj + " to be a number or a date";
|
|
2768
|
+
} else {
|
|
2769
|
+
shouldThrow = false;
|
|
2770
|
+
}
|
|
2771
|
+
if (shouldThrow) {
|
|
2772
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
2773
|
+
}
|
|
2774
|
+
if (doLength) {
|
|
2775
|
+
let descriptor = "length", itemsCount;
|
|
2776
|
+
if (objType === "map" || objType === "set") {
|
|
2777
|
+
descriptor = "size";
|
|
2778
|
+
itemsCount = obj.size;
|
|
2779
|
+
} else {
|
|
2780
|
+
itemsCount = obj.length;
|
|
2781
|
+
}
|
|
2782
|
+
this.assert(itemsCount <= n, "expected #{this} to have a " + descriptor + " at most #{exp} but got #{act}", "expected #{this} to have a " + descriptor + " above #{exp}", n, itemsCount);
|
|
2783
|
+
} else {
|
|
2784
|
+
this.assert(obj <= n, "expected #{this} to be at most #{exp}", "expected #{this} to be above #{exp}", n);
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
__name(assertMost, "assertMost");
|
|
2788
|
+
Assertion.addMethod("most", assertMost);
|
|
2789
|
+
Assertion.addMethod("lte", assertMost);
|
|
2790
|
+
Assertion.addMethod("lessThanOrEqual", assertMost);
|
|
2791
|
+
Assertion.addMethod("within", function(start, finish, msg) {
|
|
2792
|
+
if (msg) flag2(this, "message", msg);
|
|
2793
|
+
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), startType = type(start).toLowerCase(), finishType = type(finish).toLowerCase(), errorMessage, shouldThrow = true, range = startType === "date" && finishType === "date" ? start.toISOString() + ".." + finish.toISOString() : start + ".." + finish;
|
|
2794
|
+
if (doLength && objType !== "map" && objType !== "set") {
|
|
2795
|
+
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
2796
|
+
}
|
|
2797
|
+
if (!doLength && objType === "date" && (startType !== "date" || finishType !== "date")) {
|
|
2798
|
+
errorMessage = msgPrefix + "the arguments to within must be dates";
|
|
2799
|
+
} else if ((!isNumeric(start) || !isNumeric(finish)) && (doLength || isNumeric(obj))) {
|
|
2800
|
+
errorMessage = msgPrefix + "the arguments to within must be numbers";
|
|
2801
|
+
} else if (!doLength && objType !== "date" && !isNumeric(obj)) {
|
|
2802
|
+
let printObj = objType === "string" ? "'" + obj + "'" : obj;
|
|
2803
|
+
errorMessage = msgPrefix + "expected " + printObj + " to be a number or a date";
|
|
2804
|
+
} else {
|
|
2805
|
+
shouldThrow = false;
|
|
2806
|
+
}
|
|
2807
|
+
if (shouldThrow) {
|
|
2808
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
2809
|
+
}
|
|
2810
|
+
if (doLength) {
|
|
2811
|
+
let descriptor = "length", itemsCount;
|
|
2812
|
+
if (objType === "map" || objType === "set") {
|
|
2813
|
+
descriptor = "size";
|
|
2814
|
+
itemsCount = obj.size;
|
|
2815
|
+
} else {
|
|
2816
|
+
itemsCount = obj.length;
|
|
2817
|
+
}
|
|
2818
|
+
this.assert(itemsCount >= start && itemsCount <= finish, "expected #{this} to have a " + descriptor + " within " + range, "expected #{this} to not have a " + descriptor + " within " + range);
|
|
2819
|
+
} else {
|
|
2820
|
+
this.assert(obj >= start && obj <= finish, "expected #{this} to be within " + range, "expected #{this} to not be within " + range);
|
|
2821
|
+
}
|
|
2822
|
+
});
|
|
2823
|
+
function assertInstanceOf(constructor, msg) {
|
|
2824
|
+
if (msg) flag2(this, "message", msg);
|
|
2825
|
+
let target = flag2(this, "object");
|
|
2826
|
+
let ssfi = flag2(this, "ssfi");
|
|
2827
|
+
let flagMsg = flag2(this, "message");
|
|
2828
|
+
let isInstanceOf;
|
|
2829
|
+
try {
|
|
2830
|
+
isInstanceOf = target instanceof constructor;
|
|
2831
|
+
} catch (err) {
|
|
2832
|
+
if (err instanceof TypeError) {
|
|
2833
|
+
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
2834
|
+
throw new AssertionError(flagMsg + "The instanceof assertion needs a constructor but " + type(constructor) + " was given.", void 0, ssfi);
|
|
2835
|
+
}
|
|
2836
|
+
throw err;
|
|
2837
|
+
}
|
|
2838
|
+
let name = getName(constructor);
|
|
2839
|
+
if (name == null) {
|
|
2840
|
+
name = "an unnamed constructor";
|
|
2841
|
+
}
|
|
2842
|
+
this.assert(isInstanceOf, "expected #{this} to be an instance of " + name, "expected #{this} to not be an instance of " + name);
|
|
2843
|
+
}
|
|
2844
|
+
__name(assertInstanceOf, "assertInstanceOf");
|
|
2845
|
+
Assertion.addMethod("instanceof", assertInstanceOf);
|
|
2846
|
+
Assertion.addMethod("instanceOf", assertInstanceOf);
|
|
2847
|
+
function assertProperty(name, val, msg) {
|
|
2848
|
+
if (msg) flag2(this, "message", msg);
|
|
2849
|
+
let isNested = flag2(this, "nested"), isOwn = flag2(this, "own"), flagMsg = flag2(this, "message"), obj = flag2(this, "object"), ssfi = flag2(this, "ssfi"), nameType = typeof name;
|
|
2850
|
+
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
2851
|
+
if (isNested) {
|
|
2852
|
+
if (nameType !== "string") {
|
|
2853
|
+
throw new AssertionError(flagMsg + "the argument to property must be a string when using nested syntax", void 0, ssfi);
|
|
2854
|
+
}
|
|
2855
|
+
} else {
|
|
2856
|
+
if (nameType !== "string" && nameType !== "number" && nameType !== "symbol") {
|
|
2857
|
+
throw new AssertionError(flagMsg + "the argument to property must be a string, number, or symbol", void 0, ssfi);
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
if (isNested && isOwn) {
|
|
2861
|
+
throw new AssertionError(flagMsg + 'The "nested" and "own" flags cannot be combined.', void 0, ssfi);
|
|
2862
|
+
}
|
|
2863
|
+
if (obj === null || obj === void 0) {
|
|
2864
|
+
throw new AssertionError(flagMsg + "Target cannot be null or undefined.", void 0, ssfi);
|
|
2865
|
+
}
|
|
2866
|
+
let isDeep = flag2(this, "deep"), negate = flag2(this, "negate"), pathInfo = isNested ? getPathInfo(obj, name) : null, value = isNested ? pathInfo.value : obj[name], isEql = isDeep ? flag2(this, "eql") : (val1, val2)=>val1 === val2;
|
|
2867
|
+
let descriptor = "";
|
|
2868
|
+
if (isDeep) descriptor += "deep ";
|
|
2869
|
+
if (isOwn) descriptor += "own ";
|
|
2870
|
+
if (isNested) descriptor += "nested ";
|
|
2871
|
+
descriptor += "property ";
|
|
2872
|
+
let hasProperty2;
|
|
2873
|
+
if (isOwn) hasProperty2 = Object.prototype.hasOwnProperty.call(obj, name);
|
|
2874
|
+
else if (isNested) hasProperty2 = pathInfo.exists;
|
|
2875
|
+
else hasProperty2 = hasProperty(obj, name);
|
|
2876
|
+
if (!negate || arguments.length === 1) {
|
|
2877
|
+
this.assert(hasProperty2, "expected #{this} to have " + descriptor + inspect2(name), "expected #{this} to not have " + descriptor + inspect2(name));
|
|
2878
|
+
}
|
|
2879
|
+
if (arguments.length > 1) {
|
|
2880
|
+
this.assert(hasProperty2 && isEql(val, value), "expected #{this} to have " + descriptor + inspect2(name) + " of #{exp}, but got #{act}", "expected #{this} to not have " + descriptor + inspect2(name) + " of #{act}", val, value);
|
|
2881
|
+
}
|
|
2882
|
+
flag2(this, "object", value);
|
|
2883
|
+
}
|
|
2884
|
+
__name(assertProperty, "assertProperty");
|
|
2885
|
+
Assertion.addMethod("property", assertProperty);
|
|
2886
|
+
function assertOwnProperty(_name, _value, _msg) {
|
|
2887
|
+
flag2(this, "own", true);
|
|
2888
|
+
assertProperty.apply(this, arguments);
|
|
2889
|
+
}
|
|
2890
|
+
__name(assertOwnProperty, "assertOwnProperty");
|
|
2891
|
+
Assertion.addMethod("ownProperty", assertOwnProperty);
|
|
2892
|
+
Assertion.addMethod("haveOwnProperty", assertOwnProperty);
|
|
2893
|
+
function assertOwnPropertyDescriptor(name, descriptor, msg) {
|
|
2894
|
+
if (typeof descriptor === "string") {
|
|
2895
|
+
msg = descriptor;
|
|
2896
|
+
descriptor = null;
|
|
2897
|
+
}
|
|
2898
|
+
if (msg) flag2(this, "message", msg);
|
|
2899
|
+
let obj = flag2(this, "object");
|
|
2900
|
+
let actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
|
|
2901
|
+
let eql = flag2(this, "eql");
|
|
2902
|
+
if (actualDescriptor && descriptor) {
|
|
2903
|
+
this.assert(eql(descriptor, actualDescriptor), "expected the own property descriptor for " + inspect2(name) + " on #{this} to match " + inspect2(descriptor) + ", got " + inspect2(actualDescriptor), "expected the own property descriptor for " + inspect2(name) + " on #{this} to not match " + inspect2(descriptor), descriptor, actualDescriptor, true);
|
|
2904
|
+
} else {
|
|
2905
|
+
this.assert(actualDescriptor, "expected #{this} to have an own property descriptor for " + inspect2(name), "expected #{this} to not have an own property descriptor for " + inspect2(name));
|
|
2906
|
+
}
|
|
2907
|
+
flag2(this, "object", actualDescriptor);
|
|
2908
|
+
}
|
|
2909
|
+
__name(assertOwnPropertyDescriptor, "assertOwnPropertyDescriptor");
|
|
2910
|
+
Assertion.addMethod("ownPropertyDescriptor", assertOwnPropertyDescriptor);
|
|
2911
|
+
Assertion.addMethod("haveOwnPropertyDescriptor", assertOwnPropertyDescriptor);
|
|
2912
|
+
function assertLengthChain() {
|
|
2913
|
+
flag2(this, "doLength", true);
|
|
2914
|
+
}
|
|
2915
|
+
__name(assertLengthChain, "assertLengthChain");
|
|
2916
|
+
function assertLength(n, msg) {
|
|
2917
|
+
if (msg) flag2(this, "message", msg);
|
|
2918
|
+
let obj = flag2(this, "object"), objType = type(obj).toLowerCase(), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi"), descriptor = "length", itemsCount;
|
|
2919
|
+
switch(objType){
|
|
2920
|
+
case "map":
|
|
2921
|
+
case "set":
|
|
2922
|
+
descriptor = "size";
|
|
2923
|
+
itemsCount = obj.size;
|
|
2924
|
+
break;
|
|
2925
|
+
default:
|
|
2926
|
+
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
2927
|
+
itemsCount = obj.length;
|
|
2928
|
+
}
|
|
2929
|
+
this.assert(itemsCount == n, "expected #{this} to have a " + descriptor + " of #{exp} but got #{act}", "expected #{this} to not have a " + descriptor + " of #{act}", n, itemsCount);
|
|
2930
|
+
}
|
|
2931
|
+
__name(assertLength, "assertLength");
|
|
2932
|
+
Assertion.addChainableMethod("length", assertLength, assertLengthChain);
|
|
2933
|
+
Assertion.addChainableMethod("lengthOf", assertLength, assertLengthChain);
|
|
2934
|
+
function assertMatch(re, msg) {
|
|
2935
|
+
if (msg) flag2(this, "message", msg);
|
|
2936
|
+
let obj = flag2(this, "object");
|
|
2937
|
+
this.assert(re.exec(obj), "expected #{this} to match " + re, "expected #{this} not to match " + re);
|
|
2938
|
+
}
|
|
2939
|
+
__name(assertMatch, "assertMatch");
|
|
2940
|
+
Assertion.addMethod("match", assertMatch);
|
|
2941
|
+
Assertion.addMethod("matches", assertMatch);
|
|
2942
|
+
Assertion.addMethod("string", function(str, msg) {
|
|
2943
|
+
if (msg) flag2(this, "message", msg);
|
|
2944
|
+
let obj = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2945
|
+
new Assertion(obj, flagMsg, ssfi, true).is.a("string");
|
|
2946
|
+
this.assert(~obj.indexOf(str), "expected #{this} to contain " + inspect2(str), "expected #{this} to not contain " + inspect2(str));
|
|
2947
|
+
});
|
|
2948
|
+
function assertKeys(keys) {
|
|
2949
|
+
let obj = flag2(this, "object"), objType = type(obj), keysType = type(keys), ssfi = flag2(this, "ssfi"), isDeep = flag2(this, "deep"), str, deepStr = "", actual, ok = true, flagMsg = flag2(this, "message");
|
|
2950
|
+
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
2951
|
+
let mixedArgsMsg = flagMsg + "when testing keys against an object or an array you must give a single Array|Object|String argument or multiple String arguments";
|
|
2952
|
+
if (objType === "Map" || objType === "Set") {
|
|
2953
|
+
deepStr = isDeep ? "deeply " : "";
|
|
2954
|
+
actual = [];
|
|
2955
|
+
obj.forEach(function(val, key) {
|
|
2956
|
+
actual.push(key);
|
|
2957
|
+
});
|
|
2958
|
+
if (keysType !== "Array") {
|
|
2959
|
+
keys = Array.prototype.slice.call(arguments);
|
|
2960
|
+
}
|
|
2961
|
+
} else {
|
|
2962
|
+
actual = getOwnEnumerableProperties(obj);
|
|
2963
|
+
switch(keysType){
|
|
2964
|
+
case "Array":
|
|
2965
|
+
if (arguments.length > 1) {
|
|
2966
|
+
throw new AssertionError(mixedArgsMsg, void 0, ssfi);
|
|
2967
|
+
}
|
|
2968
|
+
break;
|
|
2969
|
+
case "Object":
|
|
2970
|
+
if (arguments.length > 1) {
|
|
2971
|
+
throw new AssertionError(mixedArgsMsg, void 0, ssfi);
|
|
2972
|
+
}
|
|
2973
|
+
keys = Object.keys(keys);
|
|
2974
|
+
break;
|
|
2975
|
+
default:
|
|
2976
|
+
keys = Array.prototype.slice.call(arguments);
|
|
2977
|
+
}
|
|
2978
|
+
keys = keys.map(function(val) {
|
|
2979
|
+
return typeof val === "symbol" ? val : String(val);
|
|
2980
|
+
});
|
|
2981
|
+
}
|
|
2982
|
+
if (!keys.length) {
|
|
2983
|
+
throw new AssertionError(flagMsg + "keys required", void 0, ssfi);
|
|
2984
|
+
}
|
|
2985
|
+
let len = keys.length, any = flag2(this, "any"), all = flag2(this, "all"), expected = keys, isEql = isDeep ? flag2(this, "eql") : (val1, val2)=>val1 === val2;
|
|
2986
|
+
if (!any && !all) {
|
|
2987
|
+
all = true;
|
|
2988
|
+
}
|
|
2989
|
+
if (any) {
|
|
2990
|
+
ok = expected.some(function(expectedKey) {
|
|
2991
|
+
return actual.some(function(actualKey) {
|
|
2992
|
+
return isEql(expectedKey, actualKey);
|
|
2993
|
+
});
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
if (all) {
|
|
2997
|
+
ok = expected.every(function(expectedKey) {
|
|
2998
|
+
return actual.some(function(actualKey) {
|
|
2999
|
+
return isEql(expectedKey, actualKey);
|
|
3000
|
+
});
|
|
3001
|
+
});
|
|
3002
|
+
if (!flag2(this, "contains")) {
|
|
3003
|
+
ok = ok && keys.length == actual.length;
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
if (len > 1) {
|
|
3007
|
+
keys = keys.map(function(key) {
|
|
3008
|
+
return inspect2(key);
|
|
3009
|
+
});
|
|
3010
|
+
let last = keys.pop();
|
|
3011
|
+
if (all) {
|
|
3012
|
+
str = keys.join(", ") + ", and " + last;
|
|
3013
|
+
}
|
|
3014
|
+
if (any) {
|
|
3015
|
+
str = keys.join(", ") + ", or " + last;
|
|
3016
|
+
}
|
|
3017
|
+
} else {
|
|
3018
|
+
str = inspect2(keys[0]);
|
|
3019
|
+
}
|
|
3020
|
+
str = (len > 1 ? "keys " : "key ") + str;
|
|
3021
|
+
str = (flag2(this, "contains") ? "contain " : "have ") + str;
|
|
3022
|
+
this.assert(ok, "expected #{this} to " + deepStr + str, "expected #{this} to not " + deepStr + str, expected.slice(0).sort(compareByInspect), actual.sort(compareByInspect), true);
|
|
3023
|
+
}
|
|
3024
|
+
__name(assertKeys, "assertKeys");
|
|
3025
|
+
Assertion.addMethod("keys", assertKeys);
|
|
3026
|
+
Assertion.addMethod("key", assertKeys);
|
|
3027
|
+
function assertThrows(errorLike, errMsgMatcher, msg) {
|
|
3028
|
+
if (msg) flag2(this, "message", msg);
|
|
3029
|
+
let obj = flag2(this, "object"), ssfi = flag2(this, "ssfi"), flagMsg = flag2(this, "message"), negate = flag2(this, "negate") || false;
|
|
3030
|
+
new Assertion(obj, flagMsg, ssfi, true).is.a("function");
|
|
3031
|
+
if (isRegExp2(errorLike) || typeof errorLike === "string") {
|
|
3032
|
+
errMsgMatcher = errorLike;
|
|
3033
|
+
errorLike = null;
|
|
3034
|
+
}
|
|
3035
|
+
let caughtErr;
|
|
3036
|
+
let errorWasThrown = false;
|
|
3037
|
+
try {
|
|
3038
|
+
obj();
|
|
3039
|
+
} catch (err) {
|
|
3040
|
+
errorWasThrown = true;
|
|
3041
|
+
caughtErr = err;
|
|
3042
|
+
}
|
|
3043
|
+
let everyArgIsUndefined = errorLike === void 0 && errMsgMatcher === void 0;
|
|
3044
|
+
let everyArgIsDefined = Boolean(errorLike && errMsgMatcher);
|
|
3045
|
+
let errorLikeFail = false;
|
|
3046
|
+
let errMsgMatcherFail = false;
|
|
3047
|
+
if (everyArgIsUndefined || !everyArgIsUndefined && !negate) {
|
|
3048
|
+
let errorLikeString = "an error";
|
|
3049
|
+
if (errorLike instanceof Error) {
|
|
3050
|
+
errorLikeString = "#{exp}";
|
|
3051
|
+
} else if (errorLike) {
|
|
3052
|
+
errorLikeString = check_error_exports.getConstructorName(errorLike);
|
|
3053
|
+
}
|
|
3054
|
+
let actual = caughtErr;
|
|
3055
|
+
if (caughtErr instanceof Error) {
|
|
3056
|
+
actual = caughtErr.toString();
|
|
3057
|
+
} else if (typeof caughtErr === "string") {
|
|
3058
|
+
actual = caughtErr;
|
|
3059
|
+
} else if (caughtErr && (typeof caughtErr === "object" || typeof caughtErr === "function")) {
|
|
3060
|
+
try {
|
|
3061
|
+
actual = check_error_exports.getConstructorName(caughtErr);
|
|
3062
|
+
} catch (_err) {}
|
|
3063
|
+
}
|
|
3064
|
+
this.assert(errorWasThrown, "expected #{this} to throw " + errorLikeString, "expected #{this} to not throw an error but #{act} was thrown", errorLike && errorLike.toString(), actual);
|
|
3065
|
+
}
|
|
3066
|
+
if (errorLike && caughtErr) {
|
|
3067
|
+
if (errorLike instanceof Error) {
|
|
3068
|
+
let isCompatibleInstance = check_error_exports.compatibleInstance(caughtErr, errorLike);
|
|
3069
|
+
if (isCompatibleInstance === negate) {
|
|
3070
|
+
if (everyArgIsDefined && negate) {
|
|
3071
|
+
errorLikeFail = true;
|
|
3072
|
+
} else {
|
|
3073
|
+
this.assert(negate, "expected #{this} to throw #{exp} but #{act} was thrown", "expected #{this} to not throw #{exp}" + (caughtErr && !negate ? " but #{act} was thrown" : ""), errorLike.toString(), caughtErr.toString());
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
let isCompatibleConstructor = check_error_exports.compatibleConstructor(caughtErr, errorLike);
|
|
3078
|
+
if (isCompatibleConstructor === negate) {
|
|
3079
|
+
if (everyArgIsDefined && negate) {
|
|
3080
|
+
errorLikeFail = true;
|
|
3081
|
+
} else {
|
|
3082
|
+
this.assert(negate, "expected #{this} to throw #{exp} but #{act} was thrown", "expected #{this} to not throw #{exp}" + (caughtErr ? " but #{act} was thrown" : ""), errorLike instanceof Error ? errorLike.toString() : errorLike && check_error_exports.getConstructorName(errorLike), caughtErr instanceof Error ? caughtErr.toString() : caughtErr && check_error_exports.getConstructorName(caughtErr));
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
if (caughtErr && errMsgMatcher !== void 0 && errMsgMatcher !== null) {
|
|
3087
|
+
let placeholder = "including";
|
|
3088
|
+
if (isRegExp2(errMsgMatcher)) {
|
|
3089
|
+
placeholder = "matching";
|
|
3090
|
+
}
|
|
3091
|
+
let isCompatibleMessage = check_error_exports.compatibleMessage(caughtErr, errMsgMatcher);
|
|
3092
|
+
if (isCompatibleMessage === negate) {
|
|
3093
|
+
if (everyArgIsDefined && negate) {
|
|
3094
|
+
errMsgMatcherFail = true;
|
|
3095
|
+
} else {
|
|
3096
|
+
this.assert(negate, "expected #{this} to throw error " + placeholder + " #{exp} but got #{act}", "expected #{this} to throw error not " + placeholder + " #{exp}", errMsgMatcher, check_error_exports.getMessage(caughtErr));
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
if (errorLikeFail && errMsgMatcherFail) {
|
|
3101
|
+
this.assert(negate, "expected #{this} to throw #{exp} but #{act} was thrown", "expected #{this} to not throw #{exp}" + (caughtErr ? " but #{act} was thrown" : ""), errorLike instanceof Error ? errorLike.toString() : errorLike && check_error_exports.getConstructorName(errorLike), caughtErr instanceof Error ? caughtErr.toString() : caughtErr && check_error_exports.getConstructorName(caughtErr));
|
|
3102
|
+
}
|
|
3103
|
+
flag2(this, "object", caughtErr);
|
|
3104
|
+
}
|
|
3105
|
+
__name(assertThrows, "assertThrows");
|
|
3106
|
+
Assertion.addMethod("throw", assertThrows);
|
|
3107
|
+
Assertion.addMethod("throws", assertThrows);
|
|
3108
|
+
Assertion.addMethod("Throw", assertThrows);
|
|
3109
|
+
function respondTo(method, msg) {
|
|
3110
|
+
if (msg) flag2(this, "message", msg);
|
|
3111
|
+
let obj = flag2(this, "object"), itself = flag2(this, "itself"), context = "function" === typeof obj && !itself ? obj.prototype[method] : obj[method];
|
|
3112
|
+
this.assert("function" === typeof context, "expected #{this} to respond to " + inspect2(method), "expected #{this} to not respond to " + inspect2(method));
|
|
3113
|
+
}
|
|
3114
|
+
__name(respondTo, "respondTo");
|
|
3115
|
+
Assertion.addMethod("respondTo", respondTo);
|
|
3116
|
+
Assertion.addMethod("respondsTo", respondTo);
|
|
3117
|
+
Assertion.addProperty("itself", function() {
|
|
3118
|
+
flag2(this, "itself", true);
|
|
3119
|
+
});
|
|
3120
|
+
function satisfy(matcher, msg) {
|
|
3121
|
+
if (msg) flag2(this, "message", msg);
|
|
3122
|
+
let obj = flag2(this, "object");
|
|
3123
|
+
let result = matcher(obj);
|
|
3124
|
+
this.assert(result, "expected #{this} to satisfy " + objDisplay(matcher), "expected #{this} to not satisfy" + objDisplay(matcher), flag2(this, "negate") ? false : true, result);
|
|
3125
|
+
}
|
|
3126
|
+
__name(satisfy, "satisfy");
|
|
3127
|
+
Assertion.addMethod("satisfy", satisfy);
|
|
3128
|
+
Assertion.addMethod("satisfies", satisfy);
|
|
3129
|
+
function closeTo(expected, delta, msg) {
|
|
3130
|
+
if (msg) flag2(this, "message", msg);
|
|
3131
|
+
let obj = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
3132
|
+
new Assertion(obj, flagMsg, ssfi, true).is.numeric;
|
|
3133
|
+
let message = "A `delta` value is required for `closeTo`";
|
|
3134
|
+
if (delta == void 0) {
|
|
3135
|
+
throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, void 0, ssfi);
|
|
3136
|
+
}
|
|
3137
|
+
new Assertion(delta, flagMsg, ssfi, true).is.numeric;
|
|
3138
|
+
message = "A `expected` value is required for `closeTo`";
|
|
3139
|
+
if (expected == void 0) {
|
|
3140
|
+
throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, void 0, ssfi);
|
|
3141
|
+
}
|
|
3142
|
+
new Assertion(expected, flagMsg, ssfi, true).is.numeric;
|
|
3143
|
+
const abs = __name((x)=>x < 0n ? -x : x, "abs");
|
|
3144
|
+
const strip = __name((number)=>parseFloat(parseFloat(number).toPrecision(12)), "strip");
|
|
3145
|
+
this.assert(strip(abs(obj - expected)) <= delta, "expected #{this} to be close to " + expected + " +/- " + delta, "expected #{this} not to be close to " + expected + " +/- " + delta);
|
|
3146
|
+
}
|
|
3147
|
+
__name(closeTo, "closeTo");
|
|
3148
|
+
Assertion.addMethod("closeTo", closeTo);
|
|
3149
|
+
Assertion.addMethod("approximately", closeTo);
|
|
3150
|
+
function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
|
|
3151
|
+
let superset = Array.from(_superset);
|
|
3152
|
+
let subset = Array.from(_subset);
|
|
3153
|
+
if (!contains) {
|
|
3154
|
+
if (subset.length !== superset.length) return false;
|
|
3155
|
+
superset = superset.slice();
|
|
3156
|
+
}
|
|
3157
|
+
return subset.every(function(elem, idx) {
|
|
3158
|
+
if (ordered) return cmp ? cmp(elem, superset[idx]) : elem === superset[idx];
|
|
3159
|
+
if (!cmp) {
|
|
3160
|
+
let matchIdx = superset.indexOf(elem);
|
|
3161
|
+
if (matchIdx === -1) return false;
|
|
3162
|
+
if (!contains) superset.splice(matchIdx, 1);
|
|
3163
|
+
return true;
|
|
3164
|
+
}
|
|
3165
|
+
return superset.some(function(elem2, matchIdx) {
|
|
3166
|
+
if (!cmp(elem, elem2)) return false;
|
|
3167
|
+
if (!contains) superset.splice(matchIdx, 1);
|
|
3168
|
+
return true;
|
|
3169
|
+
});
|
|
3170
|
+
});
|
|
3171
|
+
}
|
|
3172
|
+
__name(isSubsetOf, "isSubsetOf");
|
|
3173
|
+
Assertion.addMethod("members", function(subset, msg) {
|
|
3174
|
+
if (msg) flag2(this, "message", msg);
|
|
3175
|
+
let obj = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
3176
|
+
new Assertion(obj, flagMsg, ssfi, true).to.be.iterable;
|
|
3177
|
+
new Assertion(subset, flagMsg, ssfi, true).to.be.iterable;
|
|
3178
|
+
let contains = flag2(this, "contains");
|
|
3179
|
+
let ordered = flag2(this, "ordered");
|
|
3180
|
+
let subject, failMsg, failNegateMsg;
|
|
3181
|
+
if (contains) {
|
|
3182
|
+
subject = ordered ? "an ordered superset" : "a superset";
|
|
3183
|
+
failMsg = "expected #{this} to be " + subject + " of #{exp}";
|
|
3184
|
+
failNegateMsg = "expected #{this} to not be " + subject + " of #{exp}";
|
|
3185
|
+
} else {
|
|
3186
|
+
subject = ordered ? "ordered members" : "members";
|
|
3187
|
+
failMsg = "expected #{this} to have the same " + subject + " as #{exp}";
|
|
3188
|
+
failNegateMsg = "expected #{this} to not have the same " + subject + " as #{exp}";
|
|
3189
|
+
}
|
|
3190
|
+
let cmp = flag2(this, "deep") ? flag2(this, "eql") : void 0;
|
|
3191
|
+
this.assert(isSubsetOf(subset, obj, cmp, contains, ordered), failMsg, failNegateMsg, subset, obj, true);
|
|
3192
|
+
});
|
|
3193
|
+
Assertion.addProperty("iterable", function(msg) {
|
|
3194
|
+
if (msg) flag2(this, "message", msg);
|
|
3195
|
+
let obj = flag2(this, "object");
|
|
3196
|
+
this.assert(obj != void 0 && obj[Symbol.iterator], "expected #{this} to be an iterable", "expected #{this} to not be an iterable", obj);
|
|
3197
|
+
});
|
|
3198
|
+
function oneOf(list, msg) {
|
|
3199
|
+
if (msg) flag2(this, "message", msg);
|
|
3200
|
+
let expected = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi"), contains = flag2(this, "contains"), isDeep = flag2(this, "deep"), eql = flag2(this, "eql");
|
|
3201
|
+
new Assertion(list, flagMsg, ssfi, true).to.be.an("array");
|
|
3202
|
+
if (contains) {
|
|
3203
|
+
this.assert(list.some(function(possibility) {
|
|
3204
|
+
return expected.indexOf(possibility) > -1;
|
|
3205
|
+
}), "expected #{this} to contain one of #{exp}", "expected #{this} to not contain one of #{exp}", list, expected);
|
|
3206
|
+
} else {
|
|
3207
|
+
if (isDeep) {
|
|
3208
|
+
this.assert(list.some(function(possibility) {
|
|
3209
|
+
return eql(expected, possibility);
|
|
3210
|
+
}), "expected #{this} to deeply equal one of #{exp}", "expected #{this} to deeply equal one of #{exp}", list, expected);
|
|
3211
|
+
} else {
|
|
3212
|
+
this.assert(list.indexOf(expected) > -1, "expected #{this} to be one of #{exp}", "expected #{this} to not be one of #{exp}", list, expected);
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
__name(oneOf, "oneOf");
|
|
3217
|
+
Assertion.addMethod("oneOf", oneOf);
|
|
3218
|
+
function assertChanges(subject, prop, msg) {
|
|
3219
|
+
if (msg) flag2(this, "message", msg);
|
|
3220
|
+
let fn = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
3221
|
+
new Assertion(fn, flagMsg, ssfi, true).is.a("function");
|
|
3222
|
+
let initial;
|
|
3223
|
+
if (!prop) {
|
|
3224
|
+
new Assertion(subject, flagMsg, ssfi, true).is.a("function");
|
|
3225
|
+
initial = subject();
|
|
3226
|
+
} else {
|
|
3227
|
+
new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
|
|
3228
|
+
initial = subject[prop];
|
|
3229
|
+
}
|
|
3230
|
+
fn();
|
|
3231
|
+
let final = prop === void 0 || prop === null ? subject() : subject[prop];
|
|
3232
|
+
let msgObj = prop === void 0 || prop === null ? initial : "." + prop;
|
|
3233
|
+
flag2(this, "deltaMsgObj", msgObj);
|
|
3234
|
+
flag2(this, "initialDeltaValue", initial);
|
|
3235
|
+
flag2(this, "finalDeltaValue", final);
|
|
3236
|
+
flag2(this, "deltaBehavior", "change");
|
|
3237
|
+
flag2(this, "realDelta", final !== initial);
|
|
3238
|
+
this.assert(initial !== final, "expected " + msgObj + " to change", "expected " + msgObj + " to not change");
|
|
3239
|
+
}
|
|
3240
|
+
__name(assertChanges, "assertChanges");
|
|
3241
|
+
Assertion.addMethod("change", assertChanges);
|
|
3242
|
+
Assertion.addMethod("changes", assertChanges);
|
|
3243
|
+
function assertIncreases(subject, prop, msg) {
|
|
3244
|
+
if (msg) flag2(this, "message", msg);
|
|
3245
|
+
let fn = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
3246
|
+
new Assertion(fn, flagMsg, ssfi, true).is.a("function");
|
|
3247
|
+
let initial;
|
|
3248
|
+
if (!prop) {
|
|
3249
|
+
new Assertion(subject, flagMsg, ssfi, true).is.a("function");
|
|
3250
|
+
initial = subject();
|
|
3251
|
+
} else {
|
|
3252
|
+
new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
|
|
3253
|
+
initial = subject[prop];
|
|
3254
|
+
}
|
|
3255
|
+
new Assertion(initial, flagMsg, ssfi, true).is.a("number");
|
|
3256
|
+
fn();
|
|
3257
|
+
let final = prop === void 0 || prop === null ? subject() : subject[prop];
|
|
3258
|
+
let msgObj = prop === void 0 || prop === null ? initial : "." + prop;
|
|
3259
|
+
flag2(this, "deltaMsgObj", msgObj);
|
|
3260
|
+
flag2(this, "initialDeltaValue", initial);
|
|
3261
|
+
flag2(this, "finalDeltaValue", final);
|
|
3262
|
+
flag2(this, "deltaBehavior", "increase");
|
|
3263
|
+
flag2(this, "realDelta", final - initial);
|
|
3264
|
+
this.assert(final - initial > 0, "expected " + msgObj + " to increase", "expected " + msgObj + " to not increase");
|
|
3265
|
+
}
|
|
3266
|
+
__name(assertIncreases, "assertIncreases");
|
|
3267
|
+
Assertion.addMethod("increase", assertIncreases);
|
|
3268
|
+
Assertion.addMethod("increases", assertIncreases);
|
|
3269
|
+
function assertDecreases(subject, prop, msg) {
|
|
3270
|
+
if (msg) flag2(this, "message", msg);
|
|
3271
|
+
let fn = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
3272
|
+
new Assertion(fn, flagMsg, ssfi, true).is.a("function");
|
|
3273
|
+
let initial;
|
|
3274
|
+
if (!prop) {
|
|
3275
|
+
new Assertion(subject, flagMsg, ssfi, true).is.a("function");
|
|
3276
|
+
initial = subject();
|
|
3277
|
+
} else {
|
|
3278
|
+
new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
|
|
3279
|
+
initial = subject[prop];
|
|
3280
|
+
}
|
|
3281
|
+
new Assertion(initial, flagMsg, ssfi, true).is.a("number");
|
|
3282
|
+
fn();
|
|
3283
|
+
let final = prop === void 0 || prop === null ? subject() : subject[prop];
|
|
3284
|
+
let msgObj = prop === void 0 || prop === null ? initial : "." + prop;
|
|
3285
|
+
flag2(this, "deltaMsgObj", msgObj);
|
|
3286
|
+
flag2(this, "initialDeltaValue", initial);
|
|
3287
|
+
flag2(this, "finalDeltaValue", final);
|
|
3288
|
+
flag2(this, "deltaBehavior", "decrease");
|
|
3289
|
+
flag2(this, "realDelta", initial - final);
|
|
3290
|
+
this.assert(final - initial < 0, "expected " + msgObj + " to decrease", "expected " + msgObj + " to not decrease");
|
|
3291
|
+
}
|
|
3292
|
+
__name(assertDecreases, "assertDecreases");
|
|
3293
|
+
Assertion.addMethod("decrease", assertDecreases);
|
|
3294
|
+
Assertion.addMethod("decreases", assertDecreases);
|
|
3295
|
+
function assertDelta(delta, msg) {
|
|
3296
|
+
if (msg) flag2(this, "message", msg);
|
|
3297
|
+
let msgObj = flag2(this, "deltaMsgObj");
|
|
3298
|
+
let initial = flag2(this, "initialDeltaValue");
|
|
3299
|
+
let final = flag2(this, "finalDeltaValue");
|
|
3300
|
+
let behavior = flag2(this, "deltaBehavior");
|
|
3301
|
+
let realDelta = flag2(this, "realDelta");
|
|
3302
|
+
let expression;
|
|
3303
|
+
if (behavior === "change") {
|
|
3304
|
+
expression = Math.abs(final - initial) === Math.abs(delta);
|
|
3305
|
+
} else {
|
|
3306
|
+
expression = realDelta === Math.abs(delta);
|
|
3307
|
+
}
|
|
3308
|
+
this.assert(expression, "expected " + msgObj + " to " + behavior + " by " + delta, "expected " + msgObj + " to not " + behavior + " by " + delta);
|
|
3309
|
+
}
|
|
3310
|
+
__name(assertDelta, "assertDelta");
|
|
3311
|
+
Assertion.addMethod("by", assertDelta);
|
|
3312
|
+
Assertion.addProperty("extensible", function() {
|
|
3313
|
+
let obj = flag2(this, "object");
|
|
3314
|
+
let isExtensible = obj === Object(obj) && Object.isExtensible(obj);
|
|
3315
|
+
this.assert(isExtensible, "expected #{this} to be extensible", "expected #{this} to not be extensible");
|
|
3316
|
+
});
|
|
3317
|
+
Assertion.addProperty("sealed", function() {
|
|
3318
|
+
let obj = flag2(this, "object");
|
|
3319
|
+
let isSealed = obj === Object(obj) ? Object.isSealed(obj) : true;
|
|
3320
|
+
this.assert(isSealed, "expected #{this} to be sealed", "expected #{this} to not be sealed");
|
|
3321
|
+
});
|
|
3322
|
+
Assertion.addProperty("frozen", function() {
|
|
3323
|
+
let obj = flag2(this, "object");
|
|
3324
|
+
let isFrozen = obj === Object(obj) ? Object.isFrozen(obj) : true;
|
|
3325
|
+
this.assert(isFrozen, "expected #{this} to be frozen", "expected #{this} to not be frozen");
|
|
3326
|
+
});
|
|
3327
|
+
Assertion.addProperty("finite", function(_msg) {
|
|
3328
|
+
let obj = flag2(this, "object");
|
|
3329
|
+
this.assert(typeof obj === "number" && isFinite(obj), "expected #{this} to be a finite number", "expected #{this} to not be a finite number");
|
|
3330
|
+
});
|
|
3331
|
+
function compareSubset(expected, actual) {
|
|
3332
|
+
if (expected === actual) {
|
|
3333
|
+
return true;
|
|
3334
|
+
}
|
|
3335
|
+
if (typeof actual !== typeof expected) {
|
|
3336
|
+
return false;
|
|
3337
|
+
}
|
|
3338
|
+
if (typeof expected !== "object" || expected === null) {
|
|
3339
|
+
return expected === actual;
|
|
3340
|
+
}
|
|
3341
|
+
if (!actual) {
|
|
3342
|
+
return false;
|
|
3343
|
+
}
|
|
3344
|
+
if (Array.isArray(expected)) {
|
|
3345
|
+
if (!Array.isArray(actual)) {
|
|
3346
|
+
return false;
|
|
3347
|
+
}
|
|
3348
|
+
return expected.every(function(exp) {
|
|
3349
|
+
return actual.some(function(act) {
|
|
3350
|
+
return compareSubset(exp, act);
|
|
3351
|
+
});
|
|
3352
|
+
});
|
|
3353
|
+
}
|
|
3354
|
+
if (expected instanceof Date) {
|
|
3355
|
+
if (actual instanceof Date) {
|
|
3356
|
+
return expected.getTime() === actual.getTime();
|
|
3357
|
+
} else {
|
|
3358
|
+
return false;
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
return Object.keys(expected).every(function(key) {
|
|
3362
|
+
let expectedValue = expected[key];
|
|
3363
|
+
let actualValue = actual[key];
|
|
3364
|
+
if (typeof expectedValue === "object" && expectedValue !== null && actualValue !== null) {
|
|
3365
|
+
return compareSubset(expectedValue, actualValue);
|
|
3366
|
+
}
|
|
3367
|
+
if (typeof expectedValue === "function") {
|
|
3368
|
+
return expectedValue(actualValue);
|
|
3369
|
+
}
|
|
3370
|
+
return actualValue === expectedValue;
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3373
|
+
__name(compareSubset, "compareSubset");
|
|
3374
|
+
Assertion.addMethod("containSubset", function(expected) {
|
|
3375
|
+
const actual = flag(this, "object");
|
|
3376
|
+
const showDiff = config.showDiff;
|
|
3377
|
+
this.assert(compareSubset(expected, actual), "expected #{act} to contain subset #{exp}", "expected #{act} to not contain subset #{exp}", expected, actual, showDiff);
|
|
3378
|
+
});
|
|
3379
|
+
function expect(val, message) {
|
|
3380
|
+
return new Assertion(val, message);
|
|
3381
|
+
}
|
|
3382
|
+
__name(expect, "expect");
|
|
3383
|
+
expect.fail = function(actual, expected, message, operator) {
|
|
3384
|
+
if (arguments.length < 2) {
|
|
3385
|
+
message = actual;
|
|
3386
|
+
actual = void 0;
|
|
3387
|
+
}
|
|
3388
|
+
message = message || "expect.fail()";
|
|
3389
|
+
throw new AssertionError(message, {
|
|
3390
|
+
actual,
|
|
3391
|
+
expected,
|
|
3392
|
+
operator
|
|
3393
|
+
}, expect.fail);
|
|
3394
|
+
};
|
|
3395
|
+
var should_exports = {};
|
|
3396
|
+
__export(should_exports, {
|
|
3397
|
+
Should: ()=>Should,
|
|
3398
|
+
should: ()=>should
|
|
3399
|
+
});
|
|
3400
|
+
function loadShould() {
|
|
3401
|
+
function shouldGetter() {
|
|
3402
|
+
if (this instanceof String || this instanceof Number || this instanceof Boolean || typeof Symbol === "function" && this instanceof Symbol || typeof BigInt === "function" && this instanceof BigInt) {
|
|
3403
|
+
return new Assertion(this.valueOf(), null, shouldGetter);
|
|
3404
|
+
}
|
|
3405
|
+
return new Assertion(this, null, shouldGetter);
|
|
3406
|
+
}
|
|
3407
|
+
__name(shouldGetter, "shouldGetter");
|
|
3408
|
+
function shouldSetter(value) {
|
|
3409
|
+
Object.defineProperty(this, "should", {
|
|
3410
|
+
value,
|
|
3411
|
+
enumerable: true,
|
|
3412
|
+
configurable: true,
|
|
3413
|
+
writable: true
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
__name(shouldSetter, "shouldSetter");
|
|
3417
|
+
Object.defineProperty(Object.prototype, "should", {
|
|
3418
|
+
set: shouldSetter,
|
|
3419
|
+
get: shouldGetter,
|
|
3420
|
+
configurable: true
|
|
3421
|
+
});
|
|
3422
|
+
let should2 = {};
|
|
3423
|
+
should2.fail = function(actual, expected, message, operator) {
|
|
3424
|
+
if (arguments.length < 2) {
|
|
3425
|
+
message = actual;
|
|
3426
|
+
actual = void 0;
|
|
3427
|
+
}
|
|
3428
|
+
message = message || "should.fail()";
|
|
3429
|
+
throw new AssertionError(message, {
|
|
3430
|
+
actual,
|
|
3431
|
+
expected,
|
|
3432
|
+
operator
|
|
3433
|
+
}, should2.fail);
|
|
3434
|
+
};
|
|
3435
|
+
should2.equal = function(actual, expected, message) {
|
|
3436
|
+
new Assertion(actual, message).to.equal(expected);
|
|
3437
|
+
};
|
|
3438
|
+
should2.Throw = function(fn, errt, errs, msg) {
|
|
3439
|
+
new Assertion(fn, msg).to.Throw(errt, errs);
|
|
3440
|
+
};
|
|
3441
|
+
should2.exist = function(val, msg) {
|
|
3442
|
+
new Assertion(val, msg).to.exist;
|
|
3443
|
+
};
|
|
3444
|
+
should2.not = {};
|
|
3445
|
+
should2.not.equal = function(actual, expected, msg) {
|
|
3446
|
+
new Assertion(actual, msg).to.not.equal(expected);
|
|
3447
|
+
};
|
|
3448
|
+
should2.not.Throw = function(fn, errt, errs, msg) {
|
|
3449
|
+
new Assertion(fn, msg).to.not.Throw(errt, errs);
|
|
3450
|
+
};
|
|
3451
|
+
should2.not.exist = function(val, msg) {
|
|
3452
|
+
new Assertion(val, msg).to.not.exist;
|
|
3453
|
+
};
|
|
3454
|
+
should2["throw"] = should2["Throw"];
|
|
3455
|
+
should2.not["throw"] = should2.not["Throw"];
|
|
3456
|
+
return should2;
|
|
3457
|
+
}
|
|
3458
|
+
__name(loadShould, "loadShould");
|
|
3459
|
+
var should = loadShould;
|
|
3460
|
+
var Should = loadShould;
|
|
3461
|
+
function assert(express, errmsg) {
|
|
3462
|
+
let test2 = new Assertion(null, null, assert, true);
|
|
3463
|
+
test2.assert(express, errmsg, "[ negation message unavailable ]");
|
|
3464
|
+
}
|
|
3465
|
+
__name(assert, "assert");
|
|
3466
|
+
assert.fail = function(actual, expected, message, operator) {
|
|
3467
|
+
if (arguments.length < 2) {
|
|
3468
|
+
message = actual;
|
|
3469
|
+
actual = void 0;
|
|
3470
|
+
}
|
|
3471
|
+
message = message || "assert.fail()";
|
|
3472
|
+
throw new AssertionError(message, {
|
|
3473
|
+
actual,
|
|
3474
|
+
expected,
|
|
3475
|
+
operator
|
|
3476
|
+
}, assert.fail);
|
|
3477
|
+
};
|
|
3478
|
+
assert.isOk = function(val, msg) {
|
|
3479
|
+
new Assertion(val, msg, assert.isOk, true).is.ok;
|
|
3480
|
+
};
|
|
3481
|
+
assert.isNotOk = function(val, msg) {
|
|
3482
|
+
new Assertion(val, msg, assert.isNotOk, true).is.not.ok;
|
|
3483
|
+
};
|
|
3484
|
+
assert.equal = function(act, exp, msg) {
|
|
3485
|
+
let test2 = new Assertion(act, msg, assert.equal, true);
|
|
3486
|
+
test2.assert(exp == flag(test2, "object"), "expected #{this} to equal #{exp}", "expected #{this} to not equal #{act}", exp, act, true);
|
|
3487
|
+
};
|
|
3488
|
+
assert.notEqual = function(act, exp, msg) {
|
|
3489
|
+
let test2 = new Assertion(act, msg, assert.notEqual, true);
|
|
3490
|
+
test2.assert(exp != flag(test2, "object"), "expected #{this} to not equal #{exp}", "expected #{this} to equal #{act}", exp, act, true);
|
|
3491
|
+
};
|
|
3492
|
+
assert.strictEqual = function(act, exp, msg) {
|
|
3493
|
+
new Assertion(act, msg, assert.strictEqual, true).to.equal(exp);
|
|
3494
|
+
};
|
|
3495
|
+
assert.notStrictEqual = function(act, exp, msg) {
|
|
3496
|
+
new Assertion(act, msg, assert.notStrictEqual, true).to.not.equal(exp);
|
|
3497
|
+
};
|
|
3498
|
+
assert.deepEqual = assert.deepStrictEqual = function(act, exp, msg) {
|
|
3499
|
+
new Assertion(act, msg, assert.deepEqual, true).to.eql(exp);
|
|
3500
|
+
};
|
|
3501
|
+
assert.notDeepEqual = function(act, exp, msg) {
|
|
3502
|
+
new Assertion(act, msg, assert.notDeepEqual, true).to.not.eql(exp);
|
|
3503
|
+
};
|
|
3504
|
+
assert.isAbove = function(val, abv, msg) {
|
|
3505
|
+
new Assertion(val, msg, assert.isAbove, true).to.be.above(abv);
|
|
3506
|
+
};
|
|
3507
|
+
assert.isAtLeast = function(val, atlst, msg) {
|
|
3508
|
+
new Assertion(val, msg, assert.isAtLeast, true).to.be.least(atlst);
|
|
3509
|
+
};
|
|
3510
|
+
assert.isBelow = function(val, blw, msg) {
|
|
3511
|
+
new Assertion(val, msg, assert.isBelow, true).to.be.below(blw);
|
|
3512
|
+
};
|
|
3513
|
+
assert.isAtMost = function(val, atmst, msg) {
|
|
3514
|
+
new Assertion(val, msg, assert.isAtMost, true).to.be.most(atmst);
|
|
3515
|
+
};
|
|
3516
|
+
assert.isTrue = function(val, msg) {
|
|
3517
|
+
new Assertion(val, msg, assert.isTrue, true).is["true"];
|
|
3518
|
+
};
|
|
3519
|
+
assert.isNotTrue = function(val, msg) {
|
|
3520
|
+
new Assertion(val, msg, assert.isNotTrue, true).to.not.equal(true);
|
|
3521
|
+
};
|
|
3522
|
+
assert.isFalse = function(val, msg) {
|
|
3523
|
+
new Assertion(val, msg, assert.isFalse, true).is["false"];
|
|
3524
|
+
};
|
|
3525
|
+
assert.isNotFalse = function(val, msg) {
|
|
3526
|
+
new Assertion(val, msg, assert.isNotFalse, true).to.not.equal(false);
|
|
3527
|
+
};
|
|
3528
|
+
assert.isNull = function(val, msg) {
|
|
3529
|
+
new Assertion(val, msg, assert.isNull, true).to.equal(null);
|
|
3530
|
+
};
|
|
3531
|
+
assert.isNotNull = function(val, msg) {
|
|
3532
|
+
new Assertion(val, msg, assert.isNotNull, true).to.not.equal(null);
|
|
3533
|
+
};
|
|
3534
|
+
assert.isNaN = function(val, msg) {
|
|
3535
|
+
new Assertion(val, msg, assert.isNaN, true).to.be.NaN;
|
|
3536
|
+
};
|
|
3537
|
+
assert.isNotNaN = function(value, message) {
|
|
3538
|
+
new Assertion(value, message, assert.isNotNaN, true).not.to.be.NaN;
|
|
3539
|
+
};
|
|
3540
|
+
assert.exists = function(val, msg) {
|
|
3541
|
+
new Assertion(val, msg, assert.exists, true).to.exist;
|
|
3542
|
+
};
|
|
3543
|
+
assert.notExists = function(val, msg) {
|
|
3544
|
+
new Assertion(val, msg, assert.notExists, true).to.not.exist;
|
|
3545
|
+
};
|
|
3546
|
+
assert.isUndefined = function(val, msg) {
|
|
3547
|
+
new Assertion(val, msg, assert.isUndefined, true).to.equal(void 0);
|
|
3548
|
+
};
|
|
3549
|
+
assert.isDefined = function(val, msg) {
|
|
3550
|
+
new Assertion(val, msg, assert.isDefined, true).to.not.equal(void 0);
|
|
3551
|
+
};
|
|
3552
|
+
assert.isCallable = function(value, message) {
|
|
3553
|
+
new Assertion(value, message, assert.isCallable, true).is.callable;
|
|
3554
|
+
};
|
|
3555
|
+
assert.isNotCallable = function(value, message) {
|
|
3556
|
+
new Assertion(value, message, assert.isNotCallable, true).is.not.callable;
|
|
3557
|
+
};
|
|
3558
|
+
assert.isObject = function(val, msg) {
|
|
3559
|
+
new Assertion(val, msg, assert.isObject, true).to.be.a("object");
|
|
3560
|
+
};
|
|
3561
|
+
assert.isNotObject = function(val, msg) {
|
|
3562
|
+
new Assertion(val, msg, assert.isNotObject, true).to.not.be.a("object");
|
|
3563
|
+
};
|
|
3564
|
+
assert.isArray = function(val, msg) {
|
|
3565
|
+
new Assertion(val, msg, assert.isArray, true).to.be.an("array");
|
|
3566
|
+
};
|
|
3567
|
+
assert.isNotArray = function(val, msg) {
|
|
3568
|
+
new Assertion(val, msg, assert.isNotArray, true).to.not.be.an("array");
|
|
3569
|
+
};
|
|
3570
|
+
assert.isString = function(val, msg) {
|
|
3571
|
+
new Assertion(val, msg, assert.isString, true).to.be.a("string");
|
|
3572
|
+
};
|
|
3573
|
+
assert.isNotString = function(val, msg) {
|
|
3574
|
+
new Assertion(val, msg, assert.isNotString, true).to.not.be.a("string");
|
|
3575
|
+
};
|
|
3576
|
+
assert.isNumber = function(val, msg) {
|
|
3577
|
+
new Assertion(val, msg, assert.isNumber, true).to.be.a("number");
|
|
3578
|
+
};
|
|
3579
|
+
assert.isNotNumber = function(val, msg) {
|
|
3580
|
+
new Assertion(val, msg, assert.isNotNumber, true).to.not.be.a("number");
|
|
3581
|
+
};
|
|
3582
|
+
assert.isNumeric = function(val, msg) {
|
|
3583
|
+
new Assertion(val, msg, assert.isNumeric, true).is.numeric;
|
|
3584
|
+
};
|
|
3585
|
+
assert.isNotNumeric = function(val, msg) {
|
|
3586
|
+
new Assertion(val, msg, assert.isNotNumeric, true).is.not.numeric;
|
|
3587
|
+
};
|
|
3588
|
+
assert.isFinite = function(val, msg) {
|
|
3589
|
+
new Assertion(val, msg, assert.isFinite, true).to.be.finite;
|
|
3590
|
+
};
|
|
3591
|
+
assert.isBoolean = function(val, msg) {
|
|
3592
|
+
new Assertion(val, msg, assert.isBoolean, true).to.be.a("boolean");
|
|
3593
|
+
};
|
|
3594
|
+
assert.isNotBoolean = function(val, msg) {
|
|
3595
|
+
new Assertion(val, msg, assert.isNotBoolean, true).to.not.be.a("boolean");
|
|
3596
|
+
};
|
|
3597
|
+
assert.typeOf = function(val, type3, msg) {
|
|
3598
|
+
new Assertion(val, msg, assert.typeOf, true).to.be.a(type3);
|
|
3599
|
+
};
|
|
3600
|
+
assert.notTypeOf = function(value, type3, message) {
|
|
3601
|
+
new Assertion(value, message, assert.notTypeOf, true).to.not.be.a(type3);
|
|
3602
|
+
};
|
|
3603
|
+
assert.instanceOf = function(val, type3, msg) {
|
|
3604
|
+
new Assertion(val, msg, assert.instanceOf, true).to.be.instanceOf(type3);
|
|
3605
|
+
};
|
|
3606
|
+
assert.notInstanceOf = function(val, type3, msg) {
|
|
3607
|
+
new Assertion(val, msg, assert.notInstanceOf, true).to.not.be.instanceOf(type3);
|
|
3608
|
+
};
|
|
3609
|
+
assert.include = function(exp, inc, msg) {
|
|
3610
|
+
new Assertion(exp, msg, assert.include, true).include(inc);
|
|
3611
|
+
};
|
|
3612
|
+
assert.notInclude = function(exp, inc, msg) {
|
|
3613
|
+
new Assertion(exp, msg, assert.notInclude, true).not.include(inc);
|
|
3614
|
+
};
|
|
3615
|
+
assert.deepInclude = function(exp, inc, msg) {
|
|
3616
|
+
new Assertion(exp, msg, assert.deepInclude, true).deep.include(inc);
|
|
3617
|
+
};
|
|
3618
|
+
assert.notDeepInclude = function(exp, inc, msg) {
|
|
3619
|
+
new Assertion(exp, msg, assert.notDeepInclude, true).not.deep.include(inc);
|
|
3620
|
+
};
|
|
3621
|
+
assert.nestedInclude = function(exp, inc, msg) {
|
|
3622
|
+
new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc);
|
|
3623
|
+
};
|
|
3624
|
+
assert.notNestedInclude = function(exp, inc, msg) {
|
|
3625
|
+
new Assertion(exp, msg, assert.notNestedInclude, true).not.nested.include(inc);
|
|
3626
|
+
};
|
|
3627
|
+
assert.deepNestedInclude = function(exp, inc, msg) {
|
|
3628
|
+
new Assertion(exp, msg, assert.deepNestedInclude, true).deep.nested.include(inc);
|
|
3629
|
+
};
|
|
3630
|
+
assert.notDeepNestedInclude = function(exp, inc, msg) {
|
|
3631
|
+
new Assertion(exp, msg, assert.notDeepNestedInclude, true).not.deep.nested.include(inc);
|
|
3632
|
+
};
|
|
3633
|
+
assert.ownInclude = function(exp, inc, msg) {
|
|
3634
|
+
new Assertion(exp, msg, assert.ownInclude, true).own.include(inc);
|
|
3635
|
+
};
|
|
3636
|
+
assert.notOwnInclude = function(exp, inc, msg) {
|
|
3637
|
+
new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc);
|
|
3638
|
+
};
|
|
3639
|
+
assert.deepOwnInclude = function(exp, inc, msg) {
|
|
3640
|
+
new Assertion(exp, msg, assert.deepOwnInclude, true).deep.own.include(inc);
|
|
3641
|
+
};
|
|
3642
|
+
assert.notDeepOwnInclude = function(exp, inc, msg) {
|
|
3643
|
+
new Assertion(exp, msg, assert.notDeepOwnInclude, true).not.deep.own.include(inc);
|
|
3644
|
+
};
|
|
3645
|
+
assert.match = function(exp, re, msg) {
|
|
3646
|
+
new Assertion(exp, msg, assert.match, true).to.match(re);
|
|
3647
|
+
};
|
|
3648
|
+
assert.notMatch = function(exp, re, msg) {
|
|
3649
|
+
new Assertion(exp, msg, assert.notMatch, true).to.not.match(re);
|
|
3650
|
+
};
|
|
3651
|
+
assert.property = function(obj, prop, msg) {
|
|
3652
|
+
new Assertion(obj, msg, assert.property, true).to.have.property(prop);
|
|
3653
|
+
};
|
|
3654
|
+
assert.notProperty = function(obj, prop, msg) {
|
|
3655
|
+
new Assertion(obj, msg, assert.notProperty, true).to.not.have.property(prop);
|
|
3656
|
+
};
|
|
3657
|
+
assert.propertyVal = function(obj, prop, val, msg) {
|
|
3658
|
+
new Assertion(obj, msg, assert.propertyVal, true).to.have.property(prop, val);
|
|
3659
|
+
};
|
|
3660
|
+
assert.notPropertyVal = function(obj, prop, val, msg) {
|
|
3661
|
+
new Assertion(obj, msg, assert.notPropertyVal, true).to.not.have.property(prop, val);
|
|
3662
|
+
};
|
|
3663
|
+
assert.deepPropertyVal = function(obj, prop, val, msg) {
|
|
3664
|
+
new Assertion(obj, msg, assert.deepPropertyVal, true).to.have.deep.property(prop, val);
|
|
3665
|
+
};
|
|
3666
|
+
assert.notDeepPropertyVal = function(obj, prop, val, msg) {
|
|
3667
|
+
new Assertion(obj, msg, assert.notDeepPropertyVal, true).to.not.have.deep.property(prop, val);
|
|
3668
|
+
};
|
|
3669
|
+
assert.ownProperty = function(obj, prop, msg) {
|
|
3670
|
+
new Assertion(obj, msg, assert.ownProperty, true).to.have.own.property(prop);
|
|
3671
|
+
};
|
|
3672
|
+
assert.notOwnProperty = function(obj, prop, msg) {
|
|
3673
|
+
new Assertion(obj, msg, assert.notOwnProperty, true).to.not.have.own.property(prop);
|
|
3674
|
+
};
|
|
3675
|
+
assert.ownPropertyVal = function(obj, prop, value, msg) {
|
|
3676
|
+
new Assertion(obj, msg, assert.ownPropertyVal, true).to.have.own.property(prop, value);
|
|
3677
|
+
};
|
|
3678
|
+
assert.notOwnPropertyVal = function(obj, prop, value, msg) {
|
|
3679
|
+
new Assertion(obj, msg, assert.notOwnPropertyVal, true).to.not.have.own.property(prop, value);
|
|
3680
|
+
};
|
|
3681
|
+
assert.deepOwnPropertyVal = function(obj, prop, value, msg) {
|
|
3682
|
+
new Assertion(obj, msg, assert.deepOwnPropertyVal, true).to.have.deep.own.property(prop, value);
|
|
3683
|
+
};
|
|
3684
|
+
assert.notDeepOwnPropertyVal = function(obj, prop, value, msg) {
|
|
3685
|
+
new Assertion(obj, msg, assert.notDeepOwnPropertyVal, true).to.not.have.deep.own.property(prop, value);
|
|
3686
|
+
};
|
|
3687
|
+
assert.nestedProperty = function(obj, prop, msg) {
|
|
3688
|
+
new Assertion(obj, msg, assert.nestedProperty, true).to.have.nested.property(prop);
|
|
3689
|
+
};
|
|
3690
|
+
assert.notNestedProperty = function(obj, prop, msg) {
|
|
3691
|
+
new Assertion(obj, msg, assert.notNestedProperty, true).to.not.have.nested.property(prop);
|
|
3692
|
+
};
|
|
3693
|
+
assert.nestedPropertyVal = function(obj, prop, val, msg) {
|
|
3694
|
+
new Assertion(obj, msg, assert.nestedPropertyVal, true).to.have.nested.property(prop, val);
|
|
3695
|
+
};
|
|
3696
|
+
assert.notNestedPropertyVal = function(obj, prop, val, msg) {
|
|
3697
|
+
new Assertion(obj, msg, assert.notNestedPropertyVal, true).to.not.have.nested.property(prop, val);
|
|
3698
|
+
};
|
|
3699
|
+
assert.deepNestedPropertyVal = function(obj, prop, val, msg) {
|
|
3700
|
+
new Assertion(obj, msg, assert.deepNestedPropertyVal, true).to.have.deep.nested.property(prop, val);
|
|
3701
|
+
};
|
|
3702
|
+
assert.notDeepNestedPropertyVal = function(obj, prop, val, msg) {
|
|
3703
|
+
new Assertion(obj, msg, assert.notDeepNestedPropertyVal, true).to.not.have.deep.nested.property(prop, val);
|
|
3704
|
+
};
|
|
3705
|
+
assert.lengthOf = function(exp, len, msg) {
|
|
3706
|
+
new Assertion(exp, msg, assert.lengthOf, true).to.have.lengthOf(len);
|
|
3707
|
+
};
|
|
3708
|
+
assert.hasAnyKeys = function(obj, keys, msg) {
|
|
3709
|
+
new Assertion(obj, msg, assert.hasAnyKeys, true).to.have.any.keys(keys);
|
|
3710
|
+
};
|
|
3711
|
+
assert.hasAllKeys = function(obj, keys, msg) {
|
|
3712
|
+
new Assertion(obj, msg, assert.hasAllKeys, true).to.have.all.keys(keys);
|
|
3713
|
+
};
|
|
3714
|
+
assert.containsAllKeys = function(obj, keys, msg) {
|
|
3715
|
+
new Assertion(obj, msg, assert.containsAllKeys, true).to.contain.all.keys(keys);
|
|
3716
|
+
};
|
|
3717
|
+
assert.doesNotHaveAnyKeys = function(obj, keys, msg) {
|
|
3718
|
+
new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true).to.not.have.any.keys(keys);
|
|
3719
|
+
};
|
|
3720
|
+
assert.doesNotHaveAllKeys = function(obj, keys, msg) {
|
|
3721
|
+
new Assertion(obj, msg, assert.doesNotHaveAllKeys, true).to.not.have.all.keys(keys);
|
|
3722
|
+
};
|
|
3723
|
+
assert.hasAnyDeepKeys = function(obj, keys, msg) {
|
|
3724
|
+
new Assertion(obj, msg, assert.hasAnyDeepKeys, true).to.have.any.deep.keys(keys);
|
|
3725
|
+
};
|
|
3726
|
+
assert.hasAllDeepKeys = function(obj, keys, msg) {
|
|
3727
|
+
new Assertion(obj, msg, assert.hasAllDeepKeys, true).to.have.all.deep.keys(keys);
|
|
3728
|
+
};
|
|
3729
|
+
assert.containsAllDeepKeys = function(obj, keys, msg) {
|
|
3730
|
+
new Assertion(obj, msg, assert.containsAllDeepKeys, true).to.contain.all.deep.keys(keys);
|
|
3731
|
+
};
|
|
3732
|
+
assert.doesNotHaveAnyDeepKeys = function(obj, keys, msg) {
|
|
3733
|
+
new Assertion(obj, msg, assert.doesNotHaveAnyDeepKeys, true).to.not.have.any.deep.keys(keys);
|
|
3734
|
+
};
|
|
3735
|
+
assert.doesNotHaveAllDeepKeys = function(obj, keys, msg) {
|
|
3736
|
+
new Assertion(obj, msg, assert.doesNotHaveAllDeepKeys, true).to.not.have.all.deep.keys(keys);
|
|
3737
|
+
};
|
|
3738
|
+
assert.throws = function(fn, errorLike, errMsgMatcher, msg) {
|
|
3739
|
+
if ("string" === typeof errorLike || errorLike instanceof RegExp) {
|
|
3740
|
+
errMsgMatcher = errorLike;
|
|
3741
|
+
errorLike = null;
|
|
3742
|
+
}
|
|
3743
|
+
let assertErr = new Assertion(fn, msg, assert.throws, true).to.throw(errorLike, errMsgMatcher);
|
|
3744
|
+
return flag(assertErr, "object");
|
|
3745
|
+
};
|
|
3746
|
+
assert.doesNotThrow = function(fn, errorLike, errMsgMatcher, message) {
|
|
3747
|
+
if ("string" === typeof errorLike || errorLike instanceof RegExp) {
|
|
3748
|
+
errMsgMatcher = errorLike;
|
|
3749
|
+
errorLike = null;
|
|
3750
|
+
}
|
|
3751
|
+
new Assertion(fn, message, assert.doesNotThrow, true).to.not.throw(errorLike, errMsgMatcher);
|
|
3752
|
+
};
|
|
3753
|
+
assert.operator = function(val, operator, val2, msg) {
|
|
3754
|
+
let ok;
|
|
3755
|
+
switch(operator){
|
|
3756
|
+
case "==":
|
|
3757
|
+
ok = val == val2;
|
|
3758
|
+
break;
|
|
3759
|
+
case "===":
|
|
3760
|
+
ok = val === val2;
|
|
3761
|
+
break;
|
|
3762
|
+
case ">":
|
|
3763
|
+
ok = val > val2;
|
|
3764
|
+
break;
|
|
3765
|
+
case ">=":
|
|
3766
|
+
ok = val >= val2;
|
|
3767
|
+
break;
|
|
3768
|
+
case "<":
|
|
3769
|
+
ok = val < val2;
|
|
3770
|
+
break;
|
|
3771
|
+
case "<=":
|
|
3772
|
+
ok = val <= val2;
|
|
3773
|
+
break;
|
|
3774
|
+
case "!=":
|
|
3775
|
+
ok = val != val2;
|
|
3776
|
+
break;
|
|
3777
|
+
case "!==":
|
|
3778
|
+
ok = val !== val2;
|
|
3779
|
+
break;
|
|
3780
|
+
default:
|
|
3781
|
+
msg = msg ? msg + ": " : msg;
|
|
3782
|
+
throw new AssertionError(msg + 'Invalid operator "' + operator + '"', void 0, assert.operator);
|
|
3783
|
+
}
|
|
3784
|
+
let test2 = new Assertion(ok, msg, assert.operator, true);
|
|
3785
|
+
test2.assert(true === flag(test2, "object"), "expected " + inspect2(val) + " to be " + operator + " " + inspect2(val2), "expected " + inspect2(val) + " to not be " + operator + " " + inspect2(val2));
|
|
3786
|
+
};
|
|
3787
|
+
assert.closeTo = function(act, exp, delta, msg) {
|
|
3788
|
+
new Assertion(act, msg, assert.closeTo, true).to.be.closeTo(exp, delta);
|
|
3789
|
+
};
|
|
3790
|
+
assert.approximately = function(act, exp, delta, msg) {
|
|
3791
|
+
new Assertion(act, msg, assert.approximately, true).to.be.approximately(exp, delta);
|
|
3792
|
+
};
|
|
3793
|
+
assert.sameMembers = function(set1, set2, msg) {
|
|
3794
|
+
new Assertion(set1, msg, assert.sameMembers, true).to.have.same.members(set2);
|
|
3795
|
+
};
|
|
3796
|
+
assert.notSameMembers = function(set1, set2, msg) {
|
|
3797
|
+
new Assertion(set1, msg, assert.notSameMembers, true).to.not.have.same.members(set2);
|
|
3798
|
+
};
|
|
3799
|
+
assert.sameDeepMembers = function(set1, set2, msg) {
|
|
3800
|
+
new Assertion(set1, msg, assert.sameDeepMembers, true).to.have.same.deep.members(set2);
|
|
3801
|
+
};
|
|
3802
|
+
assert.notSameDeepMembers = function(set1, set2, msg) {
|
|
3803
|
+
new Assertion(set1, msg, assert.notSameDeepMembers, true).to.not.have.same.deep.members(set2);
|
|
3804
|
+
};
|
|
3805
|
+
assert.sameOrderedMembers = function(set1, set2, msg) {
|
|
3806
|
+
new Assertion(set1, msg, assert.sameOrderedMembers, true).to.have.same.ordered.members(set2);
|
|
3807
|
+
};
|
|
3808
|
+
assert.notSameOrderedMembers = function(set1, set2, msg) {
|
|
3809
|
+
new Assertion(set1, msg, assert.notSameOrderedMembers, true).to.not.have.same.ordered.members(set2);
|
|
3810
|
+
};
|
|
3811
|
+
assert.sameDeepOrderedMembers = function(set1, set2, msg) {
|
|
3812
|
+
new Assertion(set1, msg, assert.sameDeepOrderedMembers, true).to.have.same.deep.ordered.members(set2);
|
|
3813
|
+
};
|
|
3814
|
+
assert.notSameDeepOrderedMembers = function(set1, set2, msg) {
|
|
3815
|
+
new Assertion(set1, msg, assert.notSameDeepOrderedMembers, true).to.not.have.same.deep.ordered.members(set2);
|
|
3816
|
+
};
|
|
3817
|
+
assert.includeMembers = function(superset, subset, msg) {
|
|
3818
|
+
new Assertion(superset, msg, assert.includeMembers, true).to.include.members(subset);
|
|
3819
|
+
};
|
|
3820
|
+
assert.notIncludeMembers = function(superset, subset, msg) {
|
|
3821
|
+
new Assertion(superset, msg, assert.notIncludeMembers, true).to.not.include.members(subset);
|
|
3822
|
+
};
|
|
3823
|
+
assert.includeDeepMembers = function(superset, subset, msg) {
|
|
3824
|
+
new Assertion(superset, msg, assert.includeDeepMembers, true).to.include.deep.members(subset);
|
|
3825
|
+
};
|
|
3826
|
+
assert.notIncludeDeepMembers = function(superset, subset, msg) {
|
|
3827
|
+
new Assertion(superset, msg, assert.notIncludeDeepMembers, true).to.not.include.deep.members(subset);
|
|
3828
|
+
};
|
|
3829
|
+
assert.includeOrderedMembers = function(superset, subset, msg) {
|
|
3830
|
+
new Assertion(superset, msg, assert.includeOrderedMembers, true).to.include.ordered.members(subset);
|
|
3831
|
+
};
|
|
3832
|
+
assert.notIncludeOrderedMembers = function(superset, subset, msg) {
|
|
3833
|
+
new Assertion(superset, msg, assert.notIncludeOrderedMembers, true).to.not.include.ordered.members(subset);
|
|
3834
|
+
};
|
|
3835
|
+
assert.includeDeepOrderedMembers = function(superset, subset, msg) {
|
|
3836
|
+
new Assertion(superset, msg, assert.includeDeepOrderedMembers, true).to.include.deep.ordered.members(subset);
|
|
3837
|
+
};
|
|
3838
|
+
assert.notIncludeDeepOrderedMembers = function(superset, subset, msg) {
|
|
3839
|
+
new Assertion(superset, msg, assert.notIncludeDeepOrderedMembers, true).to.not.include.deep.ordered.members(subset);
|
|
3840
|
+
};
|
|
3841
|
+
assert.oneOf = function(inList, list, msg) {
|
|
3842
|
+
new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list);
|
|
3843
|
+
};
|
|
3844
|
+
assert.isIterable = function(obj, msg) {
|
|
3845
|
+
if (obj == void 0 || !obj[Symbol.iterator]) {
|
|
3846
|
+
msg = msg ? `${msg} expected ${inspect2(obj)} to be an iterable` : `expected ${inspect2(obj)} to be an iterable`;
|
|
3847
|
+
throw new AssertionError(msg, void 0, assert.isIterable);
|
|
3848
|
+
}
|
|
3849
|
+
};
|
|
3850
|
+
assert.changes = function(fn, obj, prop, msg) {
|
|
3851
|
+
if (arguments.length === 3 && typeof obj === "function") {
|
|
3852
|
+
msg = prop;
|
|
3853
|
+
prop = null;
|
|
3854
|
+
}
|
|
3855
|
+
new Assertion(fn, msg, assert.changes, true).to.change(obj, prop);
|
|
3856
|
+
};
|
|
3857
|
+
assert.changesBy = function(fn, obj, prop, delta, msg) {
|
|
3858
|
+
if (arguments.length === 4 && typeof obj === "function") {
|
|
3859
|
+
let tmpMsg = delta;
|
|
3860
|
+
delta = prop;
|
|
3861
|
+
msg = tmpMsg;
|
|
3862
|
+
} else if (arguments.length === 3) {
|
|
3863
|
+
delta = prop;
|
|
3864
|
+
prop = null;
|
|
3865
|
+
}
|
|
3866
|
+
new Assertion(fn, msg, assert.changesBy, true).to.change(obj, prop).by(delta);
|
|
3867
|
+
};
|
|
3868
|
+
assert.doesNotChange = function(fn, obj, prop, msg) {
|
|
3869
|
+
if (arguments.length === 3 && typeof obj === "function") {
|
|
3870
|
+
msg = prop;
|
|
3871
|
+
prop = null;
|
|
3872
|
+
}
|
|
3873
|
+
return new Assertion(fn, msg, assert.doesNotChange, true).to.not.change(obj, prop);
|
|
3874
|
+
};
|
|
3875
|
+
assert.changesButNotBy = function(fn, obj, prop, delta, msg) {
|
|
3876
|
+
if (arguments.length === 4 && typeof obj === "function") {
|
|
3877
|
+
let tmpMsg = delta;
|
|
3878
|
+
delta = prop;
|
|
3879
|
+
msg = tmpMsg;
|
|
3880
|
+
} else if (arguments.length === 3) {
|
|
3881
|
+
delta = prop;
|
|
3882
|
+
prop = null;
|
|
3883
|
+
}
|
|
3884
|
+
new Assertion(fn, msg, assert.changesButNotBy, true).to.change(obj, prop).but.not.by(delta);
|
|
3885
|
+
};
|
|
3886
|
+
assert.increases = function(fn, obj, prop, msg) {
|
|
3887
|
+
if (arguments.length === 3 && typeof obj === "function") {
|
|
3888
|
+
msg = prop;
|
|
3889
|
+
prop = null;
|
|
3890
|
+
}
|
|
3891
|
+
return new Assertion(fn, msg, assert.increases, true).to.increase(obj, prop);
|
|
3892
|
+
};
|
|
3893
|
+
assert.increasesBy = function(fn, obj, prop, delta, msg) {
|
|
3894
|
+
if (arguments.length === 4 && typeof obj === "function") {
|
|
3895
|
+
let tmpMsg = delta;
|
|
3896
|
+
delta = prop;
|
|
3897
|
+
msg = tmpMsg;
|
|
3898
|
+
} else if (arguments.length === 3) {
|
|
3899
|
+
delta = prop;
|
|
3900
|
+
prop = null;
|
|
3901
|
+
}
|
|
3902
|
+
new Assertion(fn, msg, assert.increasesBy, true).to.increase(obj, prop).by(delta);
|
|
3903
|
+
};
|
|
3904
|
+
assert.doesNotIncrease = function(fn, obj, prop, msg) {
|
|
3905
|
+
if (arguments.length === 3 && typeof obj === "function") {
|
|
3906
|
+
msg = prop;
|
|
3907
|
+
prop = null;
|
|
3908
|
+
}
|
|
3909
|
+
return new Assertion(fn, msg, assert.doesNotIncrease, true).to.not.increase(obj, prop);
|
|
3910
|
+
};
|
|
3911
|
+
assert.increasesButNotBy = function(fn, obj, prop, delta, msg) {
|
|
3912
|
+
if (arguments.length === 4 && typeof obj === "function") {
|
|
3913
|
+
let tmpMsg = delta;
|
|
3914
|
+
delta = prop;
|
|
3915
|
+
msg = tmpMsg;
|
|
3916
|
+
} else if (arguments.length === 3) {
|
|
3917
|
+
delta = prop;
|
|
3918
|
+
prop = null;
|
|
3919
|
+
}
|
|
3920
|
+
new Assertion(fn, msg, assert.increasesButNotBy, true).to.increase(obj, prop).but.not.by(delta);
|
|
3921
|
+
};
|
|
3922
|
+
assert.decreases = function(fn, obj, prop, msg) {
|
|
3923
|
+
if (arguments.length === 3 && typeof obj === "function") {
|
|
3924
|
+
msg = prop;
|
|
3925
|
+
prop = null;
|
|
3926
|
+
}
|
|
3927
|
+
return new Assertion(fn, msg, assert.decreases, true).to.decrease(obj, prop);
|
|
3928
|
+
};
|
|
3929
|
+
assert.decreasesBy = function(fn, obj, prop, delta, msg) {
|
|
3930
|
+
if (arguments.length === 4 && typeof obj === "function") {
|
|
3931
|
+
let tmpMsg = delta;
|
|
3932
|
+
delta = prop;
|
|
3933
|
+
msg = tmpMsg;
|
|
3934
|
+
} else if (arguments.length === 3) {
|
|
3935
|
+
delta = prop;
|
|
3936
|
+
prop = null;
|
|
3937
|
+
}
|
|
3938
|
+
new Assertion(fn, msg, assert.decreasesBy, true).to.decrease(obj, prop).by(delta);
|
|
3939
|
+
};
|
|
3940
|
+
assert.doesNotDecrease = function(fn, obj, prop, msg) {
|
|
3941
|
+
if (arguments.length === 3 && typeof obj === "function") {
|
|
3942
|
+
msg = prop;
|
|
3943
|
+
prop = null;
|
|
3944
|
+
}
|
|
3945
|
+
return new Assertion(fn, msg, assert.doesNotDecrease, true).to.not.decrease(obj, prop);
|
|
3946
|
+
};
|
|
3947
|
+
assert.doesNotDecreaseBy = function(fn, obj, prop, delta, msg) {
|
|
3948
|
+
if (arguments.length === 4 && typeof obj === "function") {
|
|
3949
|
+
let tmpMsg = delta;
|
|
3950
|
+
delta = prop;
|
|
3951
|
+
msg = tmpMsg;
|
|
3952
|
+
} else if (arguments.length === 3) {
|
|
3953
|
+
delta = prop;
|
|
3954
|
+
prop = null;
|
|
3955
|
+
}
|
|
3956
|
+
return new Assertion(fn, msg, assert.doesNotDecreaseBy, true).to.not.decrease(obj, prop).by(delta);
|
|
3957
|
+
};
|
|
3958
|
+
assert.decreasesButNotBy = function(fn, obj, prop, delta, msg) {
|
|
3959
|
+
if (arguments.length === 4 && typeof obj === "function") {
|
|
3960
|
+
let tmpMsg = delta;
|
|
3961
|
+
delta = prop;
|
|
3962
|
+
msg = tmpMsg;
|
|
3963
|
+
} else if (arguments.length === 3) {
|
|
3964
|
+
delta = prop;
|
|
3965
|
+
prop = null;
|
|
3966
|
+
}
|
|
3967
|
+
new Assertion(fn, msg, assert.decreasesButNotBy, true).to.decrease(obj, prop).but.not.by(delta);
|
|
3968
|
+
};
|
|
3969
|
+
assert.ifError = function(val) {
|
|
3970
|
+
if (val) {
|
|
3971
|
+
throw val;
|
|
3972
|
+
}
|
|
3973
|
+
};
|
|
3974
|
+
assert.isExtensible = function(obj, msg) {
|
|
3975
|
+
new Assertion(obj, msg, assert.isExtensible, true).to.be.extensible;
|
|
3976
|
+
};
|
|
3977
|
+
assert.isNotExtensible = function(obj, msg) {
|
|
3978
|
+
new Assertion(obj, msg, assert.isNotExtensible, true).to.not.be.extensible;
|
|
3979
|
+
};
|
|
3980
|
+
assert.isSealed = function(obj, msg) {
|
|
3981
|
+
new Assertion(obj, msg, assert.isSealed, true).to.be.sealed;
|
|
3982
|
+
};
|
|
3983
|
+
assert.isNotSealed = function(obj, msg) {
|
|
3984
|
+
new Assertion(obj, msg, assert.isNotSealed, true).to.not.be.sealed;
|
|
3985
|
+
};
|
|
3986
|
+
assert.isFrozen = function(obj, msg) {
|
|
3987
|
+
new Assertion(obj, msg, assert.isFrozen, true).to.be.frozen;
|
|
3988
|
+
};
|
|
3989
|
+
assert.isNotFrozen = function(obj, msg) {
|
|
3990
|
+
new Assertion(obj, msg, assert.isNotFrozen, true).to.not.be.frozen;
|
|
3991
|
+
};
|
|
3992
|
+
assert.isEmpty = function(val, msg) {
|
|
3993
|
+
new Assertion(val, msg, assert.isEmpty, true).to.be.empty;
|
|
3994
|
+
};
|
|
3995
|
+
assert.isNotEmpty = function(val, msg) {
|
|
3996
|
+
new Assertion(val, msg, assert.isNotEmpty, true).to.not.be.empty;
|
|
3997
|
+
};
|
|
3998
|
+
assert.containsSubset = function(val, exp, msg) {
|
|
3999
|
+
new Assertion(val, msg).to.containSubset(exp);
|
|
4000
|
+
};
|
|
4001
|
+
assert.doesNotContainSubset = function(val, exp, msg) {
|
|
4002
|
+
new Assertion(val, msg).to.not.containSubset(exp);
|
|
4003
|
+
};
|
|
4004
|
+
var aliases = [
|
|
4005
|
+
[
|
|
4006
|
+
"isOk",
|
|
4007
|
+
"ok"
|
|
4008
|
+
],
|
|
4009
|
+
[
|
|
4010
|
+
"isNotOk",
|
|
4011
|
+
"notOk"
|
|
4012
|
+
],
|
|
4013
|
+
[
|
|
4014
|
+
"throws",
|
|
4015
|
+
"throw"
|
|
4016
|
+
],
|
|
4017
|
+
[
|
|
4018
|
+
"throws",
|
|
4019
|
+
"Throw"
|
|
4020
|
+
],
|
|
4021
|
+
[
|
|
4022
|
+
"isExtensible",
|
|
4023
|
+
"extensible"
|
|
4024
|
+
],
|
|
4025
|
+
[
|
|
4026
|
+
"isNotExtensible",
|
|
4027
|
+
"notExtensible"
|
|
4028
|
+
],
|
|
4029
|
+
[
|
|
4030
|
+
"isSealed",
|
|
4031
|
+
"sealed"
|
|
4032
|
+
],
|
|
4033
|
+
[
|
|
4034
|
+
"isNotSealed",
|
|
4035
|
+
"notSealed"
|
|
4036
|
+
],
|
|
4037
|
+
[
|
|
4038
|
+
"isFrozen",
|
|
4039
|
+
"frozen"
|
|
4040
|
+
],
|
|
4041
|
+
[
|
|
4042
|
+
"isNotFrozen",
|
|
4043
|
+
"notFrozen"
|
|
4044
|
+
],
|
|
4045
|
+
[
|
|
4046
|
+
"isEmpty",
|
|
4047
|
+
"empty"
|
|
4048
|
+
],
|
|
4049
|
+
[
|
|
4050
|
+
"isNotEmpty",
|
|
4051
|
+
"notEmpty"
|
|
4052
|
+
],
|
|
4053
|
+
[
|
|
4054
|
+
"isCallable",
|
|
4055
|
+
"isFunction"
|
|
4056
|
+
],
|
|
4057
|
+
[
|
|
4058
|
+
"isNotCallable",
|
|
4059
|
+
"isNotFunction"
|
|
4060
|
+
],
|
|
4061
|
+
[
|
|
4062
|
+
"containsSubset",
|
|
4063
|
+
"containSubset"
|
|
4064
|
+
]
|
|
4065
|
+
];
|
|
4066
|
+
for (const [name, as] of aliases){
|
|
4067
|
+
assert[as] = assert[name];
|
|
4068
|
+
}
|
|
4069
|
+
var used = [];
|
|
4070
|
+
function use(fn) {
|
|
4071
|
+
const exports$1 = {
|
|
4072
|
+
use,
|
|
4073
|
+
AssertionError,
|
|
4074
|
+
util: utils_exports,
|
|
4075
|
+
config,
|
|
4076
|
+
expect,
|
|
4077
|
+
assert,
|
|
4078
|
+
Assertion,
|
|
4079
|
+
...should_exports
|
|
4080
|
+
};
|
|
4081
|
+
if (!~used.indexOf(fn)) {
|
|
4082
|
+
fn(exports$1, utils_exports);
|
|
4083
|
+
used.push(fn);
|
|
4084
|
+
}
|
|
4085
|
+
return exports$1;
|
|
4086
|
+
}
|
|
4087
|
+
__name(use, "use");
|
|
4088
|
+
function isErrorInstance(obj) {
|
|
4089
|
+
return obj instanceof Error || Object.prototype.toString.call(obj) === '[object Error]';
|
|
4090
|
+
}
|
|
4091
|
+
function isRegExp(obj) {
|
|
4092
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
4093
|
+
}
|
|
4094
|
+
function compatibleInstance(thrown, errorLike) {
|
|
4095
|
+
return isErrorInstance(errorLike) && thrown === errorLike;
|
|
4096
|
+
}
|
|
4097
|
+
function compatibleConstructor(thrown, errorLike) {
|
|
4098
|
+
if (isErrorInstance(errorLike)) {
|
|
4099
|
+
return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
|
|
4100
|
+
} else if ((typeof errorLike === 'object' || typeof errorLike === 'function') && errorLike.prototype) {
|
|
4101
|
+
return thrown.constructor === errorLike || thrown instanceof errorLike;
|
|
4102
|
+
}
|
|
4103
|
+
return false;
|
|
4104
|
+
}
|
|
4105
|
+
function compatibleMessage(thrown, errMatcher) {
|
|
4106
|
+
const comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
|
|
4107
|
+
if (isRegExp(errMatcher)) {
|
|
4108
|
+
return errMatcher.test(comparisonString);
|
|
4109
|
+
} else if (typeof errMatcher === 'string') {
|
|
4110
|
+
return comparisonString.indexOf(errMatcher) !== -1;
|
|
4111
|
+
}
|
|
4112
|
+
return false;
|
|
4113
|
+
}
|
|
4114
|
+
function getConstructorName(errorLike) {
|
|
4115
|
+
let constructorName = errorLike;
|
|
4116
|
+
if (isErrorInstance(errorLike)) {
|
|
4117
|
+
constructorName = errorLike.constructor.name;
|
|
4118
|
+
} else if (typeof errorLike === 'function') {
|
|
4119
|
+
constructorName = errorLike.name;
|
|
4120
|
+
if (constructorName === '') {
|
|
4121
|
+
const newConstructorName = (new errorLike().name);
|
|
4122
|
+
constructorName = newConstructorName || constructorName;
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4125
|
+
return constructorName;
|
|
4126
|
+
}
|
|
4127
|
+
function getMessage(errorLike) {
|
|
4128
|
+
let msg = '';
|
|
4129
|
+
if (errorLike && errorLike.message) {
|
|
4130
|
+
msg = errorLike.message;
|
|
4131
|
+
} else if (typeof errorLike === 'string') {
|
|
4132
|
+
msg = errorLike;
|
|
4133
|
+
}
|
|
4134
|
+
return msg;
|
|
4135
|
+
}
|
|
4136
|
+
const checkErrorDefault = Object.freeze(Object.defineProperty({
|
|
4137
|
+
__proto__: null,
|
|
4138
|
+
compatibleConstructor,
|
|
4139
|
+
compatibleInstance,
|
|
4140
|
+
compatibleMessage,
|
|
4141
|
+
getConstructorName,
|
|
4142
|
+
getMessage
|
|
4143
|
+
}, Symbol.toStringTag, {
|
|
4144
|
+
value: 'Module'
|
|
4145
|
+
}));
|
|
4146
|
+
let checkError = checkErrorDefault;
|
|
4147
|
+
function chaiAsPromised(chai, utils) {
|
|
4148
|
+
const Assertion = chai.Assertion;
|
|
4149
|
+
const assert = chai.assert;
|
|
4150
|
+
const proxify = utils.proxify;
|
|
4151
|
+
if (utils.checkError) {
|
|
4152
|
+
checkError = utils.checkError;
|
|
4153
|
+
}
|
|
4154
|
+
function isLegacyJQueryPromise(thenable) {
|
|
4155
|
+
return (typeof thenable.catch !== 'function' && typeof thenable.always === 'function' && typeof thenable.done === 'function' && typeof thenable.fail === 'function' && typeof thenable.pipe === 'function' && typeof thenable.progress === 'function' && typeof thenable.state === 'function');
|
|
4156
|
+
}
|
|
4157
|
+
function assertIsAboutPromise(assertion) {
|
|
4158
|
+
if (typeof assertion._obj.then !== 'function') {
|
|
4159
|
+
throw new TypeError(utils.inspect(assertion._obj) + ' is not a thenable.');
|
|
4160
|
+
}
|
|
4161
|
+
if (isLegacyJQueryPromise(assertion._obj)) {
|
|
4162
|
+
throw new TypeError('Chai as Promised is incompatible with thenables of jQuery<3.0.0, sorry! Please ' + 'upgrade jQuery or use another Promises/A+ compatible library (see ' + 'http://promisesaplus.com/).');
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
function proxifyIfSupported(assertion) {
|
|
4166
|
+
return proxify === undefined ? assertion : proxify(assertion);
|
|
4167
|
+
}
|
|
4168
|
+
function method(name, asserter) {
|
|
4169
|
+
utils.addMethod(Assertion.prototype, name, function() {
|
|
4170
|
+
assertIsAboutPromise(this);
|
|
4171
|
+
return asserter.apply(this, arguments);
|
|
4172
|
+
});
|
|
4173
|
+
}
|
|
4174
|
+
function property(name, asserter) {
|
|
4175
|
+
utils.addProperty(Assertion.prototype, name, function() {
|
|
4176
|
+
assertIsAboutPromise(this);
|
|
4177
|
+
return proxifyIfSupported(asserter.apply(this, arguments));
|
|
4178
|
+
});
|
|
4179
|
+
}
|
|
4180
|
+
function doNotify(promise, done) {
|
|
4181
|
+
promise.then(()=>done(), done);
|
|
4182
|
+
}
|
|
4183
|
+
function assertIfNegated(assertion, message, extra) {
|
|
4184
|
+
assertion.assert(true, null, message, extra.expected, extra.actual);
|
|
4185
|
+
}
|
|
4186
|
+
function assertIfNotNegated(assertion, message, extra) {
|
|
4187
|
+
assertion.assert(false, message, null, extra.expected, extra.actual);
|
|
4188
|
+
}
|
|
4189
|
+
function getBasePromise(assertion) {
|
|
4190
|
+
return typeof assertion.then === 'function' ? assertion : assertion._obj;
|
|
4191
|
+
}
|
|
4192
|
+
function getReasonName(reason) {
|
|
4193
|
+
return reason instanceof Error ? reason.toString() : checkError.getConstructorName(reason);
|
|
4194
|
+
}
|
|
4195
|
+
const propertyNames = Object.getOwnPropertyNames(Assertion.prototype);
|
|
4196
|
+
const propertyDescs = {};
|
|
4197
|
+
for (const name of propertyNames){
|
|
4198
|
+
propertyDescs[name] = Object.getOwnPropertyDescriptor(Assertion.prototype, name);
|
|
4199
|
+
}
|
|
4200
|
+
property('fulfilled', function() {
|
|
4201
|
+
const derivedPromise = getBasePromise(this).then((value)=>{
|
|
4202
|
+
assertIfNegated(this, 'expected promise not to be fulfilled but it was fulfilled with #{act}', {
|
|
4203
|
+
actual: value
|
|
4204
|
+
});
|
|
4205
|
+
return value;
|
|
4206
|
+
}, (reason)=>{
|
|
4207
|
+
assertIfNotNegated(this, 'expected promise to be fulfilled but it was rejected with #{act}', {
|
|
4208
|
+
actual: getReasonName(reason)
|
|
4209
|
+
});
|
|
4210
|
+
return reason;
|
|
4211
|
+
});
|
|
4212
|
+
transferPromiseness(this, derivedPromise);
|
|
4213
|
+
return this;
|
|
4214
|
+
});
|
|
4215
|
+
property('rejected', function() {
|
|
4216
|
+
const derivedPromise = getBasePromise(this).then((value)=>{
|
|
4217
|
+
assertIfNotNegated(this, 'expected promise to be rejected but it was fulfilled with #{act}', {
|
|
4218
|
+
actual: value
|
|
4219
|
+
});
|
|
4220
|
+
return value;
|
|
4221
|
+
}, (reason)=>{
|
|
4222
|
+
assertIfNegated(this, 'expected promise not to be rejected but it was rejected with #{act}', {
|
|
4223
|
+
actual: getReasonName(reason)
|
|
4224
|
+
});
|
|
4225
|
+
return reason;
|
|
4226
|
+
});
|
|
4227
|
+
transferPromiseness(this, derivedPromise);
|
|
4228
|
+
return this;
|
|
4229
|
+
});
|
|
4230
|
+
method('rejectedWith', function(errorLike, errMsgMatcher, message) {
|
|
4231
|
+
let errorLikeName = null;
|
|
4232
|
+
const negate = utils.flag(this, 'negate') || false;
|
|
4233
|
+
if (errorLike === undefined && errMsgMatcher === undefined && message === undefined) {
|
|
4234
|
+
return this.rejected;
|
|
4235
|
+
}
|
|
4236
|
+
if (message !== undefined) {
|
|
4237
|
+
utils.flag(this, 'message', message);
|
|
4238
|
+
}
|
|
4239
|
+
if (errorLike instanceof RegExp || typeof errorLike === 'string') {
|
|
4240
|
+
errMsgMatcher = errorLike;
|
|
4241
|
+
errorLike = null;
|
|
4242
|
+
} else if (errorLike && errorLike instanceof Error) {
|
|
4243
|
+
errorLikeName = errorLike.toString();
|
|
4244
|
+
} else if (typeof errorLike === 'function') {
|
|
4245
|
+
errorLikeName = checkError.getConstructorName(errorLike);
|
|
4246
|
+
} else {
|
|
4247
|
+
errorLike = null;
|
|
4248
|
+
}
|
|
4249
|
+
const everyArgIsDefined = Boolean(errorLike && errMsgMatcher);
|
|
4250
|
+
let matcherRelation = 'including';
|
|
4251
|
+
if (errMsgMatcher instanceof RegExp) {
|
|
4252
|
+
matcherRelation = 'matching';
|
|
4253
|
+
}
|
|
4254
|
+
const derivedPromise = getBasePromise(this).then((value)=>{
|
|
4255
|
+
let assertionMessage = null;
|
|
4256
|
+
let expected = null;
|
|
4257
|
+
if (errorLike) {
|
|
4258
|
+
assertionMessage = 'expected promise to be rejected with #{exp} but it was fulfilled with #{act}';
|
|
4259
|
+
expected = errorLikeName;
|
|
4260
|
+
} else if (errMsgMatcher) {
|
|
4261
|
+
assertionMessage = `expected promise to be rejected with an error ${matcherRelation} #{exp} but ` + `it was fulfilled with #{act}`;
|
|
4262
|
+
expected = errMsgMatcher;
|
|
4263
|
+
}
|
|
4264
|
+
assertIfNotNegated(this, assertionMessage, {
|
|
4265
|
+
expected,
|
|
4266
|
+
actual: value
|
|
4267
|
+
});
|
|
4268
|
+
return value;
|
|
4269
|
+
}, (reason)=>{
|
|
4270
|
+
const errorLikeCompatible = errorLike && (errorLike instanceof Error ? checkError.compatibleInstance(reason, errorLike) : checkError.compatibleConstructor(reason, errorLike));
|
|
4271
|
+
const errMsgMatcherCompatible = errMsgMatcher === reason || (errMsgMatcher && reason && checkError.compatibleMessage(reason, errMsgMatcher));
|
|
4272
|
+
const reasonName = getReasonName(reason);
|
|
4273
|
+
if (negate && everyArgIsDefined) {
|
|
4274
|
+
if (errorLikeCompatible && errMsgMatcherCompatible) {
|
|
4275
|
+
this.assert(true, null, 'expected promise not to be rejected with #{exp} but it was rejected ' + 'with #{act}', errorLikeName, reasonName);
|
|
4276
|
+
}
|
|
4277
|
+
} else {
|
|
4278
|
+
if (errorLike) {
|
|
4279
|
+
this.assert(errorLikeCompatible, 'expected promise to be rejected with #{exp} but it was rejected with #{act}', 'expected promise not to be rejected with #{exp} but it was rejected ' + 'with #{act}', errorLikeName, reasonName);
|
|
4280
|
+
}
|
|
4281
|
+
if (errMsgMatcher) {
|
|
4282
|
+
this.assert(errMsgMatcherCompatible, `expected promise to be rejected with an error ${matcherRelation} #{exp} but got ` + `#{act}`, `expected promise not to be rejected with an error ${matcherRelation} #{exp}`, errMsgMatcher, checkError.getMessage(reason));
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
return reason;
|
|
4286
|
+
});
|
|
4287
|
+
transferPromiseness(this, derivedPromise);
|
|
4288
|
+
return this;
|
|
4289
|
+
});
|
|
4290
|
+
property('eventually', function() {
|
|
4291
|
+
utils.flag(this, 'eventually', true);
|
|
4292
|
+
return this;
|
|
4293
|
+
});
|
|
4294
|
+
method('notify', function(done) {
|
|
4295
|
+
doNotify(getBasePromise(this), done);
|
|
4296
|
+
return this;
|
|
4297
|
+
});
|
|
4298
|
+
method('become', function(value, message) {
|
|
4299
|
+
return this.eventually.deep.equal(value, message);
|
|
4300
|
+
});
|
|
4301
|
+
const methodNames = propertyNames.filter((name)=>{
|
|
4302
|
+
return name !== 'assert' && typeof propertyDescs[name].value === 'function';
|
|
4303
|
+
});
|
|
4304
|
+
methodNames.forEach((methodName)=>{
|
|
4305
|
+
Assertion.overwriteMethod(methodName, (originalMethod)=>function() {
|
|
4306
|
+
return doAsserterAsyncAndAddThen(originalMethod, this, arguments);
|
|
4307
|
+
});
|
|
4308
|
+
});
|
|
4309
|
+
const getterNames = propertyNames.filter((name)=>{
|
|
4310
|
+
return name !== '_obj' && typeof propertyDescs[name].get === 'function';
|
|
4311
|
+
});
|
|
4312
|
+
getterNames.forEach((getterName)=>{
|
|
4313
|
+
const isChainableMethod = Object.prototype.hasOwnProperty.call(Assertion.prototype.__methods, getterName);
|
|
4314
|
+
if (isChainableMethod) {
|
|
4315
|
+
Assertion.overwriteChainableMethod(getterName, (originalMethod)=>function() {
|
|
4316
|
+
return doAsserterAsyncAndAddThen(originalMethod, this, arguments);
|
|
4317
|
+
}, (originalGetter)=>function() {
|
|
4318
|
+
return doAsserterAsyncAndAddThen(originalGetter, this);
|
|
4319
|
+
});
|
|
4320
|
+
} else {
|
|
4321
|
+
Assertion.overwriteProperty(getterName, (originalGetter)=>function() {
|
|
4322
|
+
return proxifyIfSupported(doAsserterAsyncAndAddThen(originalGetter, this));
|
|
4323
|
+
});
|
|
4324
|
+
}
|
|
4325
|
+
});
|
|
4326
|
+
function doAsserterAsyncAndAddThen(asserter, assertion, args) {
|
|
4327
|
+
if (!utils.flag(assertion, 'eventually')) {
|
|
4328
|
+
asserter.apply(assertion, args);
|
|
4329
|
+
return assertion;
|
|
4330
|
+
}
|
|
4331
|
+
const derivedPromise = getBasePromise(assertion).then((value)=>{
|
|
4332
|
+
assertion._obj = value;
|
|
4333
|
+
utils.flag(assertion, 'eventually', false);
|
|
4334
|
+
return args ? transformAsserterArgs(args) : args;
|
|
4335
|
+
}).then((newArgs)=>{
|
|
4336
|
+
asserter.apply(assertion, newArgs);
|
|
4337
|
+
return assertion._obj;
|
|
4338
|
+
});
|
|
4339
|
+
transferPromiseness(assertion, derivedPromise);
|
|
4340
|
+
return assertion;
|
|
4341
|
+
}
|
|
4342
|
+
const originalAssertMethods = Object.getOwnPropertyNames(assert).filter((propName)=>{
|
|
4343
|
+
return typeof assert[propName] === 'function';
|
|
4344
|
+
});
|
|
4345
|
+
assert.isFulfilled = (promise, message)=>new Assertion(promise, message).to.be.fulfilled;
|
|
4346
|
+
assert.isRejected = (promise, errorLike, errMsgMatcher, message)=>{
|
|
4347
|
+
const assertion = new Assertion(promise, message);
|
|
4348
|
+
return assertion.to.be.rejectedWith(errorLike, errMsgMatcher, message);
|
|
4349
|
+
};
|
|
4350
|
+
assert.becomes = (promise, value, message)=>assert.eventually.deepEqual(promise, value, message);
|
|
4351
|
+
assert.doesNotBecome = (promise, value, message)=>assert.eventually.notDeepEqual(promise, value, message);
|
|
4352
|
+
assert.eventually = {};
|
|
4353
|
+
originalAssertMethods.forEach((assertMethodName)=>{
|
|
4354
|
+
assert.eventually[assertMethodName] = function(promise) {
|
|
4355
|
+
const otherArgs = Array.prototype.slice.call(arguments, 1);
|
|
4356
|
+
let customRejectionHandler;
|
|
4357
|
+
const message = arguments[assert[assertMethodName].length - 1];
|
|
4358
|
+
if (typeof message === 'string') {
|
|
4359
|
+
customRejectionHandler = (reason)=>{
|
|
4360
|
+
throw new chai.AssertionError(`${message}\n\nOriginal reason: ${utils.inspect(reason)}`);
|
|
4361
|
+
};
|
|
4362
|
+
}
|
|
4363
|
+
const returnedPromise = promise.then((fulfillmentValue)=>assert[assertMethodName].apply(assert, [
|
|
4364
|
+
fulfillmentValue
|
|
4365
|
+
].concat(otherArgs)), customRejectionHandler);
|
|
4366
|
+
returnedPromise.notify = (done)=>{
|
|
4367
|
+
doNotify(returnedPromise, done);
|
|
4368
|
+
};
|
|
4369
|
+
return returnedPromise;
|
|
4370
|
+
};
|
|
4371
|
+
});
|
|
4372
|
+
}
|
|
4373
|
+
function defaultTransferPromiseness(assertion, promise) {
|
|
4374
|
+
assertion.then = promise.then.bind(promise);
|
|
4375
|
+
}
|
|
4376
|
+
function defaultTransformAsserterArgs(values) {
|
|
4377
|
+
return values;
|
|
4378
|
+
}
|
|
4379
|
+
function transferPromiseness(assertion, promise) {
|
|
4380
|
+
{
|
|
4381
|
+
defaultTransferPromiseness(assertion, promise);
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
function transformAsserterArgs(values) {
|
|
4385
|
+
return defaultTransformAsserterArgs(values);
|
|
4386
|
+
}
|
|
4387
|
+
const echo$1 = async (api)=>{
|
|
4388
|
+
expect(await api.echo({
|
|
4389
|
+
foo: "bar"
|
|
4390
|
+
})).to.deep.equal({
|
|
4391
|
+
foo: "bar"
|
|
4392
|
+
});
|
|
4393
|
+
};
|
|
4394
|
+
const add$1 = async (api)=>{
|
|
4395
|
+
expect(await api.add(5, 3)).to.equal(8);
|
|
4396
|
+
};
|
|
4397
|
+
const mathMultiply$1 = async (api)=>{
|
|
4398
|
+
expect(await api.math.multiply(6, 7)).to.equal(42);
|
|
4399
|
+
};
|
|
4400
|
+
const mathDivide$1 = async (api)=>{
|
|
4401
|
+
expect(await api.math.divide(100, 4)).to.equal(25);
|
|
4402
|
+
};
|
|
4403
|
+
const createCallback$1 = async (api)=>{
|
|
4404
|
+
const callback = await api.createCallback();
|
|
4405
|
+
expect(await callback()).to.equal(42);
|
|
4406
|
+
};
|
|
4407
|
+
const callWithCallback$1 = async (api)=>{
|
|
4408
|
+
expect(await api.callWithCallback(()=>123)).to.equal(123);
|
|
4409
|
+
};
|
|
4410
|
+
const getDate$1 = async (api)=>{
|
|
4411
|
+
const date = await api.getDate();
|
|
4412
|
+
expect(date).to.be.instanceOf(Date);
|
|
4413
|
+
expect(Date.now() - date.getTime()).to.be.lessThan(6e4);
|
|
4414
|
+
};
|
|
4415
|
+
const getError$1 = async (api)=>{
|
|
4416
|
+
const error = await api.getError();
|
|
4417
|
+
expect(error).to.be.instanceOf(Error);
|
|
4418
|
+
expect(error.message).to.equal("Test error");
|
|
4419
|
+
};
|
|
4420
|
+
const throwError$1 = async (api)=>{
|
|
4421
|
+
await expect(api.throwError()).to.be.rejected;
|
|
4422
|
+
};
|
|
4423
|
+
const processBuffer$1 = async (api)=>{
|
|
4424
|
+
const result = await api.processBuffer(new Uint8Array([
|
|
4425
|
+
1,
|
|
4426
|
+
2,
|
|
4427
|
+
3,
|
|
4428
|
+
4
|
|
4429
|
+
]));
|
|
4430
|
+
expect(result).to.be.instanceOf(Uint8Array);
|
|
4431
|
+
expect(Array.from(result)).to.deep.equal([
|
|
4432
|
+
2,
|
|
4433
|
+
4,
|
|
4434
|
+
6,
|
|
4435
|
+
8
|
|
4436
|
+
]);
|
|
4437
|
+
};
|
|
4438
|
+
const getBuffer$1 = async (api)=>{
|
|
4439
|
+
const buffer = await api.getBuffer();
|
|
4440
|
+
expect(buffer).to.be.instanceOf(ArrayBuffer);
|
|
4441
|
+
expect(buffer.byteLength).to.equal(16);
|
|
4442
|
+
};
|
|
4443
|
+
const getPromise$1 = async (api)=>{
|
|
4444
|
+
const result = await api.getPromise();
|
|
4445
|
+
expect(result instanceof Promise ? await result : result).to.equal(123);
|
|
4446
|
+
};
|
|
4447
|
+
const getStream$1 = async (api)=>{
|
|
4448
|
+
const stream = await api.getStream();
|
|
4449
|
+
expect(stream).to.be.instanceOf(ReadableStream);
|
|
4450
|
+
const reader = stream.getReader();
|
|
4451
|
+
const chunks = [];
|
|
4452
|
+
while(true){
|
|
4453
|
+
const { done, value } = await reader.read();
|
|
4454
|
+
if (done) break;
|
|
4455
|
+
chunks.push(value);
|
|
4456
|
+
}
|
|
4457
|
+
expect(chunks.length).to.equal(2);
|
|
4458
|
+
expect(Array.from(chunks[0])).to.deep.equal([
|
|
4459
|
+
1,
|
|
4460
|
+
2,
|
|
4461
|
+
3
|
|
4462
|
+
]);
|
|
4463
|
+
expect(Array.from(chunks[1])).to.deep.equal([
|
|
4464
|
+
4,
|
|
4465
|
+
5,
|
|
4466
|
+
6
|
|
4467
|
+
]);
|
|
4468
|
+
};
|
|
4469
|
+
const base = {
|
|
4470
|
+
echo: echo$1,
|
|
4471
|
+
add: add$1,
|
|
4472
|
+
mathMultiply: mathMultiply$1,
|
|
4473
|
+
mathDivide: mathDivide$1,
|
|
4474
|
+
createCallback: createCallback$1,
|
|
4475
|
+
callWithCallback: callWithCallback$1,
|
|
4476
|
+
getDate: getDate$1,
|
|
4477
|
+
getError: getError$1,
|
|
4478
|
+
throwError: throwError$1,
|
|
4479
|
+
processBuffer: processBuffer$1,
|
|
4480
|
+
getBuffer: getBuffer$1,
|
|
4481
|
+
getPromise: getPromise$1,
|
|
4482
|
+
getStream: getStream$1
|
|
4483
|
+
};
|
|
4484
|
+
use(chaiAsPromised);
|
|
4485
|
+
let api$1;
|
|
4486
|
+
const setApi = (newApi)=>{
|
|
4487
|
+
api$1 = newApi;
|
|
4488
|
+
};
|
|
4489
|
+
const echo = ()=>base.echo(api$1);
|
|
4490
|
+
const add = ()=>base.add(api$1);
|
|
4491
|
+
const mathMultiply = ()=>base.mathMultiply(api$1);
|
|
4492
|
+
const mathDivide = ()=>base.mathDivide(api$1);
|
|
4493
|
+
const createCallback = ()=>base.createCallback(api$1);
|
|
4494
|
+
const callWithCallback = ()=>base.callWithCallback(api$1);
|
|
4495
|
+
const getDate = ()=>base.getDate(api$1);
|
|
4496
|
+
const getError = ()=>base.getError(api$1);
|
|
4497
|
+
const throwError = ()=>base.throwError(api$1);
|
|
4498
|
+
const processBuffer = ()=>base.processBuffer(api$1);
|
|
4499
|
+
const getBuffer = ()=>base.getBuffer(api$1);
|
|
4500
|
+
const getPromise = ()=>base.getPromise(api$1);
|
|
4501
|
+
const getStream = ()=>base.getStream(api$1);
|
|
4502
|
+
const contentTests = Object.freeze(Object.defineProperty({
|
|
4503
|
+
__proto__: null,
|
|
4504
|
+
add,
|
|
4505
|
+
callWithCallback,
|
|
4506
|
+
createCallback,
|
|
4507
|
+
echo,
|
|
4508
|
+
getBuffer,
|
|
4509
|
+
getDate,
|
|
4510
|
+
getError,
|
|
4511
|
+
getPromise,
|
|
4512
|
+
getStream,
|
|
4513
|
+
mathDivide,
|
|
4514
|
+
mathMultiply,
|
|
4515
|
+
processBuffer,
|
|
4516
|
+
setApi,
|
|
4517
|
+
throwError
|
|
4518
|
+
}, Symbol.toStringTag, {
|
|
4519
|
+
value: 'Module'
|
|
4520
|
+
}));
|
|
4521
|
+
const jsonOnlyCapabilities = {
|
|
4522
|
+
jsonOnly: true,
|
|
4523
|
+
messagePort: false,
|
|
4524
|
+
arrayBuffer: false,
|
|
4525
|
+
transferable: false,
|
|
4526
|
+
transferableStream: false
|
|
4527
|
+
};
|
|
4528
|
+
const port = chrome.runtime.connect({
|
|
4529
|
+
name: `content-${Date.now()}`
|
|
4530
|
+
});
|
|
4531
|
+
const api = await expose({}, {
|
|
4532
|
+
transport: {
|
|
4533
|
+
isJson: true,
|
|
4534
|
+
emit: port,
|
|
4535
|
+
receive: port
|
|
4536
|
+
},
|
|
4537
|
+
platformCapabilities: jsonOnlyCapabilities
|
|
4538
|
+
});
|
|
4539
|
+
setApi(api);
|
|
4540
|
+
const tests = {
|
|
4541
|
+
Content: contentTests
|
|
4542
|
+
};
|
|
4543
|
+
globalThis.tests = tests;
|
|
4544
|
+
const findTest = (path, key)=>{
|
|
4545
|
+
const obj = path.reduce((obj2, k)=>obj2?.[k], tests);
|
|
4546
|
+
return obj?.[key];
|
|
4547
|
+
};
|
|
4548
|
+
window.addEventListener("message", async (event)=>{
|
|
4549
|
+
if (event.source !== window) return;
|
|
4550
|
+
if (event.data?.type === "OSRA_RUN_TEST") {
|
|
4551
|
+
const { key, path, id } = event.data;
|
|
4552
|
+
try {
|
|
4553
|
+
const test = findTest(path, key);
|
|
4554
|
+
if (!test) {
|
|
4555
|
+
throw new Error(`Test not found: ${[
|
|
4556
|
+
...path,
|
|
4557
|
+
key
|
|
4558
|
+
].join(".")}`);
|
|
4559
|
+
}
|
|
4560
|
+
await test();
|
|
4561
|
+
window.postMessage({
|
|
4562
|
+
type: "OSRA_TEST_RESULT",
|
|
4563
|
+
id,
|
|
4564
|
+
success: true
|
|
4565
|
+
}, "*");
|
|
4566
|
+
} catch (error) {
|
|
4567
|
+
window.postMessage({
|
|
4568
|
+
type: "OSRA_TEST_RESULT",
|
|
4569
|
+
id,
|
|
4570
|
+
success: false,
|
|
4571
|
+
error: error instanceof Error ? error.message : String(error)
|
|
4572
|
+
}, "*");
|
|
4573
|
+
}
|
|
4574
|
+
}
|
|
4575
|
+
if (event.data?.type === "OSRA_PING") {
|
|
4576
|
+
window.postMessage({
|
|
4577
|
+
type: "OSRA_PONG"
|
|
4578
|
+
}, "*");
|
|
4579
|
+
}
|
|
4580
|
+
});
|
|
4581
|
+
window.postMessage({
|
|
4582
|
+
type: "OSRA_CONTENT_READY"
|
|
4583
|
+
}, "*");
|
|
4584
|
+
console.log("content script");
|
|
4585
|
+
})();
|