mocha 5.1.1 → 5.2.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.
@@ -26,12 +26,12 @@ exports = module.exports = NyanCat;
26
26
  * @extends Mocha.reporters.Base
27
27
  */
28
28
 
29
- function NyanCat (runner) {
29
+ function NyanCat(runner) {
30
30
  Base.call(this, runner);
31
31
 
32
32
  var self = this;
33
- var width = Base.window.width * 0.75 | 0;
34
- var nyanCatWidth = this.nyanCatWidth = 11;
33
+ var width = (Base.window.width * 0.75) | 0;
34
+ var nyanCatWidth = (this.nyanCatWidth = 11);
35
35
 
36
36
  this.colorIndex = 0;
37
37
  this.numberOfLines = 4;
@@ -39,26 +39,26 @@ function NyanCat (runner) {
39
39
  this.scoreboardWidth = 5;
40
40
  this.tick = 0;
41
41
  this.trajectories = [[], [], [], []];
42
- this.trajectoryWidthMax = (width - nyanCatWidth);
42
+ this.trajectoryWidthMax = width - nyanCatWidth;
43
43
 
44
- runner.on('start', function () {
44
+ runner.on('start', function() {
45
45
  Base.cursor.hide();
46
46
  self.draw();
47
47
  });
48
48
 
49
- runner.on('pending', function () {
49
+ runner.on('pending', function() {
50
50
  self.draw();
51
51
  });
52
52
 
53
- runner.on('pass', function () {
53
+ runner.on('pass', function() {
54
54
  self.draw();
55
55
  });
56
56
 
57
- runner.on('fail', function () {
57
+ runner.on('fail', function() {
58
58
  self.draw();
59
59
  });
60
60
 
61
- runner.once('end', function () {
61
+ runner.once('end', function() {
62
62
  Base.cursor.show();
63
63
  for (var i = 0; i < self.numberOfLines; i++) {
64
64
  write('\n');
@@ -78,7 +78,7 @@ inherits(NyanCat, Base);
78
78
  * @api private
79
79
  */
80
80
 
81
- NyanCat.prototype.draw = function () {
81
+ NyanCat.prototype.draw = function() {
82
82
  this.appendRainbow();
83
83
  this.drawScoreboard();
84
84
  this.drawRainbow();
@@ -93,10 +93,10 @@ NyanCat.prototype.draw = function () {
93
93
  * @api private
94
94
  */
95
95
 
96
- NyanCat.prototype.drawScoreboard = function () {
96
+ NyanCat.prototype.drawScoreboard = function() {
97
97
  var stats = this.stats;
98
98
 
99
- function draw (type, n) {
99
+ function draw(type, n) {
100
100
  write(' ');
101
101
  write(Base.color(type, n));
102
102
  write('\n');
@@ -116,7 +116,7 @@ NyanCat.prototype.drawScoreboard = function () {
116
116
  * @api private
117
117
  */
118
118
 
119
- NyanCat.prototype.appendRainbow = function () {
119
+ NyanCat.prototype.appendRainbow = function() {
120
120
  var segment = this.tick ? '_' : '-';
121
121
  var rainbowified = this.rainbowify(segment);
122
122
 
@@ -135,10 +135,10 @@ NyanCat.prototype.appendRainbow = function () {
135
135
  * @api private
136
136
  */
137
137
 
138
- NyanCat.prototype.drawRainbow = function () {
138
+ NyanCat.prototype.drawRainbow = function() {
139
139
  var self = this;
140
140
 
141
- this.trajectories.forEach(function (line) {
141
+ this.trajectories.forEach(function(line) {
142
142
  write('\u001b[' + self.scoreboardWidth + 'C');
143
143
  write(line.join(''));
144
144
  write('\n');
@@ -152,7 +152,7 @@ NyanCat.prototype.drawRainbow = function () {
152
152
  *
153
153
  * @api private
154
154
  */
155
- NyanCat.prototype.drawNyanCat = function () {
155
+ NyanCat.prototype.drawNyanCat = function() {
156
156
  var self = this;
157
157
  var startWidth = this.scoreboardWidth + this.trajectories[0].length;
158
158
  var dist = '\u001b[' + startWidth + 'C';
@@ -188,7 +188,7 @@ NyanCat.prototype.drawNyanCat = function () {
188
188
  * @return {string}
189
189
  */
190
190
 
191
- NyanCat.prototype.face = function () {
191
+ NyanCat.prototype.face = function() {
192
192
  var stats = this.stats;
193
193
  if (stats.failures) {
194
194
  return '( x .x)';
@@ -207,7 +207,7 @@ NyanCat.prototype.face = function () {
207
207
  * @param {number} n
208
208
  */
209
209
 
210
- NyanCat.prototype.cursorUp = function (n) {
210
+ NyanCat.prototype.cursorUp = function(n) {
211
211
  write('\u001b[' + n + 'A');
212
212
  };
213
213
 
@@ -218,7 +218,7 @@ NyanCat.prototype.cursorUp = function (n) {
218
218
  * @param {number} n
219
219
  */
220
220
 
221
- NyanCat.prototype.cursorDown = function (n) {
221
+ NyanCat.prototype.cursorDown = function(n) {
222
222
  write('\u001b[' + n + 'B');
223
223
  };
224
224
 
@@ -228,12 +228,12 @@ NyanCat.prototype.cursorDown = function (n) {
228
228
  * @api private
229
229
  * @return {Array}
230
230
  */
231
- NyanCat.prototype.generateColors = function () {
231
+ NyanCat.prototype.generateColors = function() {
232
232
  var colors = [];
233
233
 
234
- for (var i = 0; i < (6 * 7); i++) {
234
+ for (var i = 0; i < 6 * 7; i++) {
235
235
  var pi3 = Math.floor(Math.PI / 3);
236
- var n = (i * (1.0 / 6));
236
+ var n = i * (1.0 / 6);
237
237
  var r = Math.floor(3 * Math.sin(n) + 3);
238
238
  var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
239
239
  var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
@@ -250,7 +250,7 @@ NyanCat.prototype.generateColors = function () {
250
250
  * @param {string} str
251
251
  * @return {string}
252
252
  */
253
- NyanCat.prototype.rainbowify = function (str) {
253
+ NyanCat.prototype.rainbowify = function(str) {
254
254
  if (!Base.useColors) {
255
255
  return str;
256
256
  }
@@ -264,6 +264,6 @@ NyanCat.prototype.rainbowify = function (str) {
264
264
  *
265
265
  * @param {string} string A message to write to stdout.
266
266
  */
267
- function write (string) {
267
+ function write(string) {
268
268
  process.stdout.write(string);
269
269
  }
@@ -34,11 +34,11 @@ Base.colors.progress = 90;
34
34
  * @param {Runner} runner
35
35
  * @param {Object} options
36
36
  */
37
- function Progress (runner, options) {
37
+ function Progress(runner, options) {
38
38
  Base.call(this, runner);
39
39
 
40
40
  var self = this;
41
- var width = Base.window.width * 0.50 | 0;
41
+ var width = (Base.window.width * 0.5) | 0;
42
42
  var total = runner.total;
43
43
  var complete = 0;
44
44
  var lastN = -1;
@@ -54,17 +54,17 @@ function Progress (runner, options) {
54
54
  options.verbose = reporterOptions.verbose || false;
55
55
 
56
56
  // tests started
57
- runner.on('start', function () {
57
+ runner.on('start', function() {
58
58
  console.log();
59
59
  cursor.hide();
60
60
  });
61
61
 
62
62
  // tests complete
63
- runner.on('test end', function () {
63
+ runner.on('test end', function() {
64
64
  complete++;
65
65
 
66
66
  var percent = complete / total;
67
- var n = width * percent | 0;
67
+ var n = (width * percent) | 0;
68
68
  var i = width - n;
69
69
 
70
70
  if (n === lastN && !options.verbose) {
@@ -86,7 +86,7 @@ function Progress (runner, options) {
86
86
 
87
87
  // tests are complete, output some stats
88
88
  // and the failures if any
89
- runner.once('end', function () {
89
+ runner.once('end', function() {
90
90
  cursor.show();
91
91
  console.log();
92
92
  self.epilogue();
@@ -26,47 +26,49 @@ exports = module.exports = Spec;
26
26
  * @api public
27
27
  * @param {Runner} runner
28
28
  */
29
- function Spec (runner) {
29
+ function Spec(runner) {
30
30
  Base.call(this, runner);
31
31
 
32
32
  var self = this;
33
33
  var indents = 0;
34
34
  var n = 0;
35
35
 
36
- function indent () {
36
+ function indent() {
37
37
  return Array(indents).join(' ');
38
38
  }
39
39
 
40
- runner.on('start', function () {
40
+ runner.on('start', function() {
41
41
  console.log();
42
42
  });
43
43
 
44
- runner.on('suite', function (suite) {
44
+ runner.on('suite', function(suite) {
45
45
  ++indents;
46
46
  console.log(color('suite', '%s%s'), indent(), suite.title);
47
47
  });
48
48
 
49
- runner.on('suite end', function () {
49
+ runner.on('suite end', function() {
50
50
  --indents;
51
51
  if (indents === 1) {
52
52
  console.log();
53
53
  }
54
54
  });
55
55
 
56
- runner.on('pending', function (test) {
56
+ runner.on('pending', function(test) {
57
57
  var fmt = indent() + color('pending', ' - %s');
58
58
  console.log(fmt, test.title);
59
59
  });
60
60
 
61
- runner.on('pass', function (test) {
61
+ runner.on('pass', function(test) {
62
62
  var fmt;
63
63
  if (test.speed === 'fast') {
64
- fmt = indent() +
64
+ fmt =
65
+ indent() +
65
66
  color('checkmark', ' ' + Base.symbols.ok) +
66
67
  color('pass', ' %s');
67
68
  console.log(fmt, test.title);
68
69
  } else {
69
- fmt = indent() +
70
+ fmt =
71
+ indent() +
70
72
  color('checkmark', ' ' + Base.symbols.ok) +
71
73
  color('pass', ' %s') +
72
74
  color(test.speed, ' (%dms)');
@@ -74,7 +76,7 @@ function Spec (runner) {
74
76
  }
75
77
  });
76
78
 
77
- runner.on('fail', function (test) {
79
+ runner.on('fail', function(test) {
78
80
  console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
79
81
  });
80
82
 
@@ -24,32 +24,32 @@ exports = module.exports = TAP;
24
24
  * @api public
25
25
  * @param {Runner} runner
26
26
  */
27
- function TAP (runner) {
27
+ function TAP(runner) {
28
28
  Base.call(this, runner);
29
29
 
30
30
  var n = 1;
31
31
  var passes = 0;
32
32
  var failures = 0;
33
33
 
34
- runner.on('start', function () {
34
+ runner.on('start', function() {
35
35
  var total = runner.grepTotal(runner.suite);
36
36
  console.log('%d..%d', 1, total);
37
37
  });
38
38
 
39
- runner.on('test end', function () {
39
+ runner.on('test end', function() {
40
40
  ++n;
41
41
  });
42
42
 
43
- runner.on('pending', function (test) {
43
+ runner.on('pending', function(test) {
44
44
  console.log('ok %d %s # SKIP -', n, title(test));
45
45
  });
46
46
 
47
- runner.on('pass', function (test) {
47
+ runner.on('pass', function(test) {
48
48
  passes++;
49
49
  console.log('ok %d %s', n, title(test));
50
50
  });
51
51
 
52
- runner.on('fail', function (test, err) {
52
+ runner.on('fail', function(test, err) {
53
53
  failures++;
54
54
  console.log('not ok %d %s', n, title(test));
55
55
  if (err.stack) {
@@ -57,7 +57,7 @@ function TAP (runner) {
57
57
  }
58
58
  });
59
59
 
60
- runner.once('end', function () {
60
+ runner.once('end', function() {
61
61
  console.log('# tests ' + (passes + failures));
62
62
  console.log('# pass ' + passes);
63
63
  console.log('# fail ' + failures);
@@ -71,6 +71,6 @@ function TAP (runner) {
71
71
  * @param {Object} test
72
72
  * @return {String}
73
73
  */
74
- function title (test) {
74
+ function title(test) {
75
75
  return test.fullTitle().replace(/#/g, '');
76
76
  }
@@ -42,7 +42,7 @@ exports = module.exports = XUnit;
42
42
  * @api public
43
43
  * @param {Runner} runner
44
44
  */
45
- function XUnit (runner, options) {
45
+ function XUnit(runner, options) {
46
46
  Base.call(this, runner);
47
47
 
48
48
  var stats = this.stats;
@@ -72,30 +72,36 @@ function XUnit (runner, options) {
72
72
  // fall back to the default suite name
73
73
  suiteName = suiteName || DEFAULT_SUITE_NAME;
74
74
 
75
- runner.on('pending', function (test) {
75
+ runner.on('pending', function(test) {
76
76
  tests.push(test);
77
77
  });
78
78
 
79
- runner.on('pass', function (test) {
79
+ runner.on('pass', function(test) {
80
80
  tests.push(test);
81
81
  });
82
82
 
83
- runner.on('fail', function (test) {
83
+ runner.on('fail', function(test) {
84
84
  tests.push(test);
85
85
  });
86
86
 
87
- runner.once('end', function () {
88
- self.write(tag('testsuite', {
89
- name: suiteName,
90
- tests: stats.tests,
91
- failures: stats.failures,
92
- errors: stats.failures,
93
- skipped: stats.tests - stats.failures - stats.passes,
94
- timestamp: (new Date()).toUTCString(),
95
- time: (stats.duration / 1000) || 0
96
- }, false));
97
-
98
- tests.forEach(function (t) {
87
+ runner.once('end', function() {
88
+ self.write(
89
+ tag(
90
+ 'testsuite',
91
+ {
92
+ name: suiteName,
93
+ tests: stats.tests,
94
+ failures: stats.failures,
95
+ errors: stats.failures,
96
+ skipped: stats.tests - stats.failures - stats.passes,
97
+ timestamp: new Date().toUTCString(),
98
+ time: stats.duration / 1000 || 0
99
+ },
100
+ false
101
+ )
102
+ );
103
+
104
+ tests.forEach(function(t) {
99
105
  self.test(t);
100
106
  });
101
107
 
@@ -114,9 +120,9 @@ inherits(XUnit, Base);
114
120
  * @param failures
115
121
  * @param {Function} fn
116
122
  */
117
- XUnit.prototype.done = function (failures, fn) {
123
+ XUnit.prototype.done = function(failures, fn) {
118
124
  if (this.fileStream) {
119
- this.fileStream.end(function () {
125
+ this.fileStream.end(function() {
120
126
  fn(failures);
121
127
  });
122
128
  } else {
@@ -129,7 +135,7 @@ XUnit.prototype.done = function (failures, fn) {
129
135
  *
130
136
  * @param {string} line
131
137
  */
132
- XUnit.prototype.write = function (line) {
138
+ XUnit.prototype.write = function(line) {
133
139
  if (this.fileStream) {
134
140
  this.fileStream.write(line + '\n');
135
141
  } else if (typeof process === 'object' && process.stdout) {
@@ -144,16 +150,28 @@ XUnit.prototype.write = function (line) {
144
150
  *
145
151
  * @param {Test} test
146
152
  */
147
- XUnit.prototype.test = function (test) {
153
+ XUnit.prototype.test = function(test) {
148
154
  var attrs = {
149
155
  classname: test.parent.fullTitle(),
150
156
  name: test.title,
151
- time: (test.duration / 1000) || 0
157
+ time: test.duration / 1000 || 0
152
158
  };
153
159
 
154
160
  if (test.state === 'failed') {
155
161
  var err = test.err;
156
- this.write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err.message) + '\n' + escape(err.stack))));
162
+ this.write(
163
+ tag(
164
+ 'testcase',
165
+ attrs,
166
+ false,
167
+ tag(
168
+ 'failure',
169
+ {},
170
+ false,
171
+ escape(err.message) + '\n' + escape(err.stack)
172
+ )
173
+ )
174
+ );
157
175
  } else if (test.isPending()) {
158
176
  this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
159
177
  } else {
@@ -170,7 +188,7 @@ XUnit.prototype.test = function (test) {
170
188
  * @param content
171
189
  * @return {string}
172
190
  */
173
- function tag (name, attrs, close, content) {
191
+ function tag(name, attrs, close, content) {
174
192
  var end = close ? '/>' : '>';
175
193
  var pairs = [];
176
194
  var tag;