Skip to content

Commit

Permalink
Merge pull request #6 from PlayNetwork/falseFix
Browse files Browse the repository at this point in the history
Fix conditional to check if there is a result returned from Server method
  • Loading branch information
brozeph committed Mar 22, 2018
2 parents 0baa8aa + 003f8c9 commit 2ccf319
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "4"
- "6"
- "8"
after_success:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-ipc-lib",
"version": "1.0.2",
"version": "1.0.3",
"description": "Enables creation and consumption of Unix domain socket based IPC channels between Node.js apps using JSON-RPC 2.0 as a protocol.",
"main": "./dist",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Client {
}

// resolve when a result is received
if (response && response.result) {
if (response && typeof response.result !== 'undefined') {
return resolve(response.result);
}

Expand Down Expand Up @@ -173,4 +173,4 @@ export class Client {
}
}

export default { Client };
export default { Client };
4 changes: 2 additions & 2 deletions src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Server extends EventEmitter {
}

// handle synchronous results
if (result && (!result.then || typeof result.then !== 'function')) {
if (typeof result !== 'undefined' && (!result.then || typeof result.then !== 'function')) {
debug('Server: method %s returned synchronously', socket.request.method);

// handle the result of the method when not a Promise...
Expand Down Expand Up @@ -340,4 +340,4 @@ export class Server extends EventEmitter {
}
}

export default { Server };
export default { Server };
54 changes: 53 additions & 1 deletion test/src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ describe('Client', () => {
waitToReturn : (duration, val) => new Promise((resolve) => setTimeout(
() => resolve(val),
duration))
},
d : {
falsePromise : () => Promise.resolve(false),
synchronousFalse : () => {
return false;
},
truePromise : () => Promise.resolve(true)
}
};

Expand Down Expand Up @@ -138,6 +145,51 @@ describe('Client', () => {
await server.close();
});

it('should support asynchronous server methods returning boolean true', async () => {
let
client = new Client(mockPath),
server = new Server(mockPath, mockServices);

await server.listen();

let result = await client.call('d.truePromise');

should.exist(result);
result.should.equal(true);

await server.close();
});

it('should support asynchronous server methods returning boolean false', async () => {
let
client = new Client(mockPath),
server = new Server(mockPath, mockServices);

await server.listen();

let result = await client.call('d.falsePromise');

should.exist(result);
result.should.equal(false);

await server.close();
});

it('should support synchronous server methods returning boolean false', async () => {
let
client = new Client(mockPath),
server = new Server(mockPath, mockServices);

await server.listen();

let result = await client.call('d.synchronousFalse');

should.exist(result);
result.should.equal(false);

await server.close();
});

it('should support timeout', async () => {
let
client = new Client(mockPath, { timeout : 500 }),
Expand All @@ -158,4 +210,4 @@ describe('Client', () => {
await server.close();
});
});
});
});

0 comments on commit 2ccf319

Please sign in to comment.