From 2f053816f4c6b193b452fb355c48c6bd2b52d8ac Mon Sep 17 00:00:00 2001 From: Sylvain Cau Date: Sat, 14 May 2022 18:28:41 +0800 Subject: [PATCH] test: Add revive test with puppeteer (#185) --- .github/workflows/ci.yml | 8 ++++++++ tests/cli_test.ts | 26 +++++++++++++++++++++++++- tests/deps.ts | 1 + tests/main_test.ts | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77e74969..a47d3d18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,14 @@ jobs: - name: Cache dependencies run: deno cache --no-check src/cli/deps.ts src/runtime/deps.ts src/server/deps.ts + - name: Setup puppeteer linux / mac + if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'mac') + run: PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@9.0.2/install.ts + + - name: Setup puppeteer windows + if: startsWith(matrix.os, 'windows') + run: set "PUPPETEER_PRODUCT=chrome" && deno run -A --unstable https://deno.land/x/puppeteer@9.0.2/install.ts + - name: Run tests run: deno test -A --no-check=remote diff --git a/tests/cli_test.ts b/tests/cli_test.ts index b16570fe..c54e123a 100644 --- a/tests/cli_test.ts +++ b/tests/cli_test.ts @@ -1,4 +1,10 @@ -import { assert, assertEquals, delay, TextLineStream } from "./deps.ts"; +import { + assert, + assertEquals, + delay, + puppeteer, + TextLineStream, +} from "./deps.ts"; type FileTree = { type: "file"; @@ -120,6 +126,24 @@ Deno.test({ await res.body?.cancel(); assertEquals(res.status, 200); + // verify the island is revived. + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + + await page.goto("http://localhost:8000"); + await delay(500); + const counter = await page.$("body > div > div > p"); + let counterValue = await counter?.evaluate((el) => el.textContent); + assert(counterValue === "3"); + + const buttonPlus = await page.$("body > div > div > button:nth-child(3)"); + await buttonPlus?.click(); + + counterValue = await counter?.evaluate((el) => el.textContent); + assert(counterValue === "4"); + + await browser.close(); + await lines.cancel(); serverProcess.kill("SIGTERM"); serverProcess.close(); diff --git a/tests/deps.ts b/tests/deps.ts index 3c6f7982..c5656331 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -7,3 +7,4 @@ export { TextLineStream, } from "https://deno.land/std@0.129.0/streams/delimiter.ts"; export { delay } from "https://deno.land/std@0.129.0/async/delay.ts"; +export { default as puppeteer } from "https://deno.land/x/puppeteer@9.0.2/mod.ts"; diff --git a/tests/main_test.ts b/tests/main_test.ts index ac931439..fa663d0f 100644 --- a/tests/main_test.ts +++ b/tests/main_test.ts @@ -290,7 +290,7 @@ Deno.test({ }); Deno.test({ - name: "/middleware - layer 3 middleware ", + name: "/middleware - layer 3 middleware", fn: async () => { // layered 3 should contain layer 3 middleware data const resp = await router(