@locustjs/test 1.6.3 → 2.0.0
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 +16 -4
- package/dist/index.js +1569 -1765
- package/package.json +37 -39
- package/rollup.config.js +7 -0
- package/src/Expect.js +1204 -0
- package/src/Test.js +88 -0
- package/src/TestException.js +5 -0
- package/src/TestRunner.js +331 -0
- package/src/index.js +5 -1594
- package/tests/index.js +1 -1
- package/.babelrc +0 -3
package/dist/index.js
CHANGED
|
@@ -1,1767 +1,1571 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
3
|
+
var base = require('@locustjs/base');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var exception = require('@locustjs/exception');
|
|
7
|
+
|
|
8
|
+
class TestException extends exception.Exception {}
|
|
9
|
+
|
|
10
|
+
class Expect {
|
|
11
|
+
constructor(value) {
|
|
12
|
+
this.value = value;
|
|
13
|
+
this._expected = false;
|
|
14
|
+
}
|
|
15
|
+
get expected() {
|
|
16
|
+
return this._expected;
|
|
17
|
+
}
|
|
18
|
+
toBe(value) {
|
|
19
|
+
this._expected = true;
|
|
20
|
+
|
|
21
|
+
if (this.value === value) ; else {
|
|
22
|
+
throw new TestException({
|
|
23
|
+
message: `${this.value} is not equal to ${value}`,
|
|
24
|
+
code: 1000,
|
|
25
|
+
status: "not-eq",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
notToBe(value) {
|
|
32
|
+
this._expected = true;
|
|
33
|
+
|
|
34
|
+
if (this.value === value) {
|
|
35
|
+
throw new TestException({
|
|
36
|
+
message: `${value} is equal to ${this.value}`,
|
|
37
|
+
code: 1005,
|
|
38
|
+
status: "eq",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
toBeGt(value) {
|
|
45
|
+
this._expected = true;
|
|
46
|
+
|
|
47
|
+
if (this.value <= value) {
|
|
48
|
+
throw new TestException({
|
|
49
|
+
message: `${this.value} is not greater than ${value}`,
|
|
50
|
+
code: 1001,
|
|
51
|
+
status: "lte",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
toBeGreaterThan(value) {
|
|
58
|
+
return this.toBeGt(value);
|
|
59
|
+
}
|
|
60
|
+
toBeGte(value) {
|
|
61
|
+
this._expected = true;
|
|
62
|
+
|
|
63
|
+
if (this.value < value) {
|
|
64
|
+
throw new TestException({
|
|
65
|
+
message: `${this.value} is not greater than or equal to ${value}`,
|
|
66
|
+
code: 1002,
|
|
67
|
+
status: "lt",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
toBeGreaterThanOrEqualTo(value) {
|
|
74
|
+
return this.toBeGte(value);
|
|
75
|
+
}
|
|
76
|
+
toBeLt(value) {
|
|
77
|
+
this._expected = true;
|
|
78
|
+
|
|
79
|
+
if (this.value >= value) {
|
|
80
|
+
throw new TestException({
|
|
81
|
+
message: `${this.value} is not less than ${value}`,
|
|
82
|
+
code: 1003,
|
|
83
|
+
status: "gte",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
toBeLowerThan(value) {
|
|
90
|
+
return this.toBeLt(value);
|
|
91
|
+
}
|
|
92
|
+
toBeLte(value) {
|
|
93
|
+
this._expected = true;
|
|
94
|
+
|
|
95
|
+
if (this.value > value) {
|
|
96
|
+
throw new TestException({
|
|
97
|
+
message: `${this.value} is not less than or equal to ${value}`,
|
|
98
|
+
code: 1004,
|
|
99
|
+
status: "gt",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
toBeLowerThanOrEqualTo(value) {
|
|
106
|
+
return this.toBeLte(value);
|
|
107
|
+
}
|
|
108
|
+
toBeBetween(n, m) {
|
|
109
|
+
this._expected = true;
|
|
110
|
+
|
|
111
|
+
if (!(this.value >= n && this.value < m)) {
|
|
112
|
+
throw new TestException({
|
|
113
|
+
message: `${this.value} is not between ${n} and ${m}`,
|
|
114
|
+
code: 1024,
|
|
115
|
+
status: "between",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
notToBeBetween(n, m) {
|
|
122
|
+
this._expected = true;
|
|
123
|
+
|
|
124
|
+
if (this.value >= n && this.value < m) {
|
|
125
|
+
throw new TestException({
|
|
126
|
+
message: `${this.value} is between ${n} and ${m}`,
|
|
127
|
+
code: 1044,
|
|
128
|
+
status: "not-between",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
toBeOfType(type) {
|
|
135
|
+
this._expected = true;
|
|
136
|
+
|
|
137
|
+
if (typeof this.value !== type) {
|
|
138
|
+
throw new TestException({
|
|
139
|
+
message: `${this.value} is not of type ${type}`,
|
|
140
|
+
code: 1025,
|
|
141
|
+
status: "of-type",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
notToBeOfType(type) {
|
|
148
|
+
this._expected = true;
|
|
149
|
+
|
|
150
|
+
if (typeof this.value === type) {
|
|
151
|
+
throw new TestException({
|
|
152
|
+
message: `${this.value} is of type ${type}`,
|
|
153
|
+
code: 1045,
|
|
154
|
+
status: "not-oftype",
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
toBeString() {
|
|
161
|
+
this._expected = true;
|
|
162
|
+
|
|
163
|
+
if (!base.isString(this.value)) {
|
|
164
|
+
throw new TestException({
|
|
165
|
+
message: `${this.value} is not string`,
|
|
166
|
+
code: 1026,
|
|
167
|
+
status: "is-string",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
notToBeString() {
|
|
174
|
+
this._expected = true;
|
|
175
|
+
|
|
176
|
+
if (base.isString(this.value)) {
|
|
177
|
+
throw new TestException({
|
|
178
|
+
message: `${this.value} is string`,
|
|
179
|
+
code: 1046,
|
|
180
|
+
status: "not-is-string",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
toBeSomeString() {
|
|
187
|
+
this._expected = true;
|
|
188
|
+
if (!base.isSomeString(this.value)) {
|
|
189
|
+
throw new TestException({
|
|
190
|
+
message: `${this.value} is not some string`,
|
|
191
|
+
code: 1027,
|
|
192
|
+
status: "is-some-string",
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
notToBeSomeString() {
|
|
199
|
+
this._expected = true;
|
|
200
|
+
|
|
201
|
+
if (base.isSomeString(this.value)) {
|
|
202
|
+
throw new TestException({
|
|
203
|
+
message: `${this.value} is some string`,
|
|
204
|
+
code: 1047,
|
|
205
|
+
status: "not-is-some-string",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
toBeNumber() {
|
|
212
|
+
this._expected = true;
|
|
213
|
+
|
|
214
|
+
if (!base.isNumber(this.value)) {
|
|
215
|
+
throw new TestException({
|
|
216
|
+
message: `${this.value} is not number`,
|
|
217
|
+
code: 1028,
|
|
218
|
+
status: "is-number",
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
notToBeNumber() {
|
|
225
|
+
this._expected = true;
|
|
226
|
+
|
|
227
|
+
if (base.isNumber(this.value)) {
|
|
228
|
+
throw new TestException({
|
|
229
|
+
message: `${this.value} is number`,
|
|
230
|
+
code: 1048,
|
|
231
|
+
status: "not-is-number",
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
toBeDate() {
|
|
238
|
+
this._expected = true;
|
|
239
|
+
|
|
240
|
+
if (!base.isDate(this.value)) {
|
|
241
|
+
throw new TestException({
|
|
242
|
+
message: `${this.value} is not date`,
|
|
243
|
+
code: 1029,
|
|
244
|
+
status: "is-date",
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
notToBeDate() {
|
|
251
|
+
this._expected = true;
|
|
252
|
+
|
|
253
|
+
if (base.isDate(this.value)) {
|
|
254
|
+
throw new TestException({
|
|
255
|
+
message: `${this.value} is date`,
|
|
256
|
+
code: 1049,
|
|
257
|
+
status: "not-is-date",
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
toBeBool() {
|
|
264
|
+
this._expected = true;
|
|
265
|
+
|
|
266
|
+
if (!base.isBool(this.value)) {
|
|
267
|
+
throw new TestException({
|
|
268
|
+
message: `${this.value} is not bool`,
|
|
269
|
+
code: 1030,
|
|
270
|
+
status: "is-bool",
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
notToBeBool() {
|
|
277
|
+
this._expected = true;
|
|
278
|
+
|
|
279
|
+
if (base.isBool(this.value)) {
|
|
280
|
+
throw new TestException({
|
|
281
|
+
message: `${this.value} is bool`,
|
|
282
|
+
code: 1050,
|
|
283
|
+
status: "not-is-bool",
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
toBeBasicType() {
|
|
290
|
+
this._expected = true;
|
|
291
|
+
|
|
292
|
+
if (!base.isBasic(this.value)) {
|
|
293
|
+
throw new TestException({
|
|
294
|
+
message: `${this.value} is not basic type`,
|
|
295
|
+
code: 1031,
|
|
296
|
+
status: "is-basic-type",
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
notToBeBasicType() {
|
|
303
|
+
this._expected = true;
|
|
304
|
+
|
|
305
|
+
if (base.isBasic(this.value)) {
|
|
306
|
+
throw new TestException({
|
|
307
|
+
message: `${this.value} is basic type`,
|
|
308
|
+
code: 1051,
|
|
309
|
+
status: "not-is-basic-type",
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
toBePrimitive() {
|
|
316
|
+
this._expected = true;
|
|
317
|
+
|
|
318
|
+
if (!base.isPrimitive(this.value)) {
|
|
319
|
+
throw new TestException({
|
|
320
|
+
message: `${this.value} is not primitive type`,
|
|
321
|
+
code: 1032,
|
|
322
|
+
status: "is-primitive",
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return this;
|
|
327
|
+
}
|
|
328
|
+
notToBePrimitive() {
|
|
329
|
+
this._expected = true;
|
|
330
|
+
|
|
331
|
+
if (base.isPrimitive(this.value)) {
|
|
332
|
+
throw new TestException({
|
|
333
|
+
message: `${this.value} is primitive type`,
|
|
334
|
+
code: 1052,
|
|
335
|
+
status: "not-is-primitive",
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return this;
|
|
340
|
+
}
|
|
341
|
+
toBeEmpty() {
|
|
342
|
+
this._expected = true;
|
|
343
|
+
|
|
344
|
+
if (!base.isEmpty(this.value)) {
|
|
345
|
+
throw new TestException({
|
|
346
|
+
message: `${this.value} is not empty`,
|
|
347
|
+
code: 1033,
|
|
348
|
+
status: "is-empty",
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
notToBeEmpty() {
|
|
355
|
+
this._expected = true;
|
|
356
|
+
|
|
357
|
+
if (base.isEmpty(this.value)) {
|
|
358
|
+
throw new TestException({
|
|
359
|
+
message: `${this.value} is empty`,
|
|
360
|
+
code: 1053,
|
|
361
|
+
status: "not-is-empty",
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return this;
|
|
366
|
+
}
|
|
367
|
+
toBeObject() {
|
|
368
|
+
this._expected = true;
|
|
369
|
+
|
|
370
|
+
if (!base.isObject(this.value)) {
|
|
371
|
+
throw new TestException({
|
|
372
|
+
message: `${this.value} is not object`,
|
|
373
|
+
code: 1034,
|
|
374
|
+
status: "is-object",
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
notToBeObject() {
|
|
381
|
+
this._expected = true;
|
|
382
|
+
|
|
383
|
+
if (base.isObject(this.value)) {
|
|
384
|
+
throw new TestException({
|
|
385
|
+
message: `${this.value} is object`,
|
|
386
|
+
code: 1054,
|
|
387
|
+
status: "not-is-object",
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
toBeSomeObject() {
|
|
394
|
+
this._expected = true;
|
|
395
|
+
|
|
396
|
+
if (!base.isSomeObject(this.value)) {
|
|
397
|
+
throw new TestException({
|
|
398
|
+
message: `${this.value} is not some object`,
|
|
399
|
+
code: 1035,
|
|
400
|
+
status: "is-some-object",
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
notToBeSomeObject() {
|
|
407
|
+
this._expected = true;
|
|
408
|
+
|
|
409
|
+
if (base.isSomeObject(this.value)) {
|
|
410
|
+
throw new TestException({
|
|
411
|
+
message: `${this.value} is some object`,
|
|
412
|
+
code: 1055,
|
|
413
|
+
status: "not-is-some-object",
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
419
|
+
toBeFunction() {
|
|
420
|
+
this._expected = true;
|
|
421
|
+
|
|
422
|
+
if (!base.isFunction(this.value)) {
|
|
423
|
+
throw new TestException({
|
|
424
|
+
message: `${this.value} is not function`,
|
|
425
|
+
code: 1036,
|
|
426
|
+
status: "is-function",
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
notToBeFunction() {
|
|
433
|
+
this._expected = true;
|
|
434
|
+
|
|
435
|
+
if (base.isFunction(this.value)) {
|
|
436
|
+
throw new TestException({
|
|
437
|
+
message: `${this.value} is function`,
|
|
438
|
+
code: 1056,
|
|
439
|
+
status: "not-is-function",
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
toBeNumeric() {
|
|
446
|
+
this._expected = true;
|
|
447
|
+
|
|
448
|
+
if (!base.isNumeric(this.value)) {
|
|
449
|
+
throw new TestException({
|
|
450
|
+
message: `${this.value} is not numeric`,
|
|
451
|
+
code: 1037,
|
|
452
|
+
status: "is-numeric",
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return this;
|
|
457
|
+
}
|
|
458
|
+
notToBeNumeric() {
|
|
459
|
+
this._expected = true;
|
|
460
|
+
|
|
461
|
+
if (base.isNumeric(this.value)) {
|
|
462
|
+
throw new TestException({
|
|
463
|
+
message: `${this.value} is numeric`,
|
|
464
|
+
code: 1057,
|
|
465
|
+
status: "not-is-numeric",
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return this;
|
|
470
|
+
}
|
|
471
|
+
toBeArray() {
|
|
472
|
+
this._expected = true;
|
|
473
|
+
|
|
474
|
+
if (!base.isArray(this.value)) {
|
|
475
|
+
throw new TestException({
|
|
476
|
+
message: `${this.value} is not array`,
|
|
477
|
+
code: 1038,
|
|
478
|
+
status: "is-array",
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
notToBeArray() {
|
|
485
|
+
this._expected = true;
|
|
486
|
+
|
|
487
|
+
if (base.isArray(this.value)) {
|
|
488
|
+
throw new TestException({
|
|
489
|
+
message: `${this.value} is array`,
|
|
490
|
+
code: 1058,
|
|
491
|
+
status: "not-is-array",
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return this;
|
|
496
|
+
}
|
|
497
|
+
toBeSomeArray() {
|
|
498
|
+
this._expected = true;
|
|
499
|
+
|
|
500
|
+
if (!base.isSomeArray(this.value)) {
|
|
501
|
+
throw new TestException({
|
|
502
|
+
message: `${this.value} is not some array`,
|
|
503
|
+
code: 1039,
|
|
504
|
+
status: "is-some-array",
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return this;
|
|
509
|
+
}
|
|
510
|
+
notToBeSomeArray() {
|
|
511
|
+
this._expected = true;
|
|
512
|
+
|
|
513
|
+
if (!base.isArray(this.value)) {
|
|
514
|
+
throw new TestException({
|
|
515
|
+
message: `${this.value} is not array`,
|
|
516
|
+
code: 1068,
|
|
517
|
+
status: "is-not-array",
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
if (this.value.length) {
|
|
521
|
+
throw new TestException({
|
|
522
|
+
message: `${this.value} is array`,
|
|
523
|
+
code: 1069,
|
|
524
|
+
status: "is-some-array",
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
return this;
|
|
529
|
+
}
|
|
530
|
+
toBeIterable() {
|
|
531
|
+
this._expected = true;
|
|
532
|
+
|
|
533
|
+
if (!base.isIterable(this.value)) {
|
|
534
|
+
throw new TestException({
|
|
535
|
+
message: `${this.value} is not iterable`,
|
|
536
|
+
code: 1040,
|
|
537
|
+
status: "is-iterable",
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return this;
|
|
542
|
+
}
|
|
543
|
+
notToBeIterable() {
|
|
544
|
+
this._expected = true;
|
|
545
|
+
|
|
546
|
+
if (base.isIterable(this.value)) {
|
|
547
|
+
throw new TestException({
|
|
548
|
+
message: `${this.value} is iterable`,
|
|
549
|
+
code: 1060,
|
|
550
|
+
status: "not-iterable",
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return this;
|
|
555
|
+
}
|
|
556
|
+
toBeSubClassOf(type) {
|
|
557
|
+
this._expected = true;
|
|
558
|
+
|
|
559
|
+
if (!base.isSubClassOf(this.value, type)) {
|
|
560
|
+
throw new TestException({
|
|
561
|
+
message: `${this.value} is not subclass of ${type}`,
|
|
562
|
+
code: 1041,
|
|
563
|
+
status: "is-subclass-of",
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
569
|
+
notToBeSubClassOf(type) {
|
|
570
|
+
this._expected = true;
|
|
571
|
+
|
|
572
|
+
if (base.isSubClassOf(this.value, type)) {
|
|
573
|
+
throw new TestException({
|
|
574
|
+
message: `${this.value} is subclass of ${type}`,
|
|
575
|
+
code: 1061,
|
|
576
|
+
status: "not-subclassof",
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return this;
|
|
581
|
+
}
|
|
582
|
+
toBeInstanceOf(type) {
|
|
583
|
+
this._expected = true;
|
|
584
|
+
|
|
585
|
+
if (!(this.value instanceof type)) {
|
|
586
|
+
throw new TestException({
|
|
587
|
+
message: `${this.value} is not instance of ${type}`,
|
|
588
|
+
code: 1042,
|
|
589
|
+
status: "instanceof",
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
return this;
|
|
594
|
+
}
|
|
595
|
+
notToBeInstanceOf(type) {
|
|
596
|
+
this._expected = true;
|
|
597
|
+
|
|
598
|
+
if (this.value instanceof type) {
|
|
599
|
+
throw new TestException({
|
|
600
|
+
message: `${this.value} is instance of ${type}`,
|
|
601
|
+
code: 1062,
|
|
602
|
+
status: "not-instanceof",
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return this;
|
|
607
|
+
}
|
|
608
|
+
toMatch(pattern, flags) {
|
|
609
|
+
this._expected = true;
|
|
610
|
+
|
|
611
|
+
const r = new RegExp(pattern, flags);
|
|
612
|
+
|
|
613
|
+
if (!r.test(this.value)) {
|
|
614
|
+
throw new TestException({
|
|
615
|
+
message: `${this.value} does not match ${pattern}`,
|
|
616
|
+
code: 1043,
|
|
617
|
+
status: "match",
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return this;
|
|
622
|
+
}
|
|
623
|
+
notToMatch(pattern, flags) {
|
|
624
|
+
this._expected = true;
|
|
625
|
+
|
|
626
|
+
const r = new RegExp(pattern, flags);
|
|
627
|
+
|
|
628
|
+
if (r.test(this.value)) {
|
|
629
|
+
throw new TestException({
|
|
630
|
+
message: `${this.value} matches ${pattern}`,
|
|
631
|
+
code: 1070,
|
|
632
|
+
status: "match",
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return this;
|
|
637
|
+
}
|
|
638
|
+
doesNotMatch(pattern, flags) {
|
|
639
|
+
this._expected = true;
|
|
640
|
+
|
|
641
|
+
const r = new RegExp(pattern, flags);
|
|
642
|
+
|
|
643
|
+
if (r.test(this.value)) {
|
|
644
|
+
throw new TestException({
|
|
645
|
+
message: `${this.value} matches ${pattern}`,
|
|
646
|
+
code: 1063,
|
|
647
|
+
status: "not-match",
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
toBeDefined() {
|
|
654
|
+
this._expected = true;
|
|
655
|
+
|
|
656
|
+
if (this.value === undefined) {
|
|
657
|
+
throw new TestException({
|
|
658
|
+
message: `value is undefined`,
|
|
659
|
+
code: 1006,
|
|
660
|
+
status: "undefined",
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
notToBeDefined() {
|
|
667
|
+
this._expected = true;
|
|
668
|
+
|
|
669
|
+
if (this.value !== undefined) {
|
|
670
|
+
throw new TestException({
|
|
671
|
+
message: `value is defined`,
|
|
672
|
+
code: 1071,
|
|
673
|
+
status: "defined",
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return this;
|
|
678
|
+
}
|
|
679
|
+
toBeUndefined() {
|
|
680
|
+
this._expected = true;
|
|
681
|
+
|
|
682
|
+
if (this.value !== undefined) {
|
|
683
|
+
throw new TestException({
|
|
684
|
+
message: `value is defined`,
|
|
685
|
+
code: 1007,
|
|
686
|
+
status: "defined",
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return this;
|
|
691
|
+
}
|
|
692
|
+
notToBeUndefined() {
|
|
693
|
+
this._expected = true;
|
|
694
|
+
|
|
695
|
+
if (this.value === undefined) {
|
|
696
|
+
throw new TestException({
|
|
697
|
+
message: `value is undefined`,
|
|
698
|
+
code: 1072,
|
|
699
|
+
status: "undefined",
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
return this;
|
|
704
|
+
}
|
|
705
|
+
toBeNull() {
|
|
706
|
+
this._expected = true;
|
|
707
|
+
|
|
708
|
+
if (this.value !== null) {
|
|
709
|
+
throw new TestException({
|
|
710
|
+
message: `value is not null`,
|
|
711
|
+
code: 1008,
|
|
712
|
+
status: "not-null",
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
return this;
|
|
717
|
+
}
|
|
718
|
+
notToBeNull() {
|
|
719
|
+
this._expected = true;
|
|
720
|
+
|
|
721
|
+
if (this.value === null) {
|
|
722
|
+
throw new TestException({
|
|
723
|
+
message: `value is null`,
|
|
724
|
+
code: 1009,
|
|
725
|
+
status: "null",
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
return this;
|
|
730
|
+
}
|
|
731
|
+
toBeNullOrUndefined() {
|
|
732
|
+
this._expected = true;
|
|
733
|
+
|
|
734
|
+
if (this.value == null) ; else {
|
|
735
|
+
throw new TestException({
|
|
736
|
+
message: `value is not null/undefined`,
|
|
737
|
+
code: 1010,
|
|
738
|
+
status: "not-null-or-undefined",
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
return this;
|
|
743
|
+
}
|
|
744
|
+
notToBeNullOrUndefined() {
|
|
745
|
+
this._expected = true;
|
|
746
|
+
|
|
747
|
+
if (this.value == null) {
|
|
748
|
+
throw new TestException({
|
|
749
|
+
message: `value is null/undefined`,
|
|
750
|
+
code: 1011,
|
|
751
|
+
status: "null-or-undefined",
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
return this;
|
|
756
|
+
}
|
|
757
|
+
toBeEmptyArray() {
|
|
758
|
+
this._expected = true;
|
|
759
|
+
|
|
760
|
+
if (base.isSomeArray(this.value)) {
|
|
761
|
+
throw new TestException({
|
|
762
|
+
message: `${this.value} is some array`,
|
|
763
|
+
code: 1059,
|
|
764
|
+
status: "to-be-empty-array",
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return this;
|
|
769
|
+
}
|
|
770
|
+
toBeValid(fnValidation) {
|
|
771
|
+
this._expected = true;
|
|
772
|
+
|
|
773
|
+
if (!base.isFunction(fnValidation)) {
|
|
774
|
+
throw new TestException({
|
|
775
|
+
message: `fnValidation is not function`,
|
|
776
|
+
code: 1064,
|
|
777
|
+
status: "to-be-valid",
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
if (!fnValidation(this.value)) {
|
|
781
|
+
throw new TestException({
|
|
782
|
+
message: `${this.value} is not valid`,
|
|
783
|
+
code: 1065,
|
|
784
|
+
status: "to-be-valid",
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
return this;
|
|
789
|
+
}
|
|
790
|
+
notToBeValid(fnValidation) {
|
|
791
|
+
this._expected = true;
|
|
792
|
+
|
|
793
|
+
if (!base.isFunction(fnValidation)) {
|
|
794
|
+
throw new TestException({
|
|
795
|
+
message: `fnValidation is not function`,
|
|
796
|
+
code: 1066,
|
|
797
|
+
status: "not-to-be-valid",
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
if (fnValidation(this.value)) {
|
|
801
|
+
throw new TestException({
|
|
802
|
+
message: `${this.value} is valid`,
|
|
803
|
+
code: 1067,
|
|
804
|
+
status: "not-to-be-valid",
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
return this;
|
|
809
|
+
}
|
|
810
|
+
toThrow(ex, shape = false, strict = false) {
|
|
811
|
+
this._expected = true;
|
|
812
|
+
|
|
813
|
+
if (!base.isFunction(this.value)) {
|
|
814
|
+
throw new TestException({
|
|
815
|
+
message: `given argument is not a function.`,
|
|
816
|
+
code: 1012,
|
|
817
|
+
status: "not-func",
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
let ok = false;
|
|
822
|
+
|
|
823
|
+
try {
|
|
824
|
+
this.value();
|
|
825
|
+
|
|
826
|
+
ok = true;
|
|
827
|
+
} catch (e) {
|
|
828
|
+
if (ex !== undefined) {
|
|
829
|
+
if (base.isPrimitive(ex)) {
|
|
830
|
+
if (e !== ex) {
|
|
831
|
+
throw new TestException({
|
|
832
|
+
message: `given function threw incorrect error.`,
|
|
833
|
+
code: 1018,
|
|
834
|
+
status: "incorrect-throw-error",
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
} else if (base.isFunction(ex)) {
|
|
838
|
+
if (!(e instanceof ex)) {
|
|
839
|
+
throw new TestException({
|
|
840
|
+
message: `given function threw incorrect instance.`,
|
|
841
|
+
code: 1019,
|
|
842
|
+
status: "incorrect-throw-instance",
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
} else if (base.isObject(ex)) {
|
|
846
|
+
if (shape) {
|
|
847
|
+
if (!base.equals(e, ex, strict)) {
|
|
848
|
+
throw new TestException({
|
|
849
|
+
message: `given function threw incorrect object shape.`,
|
|
850
|
+
code: 1020,
|
|
851
|
+
status: "incorrect-throw-shape",
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
} else {
|
|
855
|
+
if (e !== ex) {
|
|
856
|
+
throw new TestException({
|
|
857
|
+
message: `given function threw incorrect object.`,
|
|
858
|
+
code: 1021,
|
|
859
|
+
status: "incorrect-throw-object",
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
if (e !== ex) {
|
|
865
|
+
throw new TestException({
|
|
866
|
+
message: `given function threw incorrect value.`,
|
|
867
|
+
code: 1022,
|
|
868
|
+
status: "incorrect-throw-value",
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
} else {
|
|
873
|
+
ok = false;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if (ok) {
|
|
878
|
+
throw new TestException({
|
|
879
|
+
message: `given function ran without throwing any errors.`,
|
|
880
|
+
code: 1013,
|
|
881
|
+
status: "ran-to-completion",
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
return this;
|
|
886
|
+
}
|
|
887
|
+
notToThrow(ex, shape = false, strict = false) {
|
|
888
|
+
this._expected = true;
|
|
889
|
+
|
|
890
|
+
if (!base.isFunction(this.value)) {
|
|
891
|
+
throw new TestException({
|
|
892
|
+
message: `given argument is not a function.`,
|
|
893
|
+
code: 1012,
|
|
894
|
+
status: "not-func",
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
let ok = true;
|
|
899
|
+
let error;
|
|
900
|
+
|
|
901
|
+
try {
|
|
902
|
+
this.value();
|
|
903
|
+
|
|
904
|
+
ok = false;
|
|
905
|
+
} catch (e) {
|
|
906
|
+
error = e;
|
|
907
|
+
|
|
908
|
+
if (ex !== undefined) {
|
|
909
|
+
if (base.isPrimitive(ex)) {
|
|
910
|
+
if (e === ex) {
|
|
911
|
+
throw new TestException({
|
|
912
|
+
message: `given function threw incorrect error.`,
|
|
913
|
+
code: 1018,
|
|
914
|
+
status: "incorrect-throw-error",
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
} else if (base.isFunction(ex)) {
|
|
918
|
+
if (e instanceof ex) {
|
|
919
|
+
throw new TestException({
|
|
920
|
+
message: `given function threw incorrect instance.`,
|
|
921
|
+
code: 1019,
|
|
922
|
+
status: "incorrect-throw-instance",
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
} else if (base.isObject(ex)) {
|
|
926
|
+
if (shape) {
|
|
927
|
+
if (base.equals(e, ex, strict)) {
|
|
928
|
+
throw new TestException({
|
|
929
|
+
message: `given function threw incorrect object shape.`,
|
|
930
|
+
code: 1020,
|
|
931
|
+
status: "incorrect-throw-shape",
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
if (e === ex) {
|
|
936
|
+
throw new TestException({
|
|
937
|
+
message: `given function threw incorrect object.`,
|
|
938
|
+
code: 1021,
|
|
939
|
+
status: "incorrect-throw-object",
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
} else {
|
|
944
|
+
if (e === ex) {
|
|
945
|
+
throw new TestException({
|
|
946
|
+
message: `given function threw incorrect value.`,
|
|
947
|
+
code: 1022,
|
|
948
|
+
status: "incorrect-throw-value",
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
} else {
|
|
953
|
+
ok = true;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
if (ok) {
|
|
958
|
+
throw new TestException({
|
|
959
|
+
message: `given function threw an error.`,
|
|
960
|
+
code: 1014,
|
|
961
|
+
status: "ran-to-error",
|
|
962
|
+
innerException: error,
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
return this;
|
|
967
|
+
}
|
|
968
|
+
async toThrowAsync(ex, shape = false, strict = false) {
|
|
969
|
+
this._expected = true;
|
|
970
|
+
|
|
971
|
+
if (!base.isFunction(this.value)) {
|
|
972
|
+
throw new TestException({
|
|
973
|
+
message: `given argument is not a function.`,
|
|
974
|
+
code: 1012,
|
|
975
|
+
status: "not-func",
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
let ok = false;
|
|
980
|
+
|
|
981
|
+
try {
|
|
982
|
+
await this.value();
|
|
983
|
+
|
|
984
|
+
ok = true;
|
|
985
|
+
} catch (e) {
|
|
986
|
+
if (ex !== undefined) {
|
|
987
|
+
if (base.isPrimitive(ex)) {
|
|
988
|
+
if (e !== ex) {
|
|
989
|
+
throw new TestException({
|
|
990
|
+
message: `given function threw incorrect error.`,
|
|
991
|
+
code: 1018,
|
|
992
|
+
status: "incorrect-throw-error",
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
} else if (base.isFunction(ex)) {
|
|
996
|
+
if (!(e instanceof ex)) {
|
|
997
|
+
throw new TestException({
|
|
998
|
+
message: `given function threw incorrect instance.`,
|
|
999
|
+
code: 1019,
|
|
1000
|
+
status: "incorrect-throw-instance",
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
} else if (base.isObject(ex)) {
|
|
1004
|
+
if (shape) {
|
|
1005
|
+
if (!base.equals(e, ex, strict)) {
|
|
1006
|
+
throw new TestException({
|
|
1007
|
+
message: `given function threw incorrect object shape.`,
|
|
1008
|
+
code: 1020,
|
|
1009
|
+
status: "incorrect-throw-shape",
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
} else {
|
|
1013
|
+
if (e !== ex) {
|
|
1014
|
+
throw new TestException({
|
|
1015
|
+
message: `given function threw incorrect object.`,
|
|
1016
|
+
code: 1021,
|
|
1017
|
+
status: "incorrect-throw-object",
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
} else {
|
|
1022
|
+
if (e !== ex) {
|
|
1023
|
+
throw new TestException({
|
|
1024
|
+
message: `given function threw incorrect value.`,
|
|
1025
|
+
code: 1022,
|
|
1026
|
+
status: "incorrect-throw-value",
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
} else {
|
|
1031
|
+
ok = false;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
if (ok) {
|
|
1036
|
+
throw new TestException({
|
|
1037
|
+
message: `given function ran without throwing any errors.`,
|
|
1038
|
+
code: 1013,
|
|
1039
|
+
status: "ran-to-completion",
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
return this;
|
|
1044
|
+
}
|
|
1045
|
+
async notToThrowAsync(ex, shape = false, strict = false) {
|
|
1046
|
+
this._expected = true;
|
|
1047
|
+
|
|
1048
|
+
if (!base.isFunction(this.value)) {
|
|
1049
|
+
throw new TestException({
|
|
1050
|
+
message: `given argument is not a function.`,
|
|
1051
|
+
code: 1012,
|
|
1052
|
+
status: "not-func",
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
let ok = true;
|
|
1057
|
+
let error;
|
|
1058
|
+
|
|
1059
|
+
try {
|
|
1060
|
+
await this.value();
|
|
1061
|
+
|
|
1062
|
+
ok = false;
|
|
1063
|
+
} catch (e) {
|
|
1064
|
+
error = e;
|
|
1065
|
+
|
|
1066
|
+
if (ex !== undefined) {
|
|
1067
|
+
if (base.isPrimitive(ex)) {
|
|
1068
|
+
if (e === ex) {
|
|
1069
|
+
throw new TestException({
|
|
1070
|
+
message: `given function threw incorrect error.`,
|
|
1071
|
+
code: 1018,
|
|
1072
|
+
status: "incorrect-throw-error",
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
} else if (base.isFunction(ex)) {
|
|
1076
|
+
if (e instanceof ex) {
|
|
1077
|
+
throw new TestException({
|
|
1078
|
+
message: `given function threw incorrect instance.`,
|
|
1079
|
+
code: 1019,
|
|
1080
|
+
status: "incorrect-throw-instance",
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
} else if (base.isObject(ex)) {
|
|
1084
|
+
if (shape) {
|
|
1085
|
+
if (base.equals(e, ex, strict)) {
|
|
1086
|
+
throw new TestException({
|
|
1087
|
+
message: `given function threw incorrect object shape.`,
|
|
1088
|
+
code: 1020,
|
|
1089
|
+
status: "incorrect-throw-shape",
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
} else {
|
|
1093
|
+
if (e === ex) {
|
|
1094
|
+
throw new TestException({
|
|
1095
|
+
message: `given function threw incorrect object.`,
|
|
1096
|
+
code: 1021,
|
|
1097
|
+
status: "incorrect-throw-object",
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
} else {
|
|
1102
|
+
if (e === ex) {
|
|
1103
|
+
throw new TestException({
|
|
1104
|
+
message: `given function threw incorrect value.`,
|
|
1105
|
+
code: 1022,
|
|
1106
|
+
status: "incorrect-throw-value",
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
} else {
|
|
1111
|
+
ok = true;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (ok) {
|
|
1116
|
+
throw new TestException({
|
|
1117
|
+
message: `given function threw an error.`,
|
|
1118
|
+
code: 1014,
|
|
1119
|
+
status: "ran-to-error",
|
|
1120
|
+
innerException: error,
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
return this;
|
|
1125
|
+
}
|
|
1126
|
+
toBeTruthy() {
|
|
1127
|
+
this._expected = true;
|
|
1128
|
+
|
|
1129
|
+
if (this.value) ; else {
|
|
1130
|
+
throw new TestException({
|
|
1131
|
+
message: `${this.value} is not truthy`,
|
|
1132
|
+
code: 1015,
|
|
1133
|
+
status: "not-truthy",
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
return this;
|
|
1138
|
+
}
|
|
1139
|
+
toBeTrue() {
|
|
1140
|
+
return this.toBeTruthy();
|
|
1141
|
+
}
|
|
1142
|
+
toBeFalsy() {
|
|
1143
|
+
this._expected = true;
|
|
1144
|
+
|
|
1145
|
+
if (!this.value) ; else {
|
|
1146
|
+
throw new TestException({
|
|
1147
|
+
message: `${this.value} is not falsy`,
|
|
1148
|
+
code: 1016,
|
|
1149
|
+
status: "not-falsy",
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
return this;
|
|
1154
|
+
}
|
|
1155
|
+
toBeFalse() {
|
|
1156
|
+
return this.toBeFalsy();
|
|
1157
|
+
}
|
|
1158
|
+
toBeNaN() {
|
|
1159
|
+
this._expected = true;
|
|
1160
|
+
|
|
1161
|
+
if (isNaN(this.value)) ; else {
|
|
1162
|
+
throw new TestException({
|
|
1163
|
+
message: `${this.value} is not NaN`,
|
|
1164
|
+
code: 1017,
|
|
1165
|
+
status: "not-nan",
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
return this;
|
|
1170
|
+
}
|
|
1171
|
+
notToBeNaN() {
|
|
1172
|
+
this._expected = true;
|
|
1173
|
+
|
|
1174
|
+
if (!isNaN(this.value)) ; else {
|
|
1175
|
+
throw new TestException({
|
|
1176
|
+
message: `${this.value} is NaN`,
|
|
1177
|
+
code: 1023,
|
|
1178
|
+
status: "is-nan",
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
return this;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
class Test {
|
|
1187
|
+
constructor(name, fn) {
|
|
1188
|
+
this.name = name;
|
|
1189
|
+
this.fn = fn;
|
|
1190
|
+
}
|
|
1191
|
+
run() {
|
|
1192
|
+
return new Promise((res) => {
|
|
1193
|
+
const start = new Date();
|
|
1194
|
+
|
|
1195
|
+
if (base.isFunction(this.fn)) {
|
|
1196
|
+
const _expect = new Expect();
|
|
1197
|
+
|
|
1198
|
+
try {
|
|
1199
|
+
const _result = this.fn((x) => {
|
|
1200
|
+
_expect.value = x;
|
|
1201
|
+
|
|
1202
|
+
return _expect;
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
if (_result && base.isFunction(_result.then)) {
|
|
1206
|
+
_result
|
|
1207
|
+
.then((result) => {
|
|
1208
|
+
res({
|
|
1209
|
+
success: true,
|
|
1210
|
+
test: this.name,
|
|
1211
|
+
result,
|
|
1212
|
+
time: new Date() - start,
|
|
1213
|
+
expected: _expect.expected,
|
|
1214
|
+
});
|
|
1215
|
+
})
|
|
1216
|
+
.catch((ex) => {
|
|
1217
|
+
res({
|
|
1218
|
+
success: false,
|
|
1219
|
+
test: this.name,
|
|
1220
|
+
time: new Date() - start,
|
|
1221
|
+
expected: _expect.expected,
|
|
1222
|
+
err: new TestException({
|
|
1223
|
+
message: `test '${this.name}' failed.`,
|
|
1224
|
+
code: 501,
|
|
1225
|
+
status: "failed",
|
|
1226
|
+
innerException: ex,
|
|
1227
|
+
}),
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1230
|
+
} else {
|
|
1231
|
+
res({
|
|
1232
|
+
success: true,
|
|
1233
|
+
test: this.name,
|
|
1234
|
+
time: new Date() - start,
|
|
1235
|
+
result: _result,
|
|
1236
|
+
expected: _expect.expected,
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
} catch (ex) {
|
|
1240
|
+
res({
|
|
1241
|
+
success: false,
|
|
1242
|
+
test: this.name,
|
|
1243
|
+
time: new Date() - start,
|
|
1244
|
+
expected: _expect.expected,
|
|
1245
|
+
err: new TestException({
|
|
1246
|
+
message: `test '${this.name}' failed.`,
|
|
1247
|
+
code: 501,
|
|
1248
|
+
status: "failed",
|
|
1249
|
+
innerException: ex,
|
|
1250
|
+
}),
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
} else {
|
|
1254
|
+
res({
|
|
1255
|
+
success: false,
|
|
1256
|
+
test: this.name,
|
|
1257
|
+
time: new Date() - start,
|
|
1258
|
+
err: new TestException({
|
|
1259
|
+
message: `test '${this.name}' does not have a function to be called.`,
|
|
1260
|
+
code: 500,
|
|
1261
|
+
status: "no-func",
|
|
1262
|
+
}),
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
41
1267
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
message
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
this.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
this.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}, {
|
|
347
|
-
key: "toBeBasicType",
|
|
348
|
-
value: function toBeBasicType() {
|
|
349
|
-
this._expected = true;
|
|
350
|
-
if (!(0, _base.isBasic)(this.value)) {
|
|
351
|
-
throw new TestException({
|
|
352
|
-
message: "".concat(this.value, " is not basic type"),
|
|
353
|
-
code: 1031,
|
|
354
|
-
status: "is-basic-type"
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
return this;
|
|
358
|
-
}
|
|
359
|
-
}, {
|
|
360
|
-
key: "notToBeBasicType",
|
|
361
|
-
value: function notToBeBasicType() {
|
|
362
|
-
this._expected = true;
|
|
363
|
-
if ((0, _base.isBasic)(this.value)) {
|
|
364
|
-
throw new TestException({
|
|
365
|
-
message: "".concat(this.value, " is basic type"),
|
|
366
|
-
code: 1051,
|
|
367
|
-
status: "not-is-basic-type"
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
return this;
|
|
371
|
-
}
|
|
372
|
-
}, {
|
|
373
|
-
key: "toBePrimitive",
|
|
374
|
-
value: function toBePrimitive() {
|
|
375
|
-
this._expected = true;
|
|
376
|
-
if (!(0, _base.isPrimitive)(this.value)) {
|
|
377
|
-
throw new TestException({
|
|
378
|
-
message: "".concat(this.value, " is not primitive type"),
|
|
379
|
-
code: 1032,
|
|
380
|
-
status: "is-primitive"
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
return this;
|
|
384
|
-
}
|
|
385
|
-
}, {
|
|
386
|
-
key: "notToBePrimitive",
|
|
387
|
-
value: function notToBePrimitive() {
|
|
388
|
-
this._expected = true;
|
|
389
|
-
if ((0, _base.isPrimitive)(this.value)) {
|
|
390
|
-
throw new TestException({
|
|
391
|
-
message: "".concat(this.value, " is primitive type"),
|
|
392
|
-
code: 1052,
|
|
393
|
-
status: "not-is-primitive"
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
return this;
|
|
397
|
-
}
|
|
398
|
-
}, {
|
|
399
|
-
key: "toBeEmpty",
|
|
400
|
-
value: function toBeEmpty() {
|
|
401
|
-
this._expected = true;
|
|
402
|
-
if (!(0, _base.isEmpty)(this.value)) {
|
|
403
|
-
throw new TestException({
|
|
404
|
-
message: "".concat(this.value, " is not empty"),
|
|
405
|
-
code: 1033,
|
|
406
|
-
status: "is-empty"
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
return this;
|
|
410
|
-
}
|
|
411
|
-
}, {
|
|
412
|
-
key: "notToBeEmpty",
|
|
413
|
-
value: function notToBeEmpty() {
|
|
414
|
-
this._expected = true;
|
|
415
|
-
if ((0, _base.isEmpty)(this.value)) {
|
|
416
|
-
throw new TestException({
|
|
417
|
-
message: "".concat(this.value, " is empty"),
|
|
418
|
-
code: 1053,
|
|
419
|
-
status: "not-is-empty"
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
return this;
|
|
423
|
-
}
|
|
424
|
-
}, {
|
|
425
|
-
key: "toBeObject",
|
|
426
|
-
value: function toBeObject() {
|
|
427
|
-
this._expected = true;
|
|
428
|
-
if (!(0, _base.isObject)(this.value)) {
|
|
429
|
-
throw new TestException({
|
|
430
|
-
message: "".concat(this.value, " is not object"),
|
|
431
|
-
code: 1034,
|
|
432
|
-
status: "is-object"
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
return this;
|
|
436
|
-
}
|
|
437
|
-
}, {
|
|
438
|
-
key: "notToBeObject",
|
|
439
|
-
value: function notToBeObject() {
|
|
440
|
-
this._expected = true;
|
|
441
|
-
if ((0, _base.isObject)(this.value)) {
|
|
442
|
-
throw new TestException({
|
|
443
|
-
message: "".concat(this.value, " is object"),
|
|
444
|
-
code: 1054,
|
|
445
|
-
status: "not-is-object"
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
return this;
|
|
449
|
-
}
|
|
450
|
-
}, {
|
|
451
|
-
key: "toBeSomeObject",
|
|
452
|
-
value: function toBeSomeObject() {
|
|
453
|
-
this._expected = true;
|
|
454
|
-
if (!(0, _base.isSomeObject)(this.value)) {
|
|
455
|
-
throw new TestException({
|
|
456
|
-
message: "".concat(this.value, " is not some object"),
|
|
457
|
-
code: 1035,
|
|
458
|
-
status: "is-some-object"
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
return this;
|
|
462
|
-
}
|
|
463
|
-
}, {
|
|
464
|
-
key: "notToBeSomeObject",
|
|
465
|
-
value: function notToBeSomeObject() {
|
|
466
|
-
this._expected = true;
|
|
467
|
-
if ((0, _base.isSomeObject)(this.value)) {
|
|
468
|
-
throw new TestException({
|
|
469
|
-
message: "".concat(this.value, " is some object"),
|
|
470
|
-
code: 1055,
|
|
471
|
-
status: "not-is-some-object"
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
return this;
|
|
475
|
-
}
|
|
476
|
-
}, {
|
|
477
|
-
key: "toBeFunction",
|
|
478
|
-
value: function toBeFunction() {
|
|
479
|
-
this._expected = true;
|
|
480
|
-
if (!(0, _base.isFunction)(this.value)) {
|
|
481
|
-
throw new TestException({
|
|
482
|
-
message: "".concat(this.value, " is not function"),
|
|
483
|
-
code: 1036,
|
|
484
|
-
status: "is-function"
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
return this;
|
|
488
|
-
}
|
|
489
|
-
}, {
|
|
490
|
-
key: "notToBeFunction",
|
|
491
|
-
value: function notToBeFunction() {
|
|
492
|
-
this._expected = true;
|
|
493
|
-
if ((0, _base.isFunction)(this.value)) {
|
|
494
|
-
throw new TestException({
|
|
495
|
-
message: "".concat(this.value, " is function"),
|
|
496
|
-
code: 1056,
|
|
497
|
-
status: "not-is-function"
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
return this;
|
|
501
|
-
}
|
|
502
|
-
}, {
|
|
503
|
-
key: "toBeNumeric",
|
|
504
|
-
value: function toBeNumeric() {
|
|
505
|
-
this._expected = true;
|
|
506
|
-
if (!(0, _base.isNumeric)(this.value)) {
|
|
507
|
-
throw new TestException({
|
|
508
|
-
message: "".concat(this.value, " is not numeric"),
|
|
509
|
-
code: 1037,
|
|
510
|
-
status: "is-numeric"
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
return this;
|
|
514
|
-
}
|
|
515
|
-
}, {
|
|
516
|
-
key: "notToBeNumeric",
|
|
517
|
-
value: function notToBeNumeric() {
|
|
518
|
-
this._expected = true;
|
|
519
|
-
if ((0, _base.isNumeric)(this.value)) {
|
|
520
|
-
throw new TestException({
|
|
521
|
-
message: "".concat(this.value, " is numeric"),
|
|
522
|
-
code: 1057,
|
|
523
|
-
status: "not-is-numeric"
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
return this;
|
|
527
|
-
}
|
|
528
|
-
}, {
|
|
529
|
-
key: "toBeArray",
|
|
530
|
-
value: function toBeArray() {
|
|
531
|
-
this._expected = true;
|
|
532
|
-
if (!(0, _base.isArray)(this.value)) {
|
|
533
|
-
throw new TestException({
|
|
534
|
-
message: "".concat(this.value, " is not array"),
|
|
535
|
-
code: 1038,
|
|
536
|
-
status: "is-array"
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
return this;
|
|
540
|
-
}
|
|
541
|
-
}, {
|
|
542
|
-
key: "notToBeArray",
|
|
543
|
-
value: function notToBeArray() {
|
|
544
|
-
this._expected = true;
|
|
545
|
-
if ((0, _base.isArray)(this.value)) {
|
|
546
|
-
throw new TestException({
|
|
547
|
-
message: "".concat(this.value, " is array"),
|
|
548
|
-
code: 1058,
|
|
549
|
-
status: "not-is-array"
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
return this;
|
|
553
|
-
}
|
|
554
|
-
}, {
|
|
555
|
-
key: "toBeSomeArray",
|
|
556
|
-
value: function toBeSomeArray() {
|
|
557
|
-
this._expected = true;
|
|
558
|
-
if (!(0, _base.isSomeArray)(this.value)) {
|
|
559
|
-
throw new TestException({
|
|
560
|
-
message: "".concat(this.value, " is not some array"),
|
|
561
|
-
code: 1039,
|
|
562
|
-
status: "is-some-array"
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
return this;
|
|
566
|
-
}
|
|
567
|
-
}, {
|
|
568
|
-
key: "notToBeSomeArray",
|
|
569
|
-
value: function notToBeSomeArray() {
|
|
570
|
-
this._expected = true;
|
|
571
|
-
if (!(0, _base.isArray)(this.value)) {
|
|
572
|
-
throw new TestException({
|
|
573
|
-
message: "".concat(this.value, " is not array"),
|
|
574
|
-
code: 1068,
|
|
575
|
-
status: "is-not-array"
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
if (this.value.length) {
|
|
579
|
-
throw new TestException({
|
|
580
|
-
message: "".concat(this.value, " is array"),
|
|
581
|
-
code: 1069,
|
|
582
|
-
status: "is-some-array"
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
return this;
|
|
586
|
-
}
|
|
587
|
-
}, {
|
|
588
|
-
key: "toBeIterable",
|
|
589
|
-
value: function toBeIterable() {
|
|
590
|
-
this._expected = true;
|
|
591
|
-
if (!(0, _base.isIterable)(this.value)) {
|
|
592
|
-
throw new TestException({
|
|
593
|
-
message: "".concat(this.value, " is not iterable"),
|
|
594
|
-
code: 1040,
|
|
595
|
-
status: "is-iterable"
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
return this;
|
|
599
|
-
}
|
|
600
|
-
}, {
|
|
601
|
-
key: "notToBeIterable",
|
|
602
|
-
value: function notToBeIterable() {
|
|
603
|
-
this._expected = true;
|
|
604
|
-
if ((0, _base.isIterable)(this.value)) {
|
|
605
|
-
throw new TestException({
|
|
606
|
-
message: "".concat(this.value, " is iterable"),
|
|
607
|
-
code: 1060,
|
|
608
|
-
status: "not-iterable"
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
return this;
|
|
612
|
-
}
|
|
613
|
-
}, {
|
|
614
|
-
key: "toBeSubClassOf",
|
|
615
|
-
value: function toBeSubClassOf(type) {
|
|
616
|
-
this._expected = true;
|
|
617
|
-
if (!(0, _base.isSubClassOf)(this.value, type)) {
|
|
618
|
-
throw new TestException({
|
|
619
|
-
message: "".concat(this.value, " is not subclass of ").concat(type),
|
|
620
|
-
code: 1041,
|
|
621
|
-
status: "is-subclass-of"
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
return this;
|
|
625
|
-
}
|
|
626
|
-
}, {
|
|
627
|
-
key: "notToBeSubClassOf",
|
|
628
|
-
value: function notToBeSubClassOf(type) {
|
|
629
|
-
this._expected = true;
|
|
630
|
-
if ((0, _base.isSubClassOf)(this.value, type)) {
|
|
631
|
-
throw new TestException({
|
|
632
|
-
message: "".concat(this.value, " is subclass of ").concat(type),
|
|
633
|
-
code: 1061,
|
|
634
|
-
status: "not-subclassof"
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
return this;
|
|
638
|
-
}
|
|
639
|
-
}, {
|
|
640
|
-
key: "toBeInstanceOf",
|
|
641
|
-
value: function toBeInstanceOf(type) {
|
|
642
|
-
this._expected = true;
|
|
643
|
-
if (!(this.value instanceof type)) {
|
|
644
|
-
throw new TestException({
|
|
645
|
-
message: "".concat(this.value, " is not instance of ").concat(type),
|
|
646
|
-
code: 1042,
|
|
647
|
-
status: "instanceof"
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
return this;
|
|
651
|
-
}
|
|
652
|
-
}, {
|
|
653
|
-
key: "notToBeInstanceOf",
|
|
654
|
-
value: function notToBeInstanceOf(type) {
|
|
655
|
-
this._expected = true;
|
|
656
|
-
if (this.value instanceof type) {
|
|
657
|
-
throw new TestException({
|
|
658
|
-
message: "".concat(this.value, " is instance of ").concat(type),
|
|
659
|
-
code: 1062,
|
|
660
|
-
status: "not-instanceof"
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
return this;
|
|
664
|
-
}
|
|
665
|
-
}, {
|
|
666
|
-
key: "toMatch",
|
|
667
|
-
value: function toMatch(pattern, flags) {
|
|
668
|
-
this._expected = true;
|
|
669
|
-
var r = new RegExp(pattern, flags);
|
|
670
|
-
if (!r.test(this.value)) {
|
|
671
|
-
throw new TestException({
|
|
672
|
-
message: "".concat(this.value, " does not match ").concat(pattern),
|
|
673
|
-
code: 1043,
|
|
674
|
-
status: "match"
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
return this;
|
|
678
|
-
}
|
|
679
|
-
}, {
|
|
680
|
-
key: "notToMatch",
|
|
681
|
-
value: function notToMatch(pattern, flags) {
|
|
682
|
-
this._expected = true;
|
|
683
|
-
var r = new RegExp(pattern, flags);
|
|
684
|
-
if (r.test(this.value)) {
|
|
685
|
-
throw new TestException({
|
|
686
|
-
message: "".concat(this.value, " matches ").concat(pattern),
|
|
687
|
-
code: 1070,
|
|
688
|
-
status: "match"
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
return this;
|
|
692
|
-
}
|
|
693
|
-
}, {
|
|
694
|
-
key: "doesNotMatch",
|
|
695
|
-
value: function doesNotMatch(pattern, flags) {
|
|
696
|
-
this._expected = true;
|
|
697
|
-
var r = new RegExp(pattern, flags);
|
|
698
|
-
if (r.test(this.value)) {
|
|
699
|
-
throw new TestException({
|
|
700
|
-
message: "".concat(this.value, " matches ").concat(pattern),
|
|
701
|
-
code: 1063,
|
|
702
|
-
status: "not-match"
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
return this;
|
|
706
|
-
}
|
|
707
|
-
}, {
|
|
708
|
-
key: "toBeDefined",
|
|
709
|
-
value: function toBeDefined() {
|
|
710
|
-
this._expected = true;
|
|
711
|
-
if (this.value === undefined) {
|
|
712
|
-
throw new TestException({
|
|
713
|
-
message: "value is undefined",
|
|
714
|
-
code: 1006,
|
|
715
|
-
status: "undefined"
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
return this;
|
|
719
|
-
}
|
|
720
|
-
}, {
|
|
721
|
-
key: "notToBeDefined",
|
|
722
|
-
value: function notToBeDefined() {
|
|
723
|
-
this._expected = true;
|
|
724
|
-
if (this.value !== undefined) {
|
|
725
|
-
throw new TestException({
|
|
726
|
-
message: "value is defined",
|
|
727
|
-
code: 1071,
|
|
728
|
-
status: "defined"
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
return this;
|
|
732
|
-
}
|
|
733
|
-
}, {
|
|
734
|
-
key: "toBeUndefined",
|
|
735
|
-
value: function toBeUndefined() {
|
|
736
|
-
this._expected = true;
|
|
737
|
-
if (this.value !== undefined) {
|
|
738
|
-
throw new TestException({
|
|
739
|
-
message: "value is defined",
|
|
740
|
-
code: 1007,
|
|
741
|
-
status: "defined"
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
return this;
|
|
745
|
-
}
|
|
746
|
-
}, {
|
|
747
|
-
key: "notToBeUndefined",
|
|
748
|
-
value: function notToBeUndefined() {
|
|
749
|
-
this._expected = true;
|
|
750
|
-
if (this.value === undefined) {
|
|
751
|
-
throw new TestException({
|
|
752
|
-
message: "value is undefined",
|
|
753
|
-
code: 1072,
|
|
754
|
-
status: "undefined"
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
return this;
|
|
758
|
-
}
|
|
759
|
-
}, {
|
|
760
|
-
key: "toBeNull",
|
|
761
|
-
value: function toBeNull() {
|
|
762
|
-
this._expected = true;
|
|
763
|
-
if (this.value !== null) {
|
|
764
|
-
throw new TestException({
|
|
765
|
-
message: "value is not null",
|
|
766
|
-
code: 1008,
|
|
767
|
-
status: "not-null"
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
return this;
|
|
771
|
-
}
|
|
772
|
-
}, {
|
|
773
|
-
key: "notToBeNull",
|
|
774
|
-
value: function notToBeNull() {
|
|
775
|
-
this._expected = true;
|
|
776
|
-
if (this.value === null) {
|
|
777
|
-
throw new TestException({
|
|
778
|
-
message: "value is null",
|
|
779
|
-
code: 1009,
|
|
780
|
-
status: "null"
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
return this;
|
|
784
|
-
}
|
|
785
|
-
}, {
|
|
786
|
-
key: "toBeNullOrUndefined",
|
|
787
|
-
value: function toBeNullOrUndefined() {
|
|
788
|
-
this._expected = true;
|
|
789
|
-
if (this.value == null) {} else {
|
|
790
|
-
throw new TestException({
|
|
791
|
-
message: "value is not null/undefined",
|
|
792
|
-
code: 1010,
|
|
793
|
-
status: "not-null-or-undefined"
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
return this;
|
|
797
|
-
}
|
|
798
|
-
}, {
|
|
799
|
-
key: "notToBeNullOrUndefined",
|
|
800
|
-
value: function notToBeNullOrUndefined() {
|
|
801
|
-
this._expected = true;
|
|
802
|
-
if (this.value == null) {
|
|
803
|
-
throw new TestException({
|
|
804
|
-
message: "value is null/undefined",
|
|
805
|
-
code: 1011,
|
|
806
|
-
status: "null-or-undefined"
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
return this;
|
|
810
|
-
}
|
|
811
|
-
}, {
|
|
812
|
-
key: "toBeEmptyArray",
|
|
813
|
-
value: function toBeEmptyArray() {
|
|
814
|
-
this._expected = true;
|
|
815
|
-
if ((0, _base.isSomeArray)(this.value)) {
|
|
816
|
-
throw new TestException({
|
|
817
|
-
message: "".concat(this.value, " is some array"),
|
|
818
|
-
code: 1059,
|
|
819
|
-
status: "to-be-empty-array"
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
return this;
|
|
823
|
-
}
|
|
824
|
-
}, {
|
|
825
|
-
key: "toBeValid",
|
|
826
|
-
value: function toBeValid(fnValidation) {
|
|
827
|
-
this._expected = true;
|
|
828
|
-
if (!(0, _base.isFunction)(fnValidation)) {
|
|
829
|
-
throw new TestException({
|
|
830
|
-
message: "fnValidation is not function",
|
|
831
|
-
code: 1064,
|
|
832
|
-
status: "to-be-valid"
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
if (!fnValidation(this.value)) {
|
|
836
|
-
throw new TestException({
|
|
837
|
-
message: "".concat(this.value, " is not valid"),
|
|
838
|
-
code: 1065,
|
|
839
|
-
status: "to-be-valid"
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
return this;
|
|
843
|
-
}
|
|
844
|
-
}, {
|
|
845
|
-
key: "notToBeValid",
|
|
846
|
-
value: function notToBeValid(fnValidation) {
|
|
847
|
-
this._expected = true;
|
|
848
|
-
if (!(0, _base.isFunction)(fnValidation)) {
|
|
849
|
-
throw new TestException({
|
|
850
|
-
message: "fnValidation is not function",
|
|
851
|
-
code: 1066,
|
|
852
|
-
status: "not-to-be-valid"
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
if (fnValidation(this.value)) {
|
|
856
|
-
throw new TestException({
|
|
857
|
-
message: "".concat(this.value, " is valid"),
|
|
858
|
-
code: 1067,
|
|
859
|
-
status: "not-to-be-valid"
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
return this;
|
|
863
|
-
}
|
|
864
|
-
}, {
|
|
865
|
-
key: "toThrow",
|
|
866
|
-
value: function toThrow(ex) {
|
|
867
|
-
var shape = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
868
|
-
var strict = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
869
|
-
this._expected = true;
|
|
870
|
-
if (!(0, _base.isFunction)(this.value)) {
|
|
871
|
-
throw new TestException({
|
|
872
|
-
message: "given argument is not a function.",
|
|
873
|
-
code: 1012,
|
|
874
|
-
status: "not-func"
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
var ok = false;
|
|
878
|
-
try {
|
|
879
|
-
this.value();
|
|
880
|
-
ok = true;
|
|
881
|
-
} catch (e) {
|
|
882
|
-
if (ex !== undefined) {
|
|
883
|
-
if ((0, _base.isPrimitive)(ex)) {
|
|
884
|
-
if (e !== ex) {
|
|
885
|
-
throw new TestException({
|
|
886
|
-
message: "given function threw incorrect error.",
|
|
887
|
-
code: 1018,
|
|
888
|
-
status: "incorrect-throw-error"
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
} else if ((0, _base.isFunction)(ex)) {
|
|
892
|
-
if (!(e instanceof ex)) {
|
|
893
|
-
throw new TestException({
|
|
894
|
-
message: "given function threw incorrect instance.",
|
|
895
|
-
code: 1019,
|
|
896
|
-
status: "incorrect-throw-instance"
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
} else if ((0, _base.isObject)(ex)) {
|
|
900
|
-
if (shape) {
|
|
901
|
-
if (!(0, _base.equals)(e, ex, strict)) {
|
|
902
|
-
throw new TestException({
|
|
903
|
-
message: "given function threw incorrect object shape.",
|
|
904
|
-
code: 1020,
|
|
905
|
-
status: "incorrect-throw-shape"
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
} else {
|
|
909
|
-
if (e !== ex) {
|
|
910
|
-
throw new TestException({
|
|
911
|
-
message: "given function threw incorrect object.",
|
|
912
|
-
code: 1021,
|
|
913
|
-
status: "incorrect-throw-object"
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
} else {
|
|
918
|
-
if (e !== ex) {
|
|
919
|
-
throw new TestException({
|
|
920
|
-
message: "given function threw incorrect value.",
|
|
921
|
-
code: 1022,
|
|
922
|
-
status: "incorrect-throw-value"
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
} else {
|
|
927
|
-
ok = false;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
if (ok) {
|
|
931
|
-
throw new TestException({
|
|
932
|
-
message: "given function ran without throwing any errors.",
|
|
933
|
-
code: 1013,
|
|
934
|
-
status: "ran-to-completion"
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
return this;
|
|
938
|
-
}
|
|
939
|
-
}, {
|
|
940
|
-
key: "notToThrow",
|
|
941
|
-
value: function notToThrow(ex) {
|
|
942
|
-
var shape = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
943
|
-
var strict = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
944
|
-
this._expected = true;
|
|
945
|
-
if (!(0, _base.isFunction)(this.value)) {
|
|
946
|
-
throw new TestException({
|
|
947
|
-
message: "given argument is not a function.",
|
|
948
|
-
code: 1012,
|
|
949
|
-
status: "not-func"
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
var ok = true;
|
|
953
|
-
var error;
|
|
954
|
-
try {
|
|
955
|
-
this.value();
|
|
956
|
-
ok = false;
|
|
957
|
-
} catch (e) {
|
|
958
|
-
error = e;
|
|
959
|
-
if (ex !== undefined) {
|
|
960
|
-
if ((0, _base.isPrimitive)(ex)) {
|
|
961
|
-
if (e === ex) {
|
|
962
|
-
throw new TestException({
|
|
963
|
-
message: "given function threw incorrect error.",
|
|
964
|
-
code: 1018,
|
|
965
|
-
status: "incorrect-throw-error"
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
} else if ((0, _base.isFunction)(ex)) {
|
|
969
|
-
if (e instanceof ex) {
|
|
970
|
-
throw new TestException({
|
|
971
|
-
message: "given function threw incorrect instance.",
|
|
972
|
-
code: 1019,
|
|
973
|
-
status: "incorrect-throw-instance"
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
} else if ((0, _base.isObject)(ex)) {
|
|
977
|
-
if (shape) {
|
|
978
|
-
if ((0, _base.equals)(e, ex, strict)) {
|
|
979
|
-
throw new TestException({
|
|
980
|
-
message: "given function threw incorrect object shape.",
|
|
981
|
-
code: 1020,
|
|
982
|
-
status: "incorrect-throw-shape"
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
} else {
|
|
986
|
-
if (e === ex) {
|
|
987
|
-
throw new TestException({
|
|
988
|
-
message: "given function threw incorrect object.",
|
|
989
|
-
code: 1021,
|
|
990
|
-
status: "incorrect-throw-object"
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
} else {
|
|
995
|
-
if (e === ex) {
|
|
996
|
-
throw new TestException({
|
|
997
|
-
message: "given function threw incorrect value.",
|
|
998
|
-
code: 1022,
|
|
999
|
-
status: "incorrect-throw-value"
|
|
1000
|
-
});
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
} else {
|
|
1004
|
-
ok = true;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
if (ok) {
|
|
1008
|
-
throw new TestException({
|
|
1009
|
-
message: "given function threw an error.",
|
|
1010
|
-
code: 1014,
|
|
1011
|
-
status: "ran-to-error",
|
|
1012
|
-
innerException: error
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
return this;
|
|
1016
|
-
}
|
|
1017
|
-
}, {
|
|
1018
|
-
key: "toThrowAsync",
|
|
1019
|
-
value: function () {
|
|
1020
|
-
var _toThrowAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ex) {
|
|
1021
|
-
var shape,
|
|
1022
|
-
strict,
|
|
1023
|
-
ok,
|
|
1024
|
-
_args = arguments;
|
|
1025
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1026
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1027
|
-
case 0:
|
|
1028
|
-
shape = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
|
|
1029
|
-
strict = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
|
|
1030
|
-
this._expected = true;
|
|
1031
|
-
if ((0, _base.isFunction)(this.value)) {
|
|
1032
|
-
_context.next = 5;
|
|
1033
|
-
break;
|
|
1034
|
-
}
|
|
1035
|
-
throw new TestException({
|
|
1036
|
-
message: "given argument is not a function.",
|
|
1037
|
-
code: 1012,
|
|
1038
|
-
status: "not-func"
|
|
1039
|
-
});
|
|
1040
|
-
case 5:
|
|
1041
|
-
ok = false;
|
|
1042
|
-
_context.prev = 6;
|
|
1043
|
-
_context.next = 9;
|
|
1044
|
-
return this.value();
|
|
1045
|
-
case 9:
|
|
1046
|
-
ok = true;
|
|
1047
|
-
_context.next = 40;
|
|
1048
|
-
break;
|
|
1049
|
-
case 12:
|
|
1050
|
-
_context.prev = 12;
|
|
1051
|
-
_context.t0 = _context["catch"](6);
|
|
1052
|
-
if (!(ex !== undefined)) {
|
|
1053
|
-
_context.next = 39;
|
|
1054
|
-
break;
|
|
1055
|
-
}
|
|
1056
|
-
if (!(0, _base.isPrimitive)(ex)) {
|
|
1057
|
-
_context.next = 20;
|
|
1058
|
-
break;
|
|
1059
|
-
}
|
|
1060
|
-
if (!(_context.t0 !== ex)) {
|
|
1061
|
-
_context.next = 18;
|
|
1062
|
-
break;
|
|
1063
|
-
}
|
|
1064
|
-
throw new TestException({
|
|
1065
|
-
message: "given function threw incorrect error.",
|
|
1066
|
-
code: 1018,
|
|
1067
|
-
status: "incorrect-throw-error"
|
|
1068
|
-
});
|
|
1069
|
-
case 18:
|
|
1070
|
-
_context.next = 37;
|
|
1071
|
-
break;
|
|
1072
|
-
case 20:
|
|
1073
|
-
if (!(0, _base.isFunction)(ex)) {
|
|
1074
|
-
_context.next = 25;
|
|
1075
|
-
break;
|
|
1076
|
-
}
|
|
1077
|
-
if (_context.t0 instanceof ex) {
|
|
1078
|
-
_context.next = 23;
|
|
1079
|
-
break;
|
|
1080
|
-
}
|
|
1081
|
-
throw new TestException({
|
|
1082
|
-
message: "given function threw incorrect instance.",
|
|
1083
|
-
code: 1019,
|
|
1084
|
-
status: "incorrect-throw-instance"
|
|
1085
|
-
});
|
|
1086
|
-
case 23:
|
|
1087
|
-
_context.next = 37;
|
|
1088
|
-
break;
|
|
1089
|
-
case 25:
|
|
1090
|
-
if (!(0, _base.isObject)(ex)) {
|
|
1091
|
-
_context.next = 35;
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
if (!shape) {
|
|
1095
|
-
_context.next = 31;
|
|
1096
|
-
break;
|
|
1097
|
-
}
|
|
1098
|
-
if ((0, _base.equals)(_context.t0, ex, strict)) {
|
|
1099
|
-
_context.next = 29;
|
|
1100
|
-
break;
|
|
1101
|
-
}
|
|
1102
|
-
throw new TestException({
|
|
1103
|
-
message: "given function threw incorrect object shape.",
|
|
1104
|
-
code: 1020,
|
|
1105
|
-
status: "incorrect-throw-shape"
|
|
1106
|
-
});
|
|
1107
|
-
case 29:
|
|
1108
|
-
_context.next = 33;
|
|
1109
|
-
break;
|
|
1110
|
-
case 31:
|
|
1111
|
-
if (!(_context.t0 !== ex)) {
|
|
1112
|
-
_context.next = 33;
|
|
1113
|
-
break;
|
|
1114
|
-
}
|
|
1115
|
-
throw new TestException({
|
|
1116
|
-
message: "given function threw incorrect object.",
|
|
1117
|
-
code: 1021,
|
|
1118
|
-
status: "incorrect-throw-object"
|
|
1119
|
-
});
|
|
1120
|
-
case 33:
|
|
1121
|
-
_context.next = 37;
|
|
1122
|
-
break;
|
|
1123
|
-
case 35:
|
|
1124
|
-
if (!(_context.t0 !== ex)) {
|
|
1125
|
-
_context.next = 37;
|
|
1126
|
-
break;
|
|
1127
|
-
}
|
|
1128
|
-
throw new TestException({
|
|
1129
|
-
message: "given function threw incorrect value.",
|
|
1130
|
-
code: 1022,
|
|
1131
|
-
status: "incorrect-throw-value"
|
|
1132
|
-
});
|
|
1133
|
-
case 37:
|
|
1134
|
-
_context.next = 40;
|
|
1135
|
-
break;
|
|
1136
|
-
case 39:
|
|
1137
|
-
ok = false;
|
|
1138
|
-
case 40:
|
|
1139
|
-
if (!ok) {
|
|
1140
|
-
_context.next = 42;
|
|
1141
|
-
break;
|
|
1142
|
-
}
|
|
1143
|
-
throw new TestException({
|
|
1144
|
-
message: "given function ran without throwing any errors.",
|
|
1145
|
-
code: 1013,
|
|
1146
|
-
status: "ran-to-completion"
|
|
1147
|
-
});
|
|
1148
|
-
case 42:
|
|
1149
|
-
return _context.abrupt("return", this);
|
|
1150
|
-
case 43:
|
|
1151
|
-
case "end":
|
|
1152
|
-
return _context.stop();
|
|
1153
|
-
}
|
|
1154
|
-
}, _callee, this, [[6, 12]]);
|
|
1155
|
-
}));
|
|
1156
|
-
function toThrowAsync(_x) {
|
|
1157
|
-
return _toThrowAsync.apply(this, arguments);
|
|
1158
|
-
}
|
|
1159
|
-
return toThrowAsync;
|
|
1160
|
-
}()
|
|
1161
|
-
}, {
|
|
1162
|
-
key: "notToThrowAsync",
|
|
1163
|
-
value: function () {
|
|
1164
|
-
var _notToThrowAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ex) {
|
|
1165
|
-
var shape,
|
|
1166
|
-
strict,
|
|
1167
|
-
ok,
|
|
1168
|
-
error,
|
|
1169
|
-
_args2 = arguments;
|
|
1170
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1171
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
1172
|
-
case 0:
|
|
1173
|
-
shape = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : false;
|
|
1174
|
-
strict = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
|
|
1175
|
-
this._expected = true;
|
|
1176
|
-
if ((0, _base.isFunction)(this.value)) {
|
|
1177
|
-
_context2.next = 5;
|
|
1178
|
-
break;
|
|
1179
|
-
}
|
|
1180
|
-
throw new TestException({
|
|
1181
|
-
message: "given argument is not a function.",
|
|
1182
|
-
code: 1012,
|
|
1183
|
-
status: "not-func"
|
|
1184
|
-
});
|
|
1185
|
-
case 5:
|
|
1186
|
-
ok = true;
|
|
1187
|
-
_context2.prev = 6;
|
|
1188
|
-
_context2.next = 9;
|
|
1189
|
-
return this.value();
|
|
1190
|
-
case 9:
|
|
1191
|
-
ok = false;
|
|
1192
|
-
_context2.next = 41;
|
|
1193
|
-
break;
|
|
1194
|
-
case 12:
|
|
1195
|
-
_context2.prev = 12;
|
|
1196
|
-
_context2.t0 = _context2["catch"](6);
|
|
1197
|
-
error = _context2.t0;
|
|
1198
|
-
if (!(ex !== undefined)) {
|
|
1199
|
-
_context2.next = 40;
|
|
1200
|
-
break;
|
|
1201
|
-
}
|
|
1202
|
-
if (!(0, _base.isPrimitive)(ex)) {
|
|
1203
|
-
_context2.next = 21;
|
|
1204
|
-
break;
|
|
1205
|
-
}
|
|
1206
|
-
if (!(_context2.t0 === ex)) {
|
|
1207
|
-
_context2.next = 19;
|
|
1208
|
-
break;
|
|
1209
|
-
}
|
|
1210
|
-
throw new TestException({
|
|
1211
|
-
message: "given function threw incorrect error.",
|
|
1212
|
-
code: 1018,
|
|
1213
|
-
status: "incorrect-throw-error"
|
|
1214
|
-
});
|
|
1215
|
-
case 19:
|
|
1216
|
-
_context2.next = 38;
|
|
1217
|
-
break;
|
|
1218
|
-
case 21:
|
|
1219
|
-
if (!(0, _base.isFunction)(ex)) {
|
|
1220
|
-
_context2.next = 26;
|
|
1221
|
-
break;
|
|
1222
|
-
}
|
|
1223
|
-
if (!(_context2.t0 instanceof ex)) {
|
|
1224
|
-
_context2.next = 24;
|
|
1225
|
-
break;
|
|
1226
|
-
}
|
|
1227
|
-
throw new TestException({
|
|
1228
|
-
message: "given function threw incorrect instance.",
|
|
1229
|
-
code: 1019,
|
|
1230
|
-
status: "incorrect-throw-instance"
|
|
1231
|
-
});
|
|
1232
|
-
case 24:
|
|
1233
|
-
_context2.next = 38;
|
|
1234
|
-
break;
|
|
1235
|
-
case 26:
|
|
1236
|
-
if (!(0, _base.isObject)(ex)) {
|
|
1237
|
-
_context2.next = 36;
|
|
1238
|
-
break;
|
|
1239
|
-
}
|
|
1240
|
-
if (!shape) {
|
|
1241
|
-
_context2.next = 32;
|
|
1242
|
-
break;
|
|
1243
|
-
}
|
|
1244
|
-
if (!(0, _base.equals)(_context2.t0, ex, strict)) {
|
|
1245
|
-
_context2.next = 30;
|
|
1246
|
-
break;
|
|
1247
|
-
}
|
|
1248
|
-
throw new TestException({
|
|
1249
|
-
message: "given function threw incorrect object shape.",
|
|
1250
|
-
code: 1020,
|
|
1251
|
-
status: "incorrect-throw-shape"
|
|
1252
|
-
});
|
|
1253
|
-
case 30:
|
|
1254
|
-
_context2.next = 34;
|
|
1255
|
-
break;
|
|
1256
|
-
case 32:
|
|
1257
|
-
if (!(_context2.t0 === ex)) {
|
|
1258
|
-
_context2.next = 34;
|
|
1259
|
-
break;
|
|
1260
|
-
}
|
|
1261
|
-
throw new TestException({
|
|
1262
|
-
message: "given function threw incorrect object.",
|
|
1263
|
-
code: 1021,
|
|
1264
|
-
status: "incorrect-throw-object"
|
|
1265
|
-
});
|
|
1266
|
-
case 34:
|
|
1267
|
-
_context2.next = 38;
|
|
1268
|
-
break;
|
|
1269
|
-
case 36:
|
|
1270
|
-
if (!(_context2.t0 === ex)) {
|
|
1271
|
-
_context2.next = 38;
|
|
1272
|
-
break;
|
|
1273
|
-
}
|
|
1274
|
-
throw new TestException({
|
|
1275
|
-
message: "given function threw incorrect value.",
|
|
1276
|
-
code: 1022,
|
|
1277
|
-
status: "incorrect-throw-value"
|
|
1278
|
-
});
|
|
1279
|
-
case 38:
|
|
1280
|
-
_context2.next = 41;
|
|
1281
|
-
break;
|
|
1282
|
-
case 40:
|
|
1283
|
-
ok = true;
|
|
1284
|
-
case 41:
|
|
1285
|
-
if (!ok) {
|
|
1286
|
-
_context2.next = 43;
|
|
1287
|
-
break;
|
|
1288
|
-
}
|
|
1289
|
-
throw new TestException({
|
|
1290
|
-
message: "given function threw an error.",
|
|
1291
|
-
code: 1014,
|
|
1292
|
-
status: "ran-to-error",
|
|
1293
|
-
innerException: error
|
|
1294
|
-
});
|
|
1295
|
-
case 43:
|
|
1296
|
-
return _context2.abrupt("return", this);
|
|
1297
|
-
case 44:
|
|
1298
|
-
case "end":
|
|
1299
|
-
return _context2.stop();
|
|
1300
|
-
}
|
|
1301
|
-
}, _callee2, this, [[6, 12]]);
|
|
1302
|
-
}));
|
|
1303
|
-
function notToThrowAsync(_x2) {
|
|
1304
|
-
return _notToThrowAsync.apply(this, arguments);
|
|
1305
|
-
}
|
|
1306
|
-
return notToThrowAsync;
|
|
1307
|
-
}()
|
|
1308
|
-
}, {
|
|
1309
|
-
key: "toBeTruthy",
|
|
1310
|
-
value: function toBeTruthy() {
|
|
1311
|
-
this._expected = true;
|
|
1312
|
-
if (this.value) {} else {
|
|
1313
|
-
throw new TestException({
|
|
1314
|
-
message: "".concat(this.value, " is not truthy"),
|
|
1315
|
-
code: 1015,
|
|
1316
|
-
status: "not-truthy"
|
|
1317
|
-
});
|
|
1318
|
-
}
|
|
1319
|
-
return this;
|
|
1320
|
-
}
|
|
1321
|
-
}, {
|
|
1322
|
-
key: "toBeTrue",
|
|
1323
|
-
value: function toBeTrue() {
|
|
1324
|
-
return this.toBeTruthy();
|
|
1325
|
-
}
|
|
1326
|
-
}, {
|
|
1327
|
-
key: "toBeFalsy",
|
|
1328
|
-
value: function toBeFalsy() {
|
|
1329
|
-
this._expected = true;
|
|
1330
|
-
if (!this.value) {} else {
|
|
1331
|
-
throw new TestException({
|
|
1332
|
-
message: "".concat(this.value, " is not falsy"),
|
|
1333
|
-
code: 1016,
|
|
1334
|
-
status: "not-falsy"
|
|
1335
|
-
});
|
|
1336
|
-
}
|
|
1337
|
-
return this;
|
|
1338
|
-
}
|
|
1339
|
-
}, {
|
|
1340
|
-
key: "toBeFalse",
|
|
1341
|
-
value: function toBeFalse() {
|
|
1342
|
-
return this.toBeFalsy();
|
|
1343
|
-
}
|
|
1344
|
-
}, {
|
|
1345
|
-
key: "toBeNaN",
|
|
1346
|
-
value: function toBeNaN() {
|
|
1347
|
-
this._expected = true;
|
|
1348
|
-
if (isNaN(this.value)) {} else {
|
|
1349
|
-
throw new TestException({
|
|
1350
|
-
message: "".concat(this.value, " is not NaN"),
|
|
1351
|
-
code: 1017,
|
|
1352
|
-
status: "not-nan"
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
return this;
|
|
1356
|
-
}
|
|
1357
|
-
}, {
|
|
1358
|
-
key: "notToBeNaN",
|
|
1359
|
-
value: function notToBeNaN() {
|
|
1360
|
-
this._expected = true;
|
|
1361
|
-
if (!isNaN(this.value)) {} else {
|
|
1362
|
-
throw new TestException({
|
|
1363
|
-
message: "".concat(this.value, " is NaN"),
|
|
1364
|
-
code: 1023,
|
|
1365
|
-
status: "is-nan"
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
return this;
|
|
1369
|
-
}
|
|
1370
|
-
}]);
|
|
1371
|
-
}();
|
|
1372
|
-
var Test = exports.Test = /*#__PURE__*/function () {
|
|
1373
|
-
function Test(name, fn) {
|
|
1374
|
-
_classCallCheck(this, Test);
|
|
1375
|
-
this.name = name;
|
|
1376
|
-
this.fn = fn;
|
|
1377
|
-
}
|
|
1378
|
-
return _createClass(Test, [{
|
|
1379
|
-
key: "run",
|
|
1380
|
-
value: function run() {
|
|
1381
|
-
var _this2 = this;
|
|
1382
|
-
return new Promise(function (res) {
|
|
1383
|
-
var start = new Date();
|
|
1384
|
-
if ((0, _base.isFunction)(_this2.fn)) {
|
|
1385
|
-
var _expect = new Expect();
|
|
1386
|
-
try {
|
|
1387
|
-
var _result = _this2.fn(function (x) {
|
|
1388
|
-
_expect.value = x;
|
|
1389
|
-
return _expect;
|
|
1390
|
-
});
|
|
1391
|
-
if (_result && (0, _base.isFunction)(_result.then)) {
|
|
1392
|
-
_result.then(function (result) {
|
|
1393
|
-
res({
|
|
1394
|
-
success: true,
|
|
1395
|
-
test: _this2.name,
|
|
1396
|
-
result: result,
|
|
1397
|
-
time: new Date() - start,
|
|
1398
|
-
expected: _expect.expected
|
|
1399
|
-
});
|
|
1400
|
-
})["catch"](function (ex) {
|
|
1401
|
-
res({
|
|
1402
|
-
success: false,
|
|
1403
|
-
test: _this2.name,
|
|
1404
|
-
time: new Date() - start,
|
|
1405
|
-
expected: _expect.expected,
|
|
1406
|
-
err: new TestException({
|
|
1407
|
-
message: "test '".concat(_this2.name, "' failed."),
|
|
1408
|
-
code: 501,
|
|
1409
|
-
status: "failed",
|
|
1410
|
-
innerException: ex
|
|
1411
|
-
})
|
|
1412
|
-
});
|
|
1413
|
-
});
|
|
1414
|
-
} else {
|
|
1415
|
-
res({
|
|
1416
|
-
success: true,
|
|
1417
|
-
test: _this2.name,
|
|
1418
|
-
time: new Date() - start,
|
|
1419
|
-
result: _result,
|
|
1420
|
-
expected: _expect.expected
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
} catch (ex) {
|
|
1424
|
-
res({
|
|
1425
|
-
success: false,
|
|
1426
|
-
test: _this2.name,
|
|
1427
|
-
time: new Date() - start,
|
|
1428
|
-
expected: _expect.expected,
|
|
1429
|
-
err: new TestException({
|
|
1430
|
-
message: "test '".concat(_this2.name, "' failed."),
|
|
1431
|
-
code: 501,
|
|
1432
|
-
status: "failed",
|
|
1433
|
-
innerException: ex
|
|
1434
|
-
})
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
} else {
|
|
1438
|
-
res({
|
|
1439
|
-
success: false,
|
|
1440
|
-
test: _this2.name,
|
|
1441
|
-
time: new Date() - start,
|
|
1442
|
-
err: new TestException({
|
|
1443
|
-
message: "test '".concat(_this2.name, "' does not have a function to be called."),
|
|
1444
|
-
code: 500,
|
|
1445
|
-
status: "no-func"
|
|
1446
|
-
})
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
});
|
|
1450
|
-
}
|
|
1451
|
-
}]);
|
|
1452
|
-
}();
|
|
1453
|
-
var reset = "\x1b[0m";
|
|
1454
|
-
var bright = "\x1b[1m";
|
|
1455
|
-
var dim = "\x1b[2m";
|
|
1456
|
-
var underscore = "\x1b[4m";
|
|
1457
|
-
var blink = "\x1b[5m";
|
|
1458
|
-
var reverse = "\x1b[7m";
|
|
1459
|
-
var hidden = "\x1b[8m";
|
|
1460
|
-
var fgBlack = "\x1b[30m";
|
|
1461
|
-
var fgRed = "\x1b[31m";
|
|
1462
|
-
var fgGreen = "\x1b[32m";
|
|
1463
|
-
var fgYellow = "\x1b[33m";
|
|
1464
|
-
var fgBlue = "\x1b[34m";
|
|
1465
|
-
var fgMagenta = "\x1b[35m";
|
|
1466
|
-
var fgCyan = "\x1b[36m";
|
|
1467
|
-
var fgWhite = "\x1b[37m";
|
|
1468
|
-
var fgGray = "\x1b[90m";
|
|
1469
|
-
var bgBlack = "\x1b[40m";
|
|
1470
|
-
var bgRed = "\x1b[41m";
|
|
1471
|
-
var bgGreen = "\x1b[42m";
|
|
1472
|
-
var bgYellow = "\x1b[43m";
|
|
1473
|
-
var bgBlue = "\x1b[44m";
|
|
1474
|
-
var bgMagenta = "\x1b[45m";
|
|
1475
|
-
var bgCyan = "\x1b[46m";
|
|
1476
|
-
var bgWhite = "\x1b[47m";
|
|
1477
|
-
var bgGray = "\x1b[100m";
|
|
1478
|
-
var TestRunner = /*#__PURE__*/function () {
|
|
1479
|
-
function TestRunner() {
|
|
1480
|
-
_classCallCheck(this, TestRunner);
|
|
1481
|
-
this._init();
|
|
1482
|
-
}
|
|
1483
|
-
return _createClass(TestRunner, [{
|
|
1484
|
-
key: "_init",
|
|
1485
|
-
value: function _init() {
|
|
1486
|
-
this._passed = 0;
|
|
1487
|
-
this._failed = 0;
|
|
1488
|
-
this._faulted = 0;
|
|
1489
|
-
this._unknown = 0;
|
|
1490
|
-
this._results = [];
|
|
1491
|
-
this._errors = [];
|
|
1492
|
-
}
|
|
1493
|
-
}, {
|
|
1494
|
-
key: "_runSingle",
|
|
1495
|
-
value: function () {
|
|
1496
|
-
var _runSingle2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(test, onProgress, i) {
|
|
1497
|
-
var tr;
|
|
1498
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1499
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
1500
|
-
case 0:
|
|
1501
|
-
if ((0, _base.isFunction)(onProgress)) {
|
|
1502
|
-
try {
|
|
1503
|
-
onProgress({
|
|
1504
|
-
source: this,
|
|
1505
|
-
test: test,
|
|
1506
|
-
index: i
|
|
1507
|
-
});
|
|
1508
|
-
} catch (ex) {
|
|
1509
|
-
this._errors.push({
|
|
1510
|
-
index: i,
|
|
1511
|
-
test: test.name,
|
|
1512
|
-
err: new TestException({
|
|
1513
|
-
message: "onProgress failed for test '".concat(test.name, " at index ").concat(i, "'."),
|
|
1514
|
-
code: 1500,
|
|
1515
|
-
status: "progress-failed",
|
|
1516
|
-
innerException: ex
|
|
1517
|
-
})
|
|
1518
|
-
});
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
_context3.next = 3;
|
|
1522
|
-
return test.run();
|
|
1523
|
-
case 3:
|
|
1524
|
-
tr = _context3.sent;
|
|
1525
|
-
this._results.push(tr);
|
|
1526
|
-
if ((0, _base.isObject)(tr.err)) {
|
|
1527
|
-
if (!tr.expected) {
|
|
1528
|
-
this._faulted++;
|
|
1529
|
-
} else {
|
|
1530
|
-
this._failed++;
|
|
1531
|
-
}
|
|
1532
|
-
} else if (!tr.expected) {
|
|
1533
|
-
this._unknown++;
|
|
1534
|
-
} else if (tr.success) {
|
|
1535
|
-
this._passed++;
|
|
1536
|
-
} else {
|
|
1537
|
-
this._failed++;
|
|
1538
|
-
}
|
|
1539
|
-
case 6:
|
|
1540
|
-
case "end":
|
|
1541
|
-
return _context3.stop();
|
|
1542
|
-
}
|
|
1543
|
-
}, _callee3, this);
|
|
1544
|
-
}));
|
|
1545
|
-
function _runSingle(_x3, _x4, _x5) {
|
|
1546
|
-
return _runSingle2.apply(this, arguments);
|
|
1547
|
-
}
|
|
1548
|
-
return _runSingle;
|
|
1549
|
-
}()
|
|
1550
|
-
}, {
|
|
1551
|
-
key: "result",
|
|
1552
|
-
get: function get() {
|
|
1553
|
-
return {
|
|
1554
|
-
passed: this._passed,
|
|
1555
|
-
failed: this._failed,
|
|
1556
|
-
faulted: this._faulted,
|
|
1557
|
-
results: this._results,
|
|
1558
|
-
errors: this._errors
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
}, {
|
|
1562
|
-
key: "run",
|
|
1563
|
-
value: function run(tests, onProgress) {
|
|
1564
|
-
var _this3 = this;
|
|
1565
|
-
this._init();
|
|
1566
|
-
return new Promise(function (res) {
|
|
1567
|
-
if (tests) {
|
|
1568
|
-
if (tests instanceof Test) {
|
|
1569
|
-
tests = [tests];
|
|
1570
|
-
}
|
|
1571
|
-
if ((0, _base.isArray)(tests)) {
|
|
1572
|
-
var _tests = tests.map(function (test) {
|
|
1573
|
-
var _test = test;
|
|
1574
|
-
if ((0, _base.isArray)(test)) {
|
|
1575
|
-
if (test.length == 2) {
|
|
1576
|
-
_test = new Test(test[0], test[1]);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
return _test;
|
|
1580
|
-
}).filter(function (test) {
|
|
1581
|
-
return test instanceof Test;
|
|
1582
|
-
}).map(function (test, i) {
|
|
1583
|
-
return _this3._runSingle(test, onProgress, i);
|
|
1584
|
-
});
|
|
1585
|
-
Promise.all(_tests).then(function (_) {
|
|
1586
|
-
return res(_this3.result);
|
|
1587
|
-
})["catch"](function (ex) {
|
|
1588
|
-
_this3._errors.push({
|
|
1589
|
-
err: new TestException({
|
|
1590
|
-
message: "not all tests succeeded. check errors.",
|
|
1591
|
-
code: 1503,
|
|
1592
|
-
status: "partial-finished",
|
|
1593
|
-
innerException: ex
|
|
1594
|
-
})
|
|
1595
|
-
});
|
|
1596
|
-
res(_this3.result);
|
|
1597
|
-
});
|
|
1598
|
-
} else {
|
|
1599
|
-
_this3._errors.push({
|
|
1600
|
-
err: new TestException({
|
|
1601
|
-
message: "invalid tests. expected array or a single test.",
|
|
1602
|
-
code: 1502,
|
|
1603
|
-
status: "invalid-tests"
|
|
1604
|
-
})
|
|
1605
|
-
});
|
|
1606
|
-
res(_this3.result);
|
|
1607
|
-
}
|
|
1608
|
-
} else {
|
|
1609
|
-
_this3._errors.push({
|
|
1610
|
-
err: new TestException({
|
|
1611
|
-
message: "no tests given to be ran.",
|
|
1612
|
-
code: 1501,
|
|
1613
|
-
status: "no-tests"
|
|
1614
|
-
})
|
|
1615
|
-
});
|
|
1616
|
-
res(_this3.result);
|
|
1617
|
-
}
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
}, {
|
|
1621
|
-
key: "_getTime",
|
|
1622
|
-
value: function _getTime(time) {
|
|
1623
|
-
return "".concat(time / 1000, " sec");
|
|
1624
|
-
}
|
|
1625
|
-
}, {
|
|
1626
|
-
key: "report",
|
|
1627
|
-
value: function report(detailed) {
|
|
1628
|
-
var _this4 = this;
|
|
1629
|
-
var time = 0;
|
|
1630
|
-
console.log("Finished.\n");
|
|
1631
|
-
var _loop = function _loop() {
|
|
1632
|
-
var testResult = _this4._results[i];
|
|
1633
|
-
var t = "(".concat(_this4._getTime(testResult.time), ")");
|
|
1634
|
-
if (detailed) {
|
|
1635
|
-
var message = "\n" + (i + 1) + ". ";
|
|
1636
|
-
var err = (0, _base.isObject)(testResult.err) ? testResult.err.toString().split("\n") : [];
|
|
1637
|
-
err = err.map(function (msg, i) {
|
|
1638
|
-
return "\t".concat(i == err.length - 1 ? "".concat(fgYellow) : "".concat(fgGray, "error ").concat(testResult.err.code, ": ")).concat(msg).concat(reset);
|
|
1639
|
-
}).join("\n");
|
|
1640
|
-
if ((0, _base.isObject)(testResult.err)) {
|
|
1641
|
-
if (!testResult.expected) {
|
|
1642
|
-
message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgYellow, "faulted").concat(reset, " ").concat(t);
|
|
1643
|
-
message += "\n";
|
|
1644
|
-
message += "".concat(fgGray).concat(err, " ").concat(reset);
|
|
1645
|
-
} else {
|
|
1646
|
-
message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgRed, "failed").concat(reset, " ").concat(t);
|
|
1647
|
-
message += "\n";
|
|
1648
|
-
message += "".concat(fgGray).concat(err, " ").concat(reset);
|
|
1649
|
-
}
|
|
1650
|
-
} else if (!testResult.expected) {
|
|
1651
|
-
message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgMagenta, "expect not used").concat(reset, " ").concat(t);
|
|
1652
|
-
if (testResult.err) {
|
|
1653
|
-
message += "\n";
|
|
1654
|
-
message += "".concat(fgGray).concat(err, " ").concat(reset);
|
|
1655
|
-
}
|
|
1656
|
-
} else if (testResult.success) {
|
|
1657
|
-
message += "".concat(fgWhite).concat(testResult.test, ": ").concat(fgGreen, "passed").concat(reset, " ").concat(t);
|
|
1658
|
-
} else {
|
|
1659
|
-
message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgRed, "failed").concat(reset, " ").concat(t);
|
|
1660
|
-
message += "\n";
|
|
1661
|
-
message += "".concat(fgGray).concat(err, " ").concat(reset);
|
|
1662
|
-
}
|
|
1663
|
-
console.log(message);
|
|
1664
|
-
}
|
|
1665
|
-
time += testResult.time;
|
|
1666
|
-
};
|
|
1667
|
-
for (var i = 0; i < this._results.length; i++) {
|
|
1668
|
-
_loop();
|
|
1669
|
-
}
|
|
1670
|
-
if (detailed && this._errors.length) {
|
|
1671
|
-
console.log("Errors:");
|
|
1672
|
-
var _iterator = _createForOfIteratorHelper(this._errors),
|
|
1673
|
-
_step;
|
|
1674
|
-
try {
|
|
1675
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1676
|
-
var error = _step.value;
|
|
1677
|
-
if (error.index !== undefined) {
|
|
1678
|
-
console.log("".concat(error.index, ". ").concat(error.test, ": ").concat(error.err.innerException.toString()));
|
|
1679
|
-
} else {
|
|
1680
|
-
console.log("".concat(error.err.toString()));
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
} catch (err) {
|
|
1684
|
-
_iterator.e(err);
|
|
1685
|
-
} finally {
|
|
1686
|
-
_iterator.f();
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
var text = (detailed ? "\n" : "") + "".concat(bright, "Number of tests: ").concat(reset).concat(this._results.length) + "\n" + "".concat(bright, "Total Time: ").concat(reset).concat(time / 1000, " sec") + "\n\n" + (this._passed > 0 ? "".concat(fgGreen, " ").concat(this._passed, " test(s) passed").concat(reset) : "0 tests passed".concat(reset)) + ", " + (this._failed > 0 ? "".concat(fgRed).concat(this._failed, " test(s) failed").concat(reset) : "0 tests failed".concat(reset)) + (this._faulted > 0 ? ", ".concat(fgYellow).concat(this._faulted, " test(s) faulted").concat(reset) : "") + (this._unknown > 0 ? ", ".concat(fgMagenta).concat(this._unknown, " test(s) are unknown").concat(reset) : "") + "\n";
|
|
1690
|
-
console.log(text);
|
|
1691
|
-
}
|
|
1692
|
-
}, {
|
|
1693
|
-
key: "log",
|
|
1694
|
-
value: function log(filename) {
|
|
1695
|
-
var content = JSON.stringify({
|
|
1696
|
-
results: this._results,
|
|
1697
|
-
errors: this._errors
|
|
1698
|
-
}, null, "\t");
|
|
1699
|
-
if (filename == null) {
|
|
1700
|
-
var d = new Date();
|
|
1701
|
-
var year = d.getFullYear().toString().padStart(4, "0");
|
|
1702
|
-
var month = (d.getMonth() + 1).toString().padStart(2, "0");
|
|
1703
|
-
var day = d.getDate().toString().padStart(2, "0");
|
|
1704
|
-
var hours = d.getHours().toString().padStart(2, "0");
|
|
1705
|
-
var minutes = d.getMinutes().toString().padStart(2, "0");
|
|
1706
|
-
var seconds = d.getSeconds().toString().padStart(2, "0");
|
|
1707
|
-
filename = "test-".concat(year, "-").concat(month, "-").concat(day, "-").concat(hours).concat(minutes).concat(seconds, ".json");
|
|
1708
|
-
}
|
|
1709
|
-
var filepath = _path["default"].join(process.cwd(), filename);
|
|
1710
|
-
try {
|
|
1711
|
-
_fs["default"].writeFileSync(filepath, content);
|
|
1712
|
-
console.log("tests outcome wrote in ".concat(filename, "."));
|
|
1713
|
-
} catch (ex) {
|
|
1714
|
-
console.log("writing tests outcome failed.\n" + ex);
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
}], [{
|
|
1718
|
-
key: "start",
|
|
1719
|
-
value: function () {
|
|
1720
|
-
var _start = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
1721
|
-
var _ref;
|
|
1722
|
-
var tr,
|
|
1723
|
-
lastArg,
|
|
1724
|
-
detailed,
|
|
1725
|
-
_tests,
|
|
1726
|
-
i,
|
|
1727
|
-
t,
|
|
1728
|
-
result,
|
|
1729
|
-
_args4 = arguments;
|
|
1730
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1731
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
1732
|
-
case 0:
|
|
1733
|
-
tr = new TestRunner();
|
|
1734
|
-
lastArg = (_ref = _args4.length - 1, _ref < 0 || _args4.length <= _ref ? undefined : _args4[_ref]);
|
|
1735
|
-
detailed = _args4.length && (0, _base.isBool)(lastArg) ? lastArg : false;
|
|
1736
|
-
_tests = [];
|
|
1737
|
-
for (i = 0; i < _args4.length; i++) {
|
|
1738
|
-
t = i < 0 || _args4.length <= i ? undefined : _args4[i];
|
|
1739
|
-
if (i != _args4.length - 1 || !(0, _base.isBool)(t)) {
|
|
1740
|
-
if ((0, _base.isIterable)(t)) {
|
|
1741
|
-
_tests = [].concat(_toConsumableArray(_tests), _toConsumableArray(t));
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
_context4.next = 7;
|
|
1746
|
-
return tr.run(_tests);
|
|
1747
|
-
case 7:
|
|
1748
|
-
result = _context4.sent;
|
|
1749
|
-
tr.report(detailed || result.failed > 0);
|
|
1750
|
-
return _context4.abrupt("return", {
|
|
1751
|
-
runner: tr,
|
|
1752
|
-
result: result
|
|
1753
|
-
});
|
|
1754
|
-
case 10:
|
|
1755
|
-
case "end":
|
|
1756
|
-
return _context4.stop();
|
|
1757
|
-
}
|
|
1758
|
-
}, _callee4);
|
|
1759
|
-
}));
|
|
1760
|
-
function start() {
|
|
1761
|
-
return _start.apply(this, arguments);
|
|
1762
|
-
}
|
|
1763
|
-
return start;
|
|
1764
|
-
}()
|
|
1765
|
-
}]);
|
|
1766
|
-
}();
|
|
1767
|
-
var _default = exports["default"] = TestRunner;
|
|
1268
|
+
|
|
1269
|
+
const reset = "\x1b[0m";
|
|
1270
|
+
const bright = "\x1b[1m";
|
|
1271
|
+
const fgRed = "\x1b[31m";
|
|
1272
|
+
const fgGreen = "\x1b[32m";
|
|
1273
|
+
const fgYellow = "\x1b[33m";
|
|
1274
|
+
const fgMagenta = "\x1b[35m";
|
|
1275
|
+
const fgWhite = "\x1b[37m";
|
|
1276
|
+
const fgGray = "\x1b[90m";
|
|
1277
|
+
|
|
1278
|
+
class TestRunner {
|
|
1279
|
+
constructor() {
|
|
1280
|
+
this._init();
|
|
1281
|
+
}
|
|
1282
|
+
_init() {
|
|
1283
|
+
this._passed = 0;
|
|
1284
|
+
this._failed = 0;
|
|
1285
|
+
this._faulted = 0;
|
|
1286
|
+
this._unknown = 0;
|
|
1287
|
+
this._results = [];
|
|
1288
|
+
this._errors = [];
|
|
1289
|
+
}
|
|
1290
|
+
async _runSingle(test, onProgress, i) {
|
|
1291
|
+
if (base.isFunction(onProgress)) {
|
|
1292
|
+
try {
|
|
1293
|
+
onProgress({ source: this, test, index: i });
|
|
1294
|
+
} catch (ex) {
|
|
1295
|
+
this._errors.push({
|
|
1296
|
+
index: i,
|
|
1297
|
+
test: test.name,
|
|
1298
|
+
err: new TestException({
|
|
1299
|
+
message: `onProgress failed for test '${test.name} at index ${i}'.`,
|
|
1300
|
+
code: 1500,
|
|
1301
|
+
status: "progress-failed",
|
|
1302
|
+
innerException: ex,
|
|
1303
|
+
}),
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
if (!(test instanceof Test)) {
|
|
1308
|
+
this._unknown++;
|
|
1309
|
+
|
|
1310
|
+
this._errors.push({
|
|
1311
|
+
index: i,
|
|
1312
|
+
err: new TestException({
|
|
1313
|
+
message: `Given test is not an instance of '@locustjs/test:Test' class.`,
|
|
1314
|
+
code: 1504,
|
|
1315
|
+
status: "invalid-test",
|
|
1316
|
+
}),
|
|
1317
|
+
});
|
|
1318
|
+
} else {
|
|
1319
|
+
const tr = await test.run();
|
|
1320
|
+
this._results.push(tr);
|
|
1321
|
+
|
|
1322
|
+
if (base.isObject(tr.err)) {
|
|
1323
|
+
if (!tr.expected) {
|
|
1324
|
+
this._faulted++;
|
|
1325
|
+
} else {
|
|
1326
|
+
this._failed++;
|
|
1327
|
+
}
|
|
1328
|
+
} else if (!tr.expected) {
|
|
1329
|
+
this._unknown++;
|
|
1330
|
+
} else if (tr.success) {
|
|
1331
|
+
this._passed++;
|
|
1332
|
+
} else {
|
|
1333
|
+
this._failed++;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
get result() {
|
|
1338
|
+
return {
|
|
1339
|
+
passed: this._passed,
|
|
1340
|
+
failed: this._failed,
|
|
1341
|
+
faulted: this._faulted,
|
|
1342
|
+
results: this._results,
|
|
1343
|
+
errors: this._errors,
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
run(tests, onProgress) {
|
|
1347
|
+
this._init();
|
|
1348
|
+
|
|
1349
|
+
return new Promise((res) => {
|
|
1350
|
+
if (tests) {
|
|
1351
|
+
if (tests instanceof Test) {
|
|
1352
|
+
tests = [tests];
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
if (base.isArray(tests)) {
|
|
1356
|
+
const _tests = tests
|
|
1357
|
+
.map((test) => {
|
|
1358
|
+
let _test = test;
|
|
1359
|
+
|
|
1360
|
+
if (base.isArray(test)) {
|
|
1361
|
+
if (test.length == 2) {
|
|
1362
|
+
_test = new Test(test[0], test[1]);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
return _test;
|
|
1367
|
+
})
|
|
1368
|
+
.map((test, i) => this._runSingle(test, onProgress, i));
|
|
1369
|
+
|
|
1370
|
+
Promise.all(_tests)
|
|
1371
|
+
.then((_) => res(this.result))
|
|
1372
|
+
.catch((ex) => {
|
|
1373
|
+
this._errors.push({
|
|
1374
|
+
err: new TestException({
|
|
1375
|
+
message: `not all tests succeeded. check errors.`,
|
|
1376
|
+
code: 1503,
|
|
1377
|
+
status: "partial-finished",
|
|
1378
|
+
innerException: ex,
|
|
1379
|
+
}),
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
res(this.result);
|
|
1383
|
+
});
|
|
1384
|
+
} else {
|
|
1385
|
+
this._errors.push({
|
|
1386
|
+
err: new TestException({
|
|
1387
|
+
message: `invalid tests. expected array or a single test.`,
|
|
1388
|
+
code: 1502,
|
|
1389
|
+
status: "invalid-tests",
|
|
1390
|
+
}),
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
res(this.result);
|
|
1394
|
+
}
|
|
1395
|
+
} else {
|
|
1396
|
+
this._errors.push({
|
|
1397
|
+
err: new TestException({
|
|
1398
|
+
message: `no tests given to be ran.`,
|
|
1399
|
+
code: 1501,
|
|
1400
|
+
status: "no-tests",
|
|
1401
|
+
}),
|
|
1402
|
+
});
|
|
1403
|
+
|
|
1404
|
+
res(this.result);
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
_getTime(time) {
|
|
1409
|
+
return `${time / 1000} sec`;
|
|
1410
|
+
}
|
|
1411
|
+
report(detailed) {
|
|
1412
|
+
let time = 0;
|
|
1413
|
+
|
|
1414
|
+
console.log("Finished.\n");
|
|
1415
|
+
|
|
1416
|
+
for (let i = 0; i < this._results.length; i++) {
|
|
1417
|
+
const testResult = this._results[i];
|
|
1418
|
+
const t = `(${this._getTime(testResult.time)})`;
|
|
1419
|
+
|
|
1420
|
+
if (detailed) {
|
|
1421
|
+
let message = "\n" + (i + 1) + ". ";
|
|
1422
|
+
let err = base.isObject(testResult.err)
|
|
1423
|
+
? testResult.err.toString().split("\n")
|
|
1424
|
+
: [];
|
|
1425
|
+
|
|
1426
|
+
err = err
|
|
1427
|
+
.map(
|
|
1428
|
+
(msg, i) =>
|
|
1429
|
+
`\t${
|
|
1430
|
+
i == err.length - 1
|
|
1431
|
+
? `${fgYellow}`
|
|
1432
|
+
: `${fgGray}error ${testResult.err.code}: `
|
|
1433
|
+
}${msg}${reset}`
|
|
1434
|
+
)
|
|
1435
|
+
.join("\n");
|
|
1436
|
+
|
|
1437
|
+
if (base.isObject(testResult.err)) {
|
|
1438
|
+
if (!testResult.expected) {
|
|
1439
|
+
message += `${bright}${fgWhite}${testResult.test}: ${fgYellow}faulted${reset} ${t}`;
|
|
1440
|
+
message += "\n";
|
|
1441
|
+
message += `${fgGray}${err} ${reset}`;
|
|
1442
|
+
} else {
|
|
1443
|
+
message += `${bright}${fgWhite}${testResult.test}: ${fgRed}failed${reset} ${t}`;
|
|
1444
|
+
message += "\n";
|
|
1445
|
+
message += `${fgGray}${err} ${reset}`;
|
|
1446
|
+
}
|
|
1447
|
+
} else if (!testResult.expected) {
|
|
1448
|
+
message += `${bright}${fgWhite}${testResult.test}: ${fgMagenta}expect not used${reset} ${t}`;
|
|
1449
|
+
|
|
1450
|
+
if (testResult.err) {
|
|
1451
|
+
message += "\n";
|
|
1452
|
+
message += `${fgGray}${err} ${reset}`;
|
|
1453
|
+
}
|
|
1454
|
+
} else if (testResult.success) {
|
|
1455
|
+
message += `${fgWhite}${testResult.test}: ${fgGreen}passed${reset} ${t}`;
|
|
1456
|
+
} else {
|
|
1457
|
+
message += `${bright}${fgWhite}${testResult.test}: ${fgRed}failed${reset} ${t}`;
|
|
1458
|
+
message += "\n";
|
|
1459
|
+
message += `${fgGray}${err} ${reset}`;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
console.log(message);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
time += testResult.time;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
if (detailed && this._errors.length) {
|
|
1469
|
+
console.log("Errors:");
|
|
1470
|
+
|
|
1471
|
+
for (let error of this._errors) {
|
|
1472
|
+
if (error.index !== undefined) {
|
|
1473
|
+
console.log(
|
|
1474
|
+
`${error.index}. ${
|
|
1475
|
+
error.test
|
|
1476
|
+
}: ${error.err.innerException.toString()}`
|
|
1477
|
+
);
|
|
1478
|
+
} else {
|
|
1479
|
+
console.log(`${error.err.toString()}`);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
const text =
|
|
1485
|
+
(detailed ? "\n" : "") +
|
|
1486
|
+
`${bright}Number of tests: ${reset}${this._results.length}` +
|
|
1487
|
+
"\n" +
|
|
1488
|
+
`${bright}Total Time: ${reset}${time / 1000} sec` +
|
|
1489
|
+
"\n\n" +
|
|
1490
|
+
(this._passed > 0
|
|
1491
|
+
? `${fgGreen} ${this._passed} test(s) passed${reset}`
|
|
1492
|
+
: `0 tests passed${reset}`) +
|
|
1493
|
+
", " +
|
|
1494
|
+
(this._failed > 0
|
|
1495
|
+
? `${fgRed}${this._failed} test(s) failed${reset}`
|
|
1496
|
+
: `0 tests failed${reset}`) +
|
|
1497
|
+
(this._faulted > 0
|
|
1498
|
+
? `, ${fgYellow}${this._faulted} test(s) faulted${reset}`
|
|
1499
|
+
: ``) +
|
|
1500
|
+
(this._unknown > 0
|
|
1501
|
+
? `, ${fgMagenta}${this._unknown} test(s) are unknown${reset}`
|
|
1502
|
+
: ``) +
|
|
1503
|
+
"\n";
|
|
1504
|
+
|
|
1505
|
+
console.log(text);
|
|
1506
|
+
}
|
|
1507
|
+
log(filename) {
|
|
1508
|
+
const content = JSON.stringify(
|
|
1509
|
+
{
|
|
1510
|
+
results: this._results,
|
|
1511
|
+
errors: this._errors,
|
|
1512
|
+
},
|
|
1513
|
+
null,
|
|
1514
|
+
"\t"
|
|
1515
|
+
);
|
|
1516
|
+
|
|
1517
|
+
if (filename == null) {
|
|
1518
|
+
const d = new Date();
|
|
1519
|
+
|
|
1520
|
+
const year = d.getFullYear().toString().padStart(4, "0");
|
|
1521
|
+
const month = (d.getMonth() + 1).toString().padStart(2, "0");
|
|
1522
|
+
const day = d.getDate().toString().padStart(2, "0");
|
|
1523
|
+
const hours = d.getHours().toString().padStart(2, "0");
|
|
1524
|
+
const minutes = d.getMinutes().toString().padStart(2, "0");
|
|
1525
|
+
const seconds = d.getSeconds().toString().padStart(2, "0");
|
|
1526
|
+
|
|
1527
|
+
filename = `test-${year}-${month}-${day}-${hours}${minutes}${seconds}.json`;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
const filepath = path.join(process.cwd(), filename);
|
|
1531
|
+
|
|
1532
|
+
try {
|
|
1533
|
+
fs.writeFileSync(filepath, content);
|
|
1534
|
+
|
|
1535
|
+
console.log(`tests outcome wrote in ${filename}.`);
|
|
1536
|
+
} catch (ex) {
|
|
1537
|
+
console.log("writing tests' report failed.\n" + ex);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
async test(...tests) {
|
|
1541
|
+
const lastArg = tests[tests.length - 1];
|
|
1542
|
+
const detailed = tests.length && base.isBool(lastArg) ? lastArg : false;
|
|
1543
|
+
let _tests = [];
|
|
1544
|
+
|
|
1545
|
+
for (let i = 0; i < tests.length; i++) {
|
|
1546
|
+
const t = tests[i];
|
|
1547
|
+
|
|
1548
|
+
if (i != tests.length - 1 || !base.isBool(t)) {
|
|
1549
|
+
if (base.isIterable(t)) {
|
|
1550
|
+
_tests = [..._tests, ...t];
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
const result = await this.run(_tests);
|
|
1556
|
+
|
|
1557
|
+
this.report(detailed || result.failed > 0);
|
|
1558
|
+
|
|
1559
|
+
return { runner: this, result };
|
|
1560
|
+
}
|
|
1561
|
+
static start(...tests) {
|
|
1562
|
+
const tr = new TestRunner();
|
|
1563
|
+
|
|
1564
|
+
return tr.test(...tests);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
exports.Expect = Expect;
|
|
1569
|
+
exports.Test = Test;
|
|
1570
|
+
exports.TestException = TestException;
|
|
1571
|
+
exports.TestRunner = TestRunner;
|