UNPKG

2.54 kBtext/coffeescriptView Raw
1should = require 'should'
2
3bus = require '../lib/bus'
4core = require '..'
5
6logLevels = require '../lib/core/logLevels'
7
8# Helper to listen to topics on the Axiom logging
9# channel without making any API calls to 'core'.
10listen = (topic, callback) ->
11
12 {channel} = core.log
13 sub = bus.subscribe {channel, topic, callback}
14
15 # Unsubscribe after being fired once
16 sub.once()
17
18# Test basic 'log' functionality
19describe '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 # Given a listener on the 'log' channel and given topic
30 listen topic, (data) ->
31
32 # We should receive a log message
33 should.exist data
34 data.should.eql color
35 done()
36
37 # When we log it via the given topic
38 core.log[topic] color
39
40methodTests = [
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 # this includes a UUID now and is non-trivial to test
58 #,
59 #method: 'delegate'
60 #args: ['channel', 'data']
61 #expected: "Calling 'core.delegate' with args: { channel: 'channel', data: 'data' }"
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# Test 'info' coverage for public 'core' API
77describe "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 # Given a listener on the 'info' topic of 'axiom.log'
88 listen 'debug', (data) ->
89 # We should receive an informational message
90 should.exist data
91
92 # With the expected details
93 data.should.eql expected
94
95 done()
96
97 # When we call the given public 'core' method
98 try core[method](args...)