@lumjs/tests 2.0.0 → 2.1.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 +19 -0
- package/TODO.md +3 -0
- package/lib/harness/plugin/node.js +32 -4
- package/lib/test/log.js +7 -6
- package/lib/test/stats.js +11 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,25 @@ and a reference to a property of a module will be in `@tests.propName` format.
|
|
|
11
11
|
|
|
12
12
|
## [Unreleased]
|
|
13
13
|
|
|
14
|
+
## [2.1.0] - 2025-11-26
|
|
15
|
+
### Changed
|
|
16
|
+
- Bumped core version to newest release with changes to _stringify_.
|
|
17
|
+
- Updated `test/stats` to support new stringify API changes.
|
|
18
|
+
- Updated `test/log` to use stringify from the test instance.
|
|
19
|
+
- Changed how `harness/node` tests to see if a file should be used as a test.
|
|
20
|
+
- addDir() method now composes the Harness options with opts argument.
|
|
21
|
+
- A new `matchFiles` option can specify a custom function that will
|
|
22
|
+
be passed the file information object and the return value will be
|
|
23
|
+
used in a boolean context to determine if the file is a test or not.
|
|
24
|
+
- If specified, `matchFiles` will be used _instead of_ the `ext` option.
|
|
25
|
+
- The `ext` option now checks for `/`, `(` or `[` characters,
|
|
26
|
+
which would indicate it is a RegExp pattern of some sort.
|
|
27
|
+
- `\.[cm]?js$` would match `.js`, `.cjs`, and `.mjs` files.
|
|
28
|
+
- `/\.js$/i` would match `.js`, `.JS`, `.Js`, and `.jS` files.
|
|
29
|
+
- If no special characters are found, the value is assumed to be
|
|
30
|
+
a single, case-sensitive file extension.
|
|
31
|
+
- The default is still `.js` if the `ext` option was not specified.
|
|
32
|
+
|
|
14
33
|
## [2.0.0] - 2024-08-14
|
|
15
34
|
### Added
|
|
16
35
|
- The `Stats` class (and `Test` which extends it) now has async support.
|
package/TODO.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# TODO
|
|
2
2
|
|
|
3
|
+
- Add explicit support for running ES Module based tests.
|
|
4
|
+
- An alternative to passing `module` object to test instances.
|
|
3
5
|
- Write tests for:
|
|
4
6
|
- `call()`
|
|
5
7
|
- `diesWith()`
|
|
@@ -9,3 +11,4 @@
|
|
|
9
11
|
- `async()` (currently used in `@lumjs/encode:v2.0.0` package).
|
|
10
12
|
- Test the `harness/parser` and associated `grammar/tap` libraries.
|
|
11
13
|
- Test the *external* test mode in `Harness`.
|
|
14
|
+
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Node.js harness plugin
|
|
2
2
|
const core = require('@lumjs/core');
|
|
3
|
-
const {N} = core.types;
|
|
3
|
+
const {N,F,S} = core.types;
|
|
4
4
|
const Plugin = require('./index');
|
|
5
5
|
const cp = require('node:child_process');
|
|
6
6
|
const getCwd = require('node:process').cwd;
|
|
7
7
|
const fs = require('node:fs');
|
|
8
8
|
const path = require('node:path');
|
|
9
|
+
const RE = /[\/\(\[]+/;
|
|
10
|
+
const WS = /\s+/g;
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Node.js Harness plugin
|
|
@@ -41,17 +43,43 @@ class NodePlugin extends Plugin
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
addDir(dir, opts
|
|
46
|
+
addDir(dir, opts, recurse)
|
|
45
47
|
{
|
|
48
|
+
opts = Object.assign({}, this.harness.options, opts);
|
|
49
|
+
|
|
46
50
|
if (typeof recurse !== N && typeof opts.recurse === N)
|
|
47
51
|
{
|
|
48
52
|
recurse = opts.recurse;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
const ext = opts.ext ?? '.js';
|
|
52
55
|
const testOpts = opts.test ?? opts;
|
|
53
56
|
const files = fs.readdirSync(dir, {encoding: 'utf8', withFileTypes: true});
|
|
54
57
|
|
|
58
|
+
let isTest = opts.matchFiles;
|
|
59
|
+
if (typeof isTest !== F)
|
|
60
|
+
{ // No custom test, let's make one.
|
|
61
|
+
let ext = opts.ext ?? '.js';
|
|
62
|
+
|
|
63
|
+
if (typeof ext === S)
|
|
64
|
+
{
|
|
65
|
+
ext = ext.trim();
|
|
66
|
+
if (ext.match(RE))
|
|
67
|
+
{ // A RegExp pattern string of some sort.
|
|
68
|
+
ext = ext.split('/').map(v => v.replaceAll(WS, '')).filter(v => v !== '');
|
|
69
|
+
ext = new RegExp(...ext);
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
{ // A simple file extension.
|
|
73
|
+
isTest = (file) => file.name.endsWith(ext);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (ext instanceof RegExp)
|
|
78
|
+
{ // RegExp filename test.
|
|
79
|
+
isTest = (file) => file.name.match(ext);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
55
83
|
for (const file of files)
|
|
56
84
|
{
|
|
57
85
|
if (file.name === '.' || file.name === '..') continue;
|
|
@@ -59,7 +87,7 @@ class NodePlugin extends Plugin
|
|
|
59
87
|
{ // Recurse to a nested directory.
|
|
60
88
|
this.addDir(path.join(dir, file.name), opts, recurse-1);
|
|
61
89
|
}
|
|
62
|
-
else if (file.isFile() && file
|
|
90
|
+
else if (file.isFile() && isTest(file))
|
|
63
91
|
{ // It would seem to be a valid test.
|
|
64
92
|
this.harness.addTest(path.join(dir, file.name), testOpts);
|
|
65
93
|
}
|
package/lib/test/log.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const types = require('@lumjs/core').types;
|
|
3
|
-
const {S,O,isArray,
|
|
3
|
+
const {S,O,isArray,def} = types;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A log representing the results of a test.
|
|
@@ -37,7 +37,6 @@ class LumTestLog
|
|
|
37
37
|
this.desc = null;
|
|
38
38
|
this.directive = null;
|
|
39
39
|
this.details = {};
|
|
40
|
-
this.stringifyDepth = test.stringifyDepth;
|
|
41
40
|
def(this, '$test$', test);
|
|
42
41
|
}
|
|
43
42
|
|
|
@@ -52,7 +51,7 @@ class LumTestLog
|
|
|
52
51
|
*/
|
|
53
52
|
tap (num)
|
|
54
53
|
{
|
|
55
|
-
const
|
|
54
|
+
const test = this.$test$;
|
|
56
55
|
|
|
57
56
|
var out;
|
|
58
57
|
if (this.ok)
|
|
@@ -81,13 +80,13 @@ class LumTestLog
|
|
|
81
80
|
const stringy = this.details.stringify;
|
|
82
81
|
|
|
83
82
|
let got = this.details.got;
|
|
84
|
-
if (stringy) got = stringify(got
|
|
83
|
+
if (stringy) got = test.stringify(got);
|
|
85
84
|
out += `# got: ${got}\n`;
|
|
86
85
|
|
|
87
86
|
if ('wanted' in this.details)
|
|
88
87
|
{
|
|
89
88
|
let want = this.details.wanted;
|
|
90
|
-
if (stringy) want = stringify(want
|
|
89
|
+
if (stringy) want = test.stringify(want);
|
|
91
90
|
out += `# expected: ${want}\n`;
|
|
92
91
|
}
|
|
93
92
|
|
|
@@ -106,7 +105,9 @@ class LumTestLog
|
|
|
106
105
|
|
|
107
106
|
for (const i in info)
|
|
108
107
|
{
|
|
109
|
-
const line = (typeof info[i] === S)
|
|
108
|
+
const line = (typeof info[i] === S)
|
|
109
|
+
? info[i]
|
|
110
|
+
: test.stringify(info[i]);
|
|
110
111
|
out += `# - ${line}\n`;
|
|
111
112
|
}
|
|
112
113
|
}
|
package/lib/test/stats.js
CHANGED
|
@@ -11,6 +11,12 @@ const DEFAULT_ASYNC_OPTS =
|
|
|
11
11
|
interval: 5,
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const DEFAULT_STRINGIFY_OPTS =
|
|
15
|
+
{
|
|
16
|
+
maxDepth: 1,
|
|
17
|
+
jsonObjects: true,
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
/**
|
|
15
21
|
* Minimalistic base class for the `Test` library.
|
|
16
22
|
*
|
|
@@ -80,8 +86,10 @@ class LumTestStats
|
|
|
80
86
|
this.id = null;
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
this.
|
|
84
|
-
|
|
89
|
+
this.stringifyOpts = Object.assign({},
|
|
90
|
+
DEFAULT_STRINGIFY_OPTS,
|
|
91
|
+
opts.stringify);
|
|
92
|
+
|
|
85
93
|
this.failed = 0;
|
|
86
94
|
this.skipped = 0;
|
|
87
95
|
this.planned = 0;
|
|
@@ -134,10 +142,9 @@ class LumTestStats
|
|
|
134
142
|
return new Log(this);
|
|
135
143
|
}
|
|
136
144
|
|
|
137
|
-
// A wrapper around types.stringify()
|
|
138
145
|
stringify(what)
|
|
139
146
|
{
|
|
140
|
-
return types.stringify(what, this.
|
|
147
|
+
return types.stringify(what, this.stringifyOpts);
|
|
141
148
|
}
|
|
142
149
|
|
|
143
150
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumjs/tests",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"bin":
|
|
6
6
|
{
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies":
|
|
29
29
|
{
|
|
30
|
-
"@lumjs/core": "^1.
|
|
30
|
+
"@lumjs/core": "^1.38.4"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "./bin/lumtest.js",
|