1 | 'use strict';
|
2 |
|
3 | var EventEmitter = require('events').EventEmitter;
|
4 |
|
5 | function Runner() {
|
6 | this._queue = [];
|
7 | }
|
8 |
|
9 | Runner.prototype = Object.create(EventEmitter.prototype);
|
10 | Runner.prototype.constructor = Runner;
|
11 |
|
12 | Runner.prototype.errorCount = 0;
|
13 |
|
14 | Runner.prototype._countErrors = function _countErrors(node) {
|
15 | var self = this;
|
16 | node.on('assertNotOk', function () { self.errorCount++; });
|
17 | node.on('childTest', _countErrors.bind(this));
|
18 | };
|
19 |
|
20 | Runner.prototype.run = function run() {
|
21 | if (this._currentTest) return;
|
22 |
|
23 | var self = this;
|
24 |
|
25 | if (this._queue.length === 0)
|
26 | this._done();
|
27 | else {
|
28 | var node = this._queue.shift();
|
29 | this.emit('test', node);
|
30 |
|
31 | node.once('treeDone', function () {
|
32 | self._currentTest = null;
|
33 | run.call(self)
|
34 | });
|
35 |
|
36 | this._countErrors(node);
|
37 |
|
38 | this._currentTest = node;
|
39 | node.run();
|
40 | }
|
41 | };
|
42 |
|
43 | Runner.prototype.enqueue = function (node) {
|
44 | this._queue.push(node);
|
45 | };
|
46 |
|
47 | Runner.prototype._done = function () {
|
48 | this.emit('done');
|
49 |
|
50 | process.exit(this.errorCount);
|
51 | };
|
52 |
|
53 | module.exports = Runner; |
\ | No newline at end of file |