Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 983aeef

Browse files
committedFeb 5, 2019
Add test for promises
1 parent e342482 commit 983aeef

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
 

‎packages/server/src/node/evaluate.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ export const evaluate = async (connection: SendableConnection, message: NewEvalM
5151
connection.send(serverMsg.serializeBinary());
5252
};
5353
try {
54-
const value = vm.runInNewContext(`(${message.getFunction()})(${argStr.join(",")})`, { require }, {
54+
const value = vm.runInNewContext(`(${message.getFunction()})(${argStr.join(",")})`, { require, setTimeout }, {
5555
timeout: message.getTimeout() || 30000,
5656
});
57-
let responder: any = value;
58-
if (value instanceof Promise) {
59-
responder = await value;
60-
}
61-
sendResp(responder);
57+
sendResp(await value);
6258
} catch (ex) {
6359
sendErr(EvalFailedMessage.Reason.EXCEPTION, ex.toString());
6460
}

‎packages/server/test/evaluate.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@ describe("Evaluate", () => {
3636

3737
expect(value[0]).toEqual("readFileSync");
3838
}, 100);
39+
40+
it("should resolve with promise", async () => {
41+
const value = await client.evaluate(async () => {
42+
await new Promise((r) => setTimeout(r, 100));
43+
44+
return "donkey";
45+
});
46+
47+
expect(value).toEqual("donkey");
48+
}, 250);
3949
});

0 commit comments

Comments
 (0)
Please sign in to comment.