Created
January 7, 2021 17:00
-
-
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
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
// 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