Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active September 28, 2024 03:45
Show Gist options
  • Save mizchi/5f67109d0719ef6dd57695e1f528ce8d to your computer and use it in GitHub Desktop.
Save mizchi/5f67109d0719ef6dd57695e1f528ce8d to your computer and use it in GitHub Desktop.
import { Browser, chromium, firefox, webkit } from "playwright";
import { afterAll, beforeAll, describe, it } from "vitest";
const browserTypes = process.env.ALL_BROWSERS
? [chromium, firefox, webkit]
: [chromium];
for (const browserType of browserTypes) {
describe(`browser:${browserType.name()}`, () => {
let browser: Browser;
beforeAll(async () => {
browser = await browserType.launch({ headless: true });
});
afterAll(async () => {
browser?.close();
});
it("evaluate with vite module", async () => {
const page = await browser.newPage();
page.on("console", (msg) => console.log(msg.text()));
await page.goto("http://localhost:3000");
await page.locator("#ready").waitFor({ state: "attached" });
await page.evaluate(() => {
return new Promise(async (r) => {
const mod = await new Function("return import('/mod.ts')")();
console.log("hello in eval", Object.keys(mod));
r(null);
});
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment