Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original if statement will actually properly filter if the response.result is truly undefined and this statement check is more specific and feels unnecessary in this case... was this a change for testing purposes that can be backed out?

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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above... if (result) will result in the same result as if (typeof result !== 'undefined'), but is more generic and a tad tighter in terms of implementation (plus more consistent with the rest of the code base). Is this a vestige from testing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think I see... the issue is that the result from the call is actually a scalar boolean value of false. In this case, your code change makes sense.

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();
});
});
});
});