mocha-compat 3.6.4 → 10.8.2
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/LICENSE +1 -1
- package/README.md +61 -110
- package/bin/_mocha +10 -0
- package/bin/mocha.js +142 -0
- package/browser-entry.js +61 -22
- package/lib/browser/highlight-tags.js +39 -0
- package/lib/browser/parse-query.js +24 -0
- package/lib/{template.html → browser/template.html} +7 -5
- package/lib/cli/cli.js +89 -0
- package/lib/cli/collect-files.js +137 -0
- package/lib/cli/commands.js +14 -0
- package/lib/cli/config.js +100 -0
- package/lib/cli/index.js +3 -0
- package/lib/cli/init.js +36 -0
- package/lib/cli/lookup-files.js +150 -0
- package/lib/cli/node-flags.js +85 -0
- package/lib/cli/one-and-dones.js +69 -0
- package/lib/cli/options.js +284 -0
- package/lib/cli/run-helpers.js +304 -0
- package/lib/cli/run-option-metadata.js +116 -0
- package/lib/cli/run.js +380 -0
- package/lib/cli/watch-run.js +377 -0
- package/lib/context.js +16 -42
- package/lib/errors.js +563 -0
- package/lib/hook.js +50 -9
- package/lib/interfaces/bdd.js +28 -29
- package/lib/interfaces/common.js +56 -21
- package/lib/interfaces/exports.js +4 -7
- package/lib/interfaces/qunit.js +10 -11
- package/lib/interfaces/tdd.js +15 -15
- package/lib/mocha.js +1073 -292
- package/lib/mocharc.json +10 -0
- package/lib/nodejs/buffered-worker-pool.js +188 -0
- package/lib/nodejs/esm-utils.js +106 -0
- package/lib/nodejs/file-unloader.js +15 -0
- package/lib/nodejs/parallel-buffered-runner.js +433 -0
- package/lib/nodejs/reporters/parallel-buffered.js +165 -0
- package/lib/nodejs/serializer.js +414 -0
- package/lib/nodejs/worker.js +151 -0
- package/lib/pending.js +3 -3
- package/lib/plugin-loader.js +286 -0
- package/lib/reporters/base.js +305 -205
- package/lib/reporters/doc.js +52 -21
- package/lib/reporters/dot.js +31 -18
- package/lib/reporters/html.js +153 -81
- package/lib/reporters/json-stream.js +53 -24
- package/lib/reporters/json.js +88 -18
- package/lib/reporters/landing.js +38 -16
- package/lib/reporters/list.js +34 -19
- package/lib/reporters/markdown.js +28 -15
- package/lib/reporters/min.js +22 -8
- package/lib/reporters/nyan.js +62 -58
- package/lib/reporters/progress.js +32 -19
- package/lib/reporters/spec.js +41 -23
- package/lib/reporters/tap.js +255 -32
- package/lib/reporters/xunit.js +89 -39
- package/lib/runnable.js +233 -148
- package/lib/runner.js +679 -380
- package/lib/stats-collector.js +83 -0
- package/lib/suite.js +376 -112
- package/lib/test.js +82 -21
- package/lib/utils.js +364 -477
- package/mocha.css +183 -54
- package/mocha.js +19840 -15846
- package/mocha.js.map +1 -0
- package/package.json +163 -336
- package/{lib/to-iso-string → vendor/serialize-javascript}/LICENSE +8 -6
- package/vendor/serialize-javascript/README.md +10 -0
- package/vendor/serialize-javascript/index.js +349 -0
- package/bin/_mocha-compat +0 -572
- package/bin/mocha-compat +0 -87
- package/bin/options.js +0 -41
- package/bower.json +0 -38
- package/images/error.png +0 -0
- package/images/ok.png +0 -0
- package/lib/browser/.eslintrc.yaml +0 -4
- package/lib/browser/debug.js +0 -7
- package/lib/browser/events.js +0 -195
- package/lib/browser/progress.js +0 -119
- package/lib/browser/tty.js +0 -13
- package/lib/ms.js +0 -130
- package/lib/to-iso-string/index.js +0 -37
- package/vendor/glob/LICENSE +0 -15
- package/vendor/glob/README.md +0 -399
- package/vendor/glob/common.js +0 -244
- package/vendor/glob/glob.js +0 -788
- package/vendor/glob/package.json +0 -55
- package/vendor/glob/sync.js +0 -486
- package/vendor/inflight/LICENSE +0 -15
- package/vendor/inflight/README.md +0 -37
- package/vendor/inflight/inflight.js +0 -54
- package/vendor/inflight/package.json +0 -29
|
@@ -1,63 +1,92 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module JSONStream
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
var Base = require('./base');
|
|
8
|
-
var
|
|
10
|
+
var constants = require('../runner').constants;
|
|
11
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
12
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
13
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
14
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
|
-
* Expose `
|
|
17
|
+
* Expose `JSONStream`.
|
|
12
18
|
*/
|
|
13
19
|
|
|
14
|
-
exports = module.exports =
|
|
20
|
+
exports = module.exports = JSONStream;
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
|
-
*
|
|
23
|
+
* Constructs a new `JSONStream` reporter instance.
|
|
18
24
|
*
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
25
|
+
* @public
|
|
26
|
+
* @class
|
|
27
|
+
* @memberof Mocha.reporters
|
|
28
|
+
* @extends Mocha.reporters.Base
|
|
29
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
30
|
+
* @param {Object} [options] - runner options
|
|
21
31
|
*/
|
|
22
|
-
function
|
|
23
|
-
Base.call(this, runner);
|
|
32
|
+
function JSONStream(runner, options) {
|
|
33
|
+
Base.call(this, runner, options);
|
|
24
34
|
|
|
25
35
|
var self = this;
|
|
26
36
|
var total = runner.total;
|
|
27
37
|
|
|
28
|
-
runner.
|
|
29
|
-
|
|
38
|
+
runner.once(EVENT_RUN_BEGIN, function () {
|
|
39
|
+
writeEvent(['start', {total}]);
|
|
30
40
|
});
|
|
31
41
|
|
|
32
|
-
runner.on(
|
|
33
|
-
|
|
42
|
+
runner.on(EVENT_TEST_PASS, function (test) {
|
|
43
|
+
writeEvent(['pass', clean(test)]);
|
|
34
44
|
});
|
|
35
45
|
|
|
36
|
-
runner.on(
|
|
46
|
+
runner.on(EVENT_TEST_FAIL, function (test, err) {
|
|
37
47
|
test = clean(test);
|
|
38
48
|
test.err = err.message;
|
|
39
49
|
test.stack = err.stack || null;
|
|
40
|
-
|
|
50
|
+
writeEvent(['fail', test]);
|
|
41
51
|
});
|
|
42
52
|
|
|
43
|
-
runner.
|
|
44
|
-
|
|
53
|
+
runner.once(EVENT_RUN_END, function () {
|
|
54
|
+
writeEvent(['end', self.stats]);
|
|
45
55
|
});
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
59
|
+
* Mocha event to be written to the output stream.
|
|
60
|
+
* @typedef {Array} JSONStream~MochaEvent
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Writes Mocha event to reporter output stream.
|
|
65
|
+
*
|
|
66
|
+
* @private
|
|
67
|
+
* @param {JSONStream~MochaEvent} event - Mocha event to be output.
|
|
68
|
+
*/
|
|
69
|
+
function writeEvent(event) {
|
|
70
|
+
process.stdout.write(JSON.stringify(event) + '\n');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns an object literal representation of `test`
|
|
75
|
+
* free of cyclic properties, etc.
|
|
51
76
|
*
|
|
52
|
-
* @
|
|
53
|
-
* @param {
|
|
54
|
-
* @return {Object}
|
|
77
|
+
* @private
|
|
78
|
+
* @param {Test} test - Instance used as data source.
|
|
79
|
+
* @return {Object} object containing pared-down test instance data
|
|
55
80
|
*/
|
|
56
|
-
function clean
|
|
81
|
+
function clean(test) {
|
|
57
82
|
return {
|
|
58
83
|
title: test.title,
|
|
59
84
|
fullTitle: test.fullTitle(),
|
|
85
|
+
file: test.file,
|
|
60
86
|
duration: test.duration,
|
|
61
|
-
currentRetry: test.currentRetry()
|
|
87
|
+
currentRetry: test.currentRetry(),
|
|
88
|
+
speed: test.speed
|
|
62
89
|
};
|
|
63
90
|
}
|
|
91
|
+
|
|
92
|
+
JSONStream.description = 'newline delimited JSON events';
|
package/lib/reporters/json.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module JSON
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
var Base = require('./base');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var path = require('path');
|
|
12
|
+
const createUnsupportedError = require('../errors').createUnsupportedError;
|
|
13
|
+
const utils = require('../utils');
|
|
14
|
+
var constants = require('../runner').constants;
|
|
15
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
16
|
+
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
|
17
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
18
|
+
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
|
19
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
8
20
|
|
|
9
21
|
/**
|
|
10
22
|
* Expose `JSON`.
|
|
@@ -13,37 +25,49 @@ var Base = require('./base');
|
|
|
13
25
|
exports = module.exports = JSONReporter;
|
|
14
26
|
|
|
15
27
|
/**
|
|
16
|
-
*
|
|
28
|
+
* Constructs a new `JSON` reporter instance.
|
|
17
29
|
*
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
30
|
+
* @public
|
|
31
|
+
* @class JSON
|
|
32
|
+
* @memberof Mocha.reporters
|
|
33
|
+
* @extends Mocha.reporters.Base
|
|
34
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
35
|
+
* @param {Object} [options] - runner options
|
|
20
36
|
*/
|
|
21
|
-
function JSONReporter
|
|
22
|
-
Base.call(this, runner);
|
|
37
|
+
function JSONReporter(runner, options = {}) {
|
|
38
|
+
Base.call(this, runner, options);
|
|
23
39
|
|
|
24
40
|
var self = this;
|
|
25
41
|
var tests = [];
|
|
26
42
|
var pending = [];
|
|
27
43
|
var failures = [];
|
|
28
44
|
var passes = [];
|
|
45
|
+
var output;
|
|
46
|
+
|
|
47
|
+
if (options.reporterOption && options.reporterOption.output) {
|
|
48
|
+
if (utils.isBrowser()) {
|
|
49
|
+
throw createUnsupportedError('file output not supported in browser');
|
|
50
|
+
}
|
|
51
|
+
output = options.reporterOption.output;
|
|
52
|
+
}
|
|
29
53
|
|
|
30
|
-
runner.on(
|
|
54
|
+
runner.on(EVENT_TEST_END, function (test) {
|
|
31
55
|
tests.push(test);
|
|
32
56
|
});
|
|
33
57
|
|
|
34
|
-
runner.on(
|
|
58
|
+
runner.on(EVENT_TEST_PASS, function (test) {
|
|
35
59
|
passes.push(test);
|
|
36
60
|
});
|
|
37
61
|
|
|
38
|
-
runner.on(
|
|
62
|
+
runner.on(EVENT_TEST_FAIL, function (test) {
|
|
39
63
|
failures.push(test);
|
|
40
64
|
});
|
|
41
65
|
|
|
42
|
-
runner.on(
|
|
66
|
+
runner.on(EVENT_TEST_PENDING, function (test) {
|
|
43
67
|
pending.push(test);
|
|
44
68
|
});
|
|
45
69
|
|
|
46
|
-
runner.
|
|
70
|
+
runner.once(EVENT_RUN_END, function () {
|
|
47
71
|
var obj = {
|
|
48
72
|
stats: self.stats,
|
|
49
73
|
tests: tests.map(clean),
|
|
@@ -54,7 +78,20 @@ function JSONReporter (runner) {
|
|
|
54
78
|
|
|
55
79
|
runner.testResults = obj;
|
|
56
80
|
|
|
57
|
-
|
|
81
|
+
var json = JSON.stringify(obj, null, 2);
|
|
82
|
+
if (output) {
|
|
83
|
+
try {
|
|
84
|
+
fs.mkdirSync(path.dirname(output), {recursive: true});
|
|
85
|
+
fs.writeFileSync(output, json);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.error(
|
|
88
|
+
`${Base.symbols.err} [mocha] writing output to "${output}" failed: ${err.message}\n`
|
|
89
|
+
);
|
|
90
|
+
process.stdout.write(json);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
process.stdout.write(json);
|
|
94
|
+
}
|
|
58
95
|
});
|
|
59
96
|
}
|
|
60
97
|
|
|
@@ -62,31 +99,64 @@ function JSONReporter (runner) {
|
|
|
62
99
|
* Return a plain-object representation of `test`
|
|
63
100
|
* free of cyclic properties etc.
|
|
64
101
|
*
|
|
65
|
-
* @
|
|
102
|
+
* @private
|
|
66
103
|
* @param {Object} test
|
|
67
104
|
* @return {Object}
|
|
68
105
|
*/
|
|
69
|
-
function clean
|
|
106
|
+
function clean(test) {
|
|
107
|
+
var err = test.err || {};
|
|
108
|
+
if (err instanceof Error) {
|
|
109
|
+
err = errorJSON(err);
|
|
110
|
+
}
|
|
111
|
+
|
|
70
112
|
return {
|
|
71
113
|
title: test.title,
|
|
72
114
|
fullTitle: test.fullTitle(),
|
|
115
|
+
file: test.file,
|
|
73
116
|
duration: test.duration,
|
|
74
117
|
currentRetry: test.currentRetry(),
|
|
75
|
-
|
|
118
|
+
speed: test.speed,
|
|
119
|
+
err: cleanCycles(err)
|
|
76
120
|
};
|
|
77
121
|
}
|
|
78
122
|
|
|
79
123
|
/**
|
|
80
|
-
*
|
|
124
|
+
* Replaces any circular references inside `obj` with '[object Object]'
|
|
81
125
|
*
|
|
82
|
-
* @
|
|
126
|
+
* @private
|
|
127
|
+
* @param {Object} obj
|
|
128
|
+
* @return {Object}
|
|
129
|
+
*/
|
|
130
|
+
function cleanCycles(obj) {
|
|
131
|
+
var cache = [];
|
|
132
|
+
return JSON.parse(
|
|
133
|
+
JSON.stringify(obj, function (key, value) {
|
|
134
|
+
if (typeof value === 'object' && value !== null) {
|
|
135
|
+
if (cache.indexOf(value) !== -1) {
|
|
136
|
+
// Instead of going in a circle, we'll print [object Object]
|
|
137
|
+
return '' + value;
|
|
138
|
+
}
|
|
139
|
+
cache.push(value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return value;
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Transform an Error object into a JSON object.
|
|
149
|
+
*
|
|
150
|
+
* @private
|
|
83
151
|
* @param {Error} err
|
|
84
152
|
* @return {Object}
|
|
85
153
|
*/
|
|
86
|
-
function errorJSON
|
|
154
|
+
function errorJSON(err) {
|
|
87
155
|
var res = {};
|
|
88
156
|
Object.getOwnPropertyNames(err).forEach(function (key) {
|
|
89
157
|
res[key] = err[key];
|
|
90
158
|
}, err);
|
|
91
159
|
return res;
|
|
92
160
|
}
|
|
161
|
+
|
|
162
|
+
JSONReporter.description = 'single JSON object';
|
package/lib/reporters/landing.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module Landing
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
var Base = require('./base');
|
|
8
10
|
var inherits = require('../utils').inherits;
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
13
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
14
|
+
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
|
15
|
+
var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
|
|
16
|
+
|
|
9
17
|
var cursor = Base.cursor;
|
|
10
18
|
var color = Base.color;
|
|
11
19
|
|
|
@@ -34,38 +42,42 @@ Base.colors['plane crash'] = 31;
|
|
|
34
42
|
Base.colors.runway = 90;
|
|
35
43
|
|
|
36
44
|
/**
|
|
37
|
-
*
|
|
45
|
+
* Constructs a new `Landing` reporter instance.
|
|
38
46
|
*
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
47
|
+
* @public
|
|
48
|
+
* @class
|
|
49
|
+
* @memberof Mocha.reporters
|
|
50
|
+
* @extends Mocha.reporters.Base
|
|
51
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
52
|
+
* @param {Object} [options] - runner options
|
|
41
53
|
*/
|
|
42
|
-
function Landing
|
|
43
|
-
Base.call(this, runner);
|
|
54
|
+
function Landing(runner, options) {
|
|
55
|
+
Base.call(this, runner, options);
|
|
44
56
|
|
|
45
57
|
var self = this;
|
|
46
|
-
var width = Base.window.width * 0.75 | 0;
|
|
47
|
-
var total = runner.total;
|
|
58
|
+
var width = (Base.window.width * 0.75) | 0;
|
|
48
59
|
var stream = process.stdout;
|
|
60
|
+
|
|
49
61
|
var plane = color('plane', '✈');
|
|
50
62
|
var crashed = -1;
|
|
51
63
|
var n = 0;
|
|
64
|
+
var total = 0;
|
|
52
65
|
|
|
53
|
-
function runway
|
|
66
|
+
function runway() {
|
|
54
67
|
var buf = Array(width).join('-');
|
|
55
68
|
return ' ' + color('runway', buf);
|
|
56
69
|
}
|
|
57
70
|
|
|
58
|
-
runner.on(
|
|
71
|
+
runner.on(EVENT_RUN_BEGIN, function () {
|
|
59
72
|
stream.write('\n\n\n ');
|
|
60
73
|
cursor.hide();
|
|
61
74
|
});
|
|
62
75
|
|
|
63
|
-
runner.on(
|
|
76
|
+
runner.on(EVENT_TEST_END, function (test) {
|
|
64
77
|
// check if the plane crashed
|
|
65
|
-
var col = crashed === -1 ? width * ++n / total | 0 : crashed;
|
|
66
|
-
|
|
78
|
+
var col = crashed === -1 ? ((width * ++n) / ++total) | 0 : crashed;
|
|
67
79
|
// show the crash
|
|
68
|
-
if (test.state ===
|
|
80
|
+
if (test.state === STATE_FAILED) {
|
|
69
81
|
plane = color('plane crash', '✈');
|
|
70
82
|
crashed = col;
|
|
71
83
|
}
|
|
@@ -81,14 +93,24 @@ function Landing (runner) {
|
|
|
81
93
|
stream.write('\u001b[0m');
|
|
82
94
|
});
|
|
83
95
|
|
|
84
|
-
runner.
|
|
96
|
+
runner.once(EVENT_RUN_END, function () {
|
|
85
97
|
cursor.show();
|
|
86
|
-
|
|
98
|
+
process.stdout.write('\n');
|
|
87
99
|
self.epilogue();
|
|
88
100
|
});
|
|
101
|
+
|
|
102
|
+
// if cursor is hidden when we ctrl-C, then it will remain hidden unless...
|
|
103
|
+
process.once('SIGINT', function () {
|
|
104
|
+
cursor.show();
|
|
105
|
+
process.nextTick(function () {
|
|
106
|
+
process.kill(process.pid, 'SIGINT');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
/**
|
|
92
112
|
* Inherit from `Base.prototype`.
|
|
93
113
|
*/
|
|
94
114
|
inherits(Landing, Base);
|
|
115
|
+
|
|
116
|
+
Landing.description = 'Unicode landing strip';
|
package/lib/reporters/list.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module List
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
var Base = require('./base');
|
|
8
10
|
var inherits = require('../utils').inherits;
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
13
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
14
|
+
var EVENT_TEST_BEGIN = constants.EVENT_TEST_BEGIN;
|
|
15
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
16
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
17
|
+
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
|
9
18
|
var color = Base.color;
|
|
10
19
|
var cursor = Base.cursor;
|
|
11
20
|
|
|
@@ -16,48 +25,54 @@ var cursor = Base.cursor;
|
|
|
16
25
|
exports = module.exports = List;
|
|
17
26
|
|
|
18
27
|
/**
|
|
19
|
-
*
|
|
28
|
+
* Constructs a new `List` reporter instance.
|
|
20
29
|
*
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
30
|
+
* @public
|
|
31
|
+
* @class
|
|
32
|
+
* @memberof Mocha.reporters
|
|
33
|
+
* @extends Mocha.reporters.Base
|
|
34
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
35
|
+
* @param {Object} [options] - runner options
|
|
23
36
|
*/
|
|
24
|
-
function List
|
|
25
|
-
Base.call(this, runner);
|
|
37
|
+
function List(runner, options) {
|
|
38
|
+
Base.call(this, runner, options);
|
|
26
39
|
|
|
27
40
|
var self = this;
|
|
28
41
|
var n = 0;
|
|
29
42
|
|
|
30
|
-
runner.on(
|
|
31
|
-
|
|
43
|
+
runner.on(EVENT_RUN_BEGIN, function () {
|
|
44
|
+
Base.consoleLog();
|
|
32
45
|
});
|
|
33
46
|
|
|
34
|
-
runner.on(
|
|
47
|
+
runner.on(EVENT_TEST_BEGIN, function (test) {
|
|
35
48
|
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
|
36
49
|
});
|
|
37
50
|
|
|
38
|
-
runner.on(
|
|
39
|
-
var fmt = color('checkmark', ' -') +
|
|
40
|
-
|
|
41
|
-
console.log(fmt, test.fullTitle());
|
|
51
|
+
runner.on(EVENT_TEST_PENDING, function (test) {
|
|
52
|
+
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
|
53
|
+
Base.consoleLog(fmt, test.fullTitle());
|
|
42
54
|
});
|
|
43
55
|
|
|
44
|
-
runner.on(
|
|
45
|
-
var fmt =
|
|
56
|
+
runner.on(EVENT_TEST_PASS, function (test) {
|
|
57
|
+
var fmt =
|
|
58
|
+
color('checkmark', ' ' + Base.symbols.ok) +
|
|
46
59
|
color('pass', ' %s: ') +
|
|
47
60
|
color(test.speed, '%dms');
|
|
48
61
|
cursor.CR();
|
|
49
|
-
|
|
62
|
+
Base.consoleLog(fmt, test.fullTitle(), test.duration);
|
|
50
63
|
});
|
|
51
64
|
|
|
52
|
-
runner.on(
|
|
65
|
+
runner.on(EVENT_TEST_FAIL, function (test) {
|
|
53
66
|
cursor.CR();
|
|
54
|
-
|
|
67
|
+
Base.consoleLog(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
|
55
68
|
});
|
|
56
69
|
|
|
57
|
-
runner.
|
|
70
|
+
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
|
58
71
|
}
|
|
59
72
|
|
|
60
73
|
/**
|
|
61
74
|
* Inherit from `Base.prototype`.
|
|
62
75
|
*/
|
|
63
76
|
inherits(List, Base);
|
|
77
|
+
|
|
78
|
+
List.description = 'like "spec" reporter but flat';
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module Markdown
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
var Base = require('./base');
|
|
8
10
|
var utils = require('../utils');
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
13
|
+
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
|
14
|
+
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
|
15
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
9
16
|
|
|
10
17
|
/**
|
|
11
18
|
* Constants
|
|
@@ -20,26 +27,30 @@ var SUITE_PREFIX = '$';
|
|
|
20
27
|
exports = module.exports = Markdown;
|
|
21
28
|
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
30
|
+
* Constructs a new `Markdown` reporter instance.
|
|
24
31
|
*
|
|
25
|
-
* @
|
|
26
|
-
* @
|
|
32
|
+
* @public
|
|
33
|
+
* @class
|
|
34
|
+
* @memberof Mocha.reporters
|
|
35
|
+
* @extends Mocha.reporters.Base
|
|
36
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
37
|
+
* @param {Object} [options] - runner options
|
|
27
38
|
*/
|
|
28
|
-
function Markdown
|
|
29
|
-
Base.call(this, runner);
|
|
39
|
+
function Markdown(runner, options) {
|
|
40
|
+
Base.call(this, runner, options);
|
|
30
41
|
|
|
31
42
|
var level = 0;
|
|
32
43
|
var buf = '';
|
|
33
44
|
|
|
34
|
-
function title
|
|
45
|
+
function title(str) {
|
|
35
46
|
return Array(level).join('#') + ' ' + str;
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
function mapTOC
|
|
49
|
+
function mapTOC(suite, obj) {
|
|
39
50
|
var ret = obj;
|
|
40
51
|
var key = SUITE_PREFIX + suite.title;
|
|
41
52
|
|
|
42
|
-
obj = obj[key] = obj[key] || {
|
|
53
|
+
obj = obj[key] = obj[key] || {suite};
|
|
43
54
|
suite.suites.forEach(function (suite) {
|
|
44
55
|
mapTOC(suite, obj);
|
|
45
56
|
});
|
|
@@ -47,7 +58,7 @@ function Markdown (runner) {
|
|
|
47
58
|
return ret;
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
function stringifyTOC
|
|
61
|
+
function stringifyTOC(obj, level) {
|
|
51
62
|
++level;
|
|
52
63
|
var buf = '';
|
|
53
64
|
var link;
|
|
@@ -65,25 +76,25 @@ function Markdown (runner) {
|
|
|
65
76
|
return buf;
|
|
66
77
|
}
|
|
67
78
|
|
|
68
|
-
function generateTOC
|
|
79
|
+
function generateTOC(suite) {
|
|
69
80
|
var obj = mapTOC(suite, {});
|
|
70
81
|
return stringifyTOC(obj, 0);
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
generateTOC(runner.suite);
|
|
74
85
|
|
|
75
|
-
runner.on(
|
|
86
|
+
runner.on(EVENT_SUITE_BEGIN, function (suite) {
|
|
76
87
|
++level;
|
|
77
88
|
var slug = utils.slug(suite.fullTitle());
|
|
78
89
|
buf += '<a name="' + slug + '"></a>' + '\n';
|
|
79
90
|
buf += title(suite.title) + '\n';
|
|
80
91
|
});
|
|
81
92
|
|
|
82
|
-
runner.on(
|
|
93
|
+
runner.on(EVENT_SUITE_END, function () {
|
|
83
94
|
--level;
|
|
84
95
|
});
|
|
85
96
|
|
|
86
|
-
runner.on(
|
|
97
|
+
runner.on(EVENT_TEST_PASS, function (test) {
|
|
87
98
|
var code = utils.clean(test.body);
|
|
88
99
|
buf += test.title + '.\n';
|
|
89
100
|
buf += '\n```js\n';
|
|
@@ -91,9 +102,11 @@ function Markdown (runner) {
|
|
|
91
102
|
buf += '```\n\n';
|
|
92
103
|
});
|
|
93
104
|
|
|
94
|
-
runner.
|
|
105
|
+
runner.once(EVENT_RUN_END, function () {
|
|
95
106
|
process.stdout.write('# TOC\n');
|
|
96
107
|
process.stdout.write(generateTOC(runner.suite));
|
|
97
108
|
process.stdout.write(buf);
|
|
98
109
|
});
|
|
99
110
|
}
|
|
111
|
+
|
|
112
|
+
Markdown.description = 'GitHub Flavored Markdown';
|
package/lib/reporters/min.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module Min
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
var Base = require('./base');
|
|
8
10
|
var inherits = require('../utils').inherits;
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
13
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* Expose `Min`.
|
|
@@ -14,25 +19,34 @@ var inherits = require('../utils').inherits;
|
|
|
14
19
|
exports = module.exports = Min;
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
|
-
*
|
|
22
|
+
* Constructs a new `Min` reporter instance.
|
|
18
23
|
*
|
|
19
|
-
* @
|
|
20
|
-
*
|
|
24
|
+
* @description
|
|
25
|
+
* This minimal test reporter is best used with '--watch'.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
* @class
|
|
29
|
+
* @memberof Mocha.reporters
|
|
30
|
+
* @extends Mocha.reporters.Base
|
|
31
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
32
|
+
* @param {Object} [options] - runner options
|
|
21
33
|
*/
|
|
22
|
-
function Min
|
|
23
|
-
Base.call(this, runner);
|
|
34
|
+
function Min(runner, options) {
|
|
35
|
+
Base.call(this, runner, options);
|
|
24
36
|
|
|
25
|
-
runner.on(
|
|
37
|
+
runner.on(EVENT_RUN_BEGIN, function () {
|
|
26
38
|
// clear screen
|
|
27
39
|
process.stdout.write('\u001b[2J');
|
|
28
40
|
// set cursor position
|
|
29
41
|
process.stdout.write('\u001b[1;3H');
|
|
30
42
|
});
|
|
31
43
|
|
|
32
|
-
runner.
|
|
44
|
+
runner.once(EVENT_RUN_END, this.epilogue.bind(this));
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
/**
|
|
36
48
|
* Inherit from `Base.prototype`.
|
|
37
49
|
*/
|
|
38
50
|
inherits(Min, Base);
|
|
51
|
+
|
|
52
|
+
Min.description = 'essentially just a summary';
|