From 0bf22dca1a550761b5e0bd8a1458cd78414e4959 Mon Sep 17 00:00:00 2001 From: Paul Gascou-Vaillancourt Date: Wed, 12 Jun 2019 11:34:20 -0400 Subject: Add watch option to test script --- scripts/frontend/test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/frontend/test.js b/scripts/frontend/test.js index dab7176f8c1..5dab97648ed 100755 --- a/scripts/frontend/test.js +++ b/scripts/frontend/test.js @@ -16,8 +16,14 @@ program .version('0.1.0') .usage('[options] ') .option('-p, --parallel', 'Run tests suites in parallel') + .option( + '-w, --watch', + 'Rerun tests when files change (tests will be run in parallel if this enabled)', + ) .parse(process.argv); +const shouldParalleslize = program.parallel || program.watch; + const isSuccess = code => code === SUCCESS_CODE; const combineExitCodes = codes => { @@ -31,7 +37,7 @@ const skipIfFail = fn => code => (isSuccess(code) ? fn() : code); const endWithEOL = str => (str[str.length - 1] === '\n' ? str : `${str}${EOL}`); const runTests = paths => { - if (program.parallel) { + if (shouldParalleslize) { return Promise.all([runJest(paths), runKarma(paths)]).then(combineExitCodes); } else { return runJest(paths).then(skipIfFail(() => runKarma(paths))); @@ -96,6 +102,10 @@ const toKarmaArgs = paths => paths.reduce((acc, path) => acc.concat('-f', replacePathForKarma(path)), []); const main = paths => { + if (program.watch) { + JEST_ARGS.push('--watch'); + KARMA_ARGS.push('--single-run', 'false', '--auto-watch'); + } runTests(paths).then(code => { console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); if (isSuccess(code)) { -- cgit v1.2.1