Skip to content

Instantly share code, notes, and snippets.

@myobie
Created January 7, 2021 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/0f9c6617d2765da3b37967a992d8a849 to your computer and use it in GitHub Desktop.
Save myobie/0f9c6617d2765da3b37967a992d8a849 to your computer and use it in GitHub Desktop.
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) {
server.close()
process.exit(isSuccess ? 0 : 1)
} else {
await watch(cwd, async paths => {
if (meaningfulFileChange(paths)) {
clear()
await buildBrowserTests(cwd)
await runTestsInBrowser({ port })
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment