1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var EventEmitter, Mocha, emitter,
|
7 | __slice = [].slice;
|
8 |
|
9 | EventEmitter = require('events').EventEmitter;
|
10 |
|
11 | module.exports = emitter = new EventEmitter;
|
12 |
|
13 | Mocha = require('mocha');
|
14 |
|
15 | module.exports.create = function(opts) {
|
16 | var api, mocha;
|
17 | mocha = new Mocha({
|
18 | reporter: function(runner) {
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var event, _i, _len, _ref, _results;
|
39 | _ref = ['start', 'end', 'suite', 'suite end', 'test', 'test end', 'hook', 'hook end', 'pass', 'fail', 'pending'];
|
40 | _results = [];
|
41 | for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
42 | event = _ref[_i];
|
43 | _results.push((function(event) {
|
44 | return runner.on(event, function() {
|
45 | var data;
|
46 | data = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
47 | return emitter.emit('spec_event', {
|
48 | source: 'mocha',
|
49 | event: event,
|
50 | data: data
|
51 | });
|
52 | });
|
53 | })(event));
|
54 | }
|
55 | return _results;
|
56 | }
|
57 | });
|
58 | return api = {
|
59 | run: function(files, callback) {
|
60 | var file, _i, _len;
|
61 | for (_i = 0, _len = files.length; _i < _len; _i++) {
|
62 | file = files[_i];
|
63 | mocha.addFile(file);
|
64 | }
|
65 | return mocha.run(callback);
|
66 | }
|
67 | };
|
68 | };
|