diff options
Diffstat (limited to 'scripts/frontend/test.js')
-rwxr-xr-x | scripts/frontend/test.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/scripts/frontend/test.js b/scripts/frontend/test.js index dab7176f8c1..71a8bebf0f2 100755 --- a/scripts/frontend/test.js +++ b/scripts/frontend/test.js @@ -5,19 +5,24 @@ const { EOL } = require('os'); const program = require('commander'); const chalk = require('chalk'); +const SUCCESS_CODE = 0; const JEST_ROUTE = 'spec/frontend'; const KARMA_ROUTE = 'spec/javascripts'; const COMMON_ARGS = ['--colors']; -const JEST_ARGS = ['--passWithNoTests']; -const KARMA_ARGS = ['--no-fail-on-empty-test-suite']; -const SUCCESS_CODE = 0; +const jestArgs = [...COMMON_ARGS, '--passWithNoTests']; +const karmaArgs = [...COMMON_ARGS, '--no-fail-on-empty-test-suite']; program - .version('0.1.0') .usage('[options] <file ...>') .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 shouldParallelize = program.parallel || program.watch; + const isSuccess = code => code === SUCCESS_CODE; const combineExitCodes = codes => { @@ -31,7 +36,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 (shouldParallelize) { return Promise.all([runJest(paths), runKarma(paths)]).then(combineExitCodes); } else { return runJest(paths).then(skipIfFail(() => runKarma(paths))); @@ -73,11 +78,11 @@ const spawnYarnScript = (cmd, args) => { }; const runJest = args => { - return spawnYarnScript('jest', [...JEST_ARGS, ...COMMON_ARGS, ...toJestArgs(args)]); + return spawnYarnScript('jest', [...jestArgs, ...toJestArgs(args)]); }; const runKarma = args => { - return spawnYarnScript('karma', [...KARMA_ARGS, ...COMMON_ARGS, ...toKarmaArgs(args)]); + return spawnYarnScript('karma', [...karmaArgs, ...toKarmaArgs(args)]); }; const replacePath = to => path => @@ -96,6 +101,10 @@ const toKarmaArgs = paths => paths.reduce((acc, path) => acc.concat('-f', replacePathForKarma(path)), []); const main = paths => { + if (program.watch) { + jestArgs.push('--watch'); + karmaArgs.push('--single-run', 'false', '--auto-watch'); + } runTests(paths).then(code => { console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); if (isSuccess(code)) { |