-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathtest-runner.js
112 lines (94 loc) · 2.55 KB
/
test-runner.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*global describe:true, it:true, before:true, after:true */
var
demand = require('must'),
fivebeans = require('../index')
;
//-------------------------------------------------------------
describe('FiveBeansRunner', function()
{
describe('constructor', function()
{
it('throws when not given an id', function()
{
function shouldThrow()
{
return new fivebeans.runner();
}
shouldThrow.must.throw(Error);
});
it('throws when not given a config path', function()
{
function shouldThrow()
{
return new fivebeans.runner('test');
}
shouldThrow.must.throw(Error);
});
it('throws if given a config path that does not exist', function()
{
function shouldThrow()
{
return new fivebeans.runner('test', '/not/a/real/path.yml');
}
shouldThrow.must.throw(Error);
});
it('creates a runner when given valid options', function()
{
var r = new fivebeans.runner('test', 'test/fixtures/runner.yml');
r.must.have.property('worker');
r.id.must.equal('test');
r.configpath.must.equal(__dirname + '/fixtures/runner.yml');
});
});
describe('readConfiguration()', function()
{
it('throws when the config requires non-existing handlers', function()
{
var r = new fivebeans.runner('test', 'test/fixtures/badconfig.yml');
function shouldThrow() { r.readConfiguration(); }
shouldThrow.must.throw(Error);
});
it('returns a config object for a good config', function()
{
var r = new fivebeans.runner('test', 'test/fixtures/runner.yml');
var config = r.readConfiguration();
config.must.be.an.object();
config.must.have.property('beanstalkd');
config.beanstalkd.host.must.equal('localhost');
config.watch.must.be.an.array();
config.ignoreDefault.must.equal(true);
});
});
describe('createWorker()', function()
{
var worker;
it('returns a worker', function(done)
{
var r = new fivebeans.runner('test', 'test/fixtures/runner.yml');
worker = r.createWorker();
worker.must.exist();
worker.must.be.an.object();
(worker instanceof fivebeans.worker).must.equal(true);
worker.once('started', done);
});
it('started the worker', function(done)
{
worker.stopped.must.equal(false);
worker.client.must.exist();
worker.once('stopped', done);
worker.stop();
});
});
describe('go()', function()
{
it('creates and starts a worker', function(done)
{
var r = new fivebeans.runner('test', 'test/fixtures/runner.yml');
r.go();
r.worker.must.exist();
r.worker.client.must.exist();
r.worker.on('stopped', done);
r.worker.stop();
});
});
});