-
-
Save HamedFathi/8329679cd03b57f6e8047511e7dae6c4 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