Last active
January 31, 2019 18:25
-
-
Save nklayman/39fa85cee3bcbb6c1917a77fb18c5a24 to your computer and use it in GitHub Desktop.
Start Quasar Dev server and then run tests
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
const execa = require('execa') | |
const readline = require('readline') | |
// Start dev server | |
const devServer = execa('quasar', ['dev']) | |
devServer.catch(e => { | |
// Throw error if it wasn't killed manually | |
if (!e.killed) throw new Error(e) | |
}) | |
const killDevServer = () => { | |
if (!devServer) { | |
process.exit(0) | |
} | |
devServer.kill() | |
} | |
// Kill dev server on exit | |
process.on('SIGINT', killDevServer) | |
process.on('SIGTERM', killDevServer) | |
// Handle Ctrl+C on Windows | |
if (process.platform === 'win32') { | |
readline | |
.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}) | |
.on('SIGINT', () => { | |
process.emit('SIGINT') | |
}) | |
} | |
// Pipe output to console | |
devServer.stdout.pipe(process.stdout) | |
devServer.stdout.on('data', data => { | |
if (/ERROR {2}Failed to compile with \d* errors/.test(data)) { | |
// Dev server errored | |
devServer.kill() | |
throw new Error('The Quasar dev server failed to start.') | |
} else if (/DONE {2}Compiled successfully in \d*ms/.test(data)) { | |
// Dev server is ready | |
startJest() | |
} | |
}) | |
function startJest () { | |
const jestRunner = execa('jest', { stdio: 'inherit' }) | |
jestRunner.on('exit', () => { | |
// When Jest is done, kill dev server | |
killDevServer() | |
}) | |
} |
In fact, this would be a brilliant application of the
quasar test command.
love it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think we should allow for flags to be passed to allow for a dev mode (pwa, ssr, etc.)