mirror of https://github.com/coder/code-server.git
Add test for promises
This commit is contained in:
parent
cff746db32
commit
8ed940ac09
|
@ -51,14 +51,10 @@ export const evaluate = async (connection: SendableConnection, message: NewEvalM
|
||||||
connection.send(serverMsg.serializeBinary());
|
connection.send(serverMsg.serializeBinary());
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const value = vm.runInNewContext(`(${message.getFunction()})(${argStr.join(",")})`, { require }, {
|
const value = vm.runInNewContext(`(${message.getFunction()})(${argStr.join(",")})`, { require, setTimeout }, {
|
||||||
timeout: message.getTimeout() || 30000,
|
timeout: message.getTimeout() || 30000,
|
||||||
});
|
});
|
||||||
let responder: any = value;
|
sendResp(await value);
|
||||||
if (value instanceof Promise) {
|
|
||||||
responder = await value;
|
|
||||||
}
|
|
||||||
sendResp(responder);
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
sendErr(EvalFailedMessage.Reason.EXCEPTION, ex.toString());
|
sendErr(EvalFailedMessage.Reason.EXCEPTION, ex.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,4 +36,14 @@ describe("Evaluate", () => {
|
||||||
|
|
||||||
expect(value[0]).toEqual("readFileSync");
|
expect(value[0]).toEqual("readFileSync");
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
it("should resolve with promise", async () => {
|
||||||
|
const value = await client.evaluate(async () => {
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
|
||||||
|
return "donkey";
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(value).toEqual("donkey");
|
||||||
|
}, 250);
|
||||||
});
|
});
|
Loading…
Reference in New Issue