@lumjs/tests 1.1.0 → 1.4.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/CHANGELOG.md CHANGED
@@ -6,6 +6,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.4.0] - 2022-07-29
10
+ ## Added
11
+ - Explicit `exports` section in `package.json` file.
12
+ - Added `test.done()` method to be used instead of `test.output()`.
13
+ - Added ability to configure the stringify depth.
14
+ - Added ability to detect if the script was ran directly.
15
+ - Added ability to check for a top-level `Harness` instance.
16
+ - Added four new *binary flag* comparitor tests to `cmp()` method.
17
+ - Added `not` alias for `!==` comparitor.
18
+ - Added `matches` method for using a regular expression to match a string.
19
+ - Added `callIs()` method that is like `call()` but takes a desired value and passes the function return value to `cmp()`, `isa()`, or other test methods.
20
+ - A new `test.ran` computed property.
21
+
22
+ ## Changed
23
+ - Enhanced a lot of docblocks.
24
+ - Updated anything using `types.stringify()` to support the depth setting.
25
+ - Updated `run()` so it can use either `call()` or `callIs()` as the underlying test method when using a custom `function` test.
26
+
27
+ ### Added
28
+ - Configuration for JSDoc.
29
+ - A few module-level *docblocks*.
30
+ ### Changed
31
+ - Updated `@lumjs/core` dependency to `^1.0.0` (no more *beta* tags!)
32
+ - Updated various *docblocks* for documentation.
33
+
34
+ ## [1.3.0] - 2022-07-27
35
+ ### Added
36
+ - `$call()` function; powers `call()`, `lives()`, `dies()`, and `diesWith()`.
37
+ - `call()` method; test the result of a function call.
38
+ - `diesWith()` method; like `dies()` but also tests the thrown `Error`.
39
+ - `run()` method; for running a bunch of similar tests with a compact syntax.
40
+ ### Changed
41
+ - How `functional` gets its list of test methods to proxy.
42
+ - Cleaned up a bunch of stuff in the `Log` class.
43
+ - Added a `details.info` structure to the `Log` class.
44
+ - Refactored `lives()` and `dies()` to use the new `$call()` function.
45
+ - Updated `ok()` to support passing `details` to it directly.
46
+ - Some further cleanups in the `Test` class.
47
+
48
+ ## [1.2.0] - 2022-07-26
49
+ ### Added
50
+ - `lives()` method; the inverse of `dies()`.
51
+ - `nota()` method; the inverse of `isa()`.
52
+ - `isntJSON()` method; the inverse of `isJSON()`.
53
+ - Tests for `isa()`, `isJSON()`, and all the new methods.
54
+ ### Changed
55
+ - `isa()` uses `core.types.isa()` method now.
56
+ - `isa()` supports multiple `wants` values, just use an Array.
57
+ - Anything that used `JSON.stringify()` now uses `core.types.stringify()`.
58
+
59
+ ## [1.1.1] - 2022-07-15
60
+ ### Fixed
61
+ - Dependency issue in `package.json` with pre-release parent.
62
+ ### Added
63
+ - A temporary `npm test` script using the `prove` utility from Perl 5.
64
+
9
65
  ## [1.1.0] - 2022-07-08
10
66
  ### Fixed
11
67
  - Changelog had wrong URLs.
@@ -26,7 +82,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
82
  - Ported from Lum.js v4 library set.
27
83
  - Added a few more features from the PHP version.
28
84
 
29
- [Unreleased]: https://github.com/supernovus/lum.tests.js/compare/v1.1.0...HEAD
85
+ [Unreleased]: https://github.com/supernovus/lum.tests.js/compare/v1.4.0...HEAD
86
+ [1.4.0]: https://github.com/supernovus/lum.tests.js/compare/v1.3.0...v1.4.0
87
+ [1.3.0]: https://github.com/supernovus/lum.tests.js/compare/v1.2.0...v1.3.0
88
+ [1.2.0]: https://github.com/supernovus/lum.tests.js/compare/v1.1.1...v1.2.0
89
+ [1.1.1]: https://github.com/supernovus/lum.tests.js/compare/v1.1.0...v1.1.1
30
90
  [1.1.0]: https://github.com/supernovus/lum.tests.js/compare/v1.0.0...v1.1.0
31
91
  [1.0.0]: https://github.com/supernovus/lum.tests.js/releases/tag/v1.0.0
32
92
 
package/TODO.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # TODO
2
2
 
3
- - Add tests for `isa()` method.
3
+ - Write tests for:
4
+ - `call()`
5
+ - `diesWith()`
6
+ - `callIs()`
7
+ - `matches()`
8
+ - `run()`
4
9
  - Write the `Harness` class, based of the Lum.php version.
5
10
  - Add tests for `Harness`.
6
- - Create 'lumtest' binary for running the harness without `prove` utility.
11
+ - Create `lumtest` binary for running the harness without `prove` utility.
7
12
 
package/jsdoc.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "tags":
3
+ {
4
+ "allowUnknownTags": true
5
+ },
6
+ "source":
7
+ {
8
+ "include": ["./lib"]
9
+ },
10
+ "opts":
11
+ {
12
+ "destination": "./docs/api",
13
+ "recurse": true
14
+ },
15
+ "plugins":
16
+ [
17
+ "plugins/markdown"
18
+ ],
19
+ "templates":
20
+ {
21
+ "cleverLinks": false,
22
+ "monospaceLinks": false,
23
+ "default":
24
+ {
25
+ "outputSourceFiles": true
26
+ },
27
+ "path": "ink-docstrap",
28
+ "theme": "cerulean",
29
+ "navType": "vertical",
30
+ "linenums": true,
31
+ "dateFormat": "YYYY-MM-DD, hh:mm:ss"
32
+ }
33
+ }
package/lib/functional.js CHANGED
@@ -2,11 +2,12 @@
2
2
  const Test = require('./test');
3
3
 
4
4
  // A list of methods we can proxy directly.
5
- const PROXY_METHODS =
6
- [
7
- 'plan', 'ok', 'fail', 'pass', 'dies', 'cmp', 'isa', 'is', 'isnt',
8
- 'isJSON', 'skip', 'diag', 'tap', 'output',
9
- ];
5
+ const PROXY_METHODS = Test.$METHODS.all;
6
+
7
+ /**
8
+ * Module defining the functional API.
9
+ * @module @lumjs/tests/functional
10
+ */
10
11
 
11
12
  /**
12
13
  * A new test instance and a set of functions wrapping it.
@@ -16,20 +17,6 @@ const PROXY_METHODS =
16
17
  * All of the rest of the properties are functions that
17
18
  * can be imported into a JS scope using destructuring, and
18
19
  * which wrap the corresponding test instance method.
19
- *
20
- * @property {function} plan
21
- * @property {function} ok
22
- * @property {function} fail
23
- * @property {function} pass
24
- * @property {function} dies
25
- * @property {function} cmp
26
- * @property {function} isa
27
- * @property {function} is
28
- * @property {function} isnt
29
- * @property {function} isJSON
30
- * @property {function} skip
31
- * @property {function} diag
32
- * @property {function} tap
33
20
  */
34
21
 
35
22
  /**
@@ -39,11 +26,12 @@ const PROXY_METHODS =
39
26
  * Usage is like:
40
27
  *
41
28
  * ```js
42
- * const {plan,ok,isa} = require('@lumjs/tests').functional({module});
29
+ * const {plan,ok,isa,done} = require('@lumjs/tests').functional({module});
43
30
  *
44
31
  * plan(2);
45
32
  * ok(true, 'ok() works');
46
33
  * isa(isa, 'function', 'isa is a function');
34
+ * done();
47
35
  *
48
36
  * ```
49
37
  *
package/lib/harness.js CHANGED
@@ -2,6 +2,11 @@
2
2
  const Test = require('./test');
3
3
  const Log = require('./log');
4
4
 
5
+ /**
6
+ * Module defining the Harness class.
7
+ * @module @lumjs/tests/harness
8
+ */
9
+
5
10
  /**
6
11
  * A class that acts as a test harness for running other tests.
7
12
  *
@@ -14,3 +19,7 @@ class Harness
14
19
  throw new Error("Not yet implemented");
15
20
  }
16
21
  }
22
+
23
+ // Export it.
24
+ module.exports = Harness;
25
+
package/lib/index.js CHANGED
@@ -1,13 +1,28 @@
1
1
  /**
2
2
  * Several test related classes.
3
+ * @module @lumjs/tests
3
4
  */
4
5
 
6
+ /**
7
+ * Test class.
8
+ * @alias module:@lumjs/tests.Test
9
+ * @see module:@lumjs/tests/test
10
+ */
5
11
  const Test = require('./test');
6
-
7
12
  module.exports.Test = Test;
13
+
14
+ /**
15
+ * Test Harness class.
16
+ * @alias module:@lumjs/tests.Harness
17
+ * @see module:@lumjs/tests/harness
18
+ */
8
19
  module.exports.Harness = require('./harness');
9
20
 
10
- // This one is not a class, but a special function.
21
+ /**
22
+ * Functional API registration.
23
+ * @alias module:@lumjs/tests.functional
24
+ * @see module:@lumjs/tests/functional
25
+ */
11
26
  module.exports.functional = require('./functional');
12
27
 
13
28
  /**
package/lib/log.js CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
- const {F,S,O} = require('@lumjs/core').types;
2
+ const types = require('@lumjs/core').types;
3
+ const {S,O,isArray,stringify,def} = types;
3
4
 
4
5
  /**
5
6
  * A log representing the results of a test.
@@ -18,7 +19,7 @@ const {F,S,O} = require('@lumjs/core').types;
18
19
  */
19
20
  class Log
20
21
  {
21
- constructor ()
22
+ constructor (test)
22
23
  {
23
24
  this.ok = false;
24
25
  this.skipped = false;
@@ -26,6 +27,8 @@ class Log
26
27
  this.desc = null;
27
28
  this.directive = null;
28
29
  this.details = {};
30
+ this.stringifyDepth = test.stringifyDepth;
31
+ def(this, '$test$', test);
29
32
  }
30
33
 
31
34
  /**
@@ -34,11 +37,13 @@ class Log
34
37
  * Generally this is never needed to be used by outside code.
35
38
  * The `Test.tap()` method uses it when generating a full log.
36
39
  *
37
- * @param {*} num - The test #
40
+ * @param {*} num - The test number.
38
41
  * @returns {string} The TAP log.
39
42
  */
40
43
  tap (num)
41
44
  {
45
+ const SD = this.stringifyDepth;
46
+
42
47
  var out;
43
48
  if (this.ok)
44
49
  out = 'ok ';
@@ -53,7 +58,7 @@ class Log
53
58
  if (typeof this.directive === S)
54
59
  out += ' # ' + this.directive;
55
60
  else if (typeof this.directive == O && this.directive instanceof Error)
56
- out += ' # ' + this.directive.name + ': ' + this.directive.message;
61
+ out += ` # ${this.directive.name}: ${this.directive.message}`;
57
62
  else if (this.skipped)
58
63
  out += ' # SKIP ' + this.skippedReason;
59
64
 
@@ -65,14 +70,28 @@ class Log
65
70
  var want = this.details.wanted;
66
71
  if (this.details.stringify)
67
72
  {
68
- got = (typeof got === F) ? got.toString() : JSON.stringify(got);
69
- want = (typeof want === F) ? want.toString() : JSON.stringify(want);
73
+ got = stringify(got, SD);
74
+ want = stringify(want, SD);
70
75
  }
71
- out += '# got: ' + got + "\n";
72
- out += '# expected: ' + want + "\n";
76
+ out += `# got: ${got}\n`;
77
+ out += `# expected: ${want}\n`;
73
78
  if (typeof this.details.comparitor === S)
74
79
  {
75
- out += '# op: ' + this.details.comparitor + "\n";
80
+ out += `# op: ${this.details.comparitor}\n`;
81
+ }
82
+ }
83
+
84
+ if ('info' in this.details)
85
+ { // Extended information. Usually an array, but can be whatever.
86
+ const info
87
+ = isArray(this.details.info)
88
+ ? this.details.info
89
+ : [this.details.info];
90
+
91
+ for (const i in info)
92
+ {
93
+ const line = (typeof info[i] === S) ? info[i] : stringify(info[i], SD);
94
+ out += `## ${line}\n`;
76
95
  }
77
96
  }
78
97