@lumjs/tests 1.0.0 → 1.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 CHANGED
@@ -6,11 +6,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.0] - 2022-07-08
10
+ ### Fixed
11
+ - Changelog had wrong URLs.
12
+ ### Changed
13
+ - Renamed `src` to `lib` like `@lumjs/core` did.
14
+ - Moved `index.js` into `lib` and updated `package.json` to reflect that.
15
+ - Updated all the tests to use the new paths.
16
+ - Changed `Test` constructor to support a bunch of options.
17
+ - `id` option will be used in the future.
18
+ - `plan` option replaces the old `plan` pararameter.
19
+ - `module` option will assign the test instance to `opts.module.exports`.
20
+ - `module` can also auto-generate an `id` if one was not passed.
21
+ - `moduleName` is used for the automatic `id` generation.
22
+ - Updated `functional()` and `new()` to pass their options to the constructor.
23
+
9
24
  ## [1.0.0] - 2022-06-22
10
25
  ### Added
11
26
  - Ported from Lum.js v4 library set.
12
27
  - Added a few more features from the PHP version.
13
28
 
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
29
+ [Unreleased]: https://github.com/supernovus/lum.tests.js/compare/v1.1.0...HEAD
30
+ [1.1.0]: https://github.com/supernovus/lum.tests.js/compare/v1.0.0...v1.1.0
31
+ [1.0.0]: https://github.com/supernovus/lum.tests.js/releases/tag/v1.0.0
16
32
 
@@ -51,17 +51,15 @@ const PROXY_METHODS =
51
51
  * and a new set of wrapper functions for the test instance, you could
52
52
  * create multiple sets of functional tests in their own private scopes.
53
53
  * Not sure why you'd want to do that, but in case you do, there ya go.
54
+ *
55
+ * @param {object} [opts] Options to pass to the `Test` constructor.
54
56
  *
55
57
  * @returns {Functional}
56
58
  *
57
59
  */
58
- function functional({plan,module}={})
60
+ function functional(opts={})
59
61
  {
60
- const test = new Test(plan);
61
- if (module)
62
- {
63
- module.exports = test;
64
- }
62
+ const test = new Test(opts);
65
63
  const functions = { test };
66
64
  for (const meth of PROXY_METHODS)
67
65
  {
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
+
File without changes
@@ -1,5 +1,5 @@
1
-
2
- const {F,S,N,isType,isInstance,def} = require('@lumjs/core').types;
1
+ const core = require('@lumjs/core');
2
+ const {F,S,N,isType,isObj,isInstance,def} = core.types;
3
3
 
4
4
  // We use a separate class to represent test logs.
5
5
  const Log = require('./log');
@@ -16,18 +16,59 @@ class Test
16
16
  /**
17
17
  * Build a new Test instance.
18
18
  *
19
- * @param {number} [plan] If used, passed to `plan()` method.
20
- *
19
+ * @param {object} [opts] Named options.
20
+ * @param {string} [opts.id] A unique test id, used by Harness.
21
+ * @param {number} [opts.plan] Passed to `plan()` method.
22
+ * @param {object} [opts.moduleName] Options for `core.modules.name()`.
23
+ * @param {object} [opts.module] The node module to export this test to.
24
+ *
25
+ * If you use this option, `opts.module.exports` will be assigned
26
+ * to the test instance, overriding anything that may have been
27
+ * assigned to it previously.
28
+ *
29
+ * Also, if this is passed, and `opts.id` was not specified, and id
30
+ * will be auto-generated based on the filename of the module.
31
+ *
21
32
  */
22
- constructor (plan)
33
+ constructor (opts={})
23
34
  {
35
+ if (typeof opts === N)
36
+ {
37
+ opts = {plan: opts};
38
+ }
39
+ else if (typeof opts === S)
40
+ {
41
+ opts = {id: opts};
42
+ }
43
+
44
+ const hasModule = isObj(opts.module);
45
+
46
+ if (typeof opts.id === S)
47
+ { // A specific id was specified.
48
+ this.id = opts.id;
49
+ }
50
+ else if (hasModule)
51
+ { // We're going to generate a simple name.
52
+ this.id = core.modules.name(opts.module, opts.moduleName);
53
+ }
54
+ else
55
+ { // An anonymous test.
56
+ this.id = null;
57
+ }
58
+
24
59
  this.failed = 0;
25
60
  this.skipped = 0;
26
61
  this.planned = 0;
27
62
  this.log = [];
28
- if (plan)
63
+
64
+ if (typeof opts.plan === N)
29
65
  {
30
- this.plan(plan);
66
+ this.plan(opts.plan);
67
+ }
68
+
69
+ if (hasModule)
70
+ { // Finally, if a module was passed, its going to export this test.
71
+ opts.module.exports = this;
31
72
  }
32
73
  }
33
74
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lumjs/tests",
3
- "version": "1.0.0",
4
- "main": "index.js",
3
+ "version": "1.1.0",
4
+ "main": "lib/index.js",
5
5
  "license": "MIT",
6
6
  "repository":
7
7
  {
package/test/basics.js CHANGED
@@ -1,4 +1,4 @@
1
- const Test = require('../index').Test;
1
+ const Test = require('../lib').Test;
2
2
  const def = require('./inc/basics.js');
3
3
 
4
4
  const test = new Test();
package/test/dies.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const def = require('./inc/dies.js');
2
2
  // Using the 'new()' function.
3
- const test = require('../index').new({module, plan: def.plan});
3
+ const test = require('../lib').new({module, plan: def.plan});
4
4
 
5
5
  for (const dt of def.diesErrors)
6
6
  {
@@ -1,6 +1,6 @@
1
1
  // Testing the basic functions of the functional testing API.
2
2
 
3
- const {test,plan,ok,pass,is,isnt,cmp,tap} = require('../index').functional();
3
+ const {test,plan,ok,pass,is,isnt,cmp,tap} = require('../lib').functional();
4
4
  const def = require('./inc/basics.js');
5
5
 
6
6
  plan(def.plan);
@@ -1,6 +1,6 @@
1
1
  const def = require('./inc/dies.js');
2
2
 
3
- const {dies,output} = require('../index').functional({module, plan: def.plan});
3
+ const {dies,output} = require('../lib').functional({module, plan: def.plan});
4
4
 
5
5
  for (const dt of def.diesErrors)
6
6
  {
package/index.js DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Several test related classes.
3
- */
4
-
5
- const Test = require('./src/test');
6
-
7
- module.exports.Test = Test;
8
- module.exports.Harness = require('./src/harness');
9
-
10
- // This one is not a class, but a special function.
11
- module.exports.functional = require('./src/functional');
12
-
13
- // This one is a quick shortcut function.
14
- module.exports.new = function({plan,module}={})
15
- {
16
- const test = new Test(plan);
17
- if (module)
18
- {
19
- module.exports = test;
20
- }
21
- return test;
22
- }
23
-