-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate event and remote-proxy tests
Refs: #145 Refs: #146 Refs: #53 PR-URL: #199 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
- Loading branch information
Showing
3 changed files
with
111 additions
and
69 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,111 @@ | ||
'use strict'; | ||
|
||
const test = require('tap'); | ||
|
||
const jstp = require('../..'); | ||
|
||
const name = 'testApp'; | ||
|
||
const interfaces = { | ||
iface: {} | ||
}; | ||
|
||
const app = { | ||
name, | ||
interfaces | ||
}; | ||
|
||
const application = new jstp.Application(app.name, app.interfaces); | ||
let server; | ||
let client; | ||
|
||
test.beforeEach((done) => { | ||
server = jstp.tcp.createServer(0, [application], app.authCallback); | ||
server.listen(() => { | ||
const port = server.address().port; | ||
client = jstp.tcp.createClient({ host: 'localhost', port }); | ||
done(); | ||
}); | ||
}); | ||
|
||
test.afterEach((done) => { | ||
client.disconnect(); | ||
server.close(); | ||
done(); | ||
}); | ||
|
||
const iface = 'iface'; | ||
const eventName = 'someEvent'; | ||
const args = ['firstArgument', 'secondArgument']; | ||
|
||
test.test('server must process an event', (test) => { | ||
client.connectAndHandshake(app.name, null, null, (error, connection) => { | ||
test.assertNot(error, 'must connect to server'); | ||
|
||
server.getClients()[0].on('event', (event) => { | ||
test.strictEqual(event.interfaceName, iface, | ||
'event interface must match'); | ||
test.strictEqual(event.remoteEventName, eventName, | ||
'event name must be equal to the emitted one'); | ||
test.strictDeepEqual(event.remoteEventArgs, args, | ||
'event arguments must be equal to the passed ones'); | ||
|
||
test.end(); | ||
}); | ||
|
||
connection.emitRemoteEvent(iface, eventName, args); | ||
}); | ||
}); | ||
|
||
test.test('client must process an event', (test) => { | ||
client.connectAndHandshake(app.name, null, null, (error, connection) => { | ||
test.assertNot(error, 'must connect to server'); | ||
|
||
connection.on('event', (event) => { | ||
test.strictEqual(event.interfaceName, iface, | ||
'event interface must match'); | ||
test.strictEqual(event.remoteEventName, eventName, | ||
'event name must be equal to the emitted one'); | ||
test.strictDeepEqual(event.remoteEventArgs, args, | ||
'event arguments must be equal to the passed ones'); | ||
test.end(); | ||
}); | ||
|
||
server.getClients()[0].emitRemoteEvent(iface, eventName, args); | ||
}); | ||
}); | ||
|
||
test.test('remote proxy must emit an event', (test) => { | ||
client.connectAndInspect(app.name, null, null, [iface], | ||
(error, connection, api) => { | ||
test.assertNot(error, 'must connect to server'); | ||
|
||
server.getClients()[0].on('event', (event) => { | ||
test.strictEqual(event.interfaceName, iface, | ||
'event interface must match'); | ||
test.strictEqual(event.remoteEventName, eventName, | ||
'event name must be equal to the emitted one'); | ||
test.strictDeepEqual(event.remoteEventArgs, args, | ||
'event arguments must be equal to the passed ones'); | ||
test.end(); | ||
}); | ||
|
||
api.iface.emit(eventName, ...args); | ||
} | ||
); | ||
}); | ||
|
||
test.test('remote proxy must process an event', (test) => { | ||
client.connectAndInspect(app.name, null, null, [iface], | ||
(error, connection, api) => { | ||
test.assertNot(error, 'must connect to server'); | ||
|
||
api.iface.on(eventName, (...eventArgs) => { | ||
test.strictDeepEqual(eventArgs, args, | ||
'event arguments must be equal to the passed ones'); | ||
test.end(); | ||
}); | ||
server.getClients()[0].emitRemoteEvent(iface, eventName, args); | ||
} | ||
); | ||
}); |
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
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