diff --git a/carol.ts b/carol.ts index 19d9ffd..6df90d7 100644 --- a/carol.ts +++ b/carol.ts @@ -98,7 +98,7 @@ class Application extends EventEmitter implements types.Application { httpHandler_: types.HttpHandler | null = null; private readonly pendingWindows_ = new Map(); private readonly windows_ = new Map(); - private readonly done_ = deferred(); + private readonly done_ = deferred(); constructor( private readonly browser: Browser, @@ -147,7 +147,7 @@ class Application extends EventEmitter implements types.Application { return result; } - async exit(): Promise { + async exit(message?: string): Promise { this.logger_.debug("[app] app.exit..."); if (this.exited_) { return; @@ -161,12 +161,12 @@ class Application extends EventEmitter implements types.Application { tryClose(this.chromeProcess.stderr); } tryClose(this.chromeProcess); - this.done_.resolve(); - this.emit(Application.Events.Exit, null); + this.done_.resolve(message); + this.emit(Application.Events.Exit, message); return this.done_; } - onExit(): Promise { + onExit(): Promise { return this.done_; } diff --git a/carol_test.ts b/carol_test.ts index 1efed36..06085d2 100644 --- a/carol_test.ts +++ b/carol_test.ts @@ -177,6 +177,25 @@ test("Application#onExit", async () => { assert(called); }); +test("Application#onExit - message", async () => { + const app = await launch({ + width: 480, + height: 320, + args: ["--headless"], + }); + const exitMessage = "my exit message"; + + let called = false; + app.onExit().then((message) => { + called = true; + assertStrictEquals(message, exitMessage); + }); + + await app.exit(exitMessage); + + assert(called); +}); + testApp( "Application#serveFolder", async (app) => { diff --git a/types.ts b/types.ts index 89a0e58..3001d90 100644 --- a/types.ts +++ b/types.ts @@ -70,12 +70,12 @@ export interface Application { /** * Close the app windows. */ - exit(): Promise; + exit(message?: string): Promise; /** * Returns the promise that will be resolved when the app is closed. */ - onExit(): Promise; + onExit(): Promise; /** * @return main window.