Skip to content

Instantly share code, notes, and snippets.

@nklayman
Last active January 31, 2019 18:25
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 nklayman/39fa85cee3bcbb6c1917a77fb18c5a24 to your computer and use it in GitHub Desktop.
Save nklayman/39fa85cee3bcbb6c1917a77fb18c5a24 to your computer and use it in GitHub Desktop.
Start Quasar Dev server and then run tests
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()
})
}
@nothingismagick
Copy link

const devServer = execa('quasar', ['dev'])

I think we should allow for flags to be passed to allow for a dev mode (pwa, ssr, etc.)

@nothingismagick
Copy link

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