HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/node_modules/cypress/lib/exec/run.js
"use strict";

var _ = require('lodash');

var debug = require('debug')('cypress:cli:run');

var util = require('../util');

var spawn = require('./spawn');

var verify = require('../tasks/verify');

var _require = require('../errors'),
    exitWithError = _require.exitWithError,
    errors = _require.errors;
/**
 * Throws an error with "details" property from
 * "errors" object.
 * @param {Object} details - Error details
 */


var throwInvalidOptionError = function throwInvalidOptionError(details) {
  if (!details) {
    details = errors.unknownError;
  } // throw this error synchronously, it will be caught later on and
  // the details will be propagated to the promise chain


  var err = new Error();
  err.details = details;
  throw err;
};
/**
 * Typically a user passes a string path to the project.
 * But "cypress open" allows using `false` to open in global mode,
 * and the user can accidentally execute `cypress run --project false`
 * which should be invalid.
 */


var isValidProject = function isValidProject(v) {
  if (typeof v === 'boolean') {
    return false;
  }

  if (v === '' || v === 'false' || v === 'true') {
    return false;
  }

  return true;
};
/**
 * Maps options collected by the CLI
 * and forms list of CLI arguments to the server.
 *
 * Note: there is lightweight validation, with errors
 * thrown synchronously.
 *
 * @returns {string[]} list of CLI arguments
 */


var processRunOptions = function processRunOptions() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  debug('processing run options %o', options);

  if (!isValidProject(options.project)) {
    debug('invalid project option %o', {
      project: options.project
    });
    return throwInvalidOptionError(errors.invalidRunProjectPath);
  }

  var args = ['--run-project', options.project];

  if (options.browser) {
    args.push('--browser', options.browser);
  }

  if (options.ci) {
    // push to display the deprecation message
    args.push('--ci'); // also automatically record

    args.push('--record', true);
  }

  if (options.ciBuildId) {
    args.push('--ci-build-id', options.ciBuildId);
  }

  if (options.config) {
    args.push('--config', options.config);
  }

  if (options.configFile !== undefined) {
    args.push('--config-file', options.configFile);
  }

  if (options.env) {
    args.push('--env', options.env);
  }

  if (options.exit === false) {
    args.push('--no-exit');
  }

  if (options.group) {
    args.push('--group', options.group);
  }

  if (options.headed) {
    args.push('--headed', options.headed);
  }

  if (options.headless) {
    if (options.headed) {
      return throwInvalidOptionError(errors.incompatibleHeadlessFlags);
    }

    args.push('--headed', !options.headless);
  } // if key is set use that - else attempt to find it by environment variable


  if (options.key == null) {
    debug('--key is not set, looking up environment variable CYPRESS_RECORD_KEY');
    options.key = util.getEnv('CYPRESS_RECORD_KEY') || util.getEnv('CYPRESS_CI_KEY');
  } // if we have a key assume we're in record mode


  if (options.key) {
    args.push('--key', options.key);
  }

  if (options.outputPath) {
    args.push('--output-path', options.outputPath);
  }

  if (options.parallel) {
    args.push('--parallel');
  }

  if (options.port) {
    args.push('--port', options.port);
  }

  if (options.quiet) {
    args.push('--quiet');
  } // if record is defined and we're not
  // already in ci mode, then send it up


  if (options.record != null && !options.ci) {
    args.push('--record', options.record);
  } // if we have a specific reporter push that into the args


  if (options.reporter) {
    args.push('--reporter', options.reporter);
  } // if we have a specific reporter push that into the args


  if (options.reporterOptions) {
    args.push('--reporter-options', options.reporterOptions);
  } // if we have specific spec(s) push that into the args


  if (options.spec) {
    args.push('--spec', options.spec);
  }

  if (options.tag) {
    args.push('--tag', options.tag);
  }

  return args;
};

module.exports = {
  processRunOptions: processRunOptions,
  isValidProject: isValidProject,
  // resolves with the number of failed tests
  start: function start() {
    var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

    _.defaults(options, {
      key: null,
      spec: null,
      reporter: null,
      reporterOptions: null,
      project: process.cwd()
    });

    function run() {
      var args;

      try {
        args = processRunOptions(options);
      } catch (err) {
        if (err.details) {
          return exitWithError(err.details)();
        }

        throw err;
      }

      debug('run to spawn.start args %j', args);
      return spawn.start(args, {
        dev: options.dev
      });
    }

    if (options.dev) {
      return run();
    }

    return verify.start().then(run);
  }
};