Files
cypress/cli/lib/exec/spawn.js
Brian Mann 101aac9c9b cli: move cli into subfolder, refactor cli scripts
-cleanup root monorepo files
-prevent downloading cypress binary when in development
-remove app-module-path
2017-06-05 17:26:51 -04:00

60 lines
1.5 KiB
JavaScript

const _ = require('lodash')
const cp = require('child_process')
const chalk = require('chalk')
const Promise = require('bluebird')
const downloadUtils = require('../download/utils')
const xvfb = require('./xvfb')
module.exports = {
start (args, options = {}) {
args = [].concat(args)
const needsXvfb = xvfb.isNeeded()
_.defaults(options, {
verify: false,
detached: false,
stdio: [process.stdin, process.stdout, 'ignore'],
})
const spawn = () => {
return new Promise((resolve) => {
const child = cp.spawn(downloadUtils.getPathToExecutable(), args, options)
if (needsXvfb) {
//// make sure we close down xvfb
//// when our spawned process exits
child.on('close', xvfb.stop)
}
//// when our spawned process exits
//// make sure we kill our own process
//// with its exit code (to bubble up errors)
child.on('exit', process.exit)
if (options.detached) {
child.unref()
}
resolve(child)
})
}
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 */
})
} else {
return spawn()
}
},
}