@lumjs/tests 1.6.0 → 1.7.1
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 +32 -2
- package/TODO.md +2 -3
- package/bin/lumtest.js +65 -0
- package/lib/grammar/README.md +6 -0
- package/lib/grammar/tap.js +996 -0
- package/lib/harness/browser.js +18 -0
- package/lib/harness/errors.js +44 -0
- package/lib/harness/index.js +260 -0
- package/lib/harness/node.js +71 -0
- package/lib/harness/parser.js +153 -0
- package/lib/harness/plugin.js +77 -0
- package/lib/harness/queuedtest.js +14 -0
- package/lib/index.js +19 -14
- package/lib/{functional.js → test/functional.js} +4 -4
- package/lib/{test.js → test/index.js} +10 -309
- package/lib/{log.js → test/log.js} +14 -8
- package/lib/test/stats.js +385 -0
- package/package.json +22 -13
- package/lib/harness.js +0 -25
- package/test/basics.js +0 -50
- package/test/data/people.js +0 -58
- package/test/dies.js +0 -17
- package/test/functional_basics.js +0 -54
- package/test/functional_dies.js +0 -17
- package/test/functional_isa.js +0 -23
- package/test/inc/basics.js +0 -72
- package/test/inc/dies.js +0 -78
- package/test/inc/isa.js +0 -110
- package/test/isa.js +0 -23
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
const core = require('@lumjs/core');
|
|
2
|
+
const {types} = core;
|
|
3
|
+
const {S,N,isObj,def} = types;
|
|
4
|
+
const Log = require('./log');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimalistic base class for the `Test` library.
|
|
8
|
+
*
|
|
9
|
+
* This provides the properties and methods related to the test statistics.
|
|
10
|
+
* It's extremely minimal and does not provide the core testing methods.
|
|
11
|
+
* See the [Test]{@link module:@lumjs/tests/test} class for that.
|
|
12
|
+
*
|
|
13
|
+
* @alias module:@lumjs/tests/test~Stats
|
|
14
|
+
*
|
|
15
|
+
* @property {number} planned - Number of tests planned, `0` if unplanned.
|
|
16
|
+
* @property {number} failed - Number of tests that failed.
|
|
17
|
+
* @property {number} skipped - Number of tests that were skipped.
|
|
18
|
+
* @property {number} ran - Number of tests ran (*calculated*).
|
|
19
|
+
* @property {string} id - Unique test id used by `Harness` libary.
|
|
20
|
+
* @property {boolean} isTop - Test module was loaded from the command line.
|
|
21
|
+
* @property {?object} harness - The top-level `Harness` if one was found.
|
|
22
|
+
*/
|
|
23
|
+
class Stats
|
|
24
|
+
{
|
|
25
|
+
/**
|
|
26
|
+
* Build a new instance.
|
|
27
|
+
*
|
|
28
|
+
* @param {object} [opts] Named options.
|
|
29
|
+
* @param {string} [opts.id] A unique test id, used by Harness.
|
|
30
|
+
* @param {number} [opts.plan] Passed to `plan()` method.
|
|
31
|
+
* @param {object} [opts.moduleName] Options for `core.modules.name()`.
|
|
32
|
+
* @param {object} [opts.module] The node module to export this test to.
|
|
33
|
+
*
|
|
34
|
+
* If you use this option, `opts.module.exports` will be assigned
|
|
35
|
+
* to the test instance, overriding anything that may have been
|
|
36
|
+
* assigned to it previously.
|
|
37
|
+
*
|
|
38
|
+
* Also, if this is passed, and `opts.id` was not specified, and id
|
|
39
|
+
* will be auto-generated based on the filename of the module.
|
|
40
|
+
*
|
|
41
|
+
* @param {number} [opts.stringify=1] The depth `stringify()` should recurse
|
|
42
|
+
* objects and Arrays before switching to plain JSON stringification.
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
constructor (opts={})
|
|
46
|
+
{
|
|
47
|
+
if (typeof opts === N)
|
|
48
|
+
{
|
|
49
|
+
opts = {plan: opts};
|
|
50
|
+
}
|
|
51
|
+
else if (typeof opts === S)
|
|
52
|
+
{
|
|
53
|
+
opts = {id: opts};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const hasModule = isObj(opts.module);
|
|
57
|
+
|
|
58
|
+
if (typeof opts.id === S)
|
|
59
|
+
{ // A specific id was specified.
|
|
60
|
+
this.id = opts.id;
|
|
61
|
+
}
|
|
62
|
+
else if (hasModule)
|
|
63
|
+
{ // We're going to generate a simple name.
|
|
64
|
+
this.id = core.modules.name(opts.module, opts.moduleName);
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
{ // An anonymous test.
|
|
68
|
+
this.id = null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.stringifyDepth = opts.stringify ?? 1;
|
|
72
|
+
|
|
73
|
+
this.failed = 0;
|
|
74
|
+
this.skipped = 0;
|
|
75
|
+
this.planned = 0;
|
|
76
|
+
|
|
77
|
+
// The test logs for each unit.
|
|
78
|
+
this.log = [];
|
|
79
|
+
|
|
80
|
+
// These will be updated below if possible.
|
|
81
|
+
this.isTop = false;
|
|
82
|
+
this.harness = null;
|
|
83
|
+
|
|
84
|
+
if (typeof opts.plan === N)
|
|
85
|
+
{
|
|
86
|
+
this.plan(opts.plan);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//console.debug('checking for module');
|
|
90
|
+
if (hasModule)
|
|
91
|
+
{ // If a module was passed, its going to export this test.
|
|
92
|
+
opts.module.exports = this;
|
|
93
|
+
//console.debug('module found');
|
|
94
|
+
// We'll also use the module to determine if we're Harnessed or not.
|
|
95
|
+
if (require.main === opts.module)
|
|
96
|
+
{ // Was called directly.
|
|
97
|
+
this.isTop = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!this.isTop)
|
|
102
|
+
{ // Try to find a Harness instance.
|
|
103
|
+
if (isObj(require.main) && require.main.exports instanceof Harness)
|
|
104
|
+
{ // We found the Harness instance.
|
|
105
|
+
this.harness = require.main.exports;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Finally, mark the test stats as not generated yet.
|
|
110
|
+
def(this, '$done', false);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Internal method.
|
|
114
|
+
$log()
|
|
115
|
+
{
|
|
116
|
+
return new Log(this);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// A wrapper around types.stringify()
|
|
120
|
+
stringify(what)
|
|
121
|
+
{
|
|
122
|
+
return types.stringify(what, this.stringifyDepth);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Indicate how many tests are planned to be run in this set.
|
|
127
|
+
*
|
|
128
|
+
* @param {number} num - The number of tests that should run.
|
|
129
|
+
*/
|
|
130
|
+
plan (num)
|
|
131
|
+
{
|
|
132
|
+
if (typeof num === N)
|
|
133
|
+
{
|
|
134
|
+
this.planned = num;
|
|
135
|
+
}
|
|
136
|
+
else if (num === false)
|
|
137
|
+
{
|
|
138
|
+
this.planned = 0;
|
|
139
|
+
}
|
|
140
|
+
else
|
|
141
|
+
{
|
|
142
|
+
throw new Error("Invalid value passed to plan()");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Check if a value is truthy, and add a log indicating the result.
|
|
148
|
+
*
|
|
149
|
+
* This is the absolute most basic method that every other testing method
|
|
150
|
+
* uses to log the results.
|
|
151
|
+
*
|
|
152
|
+
* I won't document the `desc` and `directive` parameters on any of the
|
|
153
|
+
* other methods as they are exactly the same as here.
|
|
154
|
+
*
|
|
155
|
+
* @param {*} test - Any value, usually the output of a test function.
|
|
156
|
+
* If the value evaluates as `true` (aka a truthy value), the test passes.
|
|
157
|
+
* If it evaluates as `false` (a falsey value), the test fails.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} [desc] A short description of the test.
|
|
160
|
+
* @param {(string|Error)} [directive] Further information for the log.
|
|
161
|
+
* @param {object} [details] Extra details to add to the log.
|
|
162
|
+
* @returns {Log} The test log with the results.
|
|
163
|
+
*/
|
|
164
|
+
ok (test, desc, directive, details)
|
|
165
|
+
{
|
|
166
|
+
const log = this.$log();
|
|
167
|
+
|
|
168
|
+
if (test)
|
|
169
|
+
{
|
|
170
|
+
log.ok = true;
|
|
171
|
+
}
|
|
172
|
+
else
|
|
173
|
+
{
|
|
174
|
+
this.failed++;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (typeof desc === S)
|
|
178
|
+
{
|
|
179
|
+
log.desc = desc;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (directive)
|
|
183
|
+
{
|
|
184
|
+
log.directive = directive;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (isObj(details))
|
|
188
|
+
{
|
|
189
|
+
log.details = details;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.log.push(log);
|
|
193
|
+
|
|
194
|
+
return log;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Mark a test as failed.
|
|
199
|
+
*
|
|
200
|
+
* @param {string} desc
|
|
201
|
+
* @param {*} [directive]
|
|
202
|
+
* @returns {Log}
|
|
203
|
+
*/
|
|
204
|
+
fail (desc, directive)
|
|
205
|
+
{
|
|
206
|
+
return this.ok(false, desc, directive);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Mark a test as passed.
|
|
211
|
+
*
|
|
212
|
+
* @param {string} desc
|
|
213
|
+
* @param {*} [directive]
|
|
214
|
+
* @returns {Log}
|
|
215
|
+
*/
|
|
216
|
+
pass (desc, directive)
|
|
217
|
+
{
|
|
218
|
+
return this.ok(true, desc, directive);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Skip a test.
|
|
223
|
+
*
|
|
224
|
+
* In some circumstances, there may be a situation where a
|
|
225
|
+
* test is not applicable (maybe it's an optional feature
|
|
226
|
+
* that only applies to a certain platform), and shouldn't be run.
|
|
227
|
+
* In order to maintain the correct number of tests ran, we can
|
|
228
|
+
* mark those tests as *skipped* using this method.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} [reason] - Why the test was skipped.
|
|
231
|
+
* @param {string} [desc] - A description of the test.
|
|
232
|
+
* @returns {Log}
|
|
233
|
+
*/
|
|
234
|
+
skip (reason, desc, _todo=false)
|
|
235
|
+
{
|
|
236
|
+
const log = this.ok(true, desc);
|
|
237
|
+
if (_todo)
|
|
238
|
+
log.todo = true;
|
|
239
|
+
else
|
|
240
|
+
log.skipped = true;
|
|
241
|
+
if (typeof reason === S)
|
|
242
|
+
log.reason = reason;
|
|
243
|
+
this.skipped++;
|
|
244
|
+
return log;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Mark a test as not yet implemented.
|
|
249
|
+
*
|
|
250
|
+
* This is quite different from the version in PHP.
|
|
251
|
+
* In that one `TODO` items are considered a *failure*.
|
|
252
|
+
* In this implementation, TODO items are considered
|
|
253
|
+
* to be *skipped*. They simply have a different marker
|
|
254
|
+
* in the TAP output than tests marked with `skip()`.
|
|
255
|
+
*
|
|
256
|
+
* @param {string} [reason] - What needs to be done to implement this test.
|
|
257
|
+
* @param {string} [desc] - A description of the test.
|
|
258
|
+
* @returns {Log}
|
|
259
|
+
*/
|
|
260
|
+
todo(reason, desc)
|
|
261
|
+
{
|
|
262
|
+
return this.skip(reason, desc, true);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Add diagnostics info directly to our test logs.
|
|
267
|
+
*
|
|
268
|
+
* @param {*} msg - The info to add.
|
|
269
|
+
* If this is a `string` it will be displayed as a comment as is.
|
|
270
|
+
* If it is anything else, it will be encoded as JSON first.
|
|
271
|
+
*
|
|
272
|
+
*/
|
|
273
|
+
diag (msg)
|
|
274
|
+
{
|
|
275
|
+
this.log.push(msg);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Return TAP formatted output for all the tests.
|
|
280
|
+
*
|
|
281
|
+
* @returns {string} The test logs, in TAP format.
|
|
282
|
+
*/
|
|
283
|
+
tap ()
|
|
284
|
+
{
|
|
285
|
+
let out = '';
|
|
286
|
+
if (this.planned > 0)
|
|
287
|
+
{
|
|
288
|
+
out += '1..'+this.planned+"\n";
|
|
289
|
+
}
|
|
290
|
+
let t = 1;
|
|
291
|
+
for (const log of this.log)
|
|
292
|
+
{
|
|
293
|
+
if (log instanceof Log)
|
|
294
|
+
{
|
|
295
|
+
out += log.tap(t++);
|
|
296
|
+
}
|
|
297
|
+
else
|
|
298
|
+
{ // A comment.
|
|
299
|
+
out += '# ' + (typeof log === S ? log : this.stringify(log)) + "\n";
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (this.skipped)
|
|
303
|
+
{
|
|
304
|
+
out += '# ~ Skipped '+this.skipped+" tests\n";
|
|
305
|
+
}
|
|
306
|
+
if (this.failed)
|
|
307
|
+
{
|
|
308
|
+
out += '# ~ Failed '+this.failed+(this.failed>1?' tests':' test');
|
|
309
|
+
if (this.planned)
|
|
310
|
+
out += ' out of '+this.planned;
|
|
311
|
+
out += "\n";
|
|
312
|
+
}
|
|
313
|
+
const ran = t-1;
|
|
314
|
+
if (this.planned > 0 && this.planned != ran)
|
|
315
|
+
{
|
|
316
|
+
out += '# ~ Looks like you planned '+this.planned+' but ran '+ran+" tests\n";
|
|
317
|
+
}
|
|
318
|
+
return out;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* A read-only *accessor* property alias for `tap()`.
|
|
323
|
+
* @returns {string}
|
|
324
|
+
* @see {@link module:@lumjs/tests/test#tap}
|
|
325
|
+
*/
|
|
326
|
+
get TAP()
|
|
327
|
+
{
|
|
328
|
+
return this.tap();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* A calculated property of the number of tests that were ran.
|
|
333
|
+
* @type {int}
|
|
334
|
+
*/
|
|
335
|
+
get ran ()
|
|
336
|
+
{
|
|
337
|
+
let ran = 0;
|
|
338
|
+
for (const log of this.log)
|
|
339
|
+
{
|
|
340
|
+
if (log instanceof Log)
|
|
341
|
+
{
|
|
342
|
+
ran++;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return ran;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Send the TAP output to the `console`.
|
|
350
|
+
*
|
|
351
|
+
* This is a low-level method and is no longer recommended for use.
|
|
352
|
+
* Instead call the `done()` method, which will *do the right thing*.
|
|
353
|
+
*/
|
|
354
|
+
output ()
|
|
355
|
+
{
|
|
356
|
+
console.log(this.tap());
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* We're done testing.
|
|
362
|
+
*
|
|
363
|
+
* This will mark the test-set as finished, so attempting to run further
|
|
364
|
+
* tests after will result in a `RangeError` being thrown.
|
|
365
|
+
*
|
|
366
|
+
* If no `Harness` is in use, this will also run `this.output()`.
|
|
367
|
+
*/
|
|
368
|
+
done ()
|
|
369
|
+
{
|
|
370
|
+
if (this.$done)
|
|
371
|
+
{
|
|
372
|
+
throw new RangeError('Test set is already done');
|
|
373
|
+
}
|
|
374
|
+
def(this, '$done', true);
|
|
375
|
+
return (this.harness ? this : this.output());
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
} // class Test
|
|
379
|
+
|
|
380
|
+
// Export the class
|
|
381
|
+
module.exports = Stats;
|
|
382
|
+
|
|
383
|
+
// Finally at the bottom after `module.exports` has been set, we will load
|
|
384
|
+
// the Harness class to avoid circular references failing.
|
|
385
|
+
const Harness = require('../harness');
|
package/package.json
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumjs/tests",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
|
-
"
|
|
5
|
+
"bin":
|
|
6
|
+
{
|
|
7
|
+
"lumtest": "bin/lumtest.js"
|
|
8
|
+
},
|
|
9
|
+
"exports":
|
|
6
10
|
{
|
|
7
11
|
".": "./lib/index.js",
|
|
8
|
-
"./test": "./lib/test.js",
|
|
9
|
-
"./functional": "./lib/functional.js",
|
|
10
|
-
"./harness": "./lib/harness.js",
|
|
12
|
+
"./test": "./lib/test/index.js",
|
|
13
|
+
"./test/functional": "./lib/test/functional.js",
|
|
14
|
+
"./harness": "./lib/harness/index.js",
|
|
15
|
+
"./harness/parser": "./lib/harness/parser.js",
|
|
11
16
|
"./package.json": "./package.json",
|
|
12
17
|
"./data/*": "./test/data/*.js"
|
|
13
18
|
},
|
|
14
19
|
"license": "MIT",
|
|
15
|
-
"repository":
|
|
20
|
+
"repository":
|
|
16
21
|
{
|
|
17
22
|
"type": "git",
|
|
18
23
|
"url": "https://github.com/supernovus/lum.tests.js.git"
|
|
19
24
|
},
|
|
20
|
-
"dependencies":
|
|
21
|
-
"@lumjs/core": "^1.3.0"
|
|
22
|
-
},
|
|
23
|
-
"scripts":
|
|
25
|
+
"dependencies":
|
|
24
26
|
{
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
"@lumjs/core": "^1.7.1"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "node ./bin/lumtest.js",
|
|
31
|
+
"build-docs": "jsdoc -c ./jsdoc.json",
|
|
32
|
+
"build": "npm run build:grammar",
|
|
33
|
+
"build:grammar": "./bin/build-grammar.sh tap"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"peggy": "^2.0.1"
|
|
28
37
|
}
|
|
29
38
|
}
|
package/lib/harness.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const Test = require('./test');
|
|
3
|
-
const Log = require('./log');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Module defining the Harness class.
|
|
7
|
-
* @module @lumjs/tests/harness
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A class that acts as a test harness for running other tests.
|
|
12
|
-
*
|
|
13
|
-
* Based off of the Lum.php Test\Harness class.
|
|
14
|
-
*/
|
|
15
|
-
class Harness
|
|
16
|
-
{
|
|
17
|
-
construct()
|
|
18
|
-
{
|
|
19
|
-
throw new Error("Not yet implemented");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Export it.
|
|
24
|
-
module.exports = Harness;
|
|
25
|
-
|
package/test/basics.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const Test = require('../lib').Test;
|
|
2
|
-
const def = require('./inc/basics.js');
|
|
3
|
-
const stringify = def.types.stringify;
|
|
4
|
-
|
|
5
|
-
const test = new Test();
|
|
6
|
-
test.plan(def.plan);
|
|
7
|
-
|
|
8
|
-
test.ok(def.okay, 'ok()');
|
|
9
|
-
test.pass('pass()');
|
|
10
|
-
|
|
11
|
-
for (const is of def.isTests)
|
|
12
|
-
{
|
|
13
|
-
const t = stringify(is);
|
|
14
|
-
test.is(is, is, 'is('+t+','+t+')');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
for (const [a,b] of def.isntTests)
|
|
18
|
-
{
|
|
19
|
-
const msg = `isnt(${stringify(a)},${stringify(b)})`;
|
|
20
|
-
test.isnt(a, b, msg);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
for (const args of def.cmpTests)
|
|
24
|
-
{
|
|
25
|
-
const msg = 'cmp('+stringify(args)+')';
|
|
26
|
-
test.cmp(...args, msg);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
for (const func of def.livesTests)
|
|
30
|
-
{
|
|
31
|
-
test.lives(func, `lives(${stringify(func)})`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
for (const [a,b] of def.isJsonTests)
|
|
35
|
-
{
|
|
36
|
-
const msg = `isJSON(${stringify(a)},${stringify(b)})`;
|
|
37
|
-
test.isJSON(a, b, msg);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for (const [a,b] of def.isntJsonTests)
|
|
41
|
-
{
|
|
42
|
-
const msg = `isntJSON(${stringify(a)},${stringify(b)})`;
|
|
43
|
-
test.isntJSON(a, b, msg);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// We're done, output the log.
|
|
47
|
-
console.log(test.tap());
|
|
48
|
-
|
|
49
|
-
// Re-expect the test.
|
|
50
|
-
module.exports = test;
|
package/test/data/people.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
module.exports = function (opts={})
|
|
2
|
-
{
|
|
3
|
-
let people =
|
|
4
|
-
[
|
|
5
|
-
{
|
|
6
|
-
name: 'Bob',
|
|
7
|
-
age: 40,
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
name: 'Lisa',
|
|
11
|
-
age: 25,
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
name: 'Kevin',
|
|
15
|
-
age: 18,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: 'Sarah',
|
|
19
|
-
age: 13,
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
if (opts.withRecursion)
|
|
24
|
-
{
|
|
25
|
-
people[0].kids = [people[2],people[3]];
|
|
26
|
-
people[1].kids = [people[3]];
|
|
27
|
-
people[2].kids = [];
|
|
28
|
-
people[3].kids = [];
|
|
29
|
-
people[0].parents = [];
|
|
30
|
-
people[1].parents = [];
|
|
31
|
-
people[2].parents = [people[0]];
|
|
32
|
-
people[3].parents = [people[0],people[1]];
|
|
33
|
-
}
|
|
34
|
-
else if (opts.withReferences)
|
|
35
|
-
{
|
|
36
|
-
people[0].kids = [2,3];
|
|
37
|
-
people[1].kids = [3];
|
|
38
|
-
people[2].kids = [];
|
|
39
|
-
people[3].kids = [];
|
|
40
|
-
people[0].parents = [];
|
|
41
|
-
people[1].parents = [];
|
|
42
|
-
people[2].parents = [0];
|
|
43
|
-
people[3].parents = [0,1];
|
|
44
|
-
}
|
|
45
|
-
else if (opts.withNames)
|
|
46
|
-
{
|
|
47
|
-
people[0].kids = [people[2].name,people[3].name];
|
|
48
|
-
people[1].kids = [people[3].name];
|
|
49
|
-
people[2].kids = [];
|
|
50
|
-
people[3].kids = [];
|
|
51
|
-
people[0].parents = [];
|
|
52
|
-
people[1].parents = [];
|
|
53
|
-
people[2].parents = [people[0].name];
|
|
54
|
-
people[3].parents = [people[0].name,people[1].name];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return people;
|
|
58
|
-
}
|
package/test/dies.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const def = require('./inc/dies.js');
|
|
2
|
-
// Using the 'new()' function.
|
|
3
|
-
const test = require('../lib').new({module, plan: def.plan});
|
|
4
|
-
|
|
5
|
-
for (const dt of def.diesErrors)
|
|
6
|
-
{
|
|
7
|
-
test.dies(...dt);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
for (const dt of def.diesSyntaxErrors)
|
|
11
|
-
{
|
|
12
|
-
test.dies(...dt);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// We're done, output the log.
|
|
16
|
-
test.output();
|
|
17
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Testing the basic functions of the functional testing API.
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
{
|
|
5
|
-
test,plan,ok,pass,is,isnt,cmp,tap,isJSON,isntJSON,lives,
|
|
6
|
-
} = require('../lib').functional();
|
|
7
|
-
const def = require('./inc/basics.js');
|
|
8
|
-
const stringify = def.types.stringify;
|
|
9
|
-
|
|
10
|
-
plan(def.plan);
|
|
11
|
-
|
|
12
|
-
ok(def.okay, 'ok()');
|
|
13
|
-
pass('pass()');
|
|
14
|
-
|
|
15
|
-
for (const it of def.isTests)
|
|
16
|
-
{
|
|
17
|
-
const t = stringify(it);
|
|
18
|
-
is(it, it, 'is('+t+','+t+')');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
for (const [a,b] of def.isntTests)
|
|
22
|
-
{
|
|
23
|
-
const msg = `isnt(${stringify(a)},${stringify(b)})`;
|
|
24
|
-
isnt(a, b, msg);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for (const args of def.cmpTests)
|
|
28
|
-
{
|
|
29
|
-
const msg = 'cmp('+stringify(args)+')';
|
|
30
|
-
cmp(...args, msg);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
for (const func of def.livesTests)
|
|
34
|
-
{
|
|
35
|
-
lives(func, `lives(${stringify(func)})`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
for (const [a,b] of def.isJsonTests)
|
|
39
|
-
{
|
|
40
|
-
const msg = `isJSON(${stringify(a)},${stringify(b)})`;
|
|
41
|
-
isJSON(a, b, msg);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (const [a,b] of def.isntJsonTests)
|
|
45
|
-
{
|
|
46
|
-
const msg = `isntJSON(${stringify(a)},${stringify(b)})`;
|
|
47
|
-
isntJSON(a, b, msg);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// We're done, output the log.
|
|
51
|
-
console.log(tap());
|
|
52
|
-
|
|
53
|
-
// And re-export the test.
|
|
54
|
-
module.exports = test;
|
package/test/functional_dies.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const def = require('./inc/dies.js');
|
|
2
|
-
|
|
3
|
-
const {dies,output} = require('../lib').functional({module, plan: def.plan});
|
|
4
|
-
|
|
5
|
-
for (const dt of def.diesErrors)
|
|
6
|
-
{
|
|
7
|
-
dies(...dt);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
for (const dt of def.diesSyntaxErrors)
|
|
11
|
-
{
|
|
12
|
-
dies(...dt);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// We're done, output the log.
|
|
16
|
-
output();
|
|
17
|
-
|
package/test/functional_isa.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const {test,plan,tap,isa,nota} = require('../lib').functional();
|
|
2
|
-
const def = require('./inc/isa.js');
|
|
3
|
-
const getLabel = def.label;
|
|
4
|
-
|
|
5
|
-
plan(def.plan);
|
|
6
|
-
|
|
7
|
-
for (const isaTest of def.isaTests)
|
|
8
|
-
{
|
|
9
|
-
const label = getLabel('isa',isaTest);
|
|
10
|
-
isa(isaTest[0], isaTest[1], label);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (const notaTest of def.notaTests)
|
|
14
|
-
{
|
|
15
|
-
const label = getLabel('nota',notaTest);
|
|
16
|
-
nota(notaTest[0], notaTest[1], label);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// We're done, output the log.
|
|
20
|
-
console.log(tap());
|
|
21
|
-
|
|
22
|
-
// And re-export the test.
|
|
23
|
-
module.exports = test;
|