diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /scripts/frontend | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'scripts/frontend')
-rwxr-xr-x | scripts/frontend/test.js | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/scripts/frontend/test.js b/scripts/frontend/test.js deleted file mode 100755 index 71a8bebf0f2..00000000000 --- a/scripts/frontend/test.js +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env node - -const { spawn } = require('child_process'); -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 jestArgs = [...COMMON_ARGS, '--passWithNoTests']; -const karmaArgs = [...COMMON_ARGS, '--no-fail-on-empty-test-suite']; - -program - .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 => { - 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 (shouldParallelize) { - 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', [...jestArgs, ...toJestArgs(args)]); -}; - -const runKarma = args => { - return spawnYarnScript('karma', [...karmaArgs, ...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 => { - if (program.watch) { - jestArgs.push('--watch'); - karmaArgs.push('--single-run', 'false', '--auto-watch'); - } - 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); |