Last active
September 28, 2024 03:45
-
-
Save mizchi/5f67109d0719ef6dd57695e1f528ce8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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