From 61c61cd76e82943ce92a73e1123e6e4f201f0717 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 20 Jun 2017 10:23:22 -0400 Subject: [PATCH] cli: use same path to report error in spawn, close #151 --- cli/__snapshots__/run_spec.js.snap-shot | 6 +++--- cli/lib/exec/spawn.js | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cli/__snapshots__/run_spec.js.snap-shot b/cli/__snapshots__/run_spec.js.snap-shot index a4d6395b77..306944e6a8 100644 --- a/cli/__snapshots__/run_spec.js.snap-shot +++ b/cli/__snapshots__/run_spec.js.snap-shot @@ -1,5 +1,5 @@ exports['passes --browser option 1'] = [ - "--project", + "--run-project", null, "--cli-version", "0.0.0", @@ -17,7 +17,7 @@ exports['removes --record option when using --browser 1'] = [ ] exports['passes --record option 1'] = [ - "--project", + "--run-project", null, "--record", "my record id", @@ -26,7 +26,7 @@ exports['passes --record option 1'] = [ ] exports['does not remove --record option when using --browser 1'] = [ - "--project", + "--run-project", null, "--record", "foo", diff --git a/cli/lib/exec/spawn.js b/cli/lib/exec/spawn.js index f4e9b3565f..f619f0eb03 100644 --- a/cli/lib/exec/spawn.js +++ b/cli/lib/exec/spawn.js @@ -1,11 +1,18 @@ const _ = require('lodash') const cp = require('child_process') -const chalk = require('chalk') +// const chalk = require('chalk') const Promise = require('bluebird') const debug = require('debug')('cypress:cli') const downloadUtils = require('../download/utils') const xvfb = require('./xvfb') +const { formErrorText, errors } = require('../download/errors') + +const logAndFail = (info) => (err) => { + const text = formErrorText(info, err) + console.log(text) // eslint-disable-line no-console + process.exit(1) +} module.exports = { start (args, options = {}) { @@ -49,15 +56,7 @@ module.exports = { if (needsXvfb) { return xvfb.start() .then(spawn) - .catch(() => { - /* eslint-disable no-console */ - console.log('') - console.log(chalk.bgRed.white(' -Error- ')) - console.log(chalk.red.underline('Could not start Cypress headlessly. Your CI provider must support XVFB.')) - console.log('') - process.exit(1) - /* eslint-enable no-console */ - }) + .catch(logAndFail(errors.missingXvfb)) } else { return spawn() }