Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50660 views
1
/*
2
* app-test.js: Tests for core App methods and configuration.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var events = require('eventemitter2'),
10
vows = require('vows'),
11
assert = require('../helpers/assert'),
12
broadway = require('../../lib/broadway');
13
14
vows.describe('broadway/app').addBatch({
15
"An initialized instance of broadway.App with three plugins": {
16
topic: function () {
17
var app = new broadway.App(),
18
that = this,
19
three;
20
21
that.init = [];
22
23
three = {
24
name: 'three',
25
init: function (cb) {
26
process.nextTick(function () {
27
that.init.push('three');
28
cb();
29
})
30
}
31
};
32
33
// First plugin. Includes an init step.
34
app.use({
35
attach: function () {
36
this.place = 'rackspace';
37
},
38
39
init: function (cb) {
40
var self = this;
41
42
// a nextTick isn't technically necessary, but it does make this
43
// purely async.
44
process.nextTick(function () {
45
that.init.push('one');
46
self.letsGo = function () {
47
return 'Let\'s go to '+self.place+'!';
48
}
49
50
cb();
51
});
52
}
53
});
54
55
// Second plugin. Only involves an "attach".
56
app.use({
57
attach: function () {
58
this.oneup = function (n) {
59
n++;
60
return n;
61
}
62
}
63
});
64
65
// Third pluging. Only involves an "init".
66
app.use(three);
67
68
// Attempt to use it again. This should not invoke `init()` twice
69
app.use(three);
70
71
// Remove the plugin and use it again. This should not invoke `init()` twice
72
app.remove(three);
73
app.use(three);
74
75
// Removing a plugin which was never added should not affect the initlist
76
app.remove({
77
name: 'foo'
78
});
79
80
app.init(function (err) {
81
that.callback(err, app);
82
});
83
},
84
"shouldn't throw an error": function (err, app) {
85
assert.ok(!err);
86
},
87
"should have all its methods attached/defined": function (err, app) {
88
assert.ok(app.place);
89
assert.isFunction(app.oneup);
90
assert.isFunction(app.letsGo);
91
assert.equal(2, app.oneup(1));
92
assert.equal(app.letsGo(), 'Let\'s go to rackspace!');
93
94
//
95
// This is intentional. The second plugin does not invoke `init`.
96
//
97
assert.deepEqual(this.init, ['one', 'three']);
98
},
99
}
100
}).export(module);
101
102