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