summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2019-06-19 16:05:47 +0000
committerMike Greiling <mike@pixelcog.com>2019-06-19 16:05:47 +0000
commit6d4f33ceafbf55ae1283352d092c873221fdcbf1 (patch)
tree910bf718438de128497598da5a15313fb973ea93
parentea1b24cbe01d4d76fce693cbf329896e2203ae3d (diff)
parentbd9774e4d498b0189d2cd10239cf51bed0e89562 (diff)
downloadgitlab-ce-6d4f33ceafbf55ae1283352d092c873221fdcbf1.tar.gz
Merge branch 'test-script-watch' into 'master'
Add watch option to test script See merge request gitlab-org/gitlab-ce!29560
-rwxr-xr-xscripts/frontend/test.js23
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)) {