-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes WebChannel's test to use a fake transport instead of fake soc…
…ket io It's best to rely on the layer of code that we're directly accessing on the tested code instead of mocking something that is being used indirectly. Also, WebChannel doesn't always use SocketIO, so it's good to test it with a generic transport to make sure that it works with any transport at all, not just SocketIO.
- Loading branch information
Showing
2 changed files
with
83 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
function FakeTransport(uri) { | ||
FakeTransport.base(this, 'constructor', uri); | ||
} | ||
lfr.inherits(FakeTransport, lfr.Transport); | ||
|
||
FakeTransport.prototype.close = function() { | ||
emitAsync(this, 'close'); | ||
return this; | ||
}; | ||
|
||
FakeTransport.prototype.open = function() { | ||
this.emit('opening'); | ||
emitAsync(this, 'open'); | ||
return this; | ||
}; | ||
|
||
FakeTransport.prototype.write = function(message) { | ||
emitAsync(this, 'data', message, 10); | ||
}; | ||
|
||
function emitAsync(emitter, eventName, data, delay) { | ||
if (!delay) { | ||
delay = 0; | ||
} | ||
|
||
setTimeout(function() { | ||
emitter.emit(eventName, data); | ||
}, delay); | ||
} | ||
|
||
module.exports = FakeTransport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters