UNPKG

2.23 kBtext/coffeescriptView Raw
1should = require 'should'
2logger = require 'torch'
3
4bus = require '../lib/bus'
5core = require '..'
6
7logLevels = require '../lib/core/logLevels'
8
9# Helper to listen to topics on the Axiom logging
10# channel without making any API calls to 'core'.
11listen = (topic, callback) ->
12
13 {channel} = core.log
14 sub = bus.subscribe {channel, topic, callback}
15
16 # Unsubscribe after being fired once
17 sub.once()
18
19# Test basic 'log' functionality
20describe '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 # Given a listener on the 'log' channel and given topic
31 listen topic, (data) ->
32
33 # We should receive a log message
34 should.exist data
35 data.should.eql [color]
36 done()
37
38 # When we log it via the given topic
39 core.log[topic] color
40
41methodTests = [
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# Test 'info' coverage for public 'core' API
73describe "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 # Given a listener on the 'info' topic of 'axiom.log'
84 listen 'debug', ([data]) ->
85 # We should receive an informational message
86 should.exist data
87
88 # With the expected details
89 data.should.include expected
90
91 done()
92
93 # When we call the given public 'core' method
94 core[method] args...