Esempio n. 1
0
	_showDoctorError(e) {
		if (e instanceof EarlyReturnError) {
			return;
		}
		console.log("The Doctor didn't complete sucesfully. " + e.message);
		if (global.verboseLevel > 1) {
			console.log(VError.fullStack(e));
		}
		console.log(chalk.cyan('>'), 'Please visit our community forums for help with this error:');
		console.log(chalk.bold.white('https://community.particle.io/'));
	}
Esempio n. 2
0
  async run(executablePath, inputArgs) {
    const args = ['node', executablePath]
      .concat(inputArgs, ['--backtrace', '--format', 'json:out.json'])
      .map(arg => {
        if (_.includes(arg, '/')) {
          return path.normalize(arg)
        }
        return arg
      })
    const cwd = this.tmpDir

    let result

    if (this.spawn) {
      result = await new Promise(resolve => {
        execFile(args[0], args.slice(1), { cwd }, (error, stdout, stderr) => {
          resolve({ error, stdout, stderr })
        })
      })
    } else {
      const stdout = new PassThrough()
      const cli = new Cli({
        argv: args,
        cwd,
        stdout
      })
      let error, stderr
      try {
        if (!await cli.run()) {
          error = new Error('CLI exited with non-zero')
          error.code = 42
        }
        stderr = ''
      } catch (err) {
        error = err
        stderr = VError.fullStack(error)
      }
      stdout.end()
      result = { error, stdout: await toString(stdout), stderr }
    }

    let jsonOutput = []
    const jsonOutputPath = path.join(cwd, 'out.json')
    if (fs.existsSync(jsonOutputPath)) {
      const fileContent = fs.readFileSync(jsonOutputPath, 'utf8')
      if (fileContent) {
        jsonOutput = JSON.parse(fileContent)
      }
    }
    if (this.debug) {
      console.log(result.stdout + result.stderr) // eslint-disable-line no-console
    }
    this.lastRun = {
      error: result.error,
      errorOutput: result.stderr,
      jsonOutput,
      output: colors.strip(result.stdout)
    }
    this.verifiedLastRunError = false
    expect(this.lastRun.output).to.not.include('Unhandled rejection')
  }