From 6f5a2e362e645bab03362156dd8bd60362887984 Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Wed, 25 Aug 2021 14:28:12 +0200 Subject: [PATCH 1/8] Updated deno version to 1.13.2 and puppeteer version to 10.2.0 --- .github/workflows/ci.yml | 2 +- deps.ts | 29 ++++++++++++++--------------- test_deps.ts | 6 +++--- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bcc18f..ce10988 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: args: "install googlechrome -Version 87.0.4280.141" - uses: denoland/setup-deno@main with: - deno-version: "1.10.2" + deno-version: "1.13.2" - name: Run linter if: matrix.os == 'ubuntu-latest' run: | diff --git a/deps.ts b/deps.ts index cb9ded7..deec4c5 100644 --- a/deps.ts +++ b/deps.ts @@ -1,22 +1,22 @@ -export { exists } from "https://deno.land/std@0.97.0/fs/exists.ts"; +export { exists } from "https://deno.land/std@0.106.0/fs/exists.ts"; export { dirname, fromFileUrl, join, resolve, -} from "https://deno.land/std@0.97.0/path/mod.ts"; -export { BufReader } from "https://deno.land/std@0.97.0/io/bufio.ts"; -export { concat } from "https://deno.land/std@0.97.0/bytes/mod.ts"; +} from "https://deno.land/std@0.106.0/path/mod.ts"; +export { BufReader } from "https://deno.land/std@0.106.0/io/bufio.ts"; +export { concat } from "https://deno.land/std@0.106.0/bytes/mod.ts"; // TODO: Remove this import statement. export { decode, encode } from "https://deno.land/std@0.84.0/encoding/utf8.ts"; export { decode as decodeFromBase64, encode as encodeToBase64, -} from "https://deno.land/std@0.97.0/encoding/base64.ts"; -export { deferred } from "https://deno.land/std@0.97.0/async/deferred.ts"; -export type { Deferred } from "https://deno.land/std@0.97.0/async/deferred.ts"; +} from "https://deno.land/std@0.106.0/encoding/base64.ts"; +export { deferred } from "https://deno.land/std@0.106.0/async/deferred.ts"; +export type { Deferred } from "https://deno.land/std@0.106.0/async/deferred.ts"; -export { readAll, writeAll } from "https://deno.land/std@0.97.0/io/util.ts"; +export { readAll, writeAll } from "https://deno.land/std@0.106.0/io/util.ts"; export { assert, @@ -27,11 +27,10 @@ export { fail, } from "https://deno.land/std@0.95.0/testing/asserts.ts"; -// @deno-types="https://unpkg.com/puppeteer@5.5.0/lib/esm/puppeteer/web.d.ts" -export { default as puppeteer } from "https://unpkg.com/puppeteer@5.5.0/lib/esm/puppeteer/web.js"; -export { EventEmitter } from "https://unpkg.com/puppeteer@5.5.0/lib/esm/puppeteer/common/EventEmitter.js"; +export { default as puppeteer } from "https://unpkg.com/puppeteer@10.2.0/lib/esm/puppeteer/web.js"; +export { EventEmitter } from "https://unpkg.com/puppeteer@10.2.0/lib/esm/puppeteer/common/EventEmitter.js"; -export type { Browser } from "https://unpkg.com/puppeteer@5.5.0/lib/esm/puppeteer/common/Browser.js"; -export type { Target } from "https://unpkg.com/puppeteer@5.5.0/lib/esm/puppeteer/common/Target.js"; -export type { CDPSession } from "https://unpkg.com/puppeteer@5.5.0/lib/esm/puppeteer/common/Connection.js"; -export type { Page } from "https://unpkg.com/puppeteer@5.5.0/lib/esm/puppeteer/common/Page.js"; +export type { Browser } from "https://unpkg.com/puppeteer@10.2.0/lib/esm/puppeteer/common/Browser.js"; +export type { Target } from "https://unpkg.com/puppeteer@10.2.0/lib/esm/puppeteer/common/Target.js"; +export type { CDPSession } from "https://unpkg.com/puppeteer@10.2.0/lib/esm/puppeteer/common/Connection.js"; +export type { Page } from "https://unpkg.com/puppeteer@10.2.0/lib/esm/puppeteer/common/Page.js"; diff --git a/test_deps.ts b/test_deps.ts index 1b82de4..d9b2fbf 100644 --- a/test_deps.ts +++ b/test_deps.ts @@ -1,3 +1,3 @@ -export { serve } from "https://deno.land/std@0.97.0/http/mod.ts"; -export type { Server } from "https://deno.land/std@0.97.0/http/mod.ts"; -export { serveFile } from "https://deno.land/std@0.97.0/http/file_server.ts"; +export { serve } from "https://deno.land/std@0.106.0/http/mod.ts"; +export type { Server } from "https://deno.land/std@0.106.0/http/mod.ts"; +export { serveFile } from "https://deno.land/std@0.106.0/http/file_server.ts"; From 064f596d63f1ea36e6ade4de5d4cdc0e36704c87 Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Thu, 26 Aug 2021 19:42:04 +0200 Subject: [PATCH 2/8] Fixed flaky tests. --- carol.ts | 1 + test_deps.ts | 1 - test_util.ts | 8 ++++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/carol.ts b/carol.ts index 5a13429..974b65e 100644 --- a/carol.ts +++ b/carol.ts @@ -163,6 +163,7 @@ class Application extends EventEmitter implements types.Application { await this.browser.close(); this.done_.resolve(); this.emit(Application.Events.Exit, null); + return this.done_; } onExit(): Promise { diff --git a/test_deps.ts b/test_deps.ts index d9b2fbf..a9b969c 100644 --- a/test_deps.ts +++ b/test_deps.ts @@ -1,3 +1,2 @@ export { serve } from "https://deno.land/std@0.106.0/http/mod.ts"; export type { Server } from "https://deno.land/std@0.106.0/http/mod.ts"; -export { serveFile } from "https://deno.land/std@0.106.0/http/file_server.ts"; diff --git a/test_util.ts b/test_util.ts index 09f117c..1aca756 100644 --- a/test_util.ts +++ b/test_util.ts @@ -1,4 +1,4 @@ -import { serve, serveFile } from "./test_deps.ts"; +import { serve } from "./test_deps.ts"; import { join } from "./deps.ts"; import { locateChrome } from "./locate.ts"; import type { Application, AppOptions } from "./mod.ts"; @@ -66,7 +66,11 @@ export function startFileServer(port: number): FileServer { const server = serve({ port }); const serverPromise = (async () => { for await (const req of server) { - await req.respond(await serveFile(req, join("testdata/http", req.url))); + const body = await Deno.readFile(join("testdata/http", req.url)); + await req.respond({ + status: 200, + body, + }); } })(); return { From d31c8f378b9e5b45020a359cf24144c7e9c593b6 Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Wed, 27 Oct 2021 15:45:43 +0200 Subject: [PATCH 3/8] Allow passing of optional message to exit and onExit methods --- carol.ts | 8 ++++---- types.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/carol.ts b/carol.ts index 19d9ffd..e37e49b 100644 --- a/carol.ts +++ b/carol.ts @@ -147,7 +147,7 @@ class Application extends EventEmitter implements types.Application { return result; } - async exit(): Promise { + async exit(message?: any): 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/types.ts b/types.ts index 89a0e58..35e5cde 100644 --- a/types.ts +++ b/types.ts @@ -70,12 +70,12 @@ export interface Application { /** * Close the app windows. */ - exit(): Promise; + exit(message?: any): Promise; /** * Returns the promise that will be resolved when the app is closed. */ - onExit(): Promise; + onExit(): Promise; /** * @return main window. From c999f13d18d9f2bab0961809713cbf1d006cd855 Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Wed, 27 Oct 2021 15:52:46 +0200 Subject: [PATCH 4/8] Remove test deps --- test_deps.ts | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 test_deps.ts diff --git a/test_deps.ts b/test_deps.ts deleted file mode 100644 index a9b969c..0000000 --- a/test_deps.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { serve } from "https://deno.land/std@0.106.0/http/mod.ts"; -export type { Server } from "https://deno.land/std@0.106.0/http/mod.ts"; From 622d64f3ba531c1c211bb118e29dc99e8d11959e Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Wed, 27 Oct 2021 15:57:17 +0200 Subject: [PATCH 5/8] Updated tests --- carol_test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/carol_test.ts b/carol_test.ts index 1efed36..1d0357c 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) => { From cc1348f7fa35fd191ad0beb967c13bb90957c211 Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Wed, 27 Oct 2021 16:05:10 +0200 Subject: [PATCH 6/8] Fixed linter errors --- carol_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carol_test.ts b/carol_test.ts index 1d0357c..06085d2 100644 --- a/carol_test.ts +++ b/carol_test.ts @@ -183,7 +183,7 @@ test("Application#onExit - message", async () => { height: 320, args: ["--headless"], }); - const exitMessage = 'my exit message'; + const exitMessage = "my exit message"; let called = false; app.onExit().then((message) => { From b835539e901bce90587824b29b70f92fdb306dd0 Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Thu, 4 Nov 2021 07:56:28 +0100 Subject: [PATCH 7/8] Fixed type linting errors --- carol.ts | 4 ++-- types.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/carol.ts b/carol.ts index e37e49b..a7a9003 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(message?: any): Promise { + async exit(message?: string): Promise { this.logger_.debug("[app] app.exit..."); if (this.exited_) { return; diff --git a/types.ts b/types.ts index 35e5cde..4a1f706 100644 --- a/types.ts +++ b/types.ts @@ -70,12 +70,12 @@ export interface Application { /** * Close the app windows. */ - exit(message?: any): Promise; + exit(message?: string): Promise; /** * Returns the promise that will be resolved when the app is closed. */ - onExit(): Promise; + onExit(): Promise; /** * @return main window. From e75d24813d7a2a588b1c91b03be4c6a2768d87a7 Mon Sep 17 00:00:00 2001 From: rado_konuch Date: Thu, 4 Nov 2021 08:39:46 +0100 Subject: [PATCH 8/8] Fixed type linting errors --- carol.ts | 6 +++--- types.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/carol.ts b/carol.ts index a7a9003..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(message?: string): Promise { + async exit(message?: string): Promise { this.logger_.debug("[app] app.exit..."); if (this.exited_) { return; @@ -166,7 +166,7 @@ class Application extends EventEmitter implements types.Application { return this.done_; } - onExit(): Promise { + onExit(): Promise { return this.done_; } diff --git a/types.ts b/types.ts index 4a1f706..3001d90 100644 --- a/types.ts +++ b/types.ts @@ -70,12 +70,12 @@ export interface Application { /** * Close the app windows. */ - exit(message?: string): Promise; + exit(message?: string): Promise; /** * Returns the promise that will be resolved when the app is closed. */ - onExit(): Promise; + onExit(): Promise; /** * @return main window.