@lumjs/tests 1.0.0 → 1.3.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,11 +6,61 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.0] - 2022-07-27
10
+ ### Added
11
+ - `$call()` function; powers `call()`, `lives()`, `dies()`, and `diesWith()`.
12
+ - `call()` method; test the result of a function call.
13
+ - `diesWith()` method; like `dies()` but also tests the thrown `Error`.
14
+ - `run()` method; for running a bunch of similar tests with a compact syntax.
15
+ ### Changed
16
+ - How `functional` gets its list of test methods to proxy.
17
+ - Cleaned up a bunch of stuff in the `Log` class.
18
+ - Added a `details.info` structure to the `Log` class.
19
+ - Refactored `lives()` and `dies()` to use the new `$call()` function.
20
+ - Updated `ok()` to support passing `details` to it directly.
21
+ - Some further cleanups in the `Test` class.
22
+
23
+ ## [1.2.0] - 2022-07-26
24
+ ### Added
25
+ - `lives()` method; the inverse of `dies()`.
26
+ - `nota()` method; the inverse of `isa()`.
27
+ - `isntJSON()` method; the inverse of `isJSON()`.
28
+ - Tests for `isa()`, `isJSON()`, and all the new methods.
29
+ ### Changed
30
+ - `isa()` uses `core.types.isa()` method now.
31
+ - `isa()` supports multiple `wants` values, just use an Array.
32
+ - Anything that used `JSON.stringify()` now uses `core.types.stringify()`.
33
+
34
+ ## [1.1.1] - 2022-07-15
35
+ ### Fixed
36
+ - Dependency issue in `package.json` with pre-release parent.
37
+ ### Added
38
+ - A temporary `npm test` script using the `prove` utility from Perl 5.
39
+
40
+ ## [1.1.0] - 2022-07-08
41
+ ### Fixed
42
+ - Changelog had wrong URLs.
43
+ ### Changed
44
+ - Renamed `src` to `lib` like `@lumjs/core` did.
45
+ - Moved `index.js` into `lib` and updated `package.json` to reflect that.
46
+ - Updated all the tests to use the new paths.
47
+ - Changed `Test` constructor to support a bunch of options.
48
+ - `id` option will be used in the future.
49
+ - `plan` option replaces the old `plan` pararameter.
50
+ - `module` option will assign the test instance to `opts.module.exports`.
51
+ - `module` can also auto-generate an `id` if one was not passed.
52
+ - `moduleName` is used for the automatic `id` generation.
53
+ - Updated `functional()` and `new()` to pass their options to the constructor.
54
+
9
55
  ## [1.0.0] - 2022-06-22
10
56
  ### Added
11
57
  - Ported from Lum.js v4 library set.
12
58
  - Added a few more features from the PHP version.
13
59
 
14
- [Unreleased]: https://github.com/supernovus/simpledom/compare/v1.0.0...HEAD
15
- [1.0.0]: https://github.com/supernovus/simpledom/releases/tag/v1.0.0
60
+ [Unreleased]: https://github.com/supernovus/lum.tests.js/compare/v1.3.0...HEAD
61
+ [1.3.0]: https://github.com/supernovus/lum.tests.js/compare/v1.2.0...v1.3.0
62
+ [1.2.0]: https://github.com/supernovus/lum.tests.js/compare/v1.1.1...v1.2.0
63
+ [1.1.1]: https://github.com/supernovus/lum.tests.js/compare/v1.1.0...v1.1.1
64
+ [1.1.0]: https://github.com/supernovus/lum.tests.js/compare/v1.0.0...v1.1.0
65
+ [1.0.0]: https://github.com/supernovus/lum.tests.js/releases/tag/v1.0.0
16
66
 
package/TODO.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # TODO
2
2
 
3
- - Add tests for `isa()` method.
3
+ - Write tests for:
4
+ - `call()`
5
+ - `diesWith()`
6
+ - `run()`
4
7
  - Write the `Harness` class, based of the Lum.php version.
5
8
  - Add tests for `Harness`.
6
- - Create 'lumtest' binary for running the harness without `prove` utility.
9
+ - Create `lumtest` binary for running the harness without `prove` utility.
7
10
 
@@ -2,11 +2,7 @@
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;
10
6
 
11
7
  /**
12
8
  * A new test instance and a set of functions wrapping it.
@@ -16,20 +12,6 @@ const PROXY_METHODS =
16
12
  * All of the rest of the properties are functions that
17
13
  * can be imported into a JS scope using destructuring, and
18
14
  * 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
15
  */
34
16
 
35
17
  /**
@@ -51,17 +33,15 @@ const PROXY_METHODS =
51
33
  * and a new set of wrapper functions for the test instance, you could
52
34
  * create multiple sets of functional tests in their own private scopes.
53
35
  * Not sure why you'd want to do that, but in case you do, there ya go.
36
+ *
37
+ * @param {object} [opts] Options to pass to the `Test` constructor.
54
38
  *
55
39
  * @returns {Functional}
56
40
  *
57
41
  */
58
- function functional({plan,module}={})
42
+ function functional(opts={})
59
43
  {
60
- const test = new Test(plan);
61
- if (module)
62
- {
63
- module.exports = test;
64
- }
44
+ const test = new Test(opts);
65
45
  const functions = { test };
66
46
  for (const meth of PROXY_METHODS)
67
47
  {
File without changes
package/lib/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Several test related classes.
3
+ */
4
+
5
+ const Test = require('./test');
6
+
7
+ module.exports.Test = Test;
8
+ module.exports.Harness = require('./harness');
9
+
10
+ // This one is not a class, but a special function.
11
+ module.exports.functional = require('./functional');
12
+
13
+ /**
14
+ * Create a new Test instance.
15
+ *
16
+ * @param {object} [opts] Options to pass to the `Test` constructor.
17
+ * @returns {Test} A new test instance.
18
+ */
19
+ module.exports.new = function(opts={})
20
+ {
21
+ return new Test(opts);
22
+ }
23
+
@@ -1,5 +1,6 @@
1
1
 
2
- const {F,S,O} = require('@lumjs/core').types;
2
+ const types = require('@lumjs/core').types;
3
+ const {F,S,O,isArray,stringify} = types;
3
4
 
4
5
  /**
5
6
  * A log representing the results of a test.
@@ -34,7 +35,7 @@ class Log
34
35
  * Generally this is never needed to be used by outside code.
35
36
  * The `Test.tap()` method uses it when generating a full log.
36
37
  *
37
- * @param {*} num - The test #
38
+ * @param {*} num - The test number.
38
39
  * @returns {string} The TAP log.
39
40
  */
40
41
  tap (num)
@@ -53,7 +54,7 @@ class Log
53
54
  if (typeof this.directive === S)
54
55
  out += ' # ' + this.directive;
55
56
  else if (typeof this.directive == O && this.directive instanceof Error)
56
- out += ' # ' + this.directive.name + ': ' + this.directive.message;
57
+ out += ` # ${this.directive.name}: ${this.directive.message}`;
57
58
  else if (this.skipped)
58
59
  out += ' # SKIP ' + this.skippedReason;
59
60
 
@@ -65,14 +66,28 @@ class Log
65
66
  var want = this.details.wanted;
66
67
  if (this.details.stringify)
67
68
  {
68
- got = (typeof got === F) ? got.toString() : JSON.stringify(got);
69
- want = (typeof want === F) ? want.toString() : JSON.stringify(want);
69
+ got = stringify(got);
70
+ want = stringify(want);
70
71
  }
71
- out += '# got: ' + got + "\n";
72
- out += '# expected: ' + want + "\n";
72
+ out += `# got: ${got}\n`;
73
+ out += `# expected: ${want}\n`;
73
74
  if (typeof this.details.comparitor === S)
74
75
  {
75
- out += '# op: ' + this.details.comparitor + "\n";
76
+ out += `# op: ${this.details.comparitor}\n`;
77
+ }
78
+ }
79
+
80
+ if ('info' in this.details)
81
+ { // Extended information. Usually an array, but can be whatever.
82
+ const info
83
+ = isArray(this.details.info)
84
+ ? this.details.info
85
+ : [this.details.info];
86
+
87
+ for (const i in info)
88
+ {
89
+ const line = (typeof info[i] === S) ? info[i] : stringify(info[i]);
90
+ out += `## ${line}\n`;
76
91
  }
77
92
  }
78
93