Skip to content

Instantly share code, notes, and snippets.



Created Jan 7, 2021
What would you like to do?
Build tests with esbuild, serve them with vercel's serve-handler, then use playwright to open a browser and stream the console back to the node console
// NOTE: we are just assuming _tests is an alright place to render to
export async function buildAndRunTests (cwd: string): Promise<void> {
const [{ once }] = cliopts.parse(
['o, once', 'run the tests and then exit']
await file.mkdirs(join(cwd, '_tests'))
await buildBrowserTests(cwd)
const server = await serve(cwd, { publicPath: '_tests' })
const port = server.address().port
if (!once) { clear() }
const isSuccess = await runTestsInBrowser({ port })
if (once) {
process.exit(isSuccess ? 0 : 1)
} else {
await watch(cwd, async paths => {
if (meaningfulFileChange(paths)) {
await buildBrowserTests(cwd)
await runTestsInBrowser({ port })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment