emit.js
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var _ = require('underscore');
var expect = require('expect.js');
describe('bootstrap/emit', function () {
var context = {};
var hooks = require('../util/hooks');
beforeEach(hooks.before(context));
it('provides emit, which emits an event', function (done) {
context.spooky.start();
context.spooky.then(function () {
var fs = require('fs');
var emit =
require(fs.workingDirectory + '/lib/bootstrap/emit').emit;
emit('testing', 1, 2, 3);
});
context.spooky.once('testing', function () {
var args = _.toArray(arguments);
expect(args[0]).to.be(1);
expect(args[1]).to.be(2);
expect(args[2]).to.be(3);
done();
});
context.spooky.run();
});
it('provides console.*, which emit a console events', function (done) {
var out = [];
context.spooky.start();
context.spooky.then(function () {
var fs = require('fs');
var console =
require(fs.workingDirectory + '/lib/bootstrap/emit').console;
console.log('HEYO');
console.debug('HEYO');
console.info('HEYO');
console.warn('HEYO');
console.error('HEYO');
});
function onConsole(line) {
out.push(line);
}
context.spooky.on('console', onConsole);
context.spooky.once('run.complete', function () {
expect(out).to.contain('HEYO');
expect(out).to.contain('debug HEYO');
expect(out).to.contain('info HEYO');
expect(out).to.contain('warn HEYO');
expect(out).to.contain('error HEYO');
context.spooky.removeListener('console', onConsole);
done();
});
context.spooky.run();
});
afterEach(hooks.after(context));
});