mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-17 14:07:34 +03:00
Use atom-collaboration-server directly in specs
This commit is contained in:
parent
a22587d09b
commit
b9e23b96eb
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -7,3 +7,6 @@
|
||||
[submodule "vendor/telepath"]
|
||||
path = vendor/telepath
|
||||
url = https://github.com/github/telepath.git
|
||||
[submodule "src/packages/collaboration/vendor/atom-collaboration-server"]
|
||||
path = src/packages/collaboration/vendor/atom-collaboration-server
|
||||
url = https://github.com/github/atom-collaboration-server.git
|
||||
|
@ -82,7 +82,8 @@
|
||||
"grunt-contrib-coffee": "~0.7.0",
|
||||
"grunt-contrib-less": "~0.5.2",
|
||||
"jasmine-focused": "~0.7.0",
|
||||
"walkdir": "0.0.7"
|
||||
"walkdir": "0.0.7",
|
||||
"ws": "0.4.27"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -2,79 +2,43 @@ _ = require 'underscore'
|
||||
keytar = require 'keytar'
|
||||
{Site} = require 'telepath'
|
||||
|
||||
Server = require '../vendor/atom-collaboration-server'
|
||||
GuestSession = require '../lib/guest-session'
|
||||
HostSession = require '../lib/host-session'
|
||||
|
||||
class Server
|
||||
constructor: ->
|
||||
@channels = {}
|
||||
|
||||
getChannel: (channelName) ->
|
||||
@channels[channelName] ?= new ChannelServer(channelName)
|
||||
|
||||
createClient: -> new Client(this)
|
||||
|
||||
class Client
|
||||
@nextId: 1
|
||||
|
||||
constructor: (@server) ->
|
||||
@id = @constructor.nextId++
|
||||
|
||||
subscribe: (channelName) ->
|
||||
@server.getChannel(channelName).subscribe(this)
|
||||
|
||||
class ChannelServer
|
||||
constructor: (@name) ->
|
||||
@channelClients = {}
|
||||
|
||||
subscribe: (subscribingClient) ->
|
||||
channelClient = new ChannelClient(subscribingClient, this)
|
||||
@channelClients[subscribingClient.id] = channelClient
|
||||
setTimeout =>
|
||||
for client in @getChannelClients()
|
||||
if client is channelClient
|
||||
client.trigger 'channel:opened'
|
||||
else
|
||||
client.trigger 'channel:participant-entered'
|
||||
channelClient
|
||||
|
||||
getChannelClients: -> _.values(@channelClients)
|
||||
|
||||
send: (sendingClient, eventName, eventData) ->
|
||||
setTimeout =>
|
||||
for client in @getChannelClients() when client isnt sendingClient
|
||||
client.trigger(eventName, eventData)
|
||||
|
||||
class ChannelClient
|
||||
_.extend @prototype, require('event-emitter')
|
||||
|
||||
constructor: (@pusherClient, @channelServer) ->
|
||||
|
||||
send: (eventName, eventData) ->
|
||||
@channelServer.send(this, eventName, eventData)
|
||||
|
||||
fdescribe "Collaboration", ->
|
||||
describe "joining a host session", ->
|
||||
[hostSession, guestSession, pusher, repositoryMirrored] = []
|
||||
describe "Collaboration", ->
|
||||
describe "when a host and a guest join a channel", ->
|
||||
[server, hostSession, guestSession, repositoryMirrored] = []
|
||||
|
||||
beforeEach ->
|
||||
spyOn(keytar, 'getPassword')
|
||||
jasmine.unspy(window, 'setTimeout')
|
||||
pusherServer = new Server()
|
||||
spyOn(keytar, 'getPassword')
|
||||
|
||||
server = new Server()
|
||||
spyOn(server, 'verifyClient').andCallFake (info, verify) -> verify(true)
|
||||
|
||||
waitsFor "server to start", (started) ->
|
||||
server.once 'started', started
|
||||
server.start()
|
||||
|
||||
runs ->
|
||||
hostSession = new HostSession(new Site(1))
|
||||
guestSession = new GuestSession(hostSession.getId())
|
||||
|
||||
spyOn(hostSession, 'snapshotRepository').andCallFake (callback) ->
|
||||
callback({url: 'git://server/repo.git'})
|
||||
spyOn(hostSession, 'subscribe').andCallFake (channelName) ->
|
||||
pusherServer.createClient().subscribe(channelName)
|
||||
guestSession = new GuestSession(hostSession.getId())
|
||||
spyOn(guestSession, 'subscribe').andCallFake (channelName) ->
|
||||
pusherServer.createClient().subscribe(channelName)
|
||||
|
||||
spyOn(guestSession, 'mirrorRepository').andCallFake (repoUrl, repoSnapshot, callback) ->
|
||||
setTimeout ->
|
||||
repositoryMirrored = true
|
||||
callback()
|
||||
|
||||
it "sends the document from the host session to the guest session", ->
|
||||
afterEach ->
|
||||
waitsFor "server to stop", (stopped) ->
|
||||
server.once 'stopped', stopped
|
||||
server.stop()
|
||||
|
||||
it "sends the document and file system from the host session to the guest session", ->
|
||||
hostSession.start()
|
||||
startedHandler = jasmine.createSpy('startedHandler')
|
||||
guestSession.on 'started', startedHandler
|
||||
|
1
src/packages/collaboration/vendor/atom-collaboration-server
vendored
Submodule
1
src/packages/collaboration/vendor/atom-collaboration-server
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 438a00afc2c5b06854f8a8151de5baf249cb3520
|
Loading…
Reference in New Issue
Block a user