diff --git a/packages/protocol/src/browser/client.ts b/packages/protocol/src/browser/client.ts index 941183845..d436057ae 100644 --- a/packages/protocol/src/browser/client.ts +++ b/packages/protocol/src/browser/client.ts @@ -48,6 +48,10 @@ export class Client { }); } + public dispose(): void { + this.connection.close(); + } + public get initData(): Promise { return this.initDataPromise; } diff --git a/packages/protocol/test/evaluate.test.ts b/packages/protocol/test/evaluate.test.ts index 240b4992d..db3fe67de 100644 --- a/packages/protocol/test/evaluate.test.ts +++ b/packages/protocol/test/evaluate.test.ts @@ -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 = 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()); }); }); diff --git a/packages/protocol/test/helpers.ts b/packages/protocol/test/helpers.ts index 86a6fc911..828cf9c56 100644 --- a/packages/protocol/test/helpers.ts +++ b/packages/protocol/test/helpers.ts @@ -5,11 +5,12 @@ import { Server, ServerOptions } from "../src/node/server"; export const createClient = (serverOptions?: ServerOptions): Client => { const s2c = new Emitter(); const c2s = new Emitter(); + const closeCallbacks = 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)); }, diff --git a/packages/protocol/test/server.test.ts b/packages/protocol/test/server.test.ts index a9ac29126..bc11bbb2f 100644 --- a/packages/protocol/test/server.test.ts +++ b/packages/protocol/test/server.test.ts @@ -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(); }); });