-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathtests.ts
More file actions
32 lines (30 loc) · 825 Bytes
/
tests.ts
File metadata and controls
32 lines (30 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {
assert,
assertEquals,
} from "https://deno.land/std@0.93.0/testing/asserts.ts";
import puppeteer, { Browser } from "./mod.ts";
function browserTest(
name: string,
fn: (browser: Browser) => void | Promise<void>,
) {
Deno.test({
name,
sanitizeResources: false,
fn: async () => {
let browser: Browser | undefined = undefined;
try {
browser = await puppeteer.launch({});
await fn(browser);
} finally {
if (browser) await browser.close();
}
}
});
}
browserTest("hello world", async (browser) => {
const page = await browser.newPage();
await page.goto("https://example.com", { waitUntil: "domcontentloaded" });
const h1 = await page.$("h1");
assert(h1);
assertEquals(await h1.evaluate((e: any) => e.innerText), "Example Domain");
});