1 | should = require 'should'
|
2 |
|
3 | bus = require '../lib/bus'
|
4 | core = require '..'
|
5 |
|
6 | logLevels = require '../lib/core/logLevels'
|
7 |
|
8 |
|
9 |
|
10 | listen = (topic, callback) ->
|
11 |
|
12 | {channel} = core.log
|
13 | sub = bus.subscribe {channel, topic, callback}
|
14 |
|
15 |
|
16 | sub.once()
|
17 |
|
18 |
|
19 | describe 'log', ->
|
20 | after ->
|
21 | core.reset()
|
22 |
|
23 | for test in logLevels
|
24 | do (test) ->
|
25 | {topic, color} = test
|
26 |
|
27 | it "should log on #{topic}", (done) ->
|
28 |
|
29 |
|
30 | listen topic, (data) ->
|
31 |
|
32 |
|
33 | should.exist data
|
34 | data.should.eql color
|
35 | done()
|
36 |
|
37 |
|
38 | core.log[topic] color
|
39 |
|
40 | methodTests = [
|
41 | method: 'init'
|
42 | args: ['config', 'retriever']
|
43 | expected: "Calling 'core.init' with args: { config: 'config', retriever: 'retriever' }"
|
44 | ,
|
45 | method: 'reset'
|
46 | args: []
|
47 | expected: "Calling 'core.reset'"
|
48 | ,
|
49 | method: 'load'
|
50 | args: ['moduleName']
|
51 | expected: "Calling 'core.load' with args: { moduleName: 'moduleName' }"
|
52 | ,
|
53 | method: 'request'
|
54 | args: ['channel', 'data']
|
55 | expected: "Calling 'core.request' with args: { channel: 'channel', data: 'data' }"
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | ,
|
63 | method: 'respond'
|
64 | args: ['channel']
|
65 | expected: "Calling 'core.respond' with args: { channel: 'channel' }"
|
66 | ,
|
67 | method: 'send'
|
68 | args: ['channel', 'data']
|
69 | expected: "Calling 'core.send' with args: { channel: 'channel', data: 'data' }"
|
70 | ,
|
71 | method: 'listen'
|
72 | args: ['channel', 'topic']
|
73 | expected: "Calling 'core.listen' with args: { channel: 'channel', topic: 'topic' }"
|
74 | ]
|
75 |
|
76 |
|
77 | describe "log, 'core' API", ->
|
78 | beforeEach ->
|
79 | core.reset()
|
80 |
|
81 | for test in methodTests
|
82 | do (test) ->
|
83 | {method, args, expected} = test
|
84 |
|
85 | it "should log calls to 'core.#{method}'", (done) ->
|
86 |
|
87 |
|
88 | listen 'debug', (data) ->
|
89 |
|
90 | should.exist data
|
91 |
|
92 |
|
93 | data.should.eql expected
|
94 |
|
95 | done()
|
96 |
|
97 |
|
98 | try core[method](args...)
|