cypress 15.1.0 → 15.3.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.
Files changed (49) hide show
  1. package/bin/cypress +3 -1
  2. package/dist/VerboseRenderer.js +61 -0
  3. package/dist/cli.js +544 -0
  4. package/dist/cypress.js +104 -0
  5. package/dist/errors.js +391 -0
  6. package/dist/exec/info.js +103 -0
  7. package/dist/exec/open.js +103 -0
  8. package/dist/exec/run.js +177 -0
  9. package/dist/exec/shared.js +55 -0
  10. package/dist/exec/spawn.js +301 -0
  11. package/dist/exec/versions.js +67 -0
  12. package/dist/exec/xvfb.js +118 -0
  13. package/dist/index.js +52 -0
  14. package/dist/index.mjs +9 -0
  15. package/dist/logger.js +55 -0
  16. package/dist/tasks/cache.js +144 -0
  17. package/dist/tasks/download.js +304 -0
  18. package/dist/tasks/get-folder-size.js +44 -0
  19. package/dist/tasks/install.js +326 -0
  20. package/dist/tasks/state.js +184 -0
  21. package/dist/tasks/unzip.js +192 -0
  22. package/dist/tasks/verify.js +303 -0
  23. package/dist/util.js +452 -0
  24. package/package.json +10 -13
  25. package/types/cypress-automation.d.ts +2 -1
  26. package/types/cypress.d.ts +1 -0
  27. package/index.js +0 -27
  28. package/index.mjs +0 -17
  29. package/lib/VerboseRenderer.js +0 -58
  30. package/lib/cli.js +0 -411
  31. package/lib/cypress.js +0 -98
  32. package/lib/errors.js +0 -392
  33. package/lib/exec/info.js +0 -92
  34. package/lib/exec/open.js +0 -90
  35. package/lib/exec/run.js +0 -176
  36. package/lib/exec/shared.js +0 -62
  37. package/lib/exec/spawn.js +0 -247
  38. package/lib/exec/versions.js +0 -53
  39. package/lib/exec/xvfb.js +0 -93
  40. package/lib/fs.js +0 -4
  41. package/lib/logger.js +0 -50
  42. package/lib/tasks/cache.js +0 -132
  43. package/lib/tasks/download.js +0 -324
  44. package/lib/tasks/get-folder-size.js +0 -33
  45. package/lib/tasks/install.js +0 -368
  46. package/lib/tasks/state.js +0 -185
  47. package/lib/tasks/unzip.js +0 -200
  48. package/lib/tasks/verify.js +0 -300
  49. package/lib/util.js +0 -448
package/bin/cypress CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('../lib/cli').init()
3
+ const CLI = require('../dist/cli').default
4
+
5
+ CLI.init()
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // Vendored from @cypress/listr-verbose-renderer
7
+ const figures_1 = __importDefault(require("figures"));
8
+ const cli_cursor_1 = __importDefault(require("cli-cursor"));
9
+ const chalk_1 = __importDefault(require("chalk"));
10
+ const dayjs_1 = __importDefault(require("dayjs"));
11
+ const formattedLog = (options, output) => {
12
+ const timestamp = (0, dayjs_1.default)().format(options.dateFormat);
13
+ // eslint-disable-next-line no-console
14
+ console.log(`${chalk_1.default.dim(`[${timestamp}]`)} ${output}`);
15
+ };
16
+ const renderHelper = (task, event, options) => {
17
+ const log = formattedLog.bind(undefined, options);
18
+ if (event.type === 'STATE') {
19
+ const message = task.isPending() ? 'started' : task.state;
20
+ log(`${task.title} [${message}]`);
21
+ if (task.isSkipped() && task.output) {
22
+ log(`${figures_1.default.arrowRight} ${task.output}`);
23
+ }
24
+ }
25
+ else if (event.type === 'TITLE') {
26
+ log(`${task.title} [title changed]`);
27
+ }
28
+ };
29
+ const render = (tasks, options) => {
30
+ for (const task of tasks) {
31
+ task.subscribe((event) => {
32
+ if (event.type === 'SUBTASKS') {
33
+ render(task.subtasks, options);
34
+ return;
35
+ }
36
+ renderHelper(task, event, options);
37
+ }, (err) => {
38
+ // eslint-disable-next-line no-console
39
+ console.log(err);
40
+ });
41
+ }
42
+ };
43
+ class VerboseRenderer {
44
+ constructor(tasks, options) {
45
+ this._tasks = tasks;
46
+ this._options = Object.assign({
47
+ dateFormat: 'HH:mm:ss',
48
+ }, options);
49
+ }
50
+ static get nonTTY() {
51
+ return true;
52
+ }
53
+ render() {
54
+ cli_cursor_1.default.hide();
55
+ render(this._tasks, this._options);
56
+ }
57
+ end() {
58
+ cli_cursor_1.default.show();
59
+ }
60
+ }
61
+ exports.default = VerboseRenderer;
package/dist/cli.js ADDED
@@ -0,0 +1,544 @@
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
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ // @ts-check
16
+ const lodash_1 = __importDefault(require("lodash"));
17
+ const commander_1 = __importDefault(require("commander"));
18
+ const common_tags_1 = require("common-tags");
19
+ const log_symbols_1 = __importDefault(require("log-symbols"));
20
+ const debug_1 = __importDefault(require("debug"));
21
+ const util_1 = __importDefault(require("./util"));
22
+ const logger_1 = __importDefault(require("./logger"));
23
+ const errors_1 = require("./errors");
24
+ const cache_1 = __importDefault(require("./tasks/cache"));
25
+ const open_1 = __importDefault(require("./exec/open"));
26
+ const run_1 = __importDefault(require("./exec/run"));
27
+ const verify_1 = require("./tasks/verify");
28
+ const install_1 = __importDefault(require("./tasks/install"));
29
+ const versions_1 = __importDefault(require("./exec/versions"));
30
+ const info_1 = __importDefault(require("./exec/info"));
31
+ const debug = (0, debug_1.default)('cypress:cli:cli');
32
+ // patch "commander" method called when a user passed an unknown option
33
+ // we want to print help for the current command and exit with an error
34
+ function unknownOption(flag, type = 'option') {
35
+ if (this._allowUnknownOption)
36
+ return;
37
+ logger_1.default.error();
38
+ logger_1.default.error(` error: unknown ${type}:`, flag);
39
+ logger_1.default.error();
40
+ this.outputHelp();
41
+ process.exit(1);
42
+ }
43
+ commander_1.default.Command.prototype.unknownOption = unknownOption;
44
+ const coerceFalse = (arg) => {
45
+ return arg !== 'false';
46
+ };
47
+ const coerceAnyStringToInt = (arg) => {
48
+ return typeof arg === 'string' ? parseInt(arg) : arg;
49
+ };
50
+ const spaceDelimitedArgsMsg = (flag, args) => {
51
+ let msg = `
52
+ ${log_symbols_1.default.warning} Warning: It looks like you're passing --${flag} a space-separated list of arguments:
53
+
54
+ "${args.join(' ')}"
55
+
56
+ This will work, but it's not recommended.
57
+
58
+ If you are trying to pass multiple arguments, separate them with commas instead:
59
+ cypress run --${flag} arg1,arg2,arg3
60
+ `;
61
+ if (flag === 'spec') {
62
+ msg += `
63
+ The most common cause of this warning is using an unescaped glob pattern. If you are
64
+ trying to pass a glob pattern, escape it using quotes:
65
+ cypress run --spec "**/*.spec.js"
66
+ `;
67
+ }
68
+ logger_1.default.log();
69
+ logger_1.default.warn((0, common_tags_1.stripIndent)(msg));
70
+ logger_1.default.log();
71
+ };
72
+ const parseVariableOpts = (fnArgs, args) => {
73
+ const [opts, unknownArgs] = fnArgs;
74
+ if ((unknownArgs && unknownArgs.length) && (opts.spec || opts.tag)) {
75
+ // this will capture space-delimited args after
76
+ // flags that could have possible multiple args
77
+ // but before the next option
78
+ // --spec spec1 spec2 or --tag foo bar
79
+ const multiArgFlags = lodash_1.default.compact([
80
+ opts.spec ? 'spec' : opts.spec,
81
+ opts.tag ? 'tag' : opts.tag,
82
+ ]);
83
+ lodash_1.default.forEach(multiArgFlags, (flag) => {
84
+ const argIndex = lodash_1.default.indexOf(args, `--${flag}`) + 2;
85
+ const nextOptOffset = lodash_1.default.findIndex(lodash_1.default.slice(args, argIndex), (arg) => {
86
+ return lodash_1.default.startsWith(arg, '--');
87
+ });
88
+ const endIndex = nextOptOffset !== -1 ? argIndex + nextOptOffset : args.length;
89
+ const maybeArgs = lodash_1.default.slice(args, argIndex, endIndex);
90
+ const extraArgs = lodash_1.default.intersection(maybeArgs, unknownArgs);
91
+ if (extraArgs.length) {
92
+ opts[flag] = [opts[flag]].concat(extraArgs);
93
+ spaceDelimitedArgsMsg(flag, opts[flag]);
94
+ opts[flag] = opts[flag].join(',');
95
+ }
96
+ });
97
+ }
98
+ debug('variable-length opts parsed %o', { args, opts });
99
+ return util_1.default.parseOpts(opts);
100
+ };
101
+ const descriptions = {
102
+ autoCancelAfterFailures: 'overrides the project-level Cloud configuration to set the failed test threshold for auto cancellation or to disable auto cancellation when recording to the Cloud',
103
+ browser: 'runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.',
104
+ cacheClear: 'delete all cached binaries',
105
+ cachePrune: 'deletes all cached binaries except for the version currently in use',
106
+ cacheList: 'list cached binary versions',
107
+ cachePath: 'print the path to the binary cache',
108
+ cacheSize: 'Used with the list command to show the sizes of the cached folders',
109
+ ciBuildId: 'the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers',
110
+ component: 'runs component tests',
111
+ config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.config.{js,ts,mjs,cjs}.',
112
+ configFile: 'path to script file where configuration values are set. defaults to "cypress.config.{js,ts,mjs,cjs}".',
113
+ detached: 'runs Cypress application in detached mode',
114
+ dev: 'runs cypress in development and bypasses binary check',
115
+ e2e: 'runs end to end tests',
116
+ env: 'sets environment variables. separate multiple values with a comma. overrides any value in cypress.config.{js,ts,mjs,cjs} or cypress.env.json',
117
+ exit: 'keep the browser open after tests finish',
118
+ forceInstall: 'force install the Cypress binary',
119
+ global: 'force Cypress into global mode as if it were globally installed',
120
+ group: 'a named group for recorded runs in Cypress Cloud',
121
+ headed: 'displays the browser instead of running headlessly',
122
+ headless: 'hide the browser instead of running headed (default for cypress run)',
123
+ key: 'your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.',
124
+ parallel: 'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
125
+ port: 'runs Cypress on a specific port. overrides any value in cypress.config.{js,ts,mjs,cjs}.',
126
+ project: 'path to the project',
127
+ quiet: 'run quietly, using only the configured reporter',
128
+ record: 'records the run. sends test results, screenshots and videos to Cypress Cloud.',
129
+ reporter: 'runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"',
130
+ reporterOptions: 'options for the mocha reporter. defaults to "null"',
131
+ runnerUi: 'displays the Cypress Runner UI',
132
+ noRunnerUi: 'hides the Cypress Runner UI',
133
+ spec: 'runs specific spec file(s). defaults to "all"',
134
+ tag: 'named tag(s) for recorded runs in Cypress Cloud',
135
+ version: 'prints Cypress version',
136
+ };
137
+ const knownCommands = [
138
+ 'cache',
139
+ 'help',
140
+ '-h',
141
+ '--help',
142
+ 'install',
143
+ 'open',
144
+ 'run',
145
+ 'verify',
146
+ '-v',
147
+ '--version',
148
+ 'version',
149
+ 'info',
150
+ ];
151
+ const text = (description) => {
152
+ if (!descriptions[description]) {
153
+ throw new Error(`Could not find description for: ${description}`);
154
+ }
155
+ return descriptions[description];
156
+ };
157
+ function includesVersion(args) {
158
+ return (lodash_1.default.includes(args, '--version') ||
159
+ lodash_1.default.includes(args, '-v'));
160
+ }
161
+ function showVersions(opts) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ debug('printing Cypress version');
164
+ debug('additional arguments %o', opts);
165
+ debug('parsed version arguments %o', opts);
166
+ const reportAllVersions = (versions) => {
167
+ logger_1.default.always('Cypress package version:', versions.package);
168
+ logger_1.default.always('Cypress binary version:', versions.binary);
169
+ logger_1.default.always('Electron version:', versions.electronVersion);
170
+ logger_1.default.always('Bundled Node version:', versions.electronNodeVersion);
171
+ };
172
+ const reportComponentVersion = (componentName, versions) => {
173
+ const names = {
174
+ package: 'package',
175
+ binary: 'binary',
176
+ electron: 'electronVersion',
177
+ node: 'electronNodeVersion',
178
+ };
179
+ if (!names[componentName]) {
180
+ throw new Error(`Unknown component name "${componentName}"`);
181
+ }
182
+ const name = names[componentName];
183
+ if (!versions[name]) {
184
+ throw new Error(`Cannot find version for component "${componentName}" under property "${name}"`);
185
+ }
186
+ const version = versions[name];
187
+ logger_1.default.always(version);
188
+ };
189
+ const defaultVersions = {
190
+ package: undefined,
191
+ binary: undefined,
192
+ electronVersion: undefined,
193
+ electronNodeVersion: undefined,
194
+ };
195
+ try {
196
+ const versions = (yield versions_1.default.getVersions()) || defaultVersions;
197
+ if (opts === null || opts === void 0 ? void 0 : opts.component) {
198
+ reportComponentVersion(opts.component, versions);
199
+ }
200
+ else {
201
+ reportAllVersions(versions);
202
+ }
203
+ process.exit(0);
204
+ }
205
+ catch (e) {
206
+ util_1.default.logErrorExit1(e);
207
+ }
208
+ });
209
+ }
210
+ const createProgram = () => {
211
+ const program = new commander_1.default.Command();
212
+ // bug in commander not printing name
213
+ // in usage help docs
214
+ program._name = 'cypress';
215
+ program.usage('<command> [options]');
216
+ return program;
217
+ };
218
+ const addCypressRunCommand = (program) => {
219
+ return program
220
+ .command('run')
221
+ .usage('[options]')
222
+ .description('Runs Cypress tests from the CLI without the GUI')
223
+ .option('--auto-cancel-after-failures <test-failure-count || false>', text('autoCancelAfterFailures'))
224
+ .option('-b, --browser <browser-name-or-path>', text('browser'))
225
+ .option('--ci-build-id <id>', text('ciBuildId'))
226
+ .option('--component', text('component'))
227
+ .option('-c, --config <config>', text('config'))
228
+ .option('-C, --config-file <config-file>', text('configFile'))
229
+ .option('--e2e', text('e2e'))
230
+ .option('-e, --env <env>', text('env'))
231
+ .option('--group <name>', text('group'))
232
+ .option('-k, --key <record-key>', text('key'))
233
+ .option('--headed', text('headed'))
234
+ .option('--headless', text('headless'))
235
+ .option('--no-exit', text('exit'))
236
+ .option('--parallel', text('parallel'))
237
+ .option('-p, --port <port>', text('port'))
238
+ .option('-P, --project <project-path>', text('project'))
239
+ .option('-q, --quiet', text('quiet'))
240
+ .option('--record [bool]', text('record'), coerceFalse)
241
+ .option('-r, --reporter <reporter>', text('reporter'))
242
+ .option('--runner-ui', text('runnerUi'))
243
+ .option('--no-runner-ui', text('noRunnerUi'))
244
+ .option('-o, --reporter-options <reporter-options>', text('reporterOptions'))
245
+ .option('-s, --spec <spec>', text('spec'))
246
+ .option('-t, --tag <tag>', text('tag'))
247
+ .option('--dev', text('dev'), coerceFalse);
248
+ };
249
+ const addCypressOpenCommand = (program) => {
250
+ return program
251
+ .command('open')
252
+ .usage('[options]')
253
+ .description('Opens Cypress in the interactive GUI.')
254
+ .option('-b, --browser <browser-path>', text('browser'))
255
+ .option('--component', text('component'))
256
+ .option('-c, --config <config>', text('config'))
257
+ .option('-C, --config-file <config-file>', text('configFile'))
258
+ .option('-d, --detached [bool]', text('detached'), coerceFalse)
259
+ .option('--e2e', text('e2e'))
260
+ .option('-e, --env <env>', text('env'))
261
+ .option('--global', text('global'))
262
+ .option('-p, --port <port>', text('port'))
263
+ .option('-P, --project <project-path>', text('project'))
264
+ .option('--dev', text('dev'), coerceFalse);
265
+ };
266
+ const maybeAddInspectFlags = (program) => {
267
+ if (process.argv.includes('--dev')) {
268
+ return program
269
+ .option('--inspect', 'Node option')
270
+ .option('--inspect-brk', 'Node option');
271
+ }
272
+ return program;
273
+ };
274
+ /**
275
+ * Casts known command line options for "cypress run" to their intended type.
276
+ * For example if the user passes "--port 5005" the ".port" property should be
277
+ * a number 5005 and not a string "5005".
278
+ *
279
+ * Returns a clone of the original object.
280
+ */
281
+ const castCypressOptions = (opts) => {
282
+ // only properties that have type "string | false" in our TS definition
283
+ // require special handling, because CLI parsing takes care of purely
284
+ // boolean arguments
285
+ const castOpts = Object.assign({}, opts);
286
+ if (lodash_1.default.has(opts, 'port')) {
287
+ castOpts.port = coerceAnyStringToInt(opts.port);
288
+ }
289
+ return castOpts;
290
+ };
291
+ const cliModule = {
292
+ /**
293
+ * Parses `cypress run` command line option array into an object
294
+ * with options that you can feed into a `cypress.run()` module API call.
295
+ * @example
296
+ * const options = parseRunCommand(['cypress', 'run', '--browser', 'chrome'])
297
+ * // options is {browser: 'chrome'}
298
+ */
299
+ parseRunCommand(args) {
300
+ return new Promise((resolve, reject) => {
301
+ if (!Array.isArray(args)) {
302
+ return reject(new Error('Expected array of arguments'));
303
+ }
304
+ // make a copy of the input arguments array
305
+ // and add placeholders where "node ..." would usually be
306
+ // also remove "cypress" keyword at the start if present
307
+ const cliArgs = args[0] === 'cypress' ? [...args.slice(1)] : [...args];
308
+ cliArgs.unshift(null, null);
309
+ debug('creating program parser');
310
+ const program = createProgram();
311
+ maybeAddInspectFlags(addCypressRunCommand(program))
312
+ .action((...fnArgs) => {
313
+ debug('parsed Cypress run %o', fnArgs);
314
+ const options = parseVariableOpts(fnArgs, cliArgs);
315
+ debug('parsed options %o', options);
316
+ const casted = castCypressOptions(options);
317
+ debug('casted options %o', casted);
318
+ resolve(casted);
319
+ });
320
+ debug('parsing args: %o', cliArgs);
321
+ program.parse(cliArgs);
322
+ });
323
+ },
324
+ /**
325
+ * Parses `cypress open` command line option array into an object
326
+ * with options that you can feed into cy.openModeSystemTest test calls
327
+ * @example
328
+ * const options = parseOpenCommand(['cypress', 'open', '--browser', 'chrome'])
329
+ * // options is {browser: 'chrome'}
330
+ */
331
+ parseOpenCommand(args) {
332
+ return new Promise((resolve, reject) => {
333
+ if (!Array.isArray(args)) {
334
+ return reject(new Error('Expected array of arguments'));
335
+ }
336
+ // make a copy of the input arguments array
337
+ // and add placeholders where "node ..." would usually be
338
+ // also remove "cypress" keyword at the start if present
339
+ const cliArgs = args[0] === 'cypress' ? [...args.slice(1)] : [...args];
340
+ cliArgs.unshift(null, null);
341
+ debug('creating program parser');
342
+ const program = createProgram();
343
+ maybeAddInspectFlags(addCypressOpenCommand(program))
344
+ .action((...fnArgs) => {
345
+ debug('parsed Cypress open %o', fnArgs);
346
+ const options = parseVariableOpts(fnArgs, cliArgs);
347
+ debug('parsed options %o', options);
348
+ const casted = castCypressOptions(options);
349
+ debug('casted options %o', casted);
350
+ resolve(casted);
351
+ });
352
+ debug('parsing args: %o', cliArgs);
353
+ program.parse(cliArgs);
354
+ });
355
+ },
356
+ /**
357
+ * Parses the command line and kicks off Cypress process.
358
+ */
359
+ init(args) {
360
+ return __awaiter(this, void 0, void 0, function* () {
361
+ if (!args) {
362
+ args = process.argv;
363
+ }
364
+ const { CYPRESS_INTERNAL_ENV, CYPRESS_DOWNLOAD_USE_CA } = process.env;
365
+ if (process.env.CYPRESS_DOWNLOAD_USE_CA) {
366
+ let msg = `
367
+ ${log_symbols_1.default.warning} Warning: It looks like you're setting CYPRESS_DOWNLOAD_USE_CA=${CYPRESS_DOWNLOAD_USE_CA}
368
+
369
+ The environment variable "CYPRESS_DOWNLOAD_USE_CA" is no longer required to be set.
370
+
371
+ You can safely unset this environment variable.
372
+ `;
373
+ logger_1.default.log();
374
+ logger_1.default.warn((0, common_tags_1.stripIndent)(msg));
375
+ logger_1.default.log();
376
+ }
377
+ if (!util_1.default.isValidCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
378
+ debug('invalid CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
379
+ return (0, errors_1.exitWithError)(errors_1.errors.invalidCypressEnv)(`CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}`);
380
+ }
381
+ if (util_1.default.isNonProductionCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
382
+ debug('non-production CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
383
+ let msg = `
384
+ ${log_symbols_1.default.warning} Warning: It looks like you're passing CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}
385
+
386
+ The environment variable "CYPRESS_INTERNAL_ENV" is reserved and should only be used internally.
387
+
388
+ Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.
389
+ `;
390
+ logger_1.default.log();
391
+ logger_1.default.warn((0, common_tags_1.stripIndent)(msg));
392
+ logger_1.default.log();
393
+ }
394
+ const program = createProgram();
395
+ program
396
+ .command('help')
397
+ .description('Shows CLI help and exits')
398
+ .action(() => {
399
+ program.help();
400
+ });
401
+ const handleVersion = (cmd) => {
402
+ return cmd
403
+ .option('--component <package|binary|electron|node>', 'component to report version for')
404
+ .action((opts, ...other) => {
405
+ showVersions(util_1.default.parseOpts(opts));
406
+ });
407
+ };
408
+ handleVersion(program
409
+ .storeOptionsAsProperties()
410
+ .option('-v, --version', text('version'))
411
+ .command('version')
412
+ .description(text('version')));
413
+ maybeAddInspectFlags(addCypressOpenCommand(program))
414
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
415
+ debug('opening Cypress');
416
+ try {
417
+ const code = yield open_1.default.start(util_1.default.parseOpts(opts));
418
+ process.exit(code);
419
+ }
420
+ catch (e) {
421
+ util_1.default.logErrorExit1(e);
422
+ }
423
+ }));
424
+ maybeAddInspectFlags(addCypressRunCommand(program))
425
+ .action((...fnArgs) => __awaiter(this, void 0, void 0, function* () {
426
+ debug('running Cypress with args %o', fnArgs);
427
+ try {
428
+ const code = yield run_1.default.start(parseVariableOpts(fnArgs, args));
429
+ process.exit(code);
430
+ }
431
+ catch (e) {
432
+ util_1.default.logErrorExit1(e);
433
+ }
434
+ }));
435
+ program
436
+ .command('install')
437
+ .usage('[options]')
438
+ .description('Installs the Cypress executable matching this package\'s version')
439
+ .option('-f, --force', text('forceInstall'))
440
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
441
+ try {
442
+ yield install_1.default.start(util_1.default.parseOpts(opts));
443
+ }
444
+ catch (e) {
445
+ util_1.default.logErrorExit1(e);
446
+ }
447
+ }));
448
+ program
449
+ .command('verify')
450
+ .usage('[options]')
451
+ .description('Verifies that Cypress is installed correctly and executable')
452
+ .option('--dev', text('dev'), coerceFalse)
453
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
454
+ const defaultOpts = { force: true, welcomeMessage: false };
455
+ const parsedOpts = util_1.default.parseOpts(opts);
456
+ const options = lodash_1.default.extend(parsedOpts, defaultOpts);
457
+ try {
458
+ yield (0, verify_1.start)(options);
459
+ }
460
+ catch (e) {
461
+ util_1.default.logErrorExit1(e);
462
+ }
463
+ }));
464
+ program
465
+ .command('cache')
466
+ .usage('[command]')
467
+ .description('Manages the Cypress binary cache')
468
+ .option('list', text('cacheList'))
469
+ .option('path', text('cachePath'))
470
+ .option('clear', text('cacheClear'))
471
+ .option('prune', text('cachePrune'))
472
+ .option('--size', text('cacheSize'))
473
+ .action(function (opts, args) {
474
+ return __awaiter(this, void 0, void 0, function* () {
475
+ if (!args || !args.length) {
476
+ this.outputHelp();
477
+ process.exit(1);
478
+ }
479
+ const [command] = args;
480
+ if (!lodash_1.default.includes(['list', 'path', 'clear', 'prune'], command)) {
481
+ unknownOption.call(this, `cache ${command}`, 'command');
482
+ }
483
+ if (command === 'list') {
484
+ debug('cache command %o', {
485
+ command,
486
+ size: opts.size,
487
+ });
488
+ try {
489
+ const result = yield cache_1.default.list(opts.size);
490
+ return result;
491
+ }
492
+ catch (e) {
493
+ if (e.code === 'ENOENT') {
494
+ logger_1.default.always('No cached binary versions were found.');
495
+ process.exit(0);
496
+ }
497
+ util_1.default.logErrorExit1(e);
498
+ }
499
+ }
500
+ cache_1.default[command]();
501
+ });
502
+ });
503
+ program
504
+ .command('info')
505
+ .usage('[command]')
506
+ .description('Prints Cypress and system information')
507
+ .option('--dev', text('dev'), coerceFalse)
508
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
509
+ try {
510
+ const code = yield info_1.default.start(opts);
511
+ process.exit(code);
512
+ }
513
+ catch (e) {
514
+ util_1.default.logErrorExit1(e);
515
+ }
516
+ }));
517
+ debug('cli starts with arguments %j', args);
518
+ util_1.default.printNodeOptions();
519
+ // if there are no arguments
520
+ if (args.length <= 2) {
521
+ debug('printing help');
522
+ program.help();
523
+ // exits
524
+ }
525
+ const firstCommand = args[2];
526
+ if (!lodash_1.default.includes(knownCommands, firstCommand)) {
527
+ debug('unknown command %s', firstCommand);
528
+ logger_1.default.error('Unknown command', `"${firstCommand}"`);
529
+ program.outputHelp();
530
+ return process.exit(1);
531
+ }
532
+ if (includesVersion(args)) {
533
+ // commander 2.11.0 changes behavior
534
+ // and now does not understand top level options
535
+ // .option('-v, --version').command('version')
536
+ // so we have to manually catch '-v, --version'
537
+ handleVersion(program);
538
+ }
539
+ debug('program parsing arguments');
540
+ return program.parse(args);
541
+ });
542
+ },
543
+ };
544
+ exports.default = cliModule;