mirror of
https://github.com/coder/code-server.git
synced 2024-11-23 20:52:38 +03:00
Add test for disposing active evaluations
This commit is contained in:
parent
4a80bcb42c
commit
2889b3fede
@ -48,6 +48,10 @@ export class Client {
|
||||
});
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.connection.close();
|
||||
}
|
||||
|
||||
public get initData(): Promise<InitData> {
|
||||
return this.initDataPromise;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ describe("Evaluate", () => {
|
||||
const client = createClient();
|
||||
|
||||
it("should transfer string", async () => {
|
||||
const value = await client.evaluate(function () {
|
||||
const value = await client.evaluate(() => {
|
||||
return "hi";
|
||||
});
|
||||
|
||||
@ -58,20 +58,27 @@ describe("Evaluate", () => {
|
||||
|
||||
it("should do active process", (done) => {
|
||||
const runner = client.run((ae) => {
|
||||
ae.on("1", () => {
|
||||
ae.emit("2");
|
||||
ae.on("3", () => {
|
||||
ae.emit("close");
|
||||
});
|
||||
ae.on("first", () => {
|
||||
ae.emit("first:response");
|
||||
ae.on("second", () => ae.emit("second:response"));
|
||||
});
|
||||
|
||||
const disposeCallbacks = <Array<() => void>>[];
|
||||
const dispose = (): void => {
|
||||
disposeCallbacks.forEach((cb) => cb());
|
||||
ae.emit("disposed");
|
||||
};
|
||||
|
||||
return {
|
||||
onDidDispose: (): void => undefined,
|
||||
dispose: (): void => undefined,
|
||||
onDidDispose: (cb: () => void): number => disposeCallbacks.push(cb),
|
||||
dispose,
|
||||
};
|
||||
});
|
||||
runner.emit("1");
|
||||
runner.on("2", () => runner.emit("3"));
|
||||
runner.on("close", () => done());
|
||||
|
||||
runner.emit("first");
|
||||
runner.on("first:response", () => runner.emit("second"));
|
||||
runner.on("second:response", () => client.dispose());
|
||||
|
||||
runner.on("disposed", () => done());
|
||||
});
|
||||
});
|
||||
|
@ -5,11 +5,12 @@ import { Server, ServerOptions } from "../src/node/server";
|
||||
export const createClient = (serverOptions?: ServerOptions): Client => {
|
||||
const s2c = new Emitter<Uint8Array | Buffer>();
|
||||
const c2s = new Emitter<Uint8Array | Buffer>();
|
||||
const closeCallbacks = <Array<() => void>>[];
|
||||
|
||||
// tslint:disable-next-line
|
||||
// tslint:disable-next-line no-unused-expression
|
||||
new Server({
|
||||
close: (): void => undefined,
|
||||
onClose: (): void => undefined,
|
||||
close: (): void => closeCallbacks.forEach((cb) => cb()),
|
||||
onClose: (cb: () => void): number => closeCallbacks.push(cb),
|
||||
onMessage: (cb): void => {
|
||||
c2s.event((d) => cb(d));
|
||||
},
|
||||
@ -17,8 +18,8 @@ export const createClient = (serverOptions?: ServerOptions): Client => {
|
||||
}, serverOptions);
|
||||
|
||||
const client = new Client({
|
||||
close: (): void => undefined,
|
||||
onClose: (): void => undefined,
|
||||
close: (): void => closeCallbacks.forEach((cb) => cb()),
|
||||
onClose: (cb: () => void): number => closeCallbacks.push(cb),
|
||||
onMessage: (cb): void => {
|
||||
s2c.event((d) => cb(d));
|
||||
},
|
||||
|
@ -3,15 +3,18 @@ import { createClient } from "./helpers";
|
||||
describe("Server", () => {
|
||||
const dataDirectory = "/tmp/example";
|
||||
const workingDirectory = "/working/dir";
|
||||
const builtInExtensionsDirectory = "/tmp/example";
|
||||
const client = createClient({
|
||||
dataDirectory,
|
||||
workingDirectory,
|
||||
builtInExtensionsDirectory,
|
||||
});
|
||||
|
||||
it("should get init msg", (done) => {
|
||||
client.initData.then((data) => {
|
||||
expect(data.dataDirectory).toEqual(dataDirectory);
|
||||
expect(data.workingDirectory).toEqual(workingDirectory);
|
||||
expect(data.builtInExtensionsDirectory).toEqual(builtInExtensionsDirectory);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user