@locustjs/test 1.6.1 → 1.6.3

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 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:magenta">expect not used</span> (0 sec)
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: 8</b></div>
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>, <span style="color:red">1 test(s) failed</span>, <span style="color:magenta">2 test(s) are unknown</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
- # expect
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
@@ -923,6 +923,8 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
923
923
  });
924
924
  }
925
925
  }
926
+ } else {
927
+ ok = false;
926
928
  }
927
929
  }
928
930
  if (ok) {
@@ -998,6 +1000,8 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
998
1000
  });
999
1001
  }
1000
1002
  }
1003
+ } else {
1004
+ ok = true;
1001
1005
  }
1002
1006
  }
1003
1007
  if (ok) {
@@ -1040,13 +1044,13 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
1040
1044
  return this.value();
1041
1045
  case 9:
1042
1046
  ok = true;
1043
- _context.next = 37;
1047
+ _context.next = 40;
1044
1048
  break;
1045
1049
  case 12:
1046
1050
  _context.prev = 12;
1047
1051
  _context.t0 = _context["catch"](6);
1048
1052
  if (!(ex !== undefined)) {
1049
- _context.next = 37;
1053
+ _context.next = 39;
1050
1054
  break;
1051
1055
  }
1052
1056
  if (!(0, _base.isPrimitive)(ex)) {
@@ -1127,8 +1131,13 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
1127
1131
  status: "incorrect-throw-value"
1128
1132
  });
1129
1133
  case 37:
1134
+ _context.next = 40;
1135
+ break;
1136
+ case 39:
1137
+ ok = false;
1138
+ case 40:
1130
1139
  if (!ok) {
1131
- _context.next = 39;
1140
+ _context.next = 42;
1132
1141
  break;
1133
1142
  }
1134
1143
  throw new TestException({
@@ -1136,9 +1145,9 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
1136
1145
  code: 1013,
1137
1146
  status: "ran-to-completion"
1138
1147
  });
1139
- case 39:
1148
+ case 42:
1140
1149
  return _context.abrupt("return", this);
1141
- case 40:
1150
+ case 43:
1142
1151
  case "end":
1143
1152
  return _context.stop();
1144
1153
  }
@@ -1180,14 +1189,14 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
1180
1189
  return this.value();
1181
1190
  case 9:
1182
1191
  ok = false;
1183
- _context2.next = 38;
1192
+ _context2.next = 41;
1184
1193
  break;
1185
1194
  case 12:
1186
1195
  _context2.prev = 12;
1187
1196
  _context2.t0 = _context2["catch"](6);
1188
1197
  error = _context2.t0;
1189
1198
  if (!(ex !== undefined)) {
1190
- _context2.next = 38;
1199
+ _context2.next = 40;
1191
1200
  break;
1192
1201
  }
1193
1202
  if (!(0, _base.isPrimitive)(ex)) {
@@ -1268,8 +1277,13 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
1268
1277
  status: "incorrect-throw-value"
1269
1278
  });
1270
1279
  case 38:
1280
+ _context2.next = 41;
1281
+ break;
1282
+ case 40:
1283
+ ok = true;
1284
+ case 41:
1271
1285
  if (!ok) {
1272
- _context2.next = 40;
1286
+ _context2.next = 43;
1273
1287
  break;
1274
1288
  }
1275
1289
  throw new TestException({
@@ -1278,9 +1292,9 @@ var Expect = exports.Expect = /*#__PURE__*/function () {
1278
1292
  status: "ran-to-error",
1279
1293
  innerException: error
1280
1294
  });
1281
- case 40:
1295
+ case 43:
1282
1296
  return _context2.abrupt("return", this);
1283
- case 41:
1297
+ case 44:
1284
1298
  case "end":
1285
1299
  return _context2.stop();
1286
1300
  }
@@ -1464,13 +1478,19 @@ var bgGray = "\x1b[100m";
1464
1478
  var TestRunner = /*#__PURE__*/function () {
1465
1479
  function TestRunner() {
1466
1480
  _classCallCheck(this, TestRunner);
1467
- this._passed = 0;
1468
- this._failed = 0;
1469
- this._unknown = 0;
1470
- this._results = [];
1471
- this._errors = [];
1481
+ this._init();
1472
1482
  }
1473
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
+ }, {
1474
1494
  key: "_runSingle",
1475
1495
  value: function () {
1476
1496
  var _runSingle2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(test, onProgress, i) {
@@ -1503,7 +1523,13 @@ var TestRunner = /*#__PURE__*/function () {
1503
1523
  case 3:
1504
1524
  tr = _context3.sent;
1505
1525
  this._results.push(tr);
1506
- if (!tr.expected) {
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) {
1507
1533
  this._unknown++;
1508
1534
  } else if (tr.success) {
1509
1535
  this._passed++;
@@ -1527,6 +1553,7 @@ var TestRunner = /*#__PURE__*/function () {
1527
1553
  return {
1528
1554
  passed: this._passed,
1529
1555
  failed: this._failed,
1556
+ faulted: this._faulted,
1530
1557
  results: this._results,
1531
1558
  errors: this._errors
1532
1559
  };
@@ -1535,10 +1562,7 @@ var TestRunner = /*#__PURE__*/function () {
1535
1562
  key: "run",
1536
1563
  value: function run(tests, onProgress) {
1537
1564
  var _this3 = this;
1538
- this._passed = 0;
1539
- this._failed = 0;
1540
- this._results = [];
1541
- this._errors = [];
1565
+ this._init();
1542
1566
  return new Promise(function (res) {
1543
1567
  if (tests) {
1544
1568
  if (tests instanceof Test) {
@@ -1609,11 +1633,21 @@ var TestRunner = /*#__PURE__*/function () {
1609
1633
  var t = "(".concat(_this4._getTime(testResult.time), ")");
1610
1634
  if (detailed) {
1611
1635
  var message = "\n" + (i + 1) + ". ";
1612
- var err = !(0, _base.isNullOrEmpty)(testResult.err) ? testResult.err.toString().split("\n") : [];
1636
+ var err = (0, _base.isObject)(testResult.err) ? testResult.err.toString().split("\n") : [];
1613
1637
  err = err.map(function (msg, i) {
1614
1638
  return "\t".concat(i == err.length - 1 ? "".concat(fgYellow) : "".concat(fgGray, "error ").concat(testResult.err.code, ": ")).concat(msg).concat(reset);
1615
1639
  }).join("\n");
1616
- if (!testResult.expected) {
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) {
1617
1651
  message += "".concat(bright).concat(fgWhite).concat(testResult.test, ": ").concat(fgMagenta, "expect not used").concat(reset, " ").concat(t);
1618
1652
  if (testResult.err) {
1619
1653
  message += "\n";
@@ -1652,7 +1686,7 @@ var TestRunner = /*#__PURE__*/function () {
1652
1686
  _iterator.f();
1653
1687
  }
1654
1688
  }
1655
- var text = (detailed ? "\n" : "") + "".concat(bright, "Number of tests: ").concat(reset).concat(this._passed + this._failed) + "\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._unknown > 0 ? ", ".concat(fgMagenta, " ").concat(this._unknown, " test(s) are unknown").concat(reset) : "") + "\n";
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";
1656
1690
  console.log(text);
1657
1691
  }
1658
1692
  }, {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@locustjs/test",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "This library provides a simple test runner.",
5
- "main": "index.cjs.js",
6
- "module": "index.esm.js",
5
+ "main": "dist/index.js",
6
+ "module": "src/index.js",
7
7
  "scripts": {
8
- "build": "babel index.esm.js -o index.cjs.js",
8
+ "build": "babel ./src/index.js -o ./dist/index.js",
9
9
  "test": "node -r esm ./tests/index.js"
10
10
  },
11
11
  "repository": {
@@ -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";
@@ -887,6 +886,8 @@ class Expect {
887
886
  });
888
887
  }
889
888
  }
889
+ } else {
890
+ ok = false;
890
891
  }
891
892
  }
892
893
 
@@ -965,6 +966,8 @@ class Expect {
965
966
  });
966
967
  }
967
968
  }
969
+ } else {
970
+ ok = true;
968
971
  }
969
972
  }
970
973
 
@@ -1041,6 +1044,8 @@ class Expect {
1041
1044
  });
1042
1045
  }
1043
1046
  }
1047
+ } else {
1048
+ ok = false;
1044
1049
  }
1045
1050
  }
1046
1051
 
@@ -1119,6 +1124,8 @@ class Expect {
1119
1124
  });
1120
1125
  }
1121
1126
  }
1127
+ } else {
1128
+ ok = true;
1122
1129
  }
1123
1130
  }
1124
1131
 
@@ -1310,8 +1317,12 @@ const bgGray = "\x1b[100m";
1310
1317
 
1311
1318
  class TestRunner {
1312
1319
  constructor() {
1320
+ this._init();
1321
+ }
1322
+ _init() {
1313
1323
  this._passed = 0;
1314
1324
  this._failed = 0;
1325
+ this._faulted = 0;
1315
1326
  this._unknown = 0;
1316
1327
  this._results = [];
1317
1328
  this._errors = [];
@@ -1338,7 +1349,13 @@ class TestRunner {
1338
1349
 
1339
1350
  this._results.push(tr);
1340
1351
 
1341
- if (!tr.expected) {
1352
+ if (isObject(tr.err)) {
1353
+ if (!tr.expected) {
1354
+ this._faulted++;
1355
+ } else {
1356
+ this._failed++;
1357
+ }
1358
+ } else if (!tr.expected) {
1342
1359
  this._unknown++;
1343
1360
  } else if (tr.success) {
1344
1361
  this._passed++;
@@ -1350,15 +1367,13 @@ class TestRunner {
1350
1367
  return {
1351
1368
  passed: this._passed,
1352
1369
  failed: this._failed,
1370
+ faulted: this._faulted,
1353
1371
  results: this._results,
1354
1372
  errors: this._errors,
1355
1373
  };
1356
1374
  }
1357
1375
  run(tests, onProgress) {
1358
- this._passed = 0;
1359
- this._failed = 0;
1360
- this._results = [];
1361
- this._errors = [];
1376
+ this._init();
1362
1377
 
1363
1378
  return new Promise((res) => {
1364
1379
  if (tests) {
@@ -1434,7 +1449,7 @@ class TestRunner {
1434
1449
 
1435
1450
  if (detailed) {
1436
1451
  let message = "\n" + (i + 1) + ". ";
1437
- let err = !isNullOrEmpty(testResult.err)
1452
+ let err = isObject(testResult.err)
1438
1453
  ? testResult.err.toString().split("\n")
1439
1454
  : [];
1440
1455
 
@@ -1449,7 +1464,17 @@ class TestRunner {
1449
1464
  )
1450
1465
  .join("\n");
1451
1466
 
1452
- if (!testResult.expected) {
1467
+ if (isObject(testResult.err)) {
1468
+ if (!testResult.expected) {
1469
+ message += `${bright}${fgWhite}${testResult.test}: ${fgYellow}faulted${reset} ${t}`;
1470
+ message += "\n";
1471
+ message += `${fgGray}${err} ${reset}`;
1472
+ } else {
1473
+ message += `${bright}${fgWhite}${testResult.test}: ${fgRed}failed${reset} ${t}`;
1474
+ message += "\n";
1475
+ message += `${fgGray}${err} ${reset}`;
1476
+ }
1477
+ } else if (!testResult.expected) {
1453
1478
  message += `${bright}${fgWhite}${testResult.test}: ${fgMagenta}expect not used${reset} ${t}`;
1454
1479
 
1455
1480
  if (testResult.err) {
@@ -1488,7 +1513,7 @@ class TestRunner {
1488
1513
 
1489
1514
  const text =
1490
1515
  (detailed ? "\n" : "") +
1491
- `${bright}Number of tests: ${reset}${this._passed + this._failed}` +
1516
+ `${bright}Number of tests: ${reset}${this._results.length}` +
1492
1517
  "\n" +
1493
1518
  `${bright}Total Time: ${reset}${time / 1000} sec` +
1494
1519
  "\n\n" +
@@ -1497,10 +1522,13 @@ class TestRunner {
1497
1522
  : `0 tests passed${reset}`) +
1498
1523
  ", " +
1499
1524
  (this._failed > 0
1500
- ? `${fgRed} ${this._failed} test(s) failed${reset}`
1525
+ ? `${fgRed}${this._failed} test(s) failed${reset}`
1501
1526
  : `0 tests failed${reset}`) +
1527
+ (this._faulted > 0
1528
+ ? `, ${fgYellow}${this._faulted} test(s) faulted${reset}`
1529
+ : ``) +
1502
1530
  (this._unknown > 0
1503
- ? `, ${fgMagenta} ${this._unknown} test(s) are unknown${reset}`
1531
+ ? `, ${fgMagenta}${this._unknown} test(s) are unknown${reset}`
1504
1532
  : ``) +
1505
1533
  "\n";
1506
1534
 
package/tests/index.js CHANGED
@@ -90,7 +90,7 @@ const tests = [
90
90
  [
91
91
  "Test 7: error",
92
92
  function (expect) {
93
- const x = 10;
93
+ const x = 30;
94
94
 
95
95
  expect(x).toBeGreaterThan(20);
96
96
  },