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> {
|
public get initData(): Promise<InitData> {
|
||||||
return this.initDataPromise;
|
return this.initDataPromise;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ describe("Evaluate", () => {
|
||||||
const client = createClient();
|
const client = createClient();
|
||||||
|
|
||||||
it("should transfer string", async () => {
|
it("should transfer string", async () => {
|
||||||
const value = await client.evaluate(function () {
|
const value = await client.evaluate(() => {
|
||||||
return "hi";
|
return "hi";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -58,20 +58,27 @@ describe("Evaluate", () => {
|
||||||
|
|
||||||
it("should do active process", (done) => {
|
it("should do active process", (done) => {
|
||||||
const runner = client.run((ae) => {
|
const runner = client.run((ae) => {
|
||||||
ae.on("1", () => {
|
ae.on("first", () => {
|
||||||
ae.emit("2");
|
ae.emit("first:response");
|
||||||
ae.on("3", () => {
|
ae.on("second", () => ae.emit("second:response"));
|
||||||
ae.emit("close");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const disposeCallbacks = <Array<() => void>>[];
|
||||||
|
const dispose = (): void => {
|
||||||
|
disposeCallbacks.forEach((cb) => cb());
|
||||||
|
ae.emit("disposed");
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onDidDispose: (): void => undefined,
|
onDidDispose: (cb: () => void): number => disposeCallbacks.push(cb),
|
||||||
dispose: (): void => undefined,
|
dispose,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
runner.emit("1");
|
|
||||||
runner.on("2", () => runner.emit("3"));
|
runner.emit("first");
|
||||||
runner.on("close", () => done());
|
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 => {
|
export const createClient = (serverOptions?: ServerOptions): Client => {
|
||||||
const s2c = new Emitter<Uint8Array | Buffer>();
|
const s2c = new Emitter<Uint8Array | Buffer>();
|
||||||
const c2s = 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({
|
new Server({
|
||||||
close: (): void => undefined,
|
close: (): void => closeCallbacks.forEach((cb) => cb()),
|
||||||
onClose: (): void => undefined,
|
onClose: (cb: () => void): number => closeCallbacks.push(cb),
|
||||||
onMessage: (cb): void => {
|
onMessage: (cb): void => {
|
||||||
c2s.event((d) => cb(d));
|
c2s.event((d) => cb(d));
|
||||||
},
|
},
|
||||||
|
@ -17,8 +18,8 @@ export const createClient = (serverOptions?: ServerOptions): Client => {
|
||||||
}, serverOptions);
|
}, serverOptions);
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
close: (): void => undefined,
|
close: (): void => closeCallbacks.forEach((cb) => cb()),
|
||||||
onClose: (): void => undefined,
|
onClose: (cb: () => void): number => closeCallbacks.push(cb),
|
||||||
onMessage: (cb): void => {
|
onMessage: (cb): void => {
|
||||||
s2c.event((d) => cb(d));
|
s2c.event((d) => cb(d));
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,15 +3,18 @@ import { createClient } from "./helpers";
|
||||||
describe("Server", () => {
|
describe("Server", () => {
|
||||||
const dataDirectory = "/tmp/example";
|
const dataDirectory = "/tmp/example";
|
||||||
const workingDirectory = "/working/dir";
|
const workingDirectory = "/working/dir";
|
||||||
|
const builtInExtensionsDirectory = "/tmp/example";
|
||||||
const client = createClient({
|
const client = createClient({
|
||||||
dataDirectory,
|
dataDirectory,
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
|
builtInExtensionsDirectory,
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should get init msg", (done) => {
|
it("should get init msg", (done) => {
|
||||||
client.initData.then((data) => {
|
client.initData.then((data) => {
|
||||||
expect(data.dataDirectory).toEqual(dataDirectory);
|
expect(data.dataDirectory).toEqual(dataDirectory);
|
||||||
expect(data.workingDirectory).toEqual(workingDirectory);
|
expect(data.workingDirectory).toEqual(workingDirectory);
|
||||||
|
expect(data.builtInExtensionsDirectory).toEqual(builtInExtensionsDirectory);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue