mocha 6.0.0-1 → 6.0.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.
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
5
+ .EVENT_FILE_PRE_REQUIRE;
4
6
 
5
7
  /**
6
8
  * QUnit-style interface:
@@ -30,7 +32,7 @@ var Test = require('../test');
30
32
  module.exports = function qUnitInterface(suite) {
31
33
  var suites = [suite];
32
34
 
33
- suite.on('pre-require', function(context, file, mocha) {
35
+ suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
34
36
  var common = require('./common')(suites, context, mocha);
35
37
 
36
38
  context.before = common.before;
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
5
+ .EVENT_FILE_PRE_REQUIRE;
4
6
 
5
7
  /**
6
8
  * TDD-style interface:
@@ -30,7 +32,7 @@ var Test = require('../test');
30
32
  module.exports = function(suite) {
31
33
  var suites = [suite];
32
34
 
33
- suite.on('pre-require', function(context, file, mocha) {
35
+ suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
34
36
  var common = require('./common')(suites, context, mocha);
35
37
 
36
38
  context.setup = common.beforeEach;
package/lib/mocha.js CHANGED
@@ -12,10 +12,15 @@ var builtinReporters = require('./reporters');
12
12
  var growl = require('./growl');
13
13
  var utils = require('./utils');
14
14
  var mocharc = require('./mocharc.json');
15
- var assign = require('object.assign').getPolyfill();
16
15
  var errors = require('./errors');
16
+ var Suite = require('./suite');
17
+ var createStatsCollector = require('./stats-collector');
17
18
  var createInvalidReporterError = errors.createInvalidReporterError;
18
19
  var createInvalidInterfaceError = errors.createInvalidInterfaceError;
20
+ var EVENT_FILE_PRE_REQUIRE = Suite.constants.EVENT_FILE_PRE_REQUIRE;
21
+ var EVENT_FILE_POST_REQUIRE = Suite.constants.EVENT_FILE_POST_REQUIRE;
22
+ var EVENT_FILE_REQUIRE = Suite.constants.EVENT_FILE_REQUIRE;
23
+ var sQuote = utils.sQuote;
19
24
 
20
25
  exports = module.exports = Mocha;
21
26
 
@@ -51,7 +56,7 @@ exports.Context = require('./context');
51
56
  * @memberof Mocha
52
57
  */
53
58
  exports.Runner = require('./runner');
54
- exports.Suite = require('./suite');
59
+ exports.Suite = Suite;
55
60
  exports.Hook = require('./hook');
56
61
  exports.Test = require('./test');
57
62
 
@@ -88,11 +93,11 @@ exports.Test = require('./test');
88
93
  * @param {boolean} [options.useInlineDiffs] - Use inline diffs?
89
94
  */
90
95
  function Mocha(options) {
91
- options = assign({}, mocharc, options || {});
96
+ options = utils.assign({}, mocharc, options || {});
92
97
  this.files = [];
93
98
  this.options = options;
94
99
  // root suite
95
- this.suite = new exports.Suite('', new exports.Context());
100
+ this.suite = new exports.Suite('', new exports.Context(), true);
96
101
 
97
102
  if ('useColors' in options) {
98
103
  utils.deprecate(
@@ -223,31 +228,23 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
223
228
  } catch (_err) {
224
229
  _err.code !== 'MODULE_NOT_FOUND' ||
225
230
  _err.message.indexOf('Cannot find module') !== -1
226
- ? console.warn('"' + reporter + '" reporter not found')
231
+ ? console.warn(sQuote(reporter) + ' reporter not found')
227
232
  : console.warn(
228
- '"' +
229
- reporter +
230
- '" reporter blew up with error:\n' +
233
+ sQuote(reporter) +
234
+ ' reporter blew up with error:\n' +
231
235
  err.stack
232
236
  );
233
237
  }
234
238
  } else {
235
239
  console.warn(
236
- '"' + reporter + '" reporter blew up with error:\n' + err.stack
240
+ sQuote(reporter) + ' reporter blew up with error:\n' + err.stack
237
241
  );
238
242
  }
239
243
  }
240
244
  }
241
- if (!_reporter && reporter === 'teamcity') {
242
- console.warn(
243
- 'The Teamcity reporter was moved to a package named ' +
244
- 'mocha-teamcity-reporter ' +
245
- '(https://npmjs.org/package/mocha-teamcity-reporter).'
246
- );
247
- }
248
245
  if (!_reporter) {
249
246
  throw createInvalidReporterError(
250
- 'invalid reporter "' + reporter + '"',
247
+ 'invalid reporter ' + sQuote(reporter),
251
248
  reporter
252
249
  );
253
250
  }
@@ -276,14 +273,14 @@ Mocha.prototype.ui = function(name) {
276
273
  this._ui = require(name);
277
274
  } catch (err) {
278
275
  throw createInvalidInterfaceError(
279
- 'invalid interface "' + name + '"',
276
+ 'invalid interface ' + sQuote(name),
280
277
  name
281
278
  );
282
279
  }
283
280
  }
284
281
  this._ui = this._ui(this.suite);
285
282
 
286
- this.suite.on('pre-require', function(context) {
283
+ this.suite.on(EVENT_FILE_PRE_REQUIRE, function(context) {
287
284
  exports.afterEach = context.afterEach || context.teardown;
288
285
  exports.after = context.after || context.suiteTeardown;
289
286
  exports.beforeEach = context.beforeEach || context.setup;
@@ -304,7 +301,6 @@ Mocha.prototype.ui = function(name) {
304
301
  };
305
302
 
306
303
  /**
307
- * @summary
308
304
  * Loads `files` prior to execution.
309
305
  *
310
306
  * @description
@@ -313,6 +309,8 @@ Mocha.prototype.ui = function(name) {
313
309
  *
314
310
  * @private
315
311
  * @see {@link Mocha#addFile}
312
+ * @see {@link Mocha#run}
313
+ * @see {@link Mocha#unloadFiles}
316
314
  * @param {Function} [fn] - Callback invoked upon completion.
317
315
  */
318
316
  Mocha.prototype.loadFiles = function(fn) {
@@ -320,13 +318,46 @@ Mocha.prototype.loadFiles = function(fn) {
320
318
  var suite = this.suite;
321
319
  this.files.forEach(function(file) {
322
320
  file = path.resolve(file);
323
- suite.emit('pre-require', global, file, self);
324
- suite.emit('require', require(file), file, self);
325
- suite.emit('post-require', global, file, self);
321
+ suite.emit(EVENT_FILE_PRE_REQUIRE, global, file, self);
322
+ suite.emit(EVENT_FILE_REQUIRE, require(file), file, self);
323
+ suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self);
326
324
  });
327
325
  fn && fn();
328
326
  };
329
327
 
328
+ /**
329
+ * Removes a previously loaded file from Node's `require` cache.
330
+ *
331
+ * @private
332
+ * @static
333
+ * @see {@link Mocha#unloadFiles}
334
+ * @param {string} file - Pathname of file to be unloaded.
335
+ */
336
+ Mocha.unloadFile = function(file) {
337
+ delete require.cache[require.resolve(file)];
338
+ };
339
+
340
+ /**
341
+ * Unloads `files` from Node's `require` cache.
342
+ *
343
+ * @description
344
+ * This allows files to be "freshly" reloaded, providing the ability
345
+ * to reuse a Mocha instance programmatically.
346
+ *
347
+ * <strong>Intended for consumers &mdash; not used internally</strong>
348
+ *
349
+ * @public
350
+ * @see {@link Mocha.unloadFile}
351
+ * @see {@link Mocha#loadFiles}
352
+ * @see {@link Mocha#run}
353
+ * @returns {Mocha} this
354
+ * @chainable
355
+ */
356
+ Mocha.prototype.unloadFiles = function() {
357
+ this.files.forEach(Mocha.unloadFile);
358
+ return this;
359
+ };
360
+
330
361
  /**
331
362
  * Sets `grep` filter after escaping RegExp special characters.
332
363
  *
@@ -512,7 +543,9 @@ Mocha.prototype._growl = growl.notify;
512
543
  * mocha.globals(['jQuery', 'MyLib']);
513
544
  */
514
545
  Mocha.prototype.globals = function(globals) {
515
- this.options.globals = (this.options.globals || []).concat(globals);
546
+ this.options.globals = (this.options.globals || [])
547
+ .concat(globals)
548
+ .filter(Boolean);
516
549
  return this;
517
550
  };
518
551
 
@@ -744,8 +777,7 @@ Object.defineProperty(Mocha.prototype, 'version', {
744
777
  */
745
778
 
746
779
  /**
747
- * @summary
748
- * Runs tests and invokes `fn()` when complete.
780
+ * Runs root suite and invokes `fn()` when complete.
749
781
  *
750
782
  * @description
751
783
  * To run tests multiple times (or to run tests in files that are
@@ -754,6 +786,7 @@ Object.defineProperty(Mocha.prototype, 'version', {
754
786
  *
755
787
  * @public
756
788
  * @see {@link Mocha#loadFiles}
789
+ * @see {@link Mocha#unloadFiles}
757
790
  * @see {@link Runner#run}
758
791
  * @param {DoneCB} [fn] - Callback invoked when test execution completed.
759
792
  * @return {Runner} runner instance
@@ -766,6 +799,7 @@ Mocha.prototype.run = function(fn) {
766
799
  var options = this.options;
767
800
  options.files = this.files;
768
801
  var runner = new exports.Runner(suite, options.delay);
802
+ createStatsCollector(runner);
769
803
  var reporter = new this._reporter(runner, options);
770
804
  runner.ignoreLeaks = options.ignoreLeaks !== false;
771
805
  runner.fullStackTrace = options.fullStackTrace;
@@ -789,7 +823,7 @@ Mocha.prototype.run = function(fn) {
789
823
  exports.reporters.Base.hideDiff = options.hideDiff;
790
824
 
791
825
  function done(failures) {
792
- fn = fn || function fn() {};
826
+ fn = fn || utils.noop;
793
827
  if (reporter.done) {
794
828
  reporter.done(failures, fn);
795
829
  } else {
@@ -11,6 +11,9 @@ var diff = require('diff');
11
11
  var milliseconds = require('ms');
12
12
  var utils = require('../utils');
13
13
  var supportsColor = process.browser ? null : require('supports-color');
14
+ var constants = require('../runner').constants;
15
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
16
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
14
17
 
15
18
  /**
16
19
  * Expose `Base`.
@@ -274,7 +277,7 @@ function Base(runner) {
274
277
  this.stats = runner.stats; // assigned so Reporters keep a closer reference
275
278
  this.runner = runner;
276
279
 
277
- runner.on('pass', function(test) {
280
+ runner.on(EVENT_TEST_PASS, function(test) {
278
281
  if (test.duration > test.slow()) {
279
282
  test.speed = 'slow';
280
283
  } else if (test.duration > test.slow() / 2) {
@@ -284,7 +287,7 @@ function Base(runner) {
284
287
  }
285
288
  });
286
289
 
287
- runner.on('fail', function(test, err) {
290
+ runner.on(EVENT_TEST_FAIL, function(test, err) {
288
291
  if (showDiff(err)) {
289
292
  stringifyDiffObjs(err);
290
293
  }
@@ -8,6 +8,11 @@
8
8
 
9
9
  var Base = require('./base');
10
10
  var utils = require('../utils');
11
+ var constants = require('../runner').constants;
12
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
13
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
14
+ var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
15
+ var EVENT_SUITE_END = constants.EVENT_SUITE_END;
11
16
 
12
17
  /**
13
18
  * Expose `Doc`.
@@ -33,7 +38,7 @@ function Doc(runner) {
33
38
  return Array(indents).join(' ');
34
39
  }
35
40
 
36
- runner.on('suite', function(suite) {
41
+ runner.on(EVENT_SUITE_BEGIN, function(suite) {
37
42
  if (suite.root) {
38
43
  return;
39
44
  }
@@ -44,7 +49,7 @@ function Doc(runner) {
44
49
  console.log('%s<dl>', indent());
45
50
  });
46
51
 
47
- runner.on('suite end', function(suite) {
52
+ runner.on(EVENT_SUITE_END, function(suite) {
48
53
  if (suite.root) {
49
54
  return;
50
55
  }
@@ -54,13 +59,13 @@ function Doc(runner) {
54
59
  --indents;
55
60
  });
56
61
 
57
- runner.on('pass', function(test) {
62
+ runner.on(EVENT_TEST_PASS, function(test) {
58
63
  console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
59
64
  var code = utils.escape(utils.clean(test.body));
60
65
  console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
61
66
  });
62
67
 
63
- runner.on('fail', function(test, err) {
68
+ runner.on(EVENT_TEST_FAIL, function(test, err) {
64
69
  console.log(
65
70
  '%s <dt class="error">%s</dt>',
66
71
  indent(),
@@ -8,6 +8,12 @@
8
8
 
9
9
  var Base = require('./base');
10
10
  var inherits = require('../utils').inherits;
11
+ var constants = require('../runner').constants;
12
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
13
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
14
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
15
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
16
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
11
17
 
12
18
  /**
13
19
  * Expose `Dot`.
@@ -31,18 +37,18 @@ function Dot(runner) {
31
37
  var width = (Base.window.width * 0.75) | 0;
32
38
  var n = -1;
33
39
 
34
- runner.on('start', function() {
40
+ runner.on(EVENT_RUN_BEGIN, function() {
35
41
  process.stdout.write('\n');
36
42
  });
37
43
 
38
- runner.on('pending', function() {
44
+ runner.on(EVENT_TEST_PENDING, function() {
39
45
  if (++n % width === 0) {
40
46
  process.stdout.write('\n ');
41
47
  }
42
48
  process.stdout.write(Base.color('pending', Base.symbols.comma));
43
49
  });
44
50
 
45
- runner.on('pass', function(test) {
51
+ runner.on(EVENT_TEST_PASS, function(test) {
46
52
  if (++n % width === 0) {
47
53
  process.stdout.write('\n ');
48
54
  }
@@ -53,14 +59,14 @@ function Dot(runner) {
53
59
  }
54
60
  });
55
61
 
56
- runner.on('fail', function() {
62
+ runner.on(EVENT_TEST_FAIL, function() {
57
63
  if (++n % width === 0) {
58
64
  process.stdout.write('\n ');
59
65
  }
60
66
  process.stdout.write(Base.color('fail', Base.symbols.bang));
61
67
  });
62
68
 
63
- runner.once('end', function() {
69
+ runner.once(EVENT_RUN_END, function() {
64
70
  console.log();
65
71
  self.epilogue();
66
72
  });
@@ -12,6 +12,12 @@ var Base = require('./base');
12
12
  var utils = require('../utils');
13
13
  var Progress = require('../browser/progress');
14
14
  var escapeRe = require('escape-string-regexp');
15
+ var constants = require('../runner').constants;
16
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
17
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
18
+ var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
19
+ var EVENT_SUITE_END = constants.EVENT_SUITE_END;
20
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
15
21
  var escape = utils.escape;
16
22
 
17
23
  /**
@@ -112,7 +118,7 @@ function HTML(runner) {
112
118
  progress.size(40);
113
119
  }
114
120
 
115
- runner.on('suite', function(suite) {
121
+ runner.on(EVENT_SUITE_BEGIN, function(suite) {
116
122
  if (suite.root) {
117
123
  return;
118
124
  }
@@ -131,7 +137,7 @@ function HTML(runner) {
131
137
  el.appendChild(stack[0]);
132
138
  });
133
139
 
134
- runner.on('suite end', function(suite) {
140
+ runner.on(EVENT_SUITE_END, function(suite) {
135
141
  if (suite.root) {
136
142
  updateStats();
137
143
  return;
@@ -139,7 +145,7 @@ function HTML(runner) {
139
145
  stack.shift();
140
146
  });
141
147
 
142
- runner.on('pass', function(test) {
148
+ runner.on(EVENT_TEST_PASS, function(test) {
143
149
  var url = self.testURL(test);
144
150
  var markup =
145
151
  '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> ' +
@@ -152,7 +158,7 @@ function HTML(runner) {
152
158
  updateStats();
153
159
  });
154
160
 
155
- runner.on('fail', function(test) {
161
+ runner.on(EVENT_TEST_FAIL, function(test) {
156
162
  var el = fragment(
157
163
  '<li class="test fail"><h2>%e <a href="%e" class="replay">' +
158
164
  playIcon +
@@ -208,7 +214,7 @@ function HTML(runner) {
208
214
  updateStats();
209
215
  });
210
216
 
211
- runner.on('pending', function(test) {
217
+ runner.on(EVENT_TEST_PENDING, function(test) {
212
218
  var el = fragment(
213
219
  '<li class="test pass pending"><h2>%e</h2></li>',
214
220
  test.title
@@ -7,6 +7,11 @@
7
7
  */
8
8
 
9
9
  var Base = require('./base');
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;
10
15
 
11
16
  /**
12
17
  * Expose `JSONStream`.
@@ -29,22 +34,22 @@ function JSONStream(runner) {
29
34
  var self = this;
30
35
  var total = runner.total;
31
36
 
32
- runner.once('start', function() {
37
+ runner.once(EVENT_RUN_BEGIN, function() {
33
38
  writeEvent(['start', {total: total}]);
34
39
  });
35
40
 
36
- runner.on('pass', function(test) {
41
+ runner.on(EVENT_TEST_PASS, function(test) {
37
42
  writeEvent(['pass', clean(test)]);
38
43
  });
39
44
 
40
- runner.on('fail', function(test, err) {
45
+ runner.on(EVENT_TEST_FAIL, function(test, err) {
41
46
  test = clean(test);
42
47
  test.err = err.message;
43
48
  test.stack = err.stack || null;
44
49
  writeEvent(['fail', test]);
45
50
  });
46
51
 
47
- runner.once('end', function() {
52
+ runner.once(EVENT_RUN_END, function() {
48
53
  writeEvent(['end', self.stats]);
49
54
  });
50
55
  }
@@ -7,6 +7,12 @@
7
7
  */
8
8
 
9
9
  var Base = require('./base');
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_TEST_END = constants.EVENT_TEST_END;
14
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
15
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
10
16
 
11
17
  /**
12
18
  * Expose `JSON`.
@@ -32,23 +38,23 @@ function JSONReporter(runner) {
32
38
  var failures = [];
33
39
  var passes = [];
34
40
 
35
- runner.on('test end', function(test) {
41
+ runner.on(EVENT_TEST_END, function(test) {
36
42
  tests.push(test);
37
43
  });
38
44
 
39
- runner.on('pass', function(test) {
45
+ runner.on(EVENT_TEST_PASS, function(test) {
40
46
  passes.push(test);
41
47
  });
42
48
 
43
- runner.on('fail', function(test) {
49
+ runner.on(EVENT_TEST_FAIL, function(test) {
44
50
  failures.push(test);
45
51
  });
46
52
 
47
- runner.on('pending', function(test) {
53
+ runner.on(EVENT_TEST_PENDING, function(test) {
48
54
  pending.push(test);
49
55
  });
50
56
 
51
- runner.once('end', function() {
57
+ runner.once(EVENT_RUN_END, function() {
52
58
  var obj = {
53
59
  stats: self.stats,
54
60
  tests: tests.map(clean),
@@ -8,6 +8,12 @@
8
8
 
9
9
  var Base = require('./base');
10
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
+
11
17
  var cursor = Base.cursor;
12
18
  var color = Base.color;
13
19
 
@@ -60,17 +66,17 @@ function Landing(runner) {
60
66
  return ' ' + color('runway', buf);
61
67
  }
62
68
 
63
- runner.on('start', function() {
69
+ runner.on(EVENT_RUN_BEGIN, function() {
64
70
  stream.write('\n\n\n ');
65
71
  cursor.hide();
66
72
  });
67
73
 
68
- runner.on('test end', function(test) {
74
+ runner.on(EVENT_TEST_END, function(test) {
69
75
  // check if the plane crashed
70
76
  var col = crashed === -1 ? ((width * ++n) / total) | 0 : crashed;
71
77
 
72
78
  // show the crash
73
- if (test.state === 'failed') {
79
+ if (test.state === STATE_FAILED) {
74
80
  plane = color('plane crash', '✈');
75
81
  crashed = col;
76
82
  }
@@ -86,7 +92,7 @@ function Landing(runner) {
86
92
  stream.write('\u001b[0m');
87
93
  });
88
94
 
89
- runner.once('end', function() {
95
+ runner.once(EVENT_RUN_END, function() {
90
96
  cursor.show();
91
97
  console.log();
92
98
  self.epilogue();
@@ -8,6 +8,13 @@
8
8
 
9
9
  var Base = require('./base');
10
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;
11
18
  var color = Base.color;
12
19
  var cursor = Base.cursor;
13
20
 
@@ -32,20 +39,20 @@ function List(runner) {
32
39
  var self = this;
33
40
  var n = 0;
34
41
 
35
- runner.on('start', function() {
42
+ runner.on(EVENT_RUN_BEGIN, function() {
36
43
  console.log();
37
44
  });
38
45
 
39
- runner.on('test', function(test) {
46
+ runner.on(EVENT_TEST_BEGIN, function(test) {
40
47
  process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
41
48
  });
42
49
 
43
- runner.on('pending', function(test) {
50
+ runner.on(EVENT_TEST_PENDING, function(test) {
44
51
  var fmt = color('checkmark', ' -') + color('pending', ' %s');
45
52
  console.log(fmt, test.fullTitle());
46
53
  });
47
54
 
48
- runner.on('pass', function(test) {
55
+ runner.on(EVENT_TEST_PASS, function(test) {
49
56
  var fmt =
50
57
  color('checkmark', ' ' + Base.symbols.ok) +
51
58
  color('pass', ' %s: ') +
@@ -54,12 +61,12 @@ function List(runner) {
54
61
  console.log(fmt, test.fullTitle(), test.duration);
55
62
  });
56
63
 
57
- runner.on('fail', function(test) {
64
+ runner.on(EVENT_TEST_FAIL, function(test) {
58
65
  cursor.CR();
59
66
  console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
60
67
  });
61
68
 
62
- runner.once('end', self.epilogue.bind(self));
69
+ runner.once(EVENT_RUN_END, self.epilogue.bind(self));
63
70
  }
64
71
 
65
72
  /**
@@ -8,6 +8,11 @@
8
8
 
9
9
  var Base = require('./base');
10
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;
11
16
 
12
17
  /**
13
18
  * Constants
@@ -77,18 +82,18 @@ function Markdown(runner) {
77
82
 
78
83
  generateTOC(runner.suite);
79
84
 
80
- runner.on('suite', function(suite) {
85
+ runner.on(EVENT_SUITE_BEGIN, function(suite) {
81
86
  ++level;
82
87
  var slug = utils.slug(suite.fullTitle());
83
88
  buf += '<a name="' + slug + '"></a>' + '\n';
84
89
  buf += title(suite.title) + '\n';
85
90
  });
86
91
 
87
- runner.on('suite end', function() {
92
+ runner.on(EVENT_SUITE_END, function() {
88
93
  --level;
89
94
  });
90
95
 
91
- runner.on('pass', function(test) {
96
+ runner.on(EVENT_TEST_PASS, function(test) {
92
97
  var code = utils.clean(test.body);
93
98
  buf += test.title + '.\n';
94
99
  buf += '\n```js\n';
@@ -96,7 +101,7 @@ function Markdown(runner) {
96
101
  buf += '```\n\n';
97
102
  });
98
103
 
99
- runner.once('end', function() {
104
+ runner.once(EVENT_RUN_END, function() {
100
105
  process.stdout.write('# TOC\n');
101
106
  process.stdout.write(generateTOC(runner.suite));
102
107
  process.stdout.write(buf);
@@ -8,6 +8,9 @@
8
8
 
9
9
  var Base = require('./base');
10
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;
11
14
 
12
15
  /**
13
16
  * Expose `Min`.
@@ -27,14 +30,14 @@ exports = module.exports = Min;
27
30
  function Min(runner) {
28
31
  Base.call(this, runner);
29
32
 
30
- runner.on('start', function() {
33
+ runner.on(EVENT_RUN_BEGIN, function() {
31
34
  // clear screen
32
35
  process.stdout.write('\u001b[2J');
33
36
  // set cursor position
34
37
  process.stdout.write('\u001b[1;3H');
35
38
  });
36
39
 
37
- runner.once('end', this.epilogue.bind(this));
40
+ runner.once(EVENT_RUN_END, this.epilogue.bind(this));
38
41
  }
39
42
 
40
43
  /**