mocha 2.2.5 → 2.3.3

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.
Files changed (50) hide show
  1. package/HISTORY.md +1034 -0
  2. package/bin/.eslintrc +3 -0
  3. package/bin/_mocha +12 -15
  4. package/bin/mocha +3 -10
  5. package/bin/options.js +6 -5
  6. package/lib/browser/debug.js +3 -3
  7. package/lib/browser/events.js +42 -26
  8. package/lib/browser/progress.js +37 -45
  9. package/lib/browser/tty.js +4 -5
  10. package/lib/context.js +26 -32
  11. package/lib/hook.js +5 -7
  12. package/lib/interfaces/bdd.js +21 -26
  13. package/lib/interfaces/common.js +33 -15
  14. package/lib/interfaces/exports.js +7 -7
  15. package/lib/interfaces/qunit.js +16 -17
  16. package/lib/interfaces/tdd.js +24 -28
  17. package/lib/mocha.js +140 -99
  18. package/lib/ms.js +43 -24
  19. package/lib/pending.js +2 -3
  20. package/lib/reporters/base.js +159 -138
  21. package/lib/reporters/doc.js +13 -13
  22. package/lib/reporters/dot.js +23 -19
  23. package/lib/reporters/html-cov.js +25 -19
  24. package/lib/reporters/html.js +130 -91
  25. package/lib/reporters/index.js +19 -17
  26. package/lib/reporters/json-cov.js +39 -41
  27. package/lib/reporters/json-stream.js +14 -17
  28. package/lib/reporters/json.js +16 -19
  29. package/lib/reporters/landing.js +20 -24
  30. package/lib/reporters/list.js +14 -16
  31. package/lib/reporters/markdown.js +17 -20
  32. package/lib/reporters/min.js +4 -5
  33. package/lib/reporters/nyan.js +49 -48
  34. package/lib/reporters/progress.js +20 -23
  35. package/lib/reporters/spec.js +23 -22
  36. package/lib/reporters/tap.js +15 -19
  37. package/lib/reporters/xunit.js +83 -63
  38. package/lib/runnable.js +134 -94
  39. package/lib/runner.js +291 -167
  40. package/lib/suite.js +105 -95
  41. package/lib/template.html +1 -1
  42. package/lib/test.js +3 -4
  43. package/lib/utils.js +227 -199
  44. package/mocha.css +35 -0
  45. package/mocha.js +8324 -2471
  46. package/package.json +250 -10
  47. package/lib/browser/escape-string-regexp.js +0 -11
  48. package/lib/browser/fs.js +0 -0
  49. package/lib/browser/glob.js +0 -0
  50. package/lib/browser/path.js +0 -0
@@ -2,9 +2,10 @@
2
2
  * Module dependencies.
3
3
  */
4
4
 
5
- var Base = require('./base')
6
- , cursor = Base.cursor
7
- , color = Base.color;
5
+ var Base = require('./base');
6
+ var inherits = require('../utils').inherits;
7
+ var color = Base.color;
8
+ var cursor = Base.cursor;
8
9
 
9
10
  /**
10
11
  * Expose `Progress`.
@@ -21,24 +22,21 @@ Base.colors.progress = 90;
21
22
  /**
22
23
  * Initialize a new `Progress` bar test reporter.
23
24
  *
25
+ * @api public
24
26
  * @param {Runner} runner
25
27
  * @param {Object} options
26
- * @api public
27
28
  */
28
-
29
29
  function Progress(runner, options) {
30
30
  Base.call(this, runner);
31
31
 
32
- var self = this
33
- , options = options || {}
34
- , stats = this.stats
35
- , width = Base.window.width * .50 | 0
36
- , total = runner.total
37
- , complete = 0
38
- , max = Math.max
39
- , lastN = -1;
32
+ var self = this;
33
+ var width = Base.window.width * .50 | 0;
34
+ var total = runner.total;
35
+ var complete = 0;
36
+ var lastN = -1;
40
37
 
41
38
  // default chars
39
+ options = options || {};
42
40
  options.open = options.open || '[';
43
41
  options.complete = options.complete || '▬';
44
42
  options.incomplete = options.incomplete || Base.symbols.dot;
@@ -46,20 +44,20 @@ function Progress(runner, options) {
46
44
  options.verbose = false;
47
45
 
48
46
  // tests started
49
- runner.on('start', function(){
47
+ runner.on('start', function() {
50
48
  console.log();
51
49
  cursor.hide();
52
50
  });
53
51
 
54
52
  // tests complete
55
- runner.on('test end', function(){
53
+ runner.on('test end', function() {
56
54
  complete++;
57
- var incomplete = total - complete
58
- , percent = complete / total
59
- , n = width * percent | 0
60
- , i = width - n;
61
55
 
62
- if (lastN === n && !options.verbose) {
56
+ var percent = complete / total;
57
+ var n = width * percent | 0;
58
+ var i = width - n;
59
+
60
+ if (n === lastN && !options.verbose) {
63
61
  // Don't re-render the line if it hasn't changed
64
62
  return;
65
63
  }
@@ -78,7 +76,7 @@ function Progress(runner, options) {
78
76
 
79
77
  // tests are complete, output some stats
80
78
  // and the failures if any
81
- runner.on('end', function(){
79
+ runner.on('end', function() {
82
80
  cursor.show();
83
81
  console.log();
84
82
  self.epilogue();
@@ -88,5 +86,4 @@ function Progress(runner, options) {
88
86
  /**
89
87
  * Inherit from `Base.prototype`.
90
88
  */
91
-
92
- Progress.prototype.__proto__ = Base.prototype;
89
+ inherits(Progress, Base);
@@ -2,9 +2,10 @@
2
2
  * Module dependencies.
3
3
  */
4
4
 
5
- var Base = require('./base')
6
- , cursor = Base.cursor
7
- , color = Base.color;
5
+ var Base = require('./base');
6
+ var inherits = require('../utils').inherits;
7
+ var color = Base.color;
8
+ var cursor = Base.cursor;
8
9
 
9
10
  /**
10
11
  * Expose `Spec`.
@@ -15,50 +16,51 @@ exports = module.exports = Spec;
15
16
  /**
16
17
  * Initialize a new `Spec` test reporter.
17
18
  *
18
- * @param {Runner} runner
19
19
  * @api public
20
+ * @param {Runner} runner
20
21
  */
21
-
22
22
  function Spec(runner) {
23
23
  Base.call(this, runner);
24
24
 
25
- var self = this
26
- , stats = this.stats
27
- , indents = 0
28
- , n = 0;
25
+ var self = this;
26
+ var indents = 0;
27
+ var n = 0;
29
28
 
30
29
  function indent() {
31
- return Array(indents).join(' ')
30
+ return Array(indents).join(' ');
32
31
  }
33
32
 
34
- runner.on('start', function(){
33
+ runner.on('start', function() {
35
34
  console.log();
36
35
  });
37
36
 
38
- runner.on('suite', function(suite){
37
+ runner.on('suite', function(suite) {
39
38
  ++indents;
40
39
  console.log(color('suite', '%s%s'), indent(), suite.title);
41
40
  });
42
41
 
43
- runner.on('suite end', function(suite){
42
+ runner.on('suite end', function() {
44
43
  --indents;
45
- if (1 == indents) console.log();
44
+ if (indents === 1) {
45
+ console.log();
46
+ }
46
47
  });
47
48
 
48
- runner.on('pending', function(test){
49
+ runner.on('pending', function(test) {
49
50
  var fmt = indent() + color('pending', ' - %s');
50
51
  console.log(fmt, test.title);
51
52
  });
52
53
 
53
- runner.on('pass', function(test){
54
- if ('fast' == test.speed) {
55
- var fmt = indent()
54
+ runner.on('pass', function(test) {
55
+ var fmt;
56
+ if (test.speed === 'fast') {
57
+ fmt = indent()
56
58
  + color('checkmark', ' ' + Base.symbols.ok)
57
59
  + color('pass', ' %s');
58
60
  cursor.CR();
59
61
  console.log(fmt, test.title);
60
62
  } else {
61
- var fmt = indent()
63
+ fmt = indent()
62
64
  + color('checkmark', ' ' + Base.symbols.ok)
63
65
  + color('pass', ' %s')
64
66
  + color(test.speed, ' (%dms)');
@@ -67,7 +69,7 @@ function Spec(runner) {
67
69
  }
68
70
  });
69
71
 
70
- runner.on('fail', function(test, err){
72
+ runner.on('fail', function(test) {
71
73
  cursor.CR();
72
74
  console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
73
75
  });
@@ -78,5 +80,4 @@ function Spec(runner) {
78
80
  /**
79
81
  * Inherit from `Base.prototype`.
80
82
  */
81
-
82
- Spec.prototype.__proto__ = Base.prototype;
83
+ inherits(Spec, Base);
@@ -2,9 +2,7 @@
2
2
  * Module dependencies.
3
3
  */
4
4
 
5
- var Base = require('./base')
6
- , cursor = Base.cursor
7
- , color = Base.color;
5
+ var Base = require('./base');
8
6
 
9
7
  /**
10
8
  * Expose `TAP`.
@@ -15,44 +13,43 @@ exports = module.exports = TAP;
15
13
  /**
16
14
  * Initialize a new `TAP` reporter.
17
15
  *
18
- * @param {Runner} runner
19
16
  * @api public
17
+ * @param {Runner} runner
20
18
  */
21
-
22
19
  function TAP(runner) {
23
20
  Base.call(this, runner);
24
21
 
25
- var self = this
26
- , stats = this.stats
27
- , n = 1
28
- , passes = 0
29
- , failures = 0;
22
+ var n = 1;
23
+ var passes = 0;
24
+ var failures = 0;
30
25
 
31
- runner.on('start', function(){
26
+ runner.on('start', function() {
32
27
  var total = runner.grepTotal(runner.suite);
33
28
  console.log('%d..%d', 1, total);
34
29
  });
35
30
 
36
- runner.on('test end', function(){
31
+ runner.on('test end', function() {
37
32
  ++n;
38
33
  });
39
34
 
40
- runner.on('pending', function(test){
35
+ runner.on('pending', function(test) {
41
36
  console.log('ok %d %s # SKIP -', n, title(test));
42
37
  });
43
38
 
44
- runner.on('pass', function(test){
39
+ runner.on('pass', function(test) {
45
40
  passes++;
46
41
  console.log('ok %d %s', n, title(test));
47
42
  });
48
43
 
49
- runner.on('fail', function(test, err){
44
+ runner.on('fail', function(test, err) {
50
45
  failures++;
51
46
  console.log('not ok %d %s', n, title(test));
52
- if (err.stack) console.log(err.stack.replace(/^/gm, ' '));
47
+ if (err.stack) {
48
+ console.log(err.stack.replace(/^/gm, ' '));
49
+ }
53
50
  });
54
51
 
55
- runner.on('end', function(){
52
+ runner.on('end', function() {
56
53
  console.log('# tests ' + (passes + failures));
57
54
  console.log('# pass ' + passes);
58
55
  console.log('# fail ' + failures);
@@ -62,11 +59,10 @@ function TAP(runner) {
62
59
  /**
63
60
  * Return a TAP-safe title of `test`
64
61
  *
62
+ * @api private
65
63
  * @param {Object} test
66
64
  * @return {String}
67
- * @api private
68
65
  */
69
-
70
66
  function title(test) {
71
67
  return test.fullTitle().replace(/#/g, '');
72
68
  }
@@ -2,20 +2,23 @@
2
2
  * Module dependencies.
3
3
  */
4
4
 
5
- var Base = require('./base')
6
- , utils = require('../utils')
7
- , fs = require('fs')
8
- , escape = utils.escape;
5
+ var Base = require('./base');
6
+ var utils = require('../utils');
7
+ var inherits = utils.inherits;
8
+ var fs = require('fs');
9
+ var escape = utils.escape;
9
10
 
10
11
  /**
11
12
  * Save timer references to avoid Sinon interfering (see GH-237).
12
13
  */
13
14
 
14
- var Date = global.Date
15
- , setTimeout = global.setTimeout
16
- , setInterval = global.setInterval
17
- , clearTimeout = global.clearTimeout
18
- , clearInterval = global.clearInterval;
15
+ /* eslint-disable no-unused-vars, no-native-reassign */
16
+ var Date = global.Date;
17
+ var setTimeout = global.setTimeout;
18
+ var setInterval = global.setInterval;
19
+ var clearTimeout = global.clearTimeout;
20
+ var clearInterval = global.clearInterval;
21
+ /* eslint-enable no-unused-vars, no-native-reassign */
19
22
 
20
23
  /**
21
24
  * Expose `XUnit`.
@@ -26,117 +29,134 @@ exports = module.exports = XUnit;
26
29
  /**
27
30
  * Initialize a new `XUnit` reporter.
28
31
  *
29
- * @param {Runner} runner
30
32
  * @api public
33
+ * @param {Runner} runner
31
34
  */
32
-
33
35
  function XUnit(runner, options) {
34
36
  Base.call(this, runner);
35
- var stats = this.stats
36
- , tests = []
37
- , self = this;
37
+
38
+ var stats = this.stats;
39
+ var tests = [];
40
+ var self = this;
38
41
 
39
42
  if (options.reporterOptions && options.reporterOptions.output) {
40
- if (! fs.createWriteStream) {
41
- throw new Error('file output not supported in browser');
42
- }
43
- self.fileStream = fs.createWriteStream(options.reporterOptions.output);
43
+ if (!fs.createWriteStream) {
44
+ throw new Error('file output not supported in browser');
45
+ }
46
+ self.fileStream = fs.createWriteStream(options.reporterOptions.output);
44
47
  }
45
48
 
46
- runner.on('pending', function(test){
49
+ runner.on('pending', function(test) {
47
50
  tests.push(test);
48
51
  });
49
52
 
50
- runner.on('pass', function(test){
53
+ runner.on('pass', function(test) {
51
54
  tests.push(test);
52
55
  });
53
56
 
54
- runner.on('fail', function(test){
57
+ runner.on('fail', function(test) {
55
58
  tests.push(test);
56
59
  });
57
60
 
58
- runner.on('end', function(){
61
+ runner.on('end', function() {
59
62
  self.write(tag('testsuite', {
60
- name: 'Mocha Tests'
61
- , tests: stats.tests
62
- , failures: stats.failures
63
- , errors: stats.failures
64
- , skipped: stats.tests - stats.failures - stats.passes
65
- , timestamp: (new Date).toUTCString()
66
- , time: (stats.duration / 1000) || 0
63
+ name: 'Mocha Tests',
64
+ tests: stats.tests,
65
+ failures: stats.failures,
66
+ errors: stats.failures,
67
+ skipped: stats.tests - stats.failures - stats.passes,
68
+ timestamp: (new Date()).toUTCString(),
69
+ time: (stats.duration / 1000) || 0
67
70
  }, false));
68
71
 
69
- tests.forEach(function(t) { self.test(t); });
72
+ tests.forEach(function(t) {
73
+ self.test(t);
74
+ });
75
+
70
76
  self.write('</testsuite>');
71
77
  });
72
78
  }
73
79
 
74
80
  /**
75
- * Override done to close the stream (if it's a file).
81
+ * Inherit from `Base.prototype`.
76
82
  */
77
- XUnit.prototype.done = function(failures, fn) {
78
- if (this.fileStream) {
79
- this.fileStream.end(function() {
80
- fn(failures);
81
- });
82
- } else {
83
- fn(failures);
84
- }
85
- };
83
+ inherits(XUnit, Base);
86
84
 
87
85
  /**
88
- * Inherit from `Base.prototype`.
86
+ * Override done to close the stream (if it's a file).
87
+ *
88
+ * @param failures
89
+ * @param {Function} fn
89
90
  */
90
-
91
- XUnit.prototype.__proto__ = Base.prototype;
91
+ XUnit.prototype.done = function(failures, fn) {
92
+ if (this.fileStream) {
93
+ this.fileStream.end(function() {
94
+ fn(failures);
95
+ });
96
+ } else {
97
+ fn(failures);
98
+ }
99
+ };
92
100
 
93
101
  /**
94
- * Write out the given line
102
+ * Write out the given line.
103
+ *
104
+ * @param {string} line
95
105
  */
96
106
  XUnit.prototype.write = function(line) {
97
- if (this.fileStream) {
98
- this.fileStream.write(line + '\n');
99
- } else {
100
- console.log(line);
101
- }
107
+ if (this.fileStream) {
108
+ this.fileStream.write(line + '\n');
109
+ } else {
110
+ console.log(line);
111
+ }
102
112
  };
103
113
 
104
114
  /**
105
115
  * Output tag for the given `test.`
116
+ *
117
+ * @param {Test} test
106
118
  */
107
-
108
- XUnit.prototype.test = function(test, ostream) {
119
+ XUnit.prototype.test = function(test) {
109
120
  var attrs = {
110
- classname: test.parent.fullTitle()
111
- , name: test.title
112
- , time: (test.duration / 1000) || 0
121
+ classname: test.parent.fullTitle(),
122
+ name: test.title,
123
+ time: (test.duration / 1000) || 0
113
124
  };
114
125
 
115
- if ('failed' == test.state) {
126
+ if (test.state === 'failed') {
116
127
  var err = test.err;
117
- this.write(tag('testcase', attrs, false, tag('failure', {}, false, cdata(escape(err.message) + "\n" + err.stack))));
128
+ this.write(tag('testcase', attrs, false, tag('failure', {}, false, cdata(escape(err.message) + '\n' + err.stack))));
118
129
  } else if (test.pending) {
119
130
  this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
120
131
  } else {
121
- this.write(tag('testcase', attrs, true) );
132
+ this.write(tag('testcase', attrs, true));
122
133
  }
123
134
  };
124
135
 
125
136
  /**
126
137
  * HTML tag helper.
138
+ *
139
+ * @param name
140
+ * @param attrs
141
+ * @param close
142
+ * @param content
143
+ * @return {string}
127
144
  */
128
-
129
145
  function tag(name, attrs, close, content) {
130
- var end = close ? '/>' : '>'
131
- , pairs = []
132
- , tag;
146
+ var end = close ? '/>' : '>';
147
+ var pairs = [];
148
+ var tag;
133
149
 
134
150
  for (var key in attrs) {
135
- pairs.push(key + '="' + escape(attrs[key]) + '"');
151
+ if (Object.prototype.hasOwnProperty.call(attrs, key)) {
152
+ pairs.push(key + '="' + escape(attrs[key]) + '"');
153
+ }
136
154
  }
137
155
 
138
156
  tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
139
- if (content) tag += content + '</' + name + end;
157
+ if (content) {
158
+ tag += content + '</' + name + end;
159
+ }
140
160
  return tag;
141
161
  }
142
162