diff options
author | egrieff <egrieff@gitlab.com> | 2019-05-27 09:48:03 +0100 |
---|---|---|
committer | egrieff <egrieff@gitlab.com> | 2019-05-27 09:48:03 +0100 |
commit | 96d8f009bc762b94e66fa96e5a38f3e3ee2faeb0 (patch) | |
tree | fec12a98a390b74892c8d035b4b461b9cf94e921 /scripts | |
parent | fd4a86884947866dff7d7165917336d094c8b276 (diff) | |
parent | 348d779beab593e0e852f5a4d285ea58db75a048 (diff) | |
download | gitlab-ce-96d8f009bc762b94e66fa96e5a38f3e3ee2faeb0.tar.gz |
Merge branch 'master' into 57825-moving-an-issue-results-in-broken-image-links-in-comments57825-moving-an-issue-results-in-broken-image-links-in-comments
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/frontend/test.js | 114 | ||||
-rw-r--r-- | scripts/prepare_build.sh | 11 |
2 files changed, 119 insertions, 6 deletions
diff --git a/scripts/frontend/test.js b/scripts/frontend/test.js new file mode 100755 index 00000000000..dab7176f8c1 --- /dev/null +++ b/scripts/frontend/test.js @@ -0,0 +1,114 @@ +#!/usr/bin/env node + +const { spawn } = require('child_process'); +const { EOL } = require('os'); +const program = require('commander'); +const chalk = require('chalk'); + +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; + +program + .version('0.1.0') + .usage('[options] <file ...>') + .option('-p, --parallel', 'Run tests suites in parallel') + .parse(process.argv); + +const isSuccess = code => code === SUCCESS_CODE; + +const combineExitCodes = codes => { + const firstFail = codes.find(x => !isSuccess(x)); + + return firstFail === undefined ? SUCCESS_CODE : firstFail; +}; + +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) { + return Promise.all([runJest(paths), runKarma(paths)]).then(combineExitCodes); + } else { + return runJest(paths).then(skipIfFail(() => runKarma(paths))); + } +}; + +const spawnYarnScript = (cmd, args) => { + return new Promise((resolve, reject) => { + const proc = spawn('yarn', ['run', cmd, ...args]); + const output = data => { + const text = data + .toString() + .split(/\r?\n/g) + .map((line, idx, { length }) => + idx === length - 1 && !line ? line : `${chalk.gray(cmd)}: ${line}`, + ) + .join(EOL); + + return endWithEOL(text); + }; + + proc.stdout.on('data', data => { + process.stdout.write(output(data)); + }); + + proc.stderr.on('data', data => { + process.stderr.write(output(data)); + }); + + proc.on('close', code => { + process.stdout.write(output(`exited with code ${code}`)); + + // We resolve even on a failure code because a `reject` would cause + // Promise.all to reject immediately (without waiting for other promises) + // to finish. + resolve(code); + }); + }); +}; + +const runJest = args => { + return spawnYarnScript('jest', [...JEST_ARGS, ...COMMON_ARGS, ...toJestArgs(args)]); +}; + +const runKarma = args => { + return spawnYarnScript('karma', [...KARMA_ARGS, ...COMMON_ARGS, ...toKarmaArgs(args)]); +}; + +const replacePath = to => path => + path + .replace(JEST_ROUTE, to) + .replace(KARMA_ROUTE, to) + .replace('app/assets/javascripts', to); + +const replacePathForJest = replacePath(JEST_ROUTE); + +const replacePathForKarma = replacePath(KARMA_ROUTE); + +const toJestArgs = paths => paths.map(replacePathForJest); + +const toKarmaArgs = paths => + paths.reduce((acc, path) => acc.concat('-f', replacePathForKarma(path)), []); + +const main = paths => { + runTests(paths).then(code => { + console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); + if (isSuccess(code)) { + console.log(chalk.bgGreen(chalk.black('All tests passed :)'))); + } else { + console.log(chalk.bgRed(chalk.white(`Some tests failed :(`))); + } + console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); + + if (!isSuccess(code)) { + process.exit(code); + } + }); +}; + +main(program.args); diff --git a/scripts/prepare_build.sh b/scripts/prepare_build.sh index 58b74f2f07d..9b0d5d4f719 100644 --- a/scripts/prepare_build.sh +++ b/scripts/prepare_build.sh @@ -5,6 +5,7 @@ export USE_BUNDLE_INSTALL=${USE_BUNDLE_INSTALL:-true} export BUNDLE_INSTALL_FLAGS="--without=production --jobs=$(nproc) --path=vendor --retry=3 --quiet" if [ "$USE_BUNDLE_INSTALL" != "false" ]; then + bundle --version bundle install --clean $BUNDLE_INSTALL_FLAGS && bundle check fi @@ -16,12 +17,10 @@ cp config/gitlab.yml.example config/gitlab.yml sed -i 's/bin_path: \/usr\/bin\/git/bin_path: \/usr\/local\/bin\/git/' config/gitlab.yml # Determine the database by looking at the job name. -# For example, we'll get pg if the job is `rspec-pg 19 20` -export GITLAB_DATABASE=$(echo $CI_JOB_NAME | cut -f1 -d' ' | cut -f2 -d-) - -# This would make the default database postgresql, and we could also use -# pg to mean postgresql. -if [ "$GITLAB_DATABASE" != 'mysql' ]; then +# This would make the default database postgresql. +if [[ "${CI_JOB_NAME#*mysql}" != "$CI_JOB_NAME" ]]; then + export GITLAB_DATABASE='mysql' +else export GITLAB_DATABASE='postgresql' fi |