cypress 15.2.0 → 15.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cypress CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const CLI = require('../lib/cli').default
3
+ const CLI = require('../dist/cli').default
4
4
 
5
5
  CLI.init()
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -15,7 +24,7 @@ const errors_1 = require("./errors");
15
24
  const cache_1 = __importDefault(require("./tasks/cache"));
16
25
  const open_1 = __importDefault(require("./exec/open"));
17
26
  const run_1 = __importDefault(require("./exec/run"));
18
- const verify_1 = __importDefault(require("./tasks/verify"));
27
+ const verify_1 = require("./tasks/verify");
19
28
  const install_1 = __importDefault(require("./tasks/install"));
20
29
  const versions_1 = __importDefault(require("./exec/versions"));
21
30
  const info_1 = __importDefault(require("./exec/info"));
@@ -29,7 +38,7 @@ function unknownOption(flag, type = 'option') {
29
38
  logger_1.default.error(` error: unknown ${type}:`, flag);
30
39
  logger_1.default.error();
31
40
  this.outputHelp();
32
- util_1.default.exit(1);
41
+ process.exit(1);
33
42
  }
34
43
  commander_1.default.Command.prototype.unknownOption = unknownOption;
35
44
  const coerceFalse = (arg) => {
@@ -115,6 +124,7 @@ const descriptions = {
115
124
  parallel: 'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
116
125
  port: 'runs Cypress on a specific port. overrides any value in cypress.config.{js,ts,mjs,cjs}.',
117
126
  project: 'path to the project',
127
+ posixExitCodes: 'use POSIX exit codes for error handling',
118
128
  quiet: 'run quietly, using only the configured reporter',
119
129
  record: 'records the run. sends test results, screenshots and videos to Cypress Cloud.',
120
130
  reporter: 'runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"',
@@ -150,50 +160,53 @@ function includesVersion(args) {
150
160
  lodash_1.default.includes(args, '-v'));
151
161
  }
152
162
  function showVersions(opts) {
153
- debug('printing Cypress version');
154
- debug('additional arguments %o', opts);
155
- debug('parsed version arguments %o', opts);
156
- const reportAllVersions = (versions) => {
157
- logger_1.default.always('Cypress package version:', versions.package);
158
- logger_1.default.always('Cypress binary version:', versions.binary);
159
- logger_1.default.always('Electron version:', versions.electronVersion);
160
- logger_1.default.always('Bundled Node version:', versions.electronNodeVersion);
161
- };
162
- const reportComponentVersion = (componentName, versions) => {
163
- const names = {
164
- package: 'package',
165
- binary: 'binary',
166
- electron: 'electronVersion',
167
- node: 'electronNodeVersion',
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ debug('printing Cypress version');
165
+ debug('additional arguments %o', opts);
166
+ debug('parsed version arguments %o', opts);
167
+ const reportAllVersions = (versions) => {
168
+ logger_1.default.always('Cypress package version:', versions.package);
169
+ logger_1.default.always('Cypress binary version:', versions.binary);
170
+ logger_1.default.always('Electron version:', versions.electronVersion);
171
+ logger_1.default.always('Bundled Node version:', versions.electronNodeVersion);
168
172
  };
169
- if (!names[componentName]) {
170
- throw new Error(`Unknown component name "${componentName}"`);
171
- }
172
- const name = names[componentName];
173
- if (!versions[name]) {
174
- throw new Error(`Cannot find version for component "${componentName}" under property "${name}"`);
175
- }
176
- const version = versions[name];
177
- logger_1.default.always(version);
178
- };
179
- const defaultVersions = {
180
- package: undefined,
181
- binary: undefined,
182
- electronVersion: undefined,
183
- electronNodeVersion: undefined,
184
- };
185
- return versions_1.default
186
- .getVersions()
187
- .then((versions = defaultVersions) => {
188
- if (opts === null || opts === void 0 ? void 0 : opts.component) {
189
- reportComponentVersion(opts.component, versions);
173
+ const reportComponentVersion = (componentName, versions) => {
174
+ const names = {
175
+ package: 'package',
176
+ binary: 'binary',
177
+ electron: 'electronVersion',
178
+ node: 'electronNodeVersion',
179
+ };
180
+ if (!names[componentName]) {
181
+ throw new Error(`Unknown component name "${componentName}"`);
182
+ }
183
+ const name = names[componentName];
184
+ if (!versions[name]) {
185
+ throw new Error(`Cannot find version for component "${componentName}" under property "${name}"`);
186
+ }
187
+ const version = versions[name];
188
+ logger_1.default.always(version);
189
+ };
190
+ const defaultVersions = {
191
+ package: undefined,
192
+ binary: undefined,
193
+ electronVersion: undefined,
194
+ electronNodeVersion: undefined,
195
+ };
196
+ try {
197
+ const versions = (yield versions_1.default.getVersions()) || defaultVersions;
198
+ if (opts === null || opts === void 0 ? void 0 : opts.component) {
199
+ reportComponentVersion(opts.component, versions);
200
+ }
201
+ else {
202
+ reportAllVersions(versions);
203
+ }
204
+ process.exit(0);
190
205
  }
191
- else {
192
- reportAllVersions(versions);
206
+ catch (e) {
207
+ util_1.default.logErrorExit1(e);
193
208
  }
194
- process.exit(0);
195
- })
196
- .catch(util_1.default.logErrorExit1);
209
+ });
197
210
  }
198
211
  const createProgram = () => {
199
212
  const program = new commander_1.default.Command();
@@ -224,6 +237,7 @@ const addCypressRunCommand = (program) => {
224
237
  .option('--parallel', text('parallel'))
225
238
  .option('-p, --port <port>', text('port'))
226
239
  .option('-P, --project <project-path>', text('project'))
240
+ .option('--posix-exit-codes', text('posixExitCodes'))
227
241
  .option('-q, --quiet', text('quiet'))
228
242
  .option('--record [bool]', text('record'), coerceFalse)
229
243
  .option('-r, --reporter <reporter>', text('reporter'))
@@ -345,171 +359,188 @@ const cliModule = {
345
359
  * Parses the command line and kicks off Cypress process.
346
360
  */
347
361
  init(args) {
348
- if (!args) {
349
- args = process.argv;
350
- }
351
- const { CYPRESS_INTERNAL_ENV, CYPRESS_DOWNLOAD_USE_CA } = process.env;
352
- if (process.env.CYPRESS_DOWNLOAD_USE_CA) {
353
- let msg = `
362
+ return __awaiter(this, void 0, void 0, function* () {
363
+ if (!args) {
364
+ args = process.argv;
365
+ }
366
+ const { CYPRESS_INTERNAL_ENV, CYPRESS_DOWNLOAD_USE_CA } = process.env;
367
+ if (process.env.CYPRESS_DOWNLOAD_USE_CA) {
368
+ let msg = `
354
369
  ${log_symbols_1.default.warning} Warning: It looks like you're setting CYPRESS_DOWNLOAD_USE_CA=${CYPRESS_DOWNLOAD_USE_CA}
355
370
 
356
371
  The environment variable "CYPRESS_DOWNLOAD_USE_CA" is no longer required to be set.
357
372
 
358
373
  You can safely unset this environment variable.
359
374
  `;
360
- logger_1.default.log();
361
- logger_1.default.warn((0, common_tags_1.stripIndent)(msg));
362
- logger_1.default.log();
363
- }
364
- if (!util_1.default.isValidCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
365
- debug('invalid CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
366
- return (0, errors_1.exitWithError)(errors_1.errors.invalidCypressEnv)(`CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}`);
367
- }
368
- if (util_1.default.isNonProductionCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
369
- debug('non-production CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
370
- let msg = `
375
+ logger_1.default.log();
376
+ logger_1.default.warn((0, common_tags_1.stripIndent)(msg));
377
+ logger_1.default.log();
378
+ }
379
+ if (!util_1.default.isValidCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
380
+ debug('invalid CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
381
+ return (0, errors_1.exitWithError)(errors_1.errors.invalidCypressEnv)(`CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}`);
382
+ }
383
+ if (util_1.default.isNonProductionCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
384
+ debug('non-production CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
385
+ let msg = `
371
386
  ${log_symbols_1.default.warning} Warning: It looks like you're passing CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}
372
387
 
373
388
  The environment variable "CYPRESS_INTERNAL_ENV" is reserved and should only be used internally.
374
389
 
375
390
  Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.
376
391
  `;
377
- logger_1.default.log();
378
- logger_1.default.warn((0, common_tags_1.stripIndent)(msg));
379
- logger_1.default.log();
380
- }
381
- const program = createProgram();
382
- program
383
- .command('help')
384
- .description('Shows CLI help and exits')
385
- .action(() => {
386
- program.help();
387
- });
388
- const handleVersion = (cmd) => {
389
- return cmd
390
- .option('--component <package|binary|electron|node>', 'component to report version for')
391
- .action((opts, ...other) => {
392
- showVersions(util_1.default.parseOpts(opts));
393
- });
394
- };
395
- handleVersion(program
396
- .storeOptionsAsProperties()
397
- .option('-v, --version', text('version'))
398
- .command('version')
399
- .description(text('version')));
400
- maybeAddInspectFlags(addCypressOpenCommand(program))
401
- .action((opts) => {
402
- debug('opening Cypress');
403
- open_1.default.start(util_1.default.parseOpts(opts))
404
- .then(util_1.default.exit)
405
- .catch(util_1.default.logErrorExit1);
406
- });
407
- maybeAddInspectFlags(addCypressRunCommand(program))
408
- .action((...fnArgs) => {
409
- debug('running Cypress with args %o', fnArgs);
410
- run_1.default.start(parseVariableOpts(fnArgs, args))
411
- .then(util_1.default.exit)
412
- .catch(util_1.default.logErrorExit1);
413
- });
414
- program
415
- .command('install')
416
- .usage('[options]')
417
- .description('Installs the Cypress executable matching this package\'s version')
418
- .option('-f, --force', text('forceInstall'))
419
- .action((opts) => {
420
- install_1.default
421
- .start(util_1.default.parseOpts(opts))
422
- .catch(util_1.default.logErrorExit1);
423
- });
424
- program
425
- .command('verify')
426
- .usage('[options]')
427
- .description('Verifies that Cypress is installed correctly and executable')
428
- .option('--dev', text('dev'), coerceFalse)
429
- .action((opts) => {
430
- const defaultOpts = { force: true, welcomeMessage: false };
431
- const parsedOpts = util_1.default.parseOpts(opts);
432
- const options = lodash_1.default.extend(parsedOpts, defaultOpts);
433
- verify_1.default
434
- .start(options)
435
- .catch(util_1.default.logErrorExit1);
436
- });
437
- program
438
- .command('cache')
439
- .usage('[command]')
440
- .description('Manages the Cypress binary cache')
441
- .option('list', text('cacheList'))
442
- .option('path', text('cachePath'))
443
- .option('clear', text('cacheClear'))
444
- .option('prune', text('cachePrune'))
445
- .option('--size', text('cacheSize'))
446
- .action(function (opts, args) {
447
- if (!args || !args.length) {
448
- this.outputHelp();
449
- util_1.default.exit(1);
392
+ logger_1.default.log();
393
+ logger_1.default.warn((0, common_tags_1.stripIndent)(msg));
394
+ logger_1.default.log();
450
395
  }
451
- const [command] = args;
452
- if (!lodash_1.default.includes(['list', 'path', 'clear', 'prune'], command)) {
453
- unknownOption.call(this, `cache ${command}`, 'command');
454
- }
455
- if (command === 'list') {
456
- debug('cache command %o', {
457
- command,
458
- size: opts.size,
396
+ const program = createProgram();
397
+ program
398
+ .command('help')
399
+ .description('Shows CLI help and exits')
400
+ .action(() => {
401
+ program.help();
402
+ });
403
+ const handleVersion = (cmd) => {
404
+ return cmd
405
+ .option('--component <package|binary|electron|node>', 'component to report version for')
406
+ .action((opts, ...other) => {
407
+ showVersions(util_1.default.parseOpts(opts));
459
408
  });
460
- return cache_1.default.list(opts.size)
461
- .catch({ code: 'ENOENT' }, () => {
462
- logger_1.default.always('No cached binary versions were found.');
463
- process.exit(0);
464
- })
465
- .catch((e) => {
466
- debug('cache list command failed with "%s"', e.message);
409
+ };
410
+ handleVersion(program
411
+ .storeOptionsAsProperties()
412
+ .option('-v, --version', text('version'))
413
+ .command('version')
414
+ .description(text('version')));
415
+ maybeAddInspectFlags(addCypressOpenCommand(program))
416
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
417
+ debug('opening Cypress');
418
+ try {
419
+ const code = yield open_1.default.start(util_1.default.parseOpts(opts));
420
+ process.exit(code);
421
+ }
422
+ catch (e) {
423
+ util_1.default.logErrorExit1(e);
424
+ }
425
+ }));
426
+ maybeAddInspectFlags(addCypressRunCommand(program))
427
+ .action((...fnArgs) => __awaiter(this, void 0, void 0, function* () {
428
+ debug('running Cypress with args %o', fnArgs);
429
+ try {
430
+ const code = yield run_1.default.start(parseVariableOpts(fnArgs, args));
431
+ process.exit(code);
432
+ }
433
+ catch (e) {
434
+ util_1.default.logErrorExit1(e);
435
+ }
436
+ }));
437
+ program
438
+ .command('install')
439
+ .usage('[options]')
440
+ .description('Installs the Cypress executable matching this package\'s version')
441
+ .option('-f, --force', text('forceInstall'))
442
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
443
+ try {
444
+ yield install_1.default.start(util_1.default.parseOpts(opts));
445
+ }
446
+ catch (e) {
467
447
  util_1.default.logErrorExit1(e);
448
+ }
449
+ }));
450
+ program
451
+ .command('verify')
452
+ .usage('[options]')
453
+ .description('Verifies that Cypress is installed correctly and executable')
454
+ .option('--dev', text('dev'), coerceFalse)
455
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
456
+ const defaultOpts = { force: true, welcomeMessage: false };
457
+ const parsedOpts = util_1.default.parseOpts(opts);
458
+ const options = lodash_1.default.extend(parsedOpts, defaultOpts);
459
+ try {
460
+ yield (0, verify_1.start)(options);
461
+ }
462
+ catch (e) {
463
+ util_1.default.logErrorExit1(e);
464
+ }
465
+ }));
466
+ program
467
+ .command('cache')
468
+ .usage('[command]')
469
+ .description('Manages the Cypress binary cache')
470
+ .option('list', text('cacheList'))
471
+ .option('path', text('cachePath'))
472
+ .option('clear', text('cacheClear'))
473
+ .option('prune', text('cachePrune'))
474
+ .option('--size', text('cacheSize'))
475
+ .action(function (opts, args) {
476
+ return __awaiter(this, void 0, void 0, function* () {
477
+ if (!args || !args.length) {
478
+ this.outputHelp();
479
+ process.exit(1);
480
+ }
481
+ const [command] = args;
482
+ if (!lodash_1.default.includes(['list', 'path', 'clear', 'prune'], command)) {
483
+ unknownOption.call(this, `cache ${command}`, 'command');
484
+ }
485
+ if (command === 'list') {
486
+ debug('cache command %o', {
487
+ command,
488
+ size: opts.size,
489
+ });
490
+ try {
491
+ const result = yield cache_1.default.list(opts.size);
492
+ return result;
493
+ }
494
+ catch (e) {
495
+ if (e.code === 'ENOENT') {
496
+ logger_1.default.always('No cached binary versions were found.');
497
+ process.exit(0);
498
+ }
499
+ util_1.default.logErrorExit1(e);
500
+ }
501
+ }
502
+ cache_1.default[command]();
468
503
  });
504
+ });
505
+ program
506
+ .command('info')
507
+ .usage('[command]')
508
+ .description('Prints Cypress and system information')
509
+ .option('--dev', text('dev'), coerceFalse)
510
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
511
+ try {
512
+ const code = yield info_1.default.start(opts);
513
+ process.exit(code);
514
+ }
515
+ catch (e) {
516
+ util_1.default.logErrorExit1(e);
517
+ }
518
+ }));
519
+ debug('cli starts with arguments %j', args);
520
+ util_1.default.printNodeOptions();
521
+ // if there are no arguments
522
+ if (args.length <= 2) {
523
+ debug('printing help');
524
+ program.help();
525
+ // exits
469
526
  }
470
- cache_1.default[command]();
471
- });
472
- program
473
- .command('info')
474
- .usage('[command]')
475
- .description('Prints Cypress and system information')
476
- .option('--dev', text('dev'), coerceFalse)
477
- .action((opts) => {
478
- info_1.default
479
- .start(opts)
480
- .then(util_1.default.exit)
481
- .catch(util_1.default.logErrorExit1);
527
+ const firstCommand = args[2];
528
+ if (!lodash_1.default.includes(knownCommands, firstCommand)) {
529
+ debug('unknown command %s', firstCommand);
530
+ logger_1.default.error('Unknown command', `"${firstCommand}"`);
531
+ program.outputHelp();
532
+ return process.exit(1);
533
+ }
534
+ if (includesVersion(args)) {
535
+ // commander 2.11.0 changes behavior
536
+ // and now does not understand top level options
537
+ // .option('-v, --version').command('version')
538
+ // so we have to manually catch '-v, --version'
539
+ handleVersion(program);
540
+ }
541
+ debug('program parsing arguments');
542
+ return program.parse(args);
482
543
  });
483
- debug('cli starts with arguments %j', args);
484
- util_1.default.printNodeOptions();
485
- // if there are no arguments
486
- if (args.length <= 2) {
487
- debug('printing help');
488
- program.help();
489
- // exits
490
- }
491
- const firstCommand = args[2];
492
- if (!lodash_1.default.includes(knownCommands, firstCommand)) {
493
- debug('unknown command %s', firstCommand);
494
- logger_1.default.error('Unknown command', `"${firstCommand}"`);
495
- program.outputHelp();
496
- return util_1.default.exit(1);
497
- }
498
- if (includesVersion(args)) {
499
- // commander 2.11.0 changes behavior
500
- // and now does not understand top level options
501
- // .option('-v, --version').command('version')
502
- // so we have to manually catch '-v, --version'
503
- handleVersion(program);
504
- }
505
- debug('program parsing arguments');
506
- return program.parse(args);
507
544
  },
508
545
  };
509
546
  exports.default = cliModule;
510
- // @ts-ignore
511
- if (!module.parent) {
512
- logger_1.default.error('This CLI module should be required from another Node module');
513
- logger_1.default.error('and not executed directly');
514
- process.exit(-1);
515
- }
@@ -1,16 +1,23 @@
1
1
  "use strict";
2
- // https://github.com/cypress-io/cypress/issues/316
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
3
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
13
  };
6
- const bluebird_1 = __importDefault(require("bluebird"));
14
+ // https://github.com/cypress-io/cypress/issues/316
7
15
  const tmp_1 = __importDefault(require("tmp"));
8
- const fs_1 = __importDefault(require("./fs"));
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
17
  const open_1 = __importDefault(require("./exec/open"));
10
18
  const run_1 = __importDefault(require("./exec/run"));
11
19
  const util_1 = __importDefault(require("./util"));
12
20
  const cli_1 = __importDefault(require("./cli"));
13
- const tmp = bluebird_1.default.promisifyAll(tmp_1.default);
14
21
  const cypressModuleApi = {
15
22
  /**
16
23
  * Opens Cypress GUI
@@ -24,29 +31,25 @@ const cypressModuleApi = {
24
31
  * Runs Cypress tests in the current project
25
32
  * @see https://on.cypress.io/module-api#cypress-run
26
33
  */
27
- run(options = {}) {
28
- if (!run_1.default.isValidProject(options.project)) {
29
- return bluebird_1.default.reject(new Error(`Invalid project path parameter: ${options.project}`));
30
- }
31
- options = util_1.default.normalizeModuleOptions(options);
32
- tmp.setGracefulCleanup();
33
- return tmp.fileAsync()
34
- .then((outputPath) => {
34
+ run() {
35
+ return __awaiter(this, arguments, void 0, function* (options = {}) {
36
+ if (!run_1.default.isValidProject(options.project)) {
37
+ throw new Error(`Invalid project path parameter: ${options.project}`);
38
+ }
39
+ options = util_1.default.normalizeModuleOptions(options);
40
+ tmp_1.default.setGracefulCleanup();
41
+ const outputPath = tmp_1.default.fileSync().name;
35
42
  options.outputPath = outputPath;
36
- return run_1.default.start(options)
37
- .then((failedTests) => {
38
- return fs_1.default.readJsonAsync(outputPath, { throws: false })
39
- .then((output) => {
40
- if (!output) {
41
- return {
42
- status: 'failed',
43
- failures: failedTests,
44
- message: 'Could not find Cypress test run results',
45
- };
46
- }
47
- return output;
48
- });
49
- });
43
+ const failedTests = yield run_1.default.start(options);
44
+ const output = yield fs_extra_1.default.readJson(outputPath, { throws: false });
45
+ if (!output) {
46
+ return {
47
+ status: 'failed',
48
+ failures: failedTests,
49
+ message: 'Could not find Cypress test run results',
50
+ };
51
+ }
52
+ return output;
50
53
  });
51
54
  },
52
55
  cli: {