run.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use strict';
  2. var _ = require('lodash');
  3. var debug = require('debug')('cypress:cli');
  4. var util = require('../util');
  5. var spawn = require('./spawn');
  6. var verify = require('../tasks/verify');
  7. // maps options collected by the CLI
  8. // and forms list of CLI arguments to the server
  9. var processRunOptions = function processRunOptions() {
  10. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  11. debug('processing run options');
  12. var args = ['--run-project', options.project];
  13. //// if key is set use that - else attempt to find it by environment variable
  14. if (options.key == null) {
  15. debug('--key is not set, looking up environment variable CYPRESS_RECORD_KEY');
  16. options.key = util.getEnv('CYPRESS_RECORD_KEY') || util.getEnv('CYPRESS_CI_KEY');
  17. }
  18. if (options.env) {
  19. args.push('--env', options.env);
  20. }
  21. if (options.config) {
  22. args.push('--config', options.config);
  23. }
  24. if (options.configFile !== undefined) {
  25. args.push('--config-file', options.configFile);
  26. }
  27. if (options.port) {
  28. args.push('--port', options.port);
  29. }
  30. // if we have specific spec(s) push that into the args
  31. if (options.spec) {
  32. args.push('--spec', options.spec);
  33. }
  34. //// if we have a specific reporter push that into the args
  35. if (options.reporter) {
  36. args.push('--reporter', options.reporter);
  37. }
  38. //// if we have a specific reporter push that into the args
  39. if (options.reporterOptions) {
  40. args.push('--reporter-options', options.reporterOptions);
  41. }
  42. if (options.ci) {
  43. //// push to display the deprecation message
  44. args.push('--ci');
  45. //// also automatically record
  46. args.push('--record', true);
  47. }
  48. //// if we have a key assume we're in record mode
  49. if (options.key) {
  50. args.push('--key', options.key);
  51. }
  52. //// if record is defined and we're not
  53. //// already in ci mode, then send it up
  54. if (options.record != null && !options.ci) {
  55. args.push('--record', options.record);
  56. }
  57. if (options.parallel) {
  58. args.push('--parallel');
  59. }
  60. if (options.group) {
  61. args.push('--group', options.group);
  62. }
  63. if (options.ciBuildId) {
  64. args.push('--ci-build-id', options.ciBuildId);
  65. }
  66. if (options.outputPath) {
  67. args.push('--output-path', options.outputPath);
  68. }
  69. if (options.browser) {
  70. args.push('--browser', options.browser);
  71. }
  72. if (options.headed) {
  73. args.push('--headed', options.headed);
  74. }
  75. if (options.exit === false) {
  76. args.push('--no-exit');
  77. }
  78. return args;
  79. };
  80. module.exports = {
  81. processRunOptions: processRunOptions,
  82. // resolves with the number of failed tests
  83. start: function start() {
  84. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  85. _.defaults(options, {
  86. key: null,
  87. spec: null,
  88. reporter: null,
  89. reporterOptions: null,
  90. project: process.cwd()
  91. });
  92. function run() {
  93. var args = processRunOptions(options);
  94. debug('run to spawn.start args %j', args);
  95. return spawn.start(args, {
  96. dev: options.dev
  97. });
  98. }
  99. if (options.dev) {
  100. return run();
  101. }
  102. return verify.start().then(run);
  103. }
  104. };