Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
/*
2
* macros.js: Test macros for using broadway and vows
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var events = require('eventemitter2'),
10
assert = require('./assert'),
11
helpers = require('./helpers'),
12
broadway = require('../../lib/broadway');
13
14
var macros = exports;
15
16
macros.shouldExtend = function (app, plugin, vows) {
17
if (arguments.length === 1) {
18
plugin = app;
19
app = vows = null;
20
}
21
else if (arguments.length === 2) {
22
app = helpers.mockApp();
23
vows = plugin;
24
plugin = app;
25
}
26
27
var context = {
28
topic: function () {
29
app = app || helpers.mockApp();
30
broadway.plugins[plugin].attach.call(app, app.options[plugin] || {});
31
32
if (broadway.plugins[plugin].init) {
33
return broadway.plugins[plugin].init.call(app, this.callback.bind(this, null, app));
34
}
35
36
this.callback(null, app);
37
},
38
"should add the appropriate properties and methods": function (_, app) {
39
assert.plugins.has[plugin](app);
40
}
41
}
42
43
return extendContext(context, vows);
44
};
45
46
macros.shouldLogEvent = function (app, event, vow) {
47
return {
48
topic: function () {
49
app = app || helpers.findApp.apply(null, arguments);
50
var logger = app.log.get('default');
51
52
this.event = event;
53
app.once('broadway::logged', this.callback.bind(this, null));
54
app.emit.apply(app, event);
55
},
56
"should log the appropriate info": vow
57
};
58
};
59
60
function extendContext (context, vows) {
61
if (vows) {
62
if (vows.topic) {
63
console.log('Cannot include topic at top-level of nested vows:');
64
console.dir(vows, 'vows');
65
process.exit(1);
66
}
67
68
Object.keys(vows).forEach(function (key) {
69
context[key] = vows[key];
70
});
71
}
72
73
return context;
74
}
75