Skip to content

Commit

Permalink
test: Add revive test with puppeteer (denoland#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylc authored May 14, 2022
1 parent ec388f8 commit 2f05381
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/install.ts

- name: Setup puppeteer windows
if: startsWith(matrix.os, 'windows')
run: set "PUPPETEER_PRODUCT=chrome" && deno run -A --unstable https://deno.land/x/[email protected]/install.ts

- name: Run tests
run: deno test -A --no-check=remote

Expand Down
26 changes: 25 additions & 1 deletion tests/cli_test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export {
TextLineStream,
} from "https://deno.land/[email protected]/streams/delimiter.ts";
export { delay } from "https://deno.land/[email protected]/async/delay.ts";
export { default as puppeteer } from "https://deno.land/x/[email protected]/mod.ts";
2 changes: 1 addition & 1 deletion tests/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2f05381

Please sign in to comment.