@lumjs/tests 1.1.1 → 1.5.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 +58 -1
- package/TODO.md +7 -2
- package/jsdoc.json +33 -0
- package/lib/functional.js +8 -20
- package/lib/harness.js +9 -0
- package/lib/index.js +17 -2
- package/lib/log.js +28 -9
- package/lib/test.js +541 -64
- package/package.json +13 -3
- package/test/basics.js +21 -3
- package/test/data/people.js +58 -0
- package/test/functional_basics.js +25 -4
- package/test/functional_isa.js +23 -0
- package/test/inc/basics.js +32 -2
- package/test/inc/isa.js +110 -0
- package/test/isa.js +23 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,59 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.5.0] - 2022-08-30
|
|
10
|
+
### Added
|
|
11
|
+
- Sample `data` used in some of the old tests.
|
|
12
|
+
### Fixed
|
|
13
|
+
- Mistakes in the changelog.
|
|
14
|
+
|
|
15
|
+
## [1.4.0] - 2022-07-29
|
|
16
|
+
### Added
|
|
17
|
+
- Configuration for JSDoc.
|
|
18
|
+
- A few module-level *docblocks*.
|
|
19
|
+
- Explicit `exports` section in `package.json` file.
|
|
20
|
+
- Added `test.done()` method to be used instead of `test.output()`.
|
|
21
|
+
- Added ability to configure the stringify depth.
|
|
22
|
+
- Added ability to detect if the script was ran directly.
|
|
23
|
+
- Added ability to check for a top-level `Harness` instance.
|
|
24
|
+
- Added four new *binary flag* comparitor tests to `cmp()` method.
|
|
25
|
+
- Added `not` alias for `!==` comparitor.
|
|
26
|
+
- Added `matches` method for using a regular expression to match a string.
|
|
27
|
+
- 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.
|
|
28
|
+
- A new `test.ran` computed property.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- Updated `@lumjs/core` dependency to `^1.0.0` (no more *beta* tags!)
|
|
32
|
+
- Updated various *docblocks* for documentation.
|
|
33
|
+
- Enhanced a lot of docblocks.
|
|
34
|
+
- Updated anything using `types.stringify()` to support the depth setting.
|
|
35
|
+
- Updated `run()` so it can use either `call()` or `callIs()` as the underlying test method when using a custom `function` test.
|
|
36
|
+
|
|
37
|
+
## [1.3.0] - 2022-07-27
|
|
38
|
+
### Added
|
|
39
|
+
- `$call()` function; powers `call()`, `lives()`, `dies()`, and `diesWith()`.
|
|
40
|
+
- `call()` method; test the result of a function call.
|
|
41
|
+
- `diesWith()` method; like `dies()` but also tests the thrown `Error`.
|
|
42
|
+
- `run()` method; for running a bunch of similar tests with a compact syntax.
|
|
43
|
+
### Changed
|
|
44
|
+
- How `functional` gets its list of test methods to proxy.
|
|
45
|
+
- Cleaned up a bunch of stuff in the `Log` class.
|
|
46
|
+
- Added a `details.info` structure to the `Log` class.
|
|
47
|
+
- Refactored `lives()` and `dies()` to use the new `$call()` function.
|
|
48
|
+
- Updated `ok()` to support passing `details` to it directly.
|
|
49
|
+
- Some further cleanups in the `Test` class.
|
|
50
|
+
|
|
51
|
+
## [1.2.0] - 2022-07-26
|
|
52
|
+
### Added
|
|
53
|
+
- `lives()` method; the inverse of `dies()`.
|
|
54
|
+
- `nota()` method; the inverse of `isa()`.
|
|
55
|
+
- `isntJSON()` method; the inverse of `isJSON()`.
|
|
56
|
+
- Tests for `isa()`, `isJSON()`, and all the new methods.
|
|
57
|
+
### Changed
|
|
58
|
+
- `isa()` uses `core.types.isa()` method now.
|
|
59
|
+
- `isa()` supports multiple `wants` values, just use an Array.
|
|
60
|
+
- Anything that used `JSON.stringify()` now uses `core.types.stringify()`.
|
|
61
|
+
|
|
9
62
|
## [1.1.1] - 2022-07-15
|
|
10
63
|
### Fixed
|
|
11
64
|
- Dependency issue in `package.json` with pre-release parent.
|
|
@@ -32,7 +85,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
32
85
|
- Ported from Lum.js v4 library set.
|
|
33
86
|
- Added a few more features from the PHP version.
|
|
34
87
|
|
|
35
|
-
[Unreleased]: https://github.com/supernovus/lum.tests.js/compare/v1.
|
|
88
|
+
[Unreleased]: https://github.com/supernovus/lum.tests.js/compare/v1.5.0...HEAD
|
|
89
|
+
[1.5.0]: https://github.com/supernovus/lum.tests.js/compare/v1.4.0...v1.5.0
|
|
90
|
+
[1.4.0]: https://github.com/supernovus/lum.tests.js/compare/v1.3.0...v1.4.0
|
|
91
|
+
[1.3.0]: https://github.com/supernovus/lum.tests.js/compare/v1.2.0...v1.3.0
|
|
92
|
+
[1.2.0]: https://github.com/supernovus/lum.tests.js/compare/v1.1.1...v1.2.0
|
|
36
93
|
[1.1.1]: https://github.com/supernovus/lum.tests.js/compare/v1.1.0...v1.1.1
|
|
37
94
|
[1.1.0]: https://github.com/supernovus/lum.tests.js/compare/v1.0.0...v1.1.0
|
|
38
95
|
[1.0.0]: https://github.com/supernovus/lum.tests.js/releases/tag/v1.0.0
|
package/TODO.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# TODO
|
|
2
2
|
|
|
3
|
-
-
|
|
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
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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
|
|
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 +=
|
|
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 = (
|
|
69
|
-
want = (
|
|
73
|
+
got = stringify(got, SD);
|
|
74
|
+
want = stringify(want, SD);
|
|
70
75
|
}
|
|
71
|
-
out +=
|
|
72
|
-
out +=
|
|
76
|
+
out += `# got: ${got}\n`;
|
|
77
|
+
out += `# expected: ${want}\n`;
|
|
73
78
|
if (typeof this.details.comparitor === S)
|
|
74
79
|
{
|
|
75
|
-
out +=
|
|
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
|
|