mocha 6.1.0 → 6.1.4
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 +1776 -1751
- package/LICENSE +22 -22
- package/README.md +105 -105
- package/bin/_mocha +10 -10
- package/bin/mocha +149 -149
- package/bin/options.js +10 -10
- package/browser-entry.js +191 -191
- package/index.js +3 -3
- package/lib/browser/growl.js +168 -168
- package/lib/browser/progress.js +119 -119
- package/lib/browser/template.html +18 -18
- package/lib/browser/tty.js +13 -13
- package/lib/cli/cli.js +69 -69
- package/lib/cli/commands.js +13 -13
- package/lib/cli/config.js +101 -101
- package/lib/cli/index.js +9 -9
- package/lib/cli/init.js +37 -37
- package/lib/cli/node-flags.js +86 -86
- package/lib/cli/one-and-dones.js +70 -70
- package/lib/cli/options.js +347 -347
- package/lib/cli/run-helpers.js +337 -337
- package/lib/cli/run-option-metadata.js +76 -76
- package/lib/cli/run.js +297 -297
- package/lib/context.js +101 -101
- package/lib/errors.js +141 -141
- package/lib/growl.js +136 -136
- package/lib/hook.js +46 -46
- package/lib/interfaces/bdd.js +118 -118
- package/lib/interfaces/common.js +191 -191
- package/lib/interfaces/exports.js +60 -60
- package/lib/interfaces/index.js +6 -6
- package/lib/interfaces/qunit.js +99 -99
- package/lib/interfaces/tdd.js +107 -107
- package/lib/mocha.js +843 -843
- package/lib/mocharc.json +10 -10
- package/lib/pending.js +12 -12
- package/lib/reporters/base.js +491 -491
- package/lib/reporters/doc.js +85 -85
- package/lib/reporters/dot.js +81 -81
- package/lib/reporters/html.js +390 -390
- package/lib/reporters/index.js +19 -19
- package/lib/reporters/json-stream.js +90 -90
- package/lib/reporters/json.js +135 -135
- package/lib/reporters/landing.js +108 -108
- package/lib/reporters/list.js +78 -78
- package/lib/reporters/markdown.js +112 -112
- package/lib/reporters/min.js +52 -52
- package/lib/reporters/nyan.js +276 -276
- package/lib/reporters/progress.js +104 -104
- package/lib/reporters/spec.js +99 -99
- package/lib/reporters/tap.js +294 -294
- package/lib/reporters/xunit.js +216 -216
- package/lib/runnable.js +496 -496
- package/lib/runner.js +1049 -1049
- package/lib/stats-collector.js +83 -83
- package/lib/suite.js +642 -642
- package/lib/test.js +51 -51
- package/lib/utils.js +897 -897
- package/mocha.css +326 -326
- package/mocha.js +8170 -8476
- package/package.json +630 -628
package/lib/reporters/landing.js
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* @module Landing
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Module dependencies.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
var Base = require('./base');
|
|
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
|
-
|
|
17
|
-
var cursor = Base.cursor;
|
|
18
|
-
var color = Base.color;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Expose `Landing`.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
exports = module.exports = Landing;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Airplane color.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
Base.colors.plane = 0;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Airplane crash color.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
Base.colors['plane crash'] = 31;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Runway color.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
Base.colors.runway = 90;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Constructs a new `Landing` reporter instance.
|
|
46
|
-
*
|
|
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
|
|
53
|
-
*/
|
|
54
|
-
function Landing(runner, options) {
|
|
55
|
-
Base.call(this, runner, options);
|
|
56
|
-
|
|
57
|
-
var self = this;
|
|
58
|
-
var width = (Base.window.width * 0.75) | 0;
|
|
59
|
-
var total = runner.total;
|
|
60
|
-
var stream = process.stdout;
|
|
61
|
-
var plane = color('plane', '✈');
|
|
62
|
-
var crashed = -1;
|
|
63
|
-
var n = 0;
|
|
64
|
-
|
|
65
|
-
function runway() {
|
|
66
|
-
var buf = Array(width).join('-');
|
|
67
|
-
return ' ' + color('runway', buf);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
runner.on(EVENT_RUN_BEGIN, function() {
|
|
71
|
-
stream.write('\n\n\n ');
|
|
72
|
-
cursor.hide();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
runner.on(EVENT_TEST_END, function(test) {
|
|
76
|
-
// check if the plane crashed
|
|
77
|
-
var col = crashed === -1 ? ((width * ++n) / total) | 0 : crashed;
|
|
78
|
-
|
|
79
|
-
// show the crash
|
|
80
|
-
if (test.state === STATE_FAILED) {
|
|
81
|
-
plane = color('plane crash', '✈');
|
|
82
|
-
crashed = col;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// render landing strip
|
|
86
|
-
stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
|
|
87
|
-
stream.write(runway());
|
|
88
|
-
stream.write('\n ');
|
|
89
|
-
stream.write(color('runway', Array(col).join('⋅')));
|
|
90
|
-
stream.write(plane);
|
|
91
|
-
stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
|
|
92
|
-
stream.write(runway());
|
|
93
|
-
stream.write('\u001b[0m');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
runner.once(EVENT_RUN_END, function() {
|
|
97
|
-
cursor.show();
|
|
98
|
-
console.log();
|
|
99
|
-
self.epilogue();
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Inherit from `Base.prototype`.
|
|
105
|
-
*/
|
|
106
|
-
inherits(Landing, Base);
|
|
107
|
-
|
|
108
|
-
Landing.description = 'Unicode landing strip';
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @module Landing
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Module dependencies.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var Base = require('./base');
|
|
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
|
+
|
|
17
|
+
var cursor = Base.cursor;
|
|
18
|
+
var color = Base.color;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Expose `Landing`.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
exports = module.exports = Landing;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Airplane color.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
Base.colors.plane = 0;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Airplane crash color.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
Base.colors['plane crash'] = 31;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Runway color.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
Base.colors.runway = 90;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a new `Landing` reporter instance.
|
|
46
|
+
*
|
|
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
|
|
53
|
+
*/
|
|
54
|
+
function Landing(runner, options) {
|
|
55
|
+
Base.call(this, runner, options);
|
|
56
|
+
|
|
57
|
+
var self = this;
|
|
58
|
+
var width = (Base.window.width * 0.75) | 0;
|
|
59
|
+
var total = runner.total;
|
|
60
|
+
var stream = process.stdout;
|
|
61
|
+
var plane = color('plane', '✈');
|
|
62
|
+
var crashed = -1;
|
|
63
|
+
var n = 0;
|
|
64
|
+
|
|
65
|
+
function runway() {
|
|
66
|
+
var buf = Array(width).join('-');
|
|
67
|
+
return ' ' + color('runway', buf);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
71
|
+
stream.write('\n\n\n ');
|
|
72
|
+
cursor.hide();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
runner.on(EVENT_TEST_END, function(test) {
|
|
76
|
+
// check if the plane crashed
|
|
77
|
+
var col = crashed === -1 ? ((width * ++n) / total) | 0 : crashed;
|
|
78
|
+
|
|
79
|
+
// show the crash
|
|
80
|
+
if (test.state === STATE_FAILED) {
|
|
81
|
+
plane = color('plane crash', '✈');
|
|
82
|
+
crashed = col;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// render landing strip
|
|
86
|
+
stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
|
|
87
|
+
stream.write(runway());
|
|
88
|
+
stream.write('\n ');
|
|
89
|
+
stream.write(color('runway', Array(col).join('⋅')));
|
|
90
|
+
stream.write(plane);
|
|
91
|
+
stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
|
|
92
|
+
stream.write(runway());
|
|
93
|
+
stream.write('\u001b[0m');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
runner.once(EVENT_RUN_END, function() {
|
|
97
|
+
cursor.show();
|
|
98
|
+
console.log();
|
|
99
|
+
self.epilogue();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Inherit from `Base.prototype`.
|
|
105
|
+
*/
|
|
106
|
+
inherits(Landing, Base);
|
|
107
|
+
|
|
108
|
+
Landing.description = 'Unicode landing strip';
|
package/lib/reporters/list.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* @module List
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Module dependencies.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
var Base = require('./base');
|
|
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;
|
|
18
|
-
var color = Base.color;
|
|
19
|
-
var cursor = Base.cursor;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Expose `List`.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
exports = module.exports = List;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Constructs a new `List` reporter instance.
|
|
29
|
-
*
|
|
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
|
|
36
|
-
*/
|
|
37
|
-
function List(runner, options) {
|
|
38
|
-
Base.call(this, runner, options);
|
|
39
|
-
|
|
40
|
-
var self = this;
|
|
41
|
-
var n = 0;
|
|
42
|
-
|
|
43
|
-
runner.on(EVENT_RUN_BEGIN, function() {
|
|
44
|
-
console.log();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
runner.on(EVENT_TEST_BEGIN, function(test) {
|
|
48
|
-
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
runner.on(EVENT_TEST_PENDING, function(test) {
|
|
52
|
-
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
|
53
|
-
console.log(fmt, test.fullTitle());
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
runner.on(EVENT_TEST_PASS, function(test) {
|
|
57
|
-
var fmt =
|
|
58
|
-
color('checkmark', ' ' + Base.symbols.ok) +
|
|
59
|
-
color('pass', ' %s: ') +
|
|
60
|
-
color(test.speed, '%dms');
|
|
61
|
-
cursor.CR();
|
|
62
|
-
console.log(fmt, test.fullTitle(), test.duration);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
runner.on(EVENT_TEST_FAIL, function(test) {
|
|
66
|
-
cursor.CR();
|
|
67
|
-
console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Inherit from `Base.prototype`.
|
|
75
|
-
*/
|
|
76
|
-
inherits(List, Base);
|
|
77
|
-
|
|
78
|
-
List.description = 'like "spec" reporter but flat';
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @module List
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Module dependencies.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var Base = require('./base');
|
|
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;
|
|
18
|
+
var color = Base.color;
|
|
19
|
+
var cursor = Base.cursor;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Expose `List`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
exports = module.exports = List;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a new `List` reporter instance.
|
|
29
|
+
*
|
|
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
|
|
36
|
+
*/
|
|
37
|
+
function List(runner, options) {
|
|
38
|
+
Base.call(this, runner, options);
|
|
39
|
+
|
|
40
|
+
var self = this;
|
|
41
|
+
var n = 0;
|
|
42
|
+
|
|
43
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
44
|
+
console.log();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
runner.on(EVENT_TEST_BEGIN, function(test) {
|
|
48
|
+
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
runner.on(EVENT_TEST_PENDING, function(test) {
|
|
52
|
+
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
|
53
|
+
console.log(fmt, test.fullTitle());
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
57
|
+
var fmt =
|
|
58
|
+
color('checkmark', ' ' + Base.symbols.ok) +
|
|
59
|
+
color('pass', ' %s: ') +
|
|
60
|
+
color(test.speed, '%dms');
|
|
61
|
+
cursor.CR();
|
|
62
|
+
console.log(fmt, test.fullTitle(), test.duration);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
runner.on(EVENT_TEST_FAIL, function(test) {
|
|
66
|
+
cursor.CR();
|
|
67
|
+
console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Inherit from `Base.prototype`.
|
|
75
|
+
*/
|
|
76
|
+
inherits(List, Base);
|
|
77
|
+
|
|
78
|
+
List.description = 'like "spec" reporter but flat';
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* @module Markdown
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Module dependencies.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
var Base = require('./base');
|
|
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;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Constants
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
var SUITE_PREFIX = '$';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Expose `Markdown`.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
exports = module.exports = Markdown;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Constructs a new `Markdown` reporter instance.
|
|
31
|
-
*
|
|
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
|
|
38
|
-
*/
|
|
39
|
-
function Markdown(runner, options) {
|
|
40
|
-
Base.call(this, runner, options);
|
|
41
|
-
|
|
42
|
-
var level = 0;
|
|
43
|
-
var buf = '';
|
|
44
|
-
|
|
45
|
-
function title(str) {
|
|
46
|
-
return Array(level).join('#') + ' ' + str;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function mapTOC(suite, obj) {
|
|
50
|
-
var ret = obj;
|
|
51
|
-
var key = SUITE_PREFIX + suite.title;
|
|
52
|
-
|
|
53
|
-
obj = obj[key] = obj[key] || {suite: suite};
|
|
54
|
-
suite.suites.forEach(function(suite) {
|
|
55
|
-
mapTOC(suite, obj);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return ret;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function stringifyTOC(obj, level) {
|
|
62
|
-
++level;
|
|
63
|
-
var buf = '';
|
|
64
|
-
var link;
|
|
65
|
-
for (var key in obj) {
|
|
66
|
-
if (key === 'suite') {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (key !== SUITE_PREFIX) {
|
|
70
|
-
link = ' - [' + key.substring(1) + ']';
|
|
71
|
-
link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
|
|
72
|
-
buf += Array(level).join(' ') + link;
|
|
73
|
-
}
|
|
74
|
-
buf += stringifyTOC(obj[key], level);
|
|
75
|
-
}
|
|
76
|
-
return buf;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function generateTOC(suite) {
|
|
80
|
-
var obj = mapTOC(suite, {});
|
|
81
|
-
return stringifyTOC(obj, 0);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
generateTOC(runner.suite);
|
|
85
|
-
|
|
86
|
-
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
|
87
|
-
++level;
|
|
88
|
-
var slug = utils.slug(suite.fullTitle());
|
|
89
|
-
buf += '<a name="' + slug + '"></a>' + '\n';
|
|
90
|
-
buf += title(suite.title) + '\n';
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
runner.on(EVENT_SUITE_END, function() {
|
|
94
|
-
--level;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
runner.on(EVENT_TEST_PASS, function(test) {
|
|
98
|
-
var code = utils.clean(test.body);
|
|
99
|
-
buf += test.title + '.\n';
|
|
100
|
-
buf += '\n```js\n';
|
|
101
|
-
buf += code + '\n';
|
|
102
|
-
buf += '```\n\n';
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
runner.once(EVENT_RUN_END, function() {
|
|
106
|
-
process.stdout.write('# TOC\n');
|
|
107
|
-
process.stdout.write(generateTOC(runner.suite));
|
|
108
|
-
process.stdout.write(buf);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
Markdown.description = 'GitHub Flavored Markdown';
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @module Markdown
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Module dependencies.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var Base = require('./base');
|
|
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;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constants
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var SUITE_PREFIX = '$';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Expose `Markdown`.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
exports = module.exports = Markdown;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a new `Markdown` reporter instance.
|
|
31
|
+
*
|
|
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
|
|
38
|
+
*/
|
|
39
|
+
function Markdown(runner, options) {
|
|
40
|
+
Base.call(this, runner, options);
|
|
41
|
+
|
|
42
|
+
var level = 0;
|
|
43
|
+
var buf = '';
|
|
44
|
+
|
|
45
|
+
function title(str) {
|
|
46
|
+
return Array(level).join('#') + ' ' + str;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function mapTOC(suite, obj) {
|
|
50
|
+
var ret = obj;
|
|
51
|
+
var key = SUITE_PREFIX + suite.title;
|
|
52
|
+
|
|
53
|
+
obj = obj[key] = obj[key] || {suite: suite};
|
|
54
|
+
suite.suites.forEach(function(suite) {
|
|
55
|
+
mapTOC(suite, obj);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return ret;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function stringifyTOC(obj, level) {
|
|
62
|
+
++level;
|
|
63
|
+
var buf = '';
|
|
64
|
+
var link;
|
|
65
|
+
for (var key in obj) {
|
|
66
|
+
if (key === 'suite') {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (key !== SUITE_PREFIX) {
|
|
70
|
+
link = ' - [' + key.substring(1) + ']';
|
|
71
|
+
link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
|
|
72
|
+
buf += Array(level).join(' ') + link;
|
|
73
|
+
}
|
|
74
|
+
buf += stringifyTOC(obj[key], level);
|
|
75
|
+
}
|
|
76
|
+
return buf;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function generateTOC(suite) {
|
|
80
|
+
var obj = mapTOC(suite, {});
|
|
81
|
+
return stringifyTOC(obj, 0);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
generateTOC(runner.suite);
|
|
85
|
+
|
|
86
|
+
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
|
87
|
+
++level;
|
|
88
|
+
var slug = utils.slug(suite.fullTitle());
|
|
89
|
+
buf += '<a name="' + slug + '"></a>' + '\n';
|
|
90
|
+
buf += title(suite.title) + '\n';
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
runner.on(EVENT_SUITE_END, function() {
|
|
94
|
+
--level;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
98
|
+
var code = utils.clean(test.body);
|
|
99
|
+
buf += test.title + '.\n';
|
|
100
|
+
buf += '\n```js\n';
|
|
101
|
+
buf += code + '\n';
|
|
102
|
+
buf += '```\n\n';
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
runner.once(EVENT_RUN_END, function() {
|
|
106
|
+
process.stdout.write('# TOC\n');
|
|
107
|
+
process.stdout.write(generateTOC(runner.suite));
|
|
108
|
+
process.stdout.write(buf);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Markdown.description = 'GitHub Flavored Markdown';
|