forked from livereload/livereload-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol_test.coffee
49 lines (35 loc) · 1.32 KB
/
protocol_test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
assert = require 'assert'
{ Parser } = require '../src/protocol'
class MockHandler
constructor: ->
@_log = []
@gotError = no
obtainLog: -> result = @_log.join("\n"); @_log = []; result
log: (message) -> @_log.push message
connected: (@protocol) ->
error: (@error) -> @gotError = yes
message: (msg) ->
switch msg.command
when 'reload' then @log "reload(#{msg.path})"
else @log msg.commmand
describe "Protocol", ->
it "should reject a bogus handshake", ->
handler = new MockHandler()
parser = new Parser(handler)
parser.process 'boo'
assert.ok handler.gotError
it "should speak protocol 6", ->
handler = new MockHandler()
parser = new Parser(handler)
parser.process '!!ver:1.6'
assert.equal 6, parser.protocol
parser.process '[ "refresh", { "path": "foo.css" } ]'
assert.equal "reload(foo.css)", handler.obtainLog()
it "should speak protocol 7", ->
handler = new MockHandler()
parser = new Parser(handler)
parser.process '{ "command": "hello", "protocols": [ "http://livereload.com/protocols/official-7" ] }'
assert.equal null, handler.error?.message
assert.equal 7, parser.protocol
parser.process '{ "command": "reload", "path": "foo.css" }'
assert.equal "reload(foo.css)", handler.obtainLog()