UNPKG

2.48 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 method: 'delegate'
58 args: ['channel', 'data']
59 expected: "Calling 'core.delegate' with args: { channel: 'channel', data: 'data' }"
60 ,
61 method: 'respond'
62 args: ['channel']
63 expected: "Calling 'core.respond' with args: { channel: 'channel' }"
64 ,
65 method: 'send'
66 args: ['channel', 'data']
67 expected: "Calling 'core.send' with args: { channel: 'channel', data: 'data' }"
68 ,
69 method: 'listen'
70 args: ['channel', 'topic']
71 expected: "Calling 'core.listen' with args: { channel: 'channel', topic: 'topic' }"
72]
73
74# Test 'info' coverage for public 'core' API
75describe "log, 'core' API", ->
76 beforeEach ->
77 core.reset()
78
79 for test in methodTests
80 do (test) ->
81 {method, args, expected} = test
82
83 it "should log calls to 'core.#{method}'", (done) ->
84
85 # Given a listener on the 'info' topic of 'axiom.log'
86 listen 'debug', (data) ->
87 # We should receive an informational message
88 should.exist data
89
90 # With the expected details
91 data.should.eql expected
92
93 done()
94
95 # When we call the given public 'core' method
96 try core[method](args...)