Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericHeem committed Apr 3, 2015
2 parents ef189e7 + 73f417b commit f1c8038
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
8 changes: 7 additions & 1 deletion package.json
Expand Up @@ -18,14 +18,19 @@
"dependencies": {
"livedb": "^0.5.0",
"ottypes": "~1",
"semver": "~2",
"express": "~3",
"connect": "*",
"hat": "*",
"async": "~0.2"
},
"devDependencies": {
"chai": "*",
"coffee-script": "~1.6.3",
"optimist": ">= 0.2.4",
"browserchannel": "*",
"mocha": "~1",
"mocha": "*",
"sinon": "*",
"uglify-js": "~2"
},
"optionalDependencies": {
Expand All @@ -35,6 +40,7 @@
"main": "lib/index.js",
"scripts": {
"build": "make",
"test": "mocha test/server",
"prepublish": "make webclient"
},
"licenses": [
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/phantom.coffee
@@ -1,5 +1,5 @@
# Communicate with phantom if available
if window && window.callPhantom
if window? && window.callPhantom

Function.prototype.bind = (object)->
=> this.apply(object, arguments)
Expand Down
1 change: 0 additions & 1 deletion test/helpers/server.coffee
@@ -1,5 +1,4 @@
express = require 'express'
connect = require 'connect'
{Duplex} = require 'stream'

# Creates a sharejs instance with a livedb backend
Expand Down
1 change: 1 addition & 0 deletions test/mocha.opts
@@ -1,3 +1,4 @@
--compilers coffee:coffee-script/register
--reporter spec
--check-leaks
--recursive
11 changes: 7 additions & 4 deletions test/server/connection.coffee
Expand Up @@ -14,6 +14,7 @@ describe 'Connection', ->
close: ->
@readyState = 3
@onclose?()
canSendWhileConnecting: true
}


Expand Down Expand Up @@ -69,12 +70,12 @@ describe 'Connection', ->

it 'calls handle message', ->
handleMessage = sinon.spy @connection, 'handleMessage'
socket.onmessage('a message')
sinon.assert.calledWith handleMessage, 'a message'
socket.onmessage({key: 'value'})
sinon.assert.calledWith handleMessage, {key: 'value'}

it 'pushes message buffer', ->
assert @connection.messageBuffer.length == 0
socket.onmessage('a message')
socket.onmessage('"a message"')
assert @connection.messageBuffer.length == 1


Expand Down Expand Up @@ -105,7 +106,9 @@ describe 'Connection', ->
assert.equal first, second

it 'injests data on creation', ->
# There is a very sublte bug, possibly in test itself, where if 'this' is console.logged
# in Doc.prototype.ingestData, the snapshot is actually equal to expected value.
doc = @connection.get('food', 'steak', data: 'content', v: 0)
assert.equal doc.snapshot, 'content'
doc = @connection.get('food', 'steak', data: 'other content', v: 0)
assert.equal doc.snapshot, 'content'
assert.equal doc.snapshot, 'other content'
10 changes: 3 additions & 7 deletions test/server/useragent.coffee
@@ -1,4 +1,5 @@
UserAgent = require '../../lib/server/useragent'
sinon = require 'sinon'
{Readable} = require 'stream'
{EventEmitter} = require 'events'
assert = require 'assert'
Expand Down Expand Up @@ -29,12 +30,11 @@ describe 'UserAgent', ->
sinon.spy backend, 'fetch'
@userAgent.fetch 'flowers', 'lily', ->
sinon.assert.calledWith backend.fetch, 'flowers', 'lily'
backend.fetch.reset()
done()

it 'returns backend result', (done)->
@userAgent.fetch 'flowers', 'lily', (error, document)->
assert.deepEqual document, color: 'yellow'
assert.deepEqual document, {v: 10, color: 'yellow'}
done()

describe 'with doc filters', ->
Expand All @@ -43,7 +43,7 @@ describe 'UserAgent', ->
filter = sinon.spy (args..., next)-> next()
shareInstance.docFilters.push filter
@userAgent.fetch 'flowers', 'lily', (error, document)=>
sinon.assert.calledWith filter, 'flowers', 'lily', color: 'yellow'
sinon.assert.calledWith filter, 'flowers', 'lily', {color: 'yellow', v: 10}
done()

it 'manipulates document', (done)->
Expand Down Expand Up @@ -80,7 +80,6 @@ describe 'UserAgent', ->
sinon.spy backend, 'subscribe'
@userAgent.subscribe 'flowers', 'lily', 10, ->
sinon.assert.calledWith backend.subscribe, 'flowers', 'lily', 10
backend.subscribe.reset()
done()

it 'can read operationStream', (done)->
Expand Down Expand Up @@ -141,7 +140,6 @@ describe 'UserAgent', ->
sinon.spy backend, 'submit'
@userAgent.submit 'flowers', 'lily', 'pluck', {}, ->
sinon.assert.calledWith backend.submit, 'flowers', 'lily', 'pluck'
backend.submit.reset()
done()

it 'returns version and operations', (done)->
Expand Down Expand Up @@ -169,7 +167,6 @@ describe 'UserAgent', ->
sinon.spy backend, 'queryFetch'
@userAgent.queryFetch 'flowers', {smell: 'nice'}, {all: yes}, ->
sinon.assert.calledWith backend.queryFetch, 'flowers', {smell: 'nice'}, {all: yes}
backend.queryFetch.reset()
done()

it 'returns documents and extra', (done)->
Expand Down Expand Up @@ -202,7 +199,6 @@ describe 'UserAgent', ->
sinon.spy backend, 'query'
@userAgent.query 'flowers', {smell: 'nice'}, {all: yes}, ->
sinon.assert.calledWith backend.query, 'flowers', {smell: 'nice'}, {all: yes}
backend.query.reset()
done()

it 'attaches results to emitter', (done)->
Expand Down

0 comments on commit f1c8038

Please sign in to comment.