@locustjs/test 1.6.0 → 1.6.2
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 +14 -4
- package/index.cjs.js +36 -16
- package/index.esm.js +34 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ const tests = [
|
|
|
14
14
|
['test 1', expect => expect(2 + 2).toBe(4)],
|
|
15
15
|
['test 2', expect => expect(undefined).toBeUndefined()],
|
|
16
16
|
['test 3', expect => expect(5).toBeGt(10)], // this test fails
|
|
17
|
+
...
|
|
17
18
|
];
|
|
18
19
|
|
|
19
20
|
const runner = new TestRunner();
|
|
@@ -44,18 +45,25 @@ Sample output:
|
|
|
44
45
|
|
|
45
46
|
8. <b>Test 8: not expected:</b> <span style="color:magenta">expect not used</span> (0 sec)
|
|
46
47
|
|
|
47
|
-
9. <b>Test 9: error without expect:</b> <span style="color:
|
|
48
|
+
9. <b>Test 9: error without expect:</b> <span style="color:yellow">faulted</span> (0 sec)
|
|
48
49
|
<div style="color:gray; margin-left: 50px">error 501: test 'Test 9: error without expect' failed.</div>
|
|
49
50
|
<div style="color:yellow; margin-left: 50px">some err</div>
|
|
50
51
|
|
|
51
52
|
10. Test 10: class: <span style="color:green">passed</span> (0 sec)
|
|
52
53
|
|
|
53
|
-
<div><b>Number of tests:
|
|
54
|
+
<div><b>Number of tests: 10</b></div>
|
|
54
55
|
<div><b>Total Time: 0.001</b> sec</div>
|
|
55
56
|
<br/>
|
|
56
|
-
<span style="color:green">7 test(s) passed</span>,
|
|
57
|
+
<span style="color:green">7 test(s) passed</span>, <span style="color:red">1 test(s) failed</span>, <span style="color:yellow">1 test(s) faulted</span>, <span style="color:magenta">1 test(s) are unknown</span>
|
|
58
|
+
|
|
59
|
+
## Test result types
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
- <span style="color:green">passed</span>: Test passed.
|
|
62
|
+
- <span style="color:red">failed</span>: Test failed (at least one `expect` did not succeed).
|
|
63
|
+
- <span style="color:yellow">faulted</span>: Test crashed (no `expect` was called).
|
|
64
|
+
- <span style="color:magenta">unknown</span>: Test executed, however, no `expect` was seen.
|
|
65
|
+
|
|
66
|
+
## expect
|
|
59
67
|
Positive
|
|
60
68
|
- `toBe(value)`
|
|
61
69
|
- `toBeGt(value)`
|
|
@@ -132,6 +140,8 @@ Negative
|
|
|
132
140
|
- `async notToThrowAsync(ex, shape = false, strict = false)`
|
|
133
141
|
- `notToBeNaN()`
|
|
134
142
|
|
|
143
|
+
## Qucik Testing
|
|
144
|
+
|
|
135
145
|
`TestRunner` has a static method `start()` that simplifies running tests.
|
|
136
146
|
|
|
137
147
|
```javascript
|
package/index.cjs.js
CHANGED
|
@@ -568,11 +568,11 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
|
|
|
568
568
|
key: "notToBeSomeArray",
|
|
569
569
|
value: function notToBeSomeArray() {
|
|
570
570
|
this._expected = true;
|
|
571
|
-
if ((0, _base.isArray)(this.value)) {
|
|
571
|
+
if (!(0, _base.isArray)(this.value)) {
|
|
572
572
|
throw new TestException({
|
|
573
|
-
message: "".concat(this.value, " is array"),
|
|
573
|
+
message: "".concat(this.value, " is not array"),
|
|
574
574
|
code: 1068,
|
|
575
|
-
status: "is-array"
|
|
575
|
+
status: "is-not-array"
|
|
576
576
|
});
|
|
577
577
|
}
|
|
578
578
|
if (this.value.length) {
|
|
@@ -1464,13 +1464,19 @@ var bgGray = "\x1b[100m";
|
|
|
1464
1464
|
var TestRunner = /*#__PURE__*/function () {
|
|
1465
1465
|
function TestRunner() {
|
|
1466
1466
|
_classCallCheck(this, TestRunner);
|
|
1467
|
-
this.
|
|
1468
|
-
this._failed = 0;
|
|
1469
|
-
this._unknown = 0;
|
|
1470
|
-
this._results = [];
|
|
1471
|
-
this._errors = [];
|
|
1467
|
+
this._init();
|
|
1472
1468
|
}
|
|
1473
1469
|
return _createClass(TestRunner, [{
|
|
1470
|
+
key: "_init",
|
|
1471
|
+
value: function _init() {
|
|
1472
|
+
this._passed = 0;
|
|
1473
|
+
this._failed = 0;
|
|
1474
|
+
this._faulted = 0;
|
|
1475
|
+
this._unknown = 0;
|
|
1476
|
+
this._results = [];
|
|
1477
|
+
this._errors = [];
|
|
1478
|
+
}
|
|
1479
|
+
}, {
|
|
1474
1480
|
key: "_runSingle",
|
|
1475
1481
|
value: function () {
|
|
1476
1482
|
var _runSingle2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(test, onProgress, i) {
|
|
@@ -1503,7 +1509,13 @@ var TestRunner = /*#__PURE__*/function () {
|
|
|
1503
1509
|
case 3:
|
|
1504
1510
|
tr = _context3.sent;
|
|
1505
1511
|
this._results.push(tr);
|
|
1506
|
-
if (
|
|
1512
|
+
if ((0, _base.isObject)(tr.err)) {
|
|
1513
|
+
if (!tr.expected) {
|
|
1514
|
+
this._faulted++;
|
|
1515
|
+
} else {
|
|
1516
|
+
this._failed++;
|
|
1517
|
+
}
|
|
1518
|
+
} else if (!tr.expected) {
|
|
1507
1519
|
this._unknown++;
|
|
1508
1520
|
} else if (tr.success) {
|
|
1509
1521
|
this._passed++;
|
|
@@ -1527,6 +1539,7 @@ var TestRunner = /*#__PURE__*/function () {
|
|
|
1527
1539
|
return {
|
|
1528
1540
|
passed: this._passed,
|
|
1529
1541
|
failed: this._failed,
|
|
1542
|
+
faulted: this._faulted,
|
|
1530
1543
|
results: this._results,
|
|
1531
1544
|
errors: this._errors
|
|
1532
1545
|
};
|
|
@@ -1535,10 +1548,7 @@ var TestRunner = /*#__PURE__*/function () {
|
|
|
1535
1548
|
key: "run",
|
|
1536
1549
|
value: function run(tests, onProgress) {
|
|
1537
1550
|
var _this3 = this;
|
|
1538
|
-
this.
|
|
1539
|
-
this._failed = 0;
|
|
1540
|
-
this._results = [];
|
|
1541
|
-
this._errors = [];
|
|
1551
|
+
this._init();
|
|
1542
1552
|
return new Promise(function (res) {
|
|
1543
1553
|
if (tests) {
|
|
1544
1554
|
if (tests instanceof Test) {
|
|
@@ -1609,11 +1619,21 @@ var TestRunner = /*#__PURE__*/function () {
|
|
|
1609
1619
|
var t = "(".concat(_this4._getTime(testResult.time), ")");
|
|
1610
1620
|
if (detailed) {
|
|
1611
1621
|
var message = "\n" + (i + 1) + ". ";
|
|
1612
|
-
var err =
|
|
1622
|
+
var err = (0, _base.isObject)(testResult.err) ? testResult.err.toString().split("\n") : [];
|
|
1613
1623
|
err = err.map(function (msg, i) {
|
|
1614
1624
|
return "\t".concat(i == err.length - 1 ? "".concat(fgYellow) : "".concat(fgGray, "error ").concat(testResult.err.code, ": ")).concat(msg).concat(reset);
|
|
1615
1625
|
}).join("\n");
|
|
1616
|
-
if (
|
|
1626
|
+
if ((0, _base.isObject)(testResult.err)) {
|
|
1627
|
+
if (!testResult.expected) {
|
|
1628
|
+
message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgYellow, "faulted").concat(reset, " ").concat(t);
|
|
1629
|
+
message += "\n";
|
|
1630
|
+
message += "".concat(fgGray).concat(err, " ").concat(reset);
|
|
1631
|
+
} else {
|
|
1632
|
+
message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgRed, "failed").concat(reset, " ").concat(t);
|
|
1633
|
+
message += "\n";
|
|
1634
|
+
message += "".concat(fgGray).concat(err, " ").concat(reset);
|
|
1635
|
+
}
|
|
1636
|
+
} else if (!testResult.expected) {
|
|
1617
1637
|
message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgMagenta, "expect not used").concat(reset, " ").concat(t);
|
|
1618
1638
|
if (testResult.err) {
|
|
1619
1639
|
message += "\n";
|
|
@@ -1652,7 +1672,7 @@ var TestRunner = /*#__PURE__*/function () {
|
|
|
1652
1672
|
_iterator.f();
|
|
1653
1673
|
}
|
|
1654
1674
|
}
|
|
1655
|
-
var text = (detailed ? "\n" : "") + "".concat(bright, "Number of tests: ").concat(reset).concat(this.
|
|
1675
|
+
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";
|
|
1656
1676
|
console.log(text);
|
|
1657
1677
|
}
|
|
1658
1678
|
}, {
|
package/index.esm.js
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
isIterable,
|
|
17
17
|
isSomeArray,
|
|
18
18
|
isSubClassOf,
|
|
19
|
-
isNullOrEmpty,
|
|
20
19
|
} from "@locustjs/base";
|
|
21
20
|
import { Exception } from "@locustjs/exception";
|
|
22
21
|
import fs from "fs";
|
|
@@ -527,11 +526,11 @@ class Expect {
|
|
|
527
526
|
notToBeSomeArray() {
|
|
528
527
|
this._expected = true;
|
|
529
528
|
|
|
530
|
-
if (isArray(this.value)) {
|
|
529
|
+
if (!isArray(this.value)) {
|
|
531
530
|
throw new TestException({
|
|
532
|
-
message: `${this.value} is array`,
|
|
531
|
+
message: `${this.value} is not array`,
|
|
533
532
|
code: 1068,
|
|
534
|
-
status: "is-array",
|
|
533
|
+
status: "is-not-array",
|
|
535
534
|
});
|
|
536
535
|
}
|
|
537
536
|
if (this.value.length) {
|
|
@@ -1310,8 +1309,12 @@ const bgGray = "\x1b[100m";
|
|
|
1310
1309
|
|
|
1311
1310
|
class TestRunner {
|
|
1312
1311
|
constructor() {
|
|
1312
|
+
this._init();
|
|
1313
|
+
}
|
|
1314
|
+
_init() {
|
|
1313
1315
|
this._passed = 0;
|
|
1314
1316
|
this._failed = 0;
|
|
1317
|
+
this._faulted = 0;
|
|
1315
1318
|
this._unknown = 0;
|
|
1316
1319
|
this._results = [];
|
|
1317
1320
|
this._errors = [];
|
|
@@ -1338,7 +1341,13 @@ class TestRunner {
|
|
|
1338
1341
|
|
|
1339
1342
|
this._results.push(tr);
|
|
1340
1343
|
|
|
1341
|
-
if (
|
|
1344
|
+
if (isObject(tr.err)) {
|
|
1345
|
+
if (!tr.expected) {
|
|
1346
|
+
this._faulted++;
|
|
1347
|
+
} else {
|
|
1348
|
+
this._failed++;
|
|
1349
|
+
}
|
|
1350
|
+
} else if (!tr.expected) {
|
|
1342
1351
|
this._unknown++;
|
|
1343
1352
|
} else if (tr.success) {
|
|
1344
1353
|
this._passed++;
|
|
@@ -1350,15 +1359,13 @@ class TestRunner {
|
|
|
1350
1359
|
return {
|
|
1351
1360
|
passed: this._passed,
|
|
1352
1361
|
failed: this._failed,
|
|
1362
|
+
faulted: this._faulted,
|
|
1353
1363
|
results: this._results,
|
|
1354
1364
|
errors: this._errors,
|
|
1355
1365
|
};
|
|
1356
1366
|
}
|
|
1357
1367
|
run(tests, onProgress) {
|
|
1358
|
-
this.
|
|
1359
|
-
this._failed = 0;
|
|
1360
|
-
this._results = [];
|
|
1361
|
-
this._errors = [];
|
|
1368
|
+
this._init();
|
|
1362
1369
|
|
|
1363
1370
|
return new Promise((res) => {
|
|
1364
1371
|
if (tests) {
|
|
@@ -1434,7 +1441,7 @@ class TestRunner {
|
|
|
1434
1441
|
|
|
1435
1442
|
if (detailed) {
|
|
1436
1443
|
let message = "\n" + (i + 1) + ". ";
|
|
1437
|
-
let err =
|
|
1444
|
+
let err = isObject(testResult.err)
|
|
1438
1445
|
? testResult.err.toString().split("\n")
|
|
1439
1446
|
: [];
|
|
1440
1447
|
|
|
@@ -1449,7 +1456,17 @@ class TestRunner {
|
|
|
1449
1456
|
)
|
|
1450
1457
|
.join("\n");
|
|
1451
1458
|
|
|
1452
|
-
if (
|
|
1459
|
+
if (isObject(testResult.err)) {
|
|
1460
|
+
if (!testResult.expected) {
|
|
1461
|
+
message += `${bright}${fgWhite}${testResult.test}: ${fgYellow}faulted${reset} ${t}`;
|
|
1462
|
+
message += "\n";
|
|
1463
|
+
message += `${fgGray}${err} ${reset}`;
|
|
1464
|
+
} else {
|
|
1465
|
+
message += `${bright}${fgWhite}${testResult.test}: ${fgRed}failed${reset} ${t}`;
|
|
1466
|
+
message += "\n";
|
|
1467
|
+
message += `${fgGray}${err} ${reset}`;
|
|
1468
|
+
}
|
|
1469
|
+
} else if (!testResult.expected) {
|
|
1453
1470
|
message += `${bright}${fgWhite}${testResult.test}: ${fgMagenta}expect not used${reset} ${t}`;
|
|
1454
1471
|
|
|
1455
1472
|
if (testResult.err) {
|
|
@@ -1488,7 +1505,7 @@ class TestRunner {
|
|
|
1488
1505
|
|
|
1489
1506
|
const text =
|
|
1490
1507
|
(detailed ? "\n" : "") +
|
|
1491
|
-
`${bright}Number of tests: ${reset}${this.
|
|
1508
|
+
`${bright}Number of tests: ${reset}${this._results.length}` +
|
|
1492
1509
|
"\n" +
|
|
1493
1510
|
`${bright}Total Time: ${reset}${time / 1000} sec` +
|
|
1494
1511
|
"\n\n" +
|
|
@@ -1497,10 +1514,13 @@ class TestRunner {
|
|
|
1497
1514
|
: `0 tests passed${reset}`) +
|
|
1498
1515
|
", " +
|
|
1499
1516
|
(this._failed > 0
|
|
1500
|
-
? `${fgRed}
|
|
1517
|
+
? `${fgRed}${this._failed} test(s) failed${reset}`
|
|
1501
1518
|
: `0 tests failed${reset}`) +
|
|
1519
|
+
(this._faulted > 0
|
|
1520
|
+
? `, ${fgYellow}${this._faulted} test(s) faulted${reset}`
|
|
1521
|
+
: ``) +
|
|
1502
1522
|
(this._unknown > 0
|
|
1503
|
-
? `, ${fgMagenta}
|
|
1523
|
+
? `, ${fgMagenta}${this._unknown} test(s) are unknown${reset}`
|
|
1504
1524
|
: ``) +
|
|
1505
1525
|
"\n";
|
|
1506
1526
|
|