cypress 4.9.0 → 4.12.1

Sign up to get free protection for your applications and to get access to all the features.
package/lib/cli.js CHANGED
@@ -1,5 +1,13 @@
1
1
  "use strict";
2
2
 
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+
5
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
8
+
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+
3
11
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
12
 
5
13
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -14,6 +22,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
22
 
15
23
  var _ = require('lodash');
16
24
 
25
+ var R = require('ramda');
26
+
17
27
  var commander = require('commander');
18
28
 
19
29
  var _require = require('common-tags'),
@@ -49,6 +59,10 @@ var coerceFalse = function coerceFalse(arg) {
49
59
  return arg !== 'false';
50
60
  };
51
61
 
62
+ var coerceAnyStringToInt = function coerceAnyStringToInt(arg) {
63
+ return typeof arg === 'string' ? parseInt(arg) : arg;
64
+ };
65
+
52
66
  var spaceDelimitedArgsMsg = function spaceDelimitedArgsMsg(flag, args) {
53
67
  var msg = "\n ".concat(logSymbols.warning, " Warning: It looks like you're passing --").concat(flag, " a space-separated list of arguments:\n\n \"").concat(args.join(' '), "\"\n\n This will work, but it's not recommended.\n\n If you are trying to pass multiple arguments, separate them with commas instead:\n cypress run --").concat(flag, " arg1,arg2,arg3\n ");
54
68
 
@@ -155,7 +169,79 @@ function showVersions() {
155
169
  })["catch"](util.logErrorExit1);
156
170
  }
157
171
 
172
+ var createProgram = function createProgram() {
173
+ var program = new commander.Command(); // bug in commander not printing name
174
+ // in usage help docs
175
+
176
+ program._name = 'cypress';
177
+ program.usage('<command> [options]');
178
+ return program;
179
+ };
180
+
181
+ var addCypressRunCommand = function addCypressRunCommand(program) {
182
+ return program.command('run').usage('[options]').description('Runs Cypress tests from the CLI without the GUI').option('-b, --browser <browser-name-or-path>', text('browserRunMode')).option('--ci-build-id <id>', text('ciBuildId')).option('-c, --config <config>', text('config')).option('-C, --config-file <config-file>', text('configFile')).option('-e, --env <env>', text('env')).option('--group <name>', text('group')).option('-k, --key <record-key>', text('key')).option('--headed', text('headed')).option('--headless', text('headless')).option('--no-exit', text('exit')).option('--parallel', text('parallel')).option('-p, --port <port>', text('port')).option('-P, --project <project-path>', text('project')).option('-q, --quiet', text('quiet')).option('--record [bool]', text('record'), coerceFalse).option('-r, --reporter <reporter>', text('reporter')).option('-o, --reporter-options <reporter-options>', text('reporterOptions')).option('-s, --spec <spec>', text('spec')).option('-t, --tag <tag>', text('tag')).option('--dev', text('dev'), coerceFalse);
183
+ };
184
+ /**
185
+ * Casts known command line options for "cypress run" to their intended type.
186
+ * For example if the user passes "--port 5005" the ".port" property should be
187
+ * a number 5005 and not a string "5005".
188
+ *
189
+ * Returns a clone of the original object.
190
+ */
191
+
192
+
193
+ var castCypressRunOptions = function castCypressRunOptions(opts) {
194
+ // only properties that have type "string | false" in our TS definition
195
+ // require special handling, because CLI parsing takes care of purely
196
+ // boolean arguments
197
+ var result = R.evolve({
198
+ port: coerceAnyStringToInt,
199
+ configFile: coerceFalse
200
+ })(opts);
201
+ return result;
202
+ };
203
+
158
204
  module.exports = {
205
+ /**
206
+ * Parses `cypress run` command line option array into an object
207
+ * with options that you can feed into a `cypress.run()` module API call.
208
+ * @example
209
+ * const options = parseRunCommand(['cypress', 'run', '--browser', 'chrome'])
210
+ * // options is {browser: 'chrome'}
211
+ */
212
+ parseRunCommand: function parseRunCommand(args) {
213
+ return new Promise(function (resolve, reject) {
214
+ if (!Array.isArray(args)) {
215
+ return reject(new Error('Expected array of arguments'));
216
+ } // make a copy of the input arguments array
217
+ // and add placeholders where "node ..." would usually be
218
+ // also remove "cypress" keyword at the start if present
219
+
220
+
221
+ var cliArgs = args[0] === 'cypress' ? _toConsumableArray(args.slice(1)) : _toConsumableArray(args);
222
+ cliArgs.unshift(null, null);
223
+ debug('creating program parser');
224
+ var program = createProgram();
225
+ addCypressRunCommand(program).action(function () {
226
+ for (var _len = arguments.length, fnArgs = new Array(_len), _key = 0; _key < _len; _key++) {
227
+ fnArgs[_key] = arguments[_key];
228
+ }
229
+
230
+ debug('parsed Cypress run %o', fnArgs);
231
+ var options = parseVariableOpts(fnArgs, cliArgs);
232
+ debug('parsed options %o', options);
233
+ var casted = castCypressRunOptions(options);
234
+ debug('casted options %o', casted);
235
+ resolve(casted);
236
+ });
237
+ debug('parsing args: %o', cliArgs);
238
+ program.parse(cliArgs);
239
+ });
240
+ },
241
+
242
+ /**
243
+ * Parses the command line and kicks off Cypress process.
244
+ */
159
245
  init: function init(args) {
160
246
  if (!args) {
161
247
  args = process.argv;
@@ -176,18 +262,14 @@ module.exports = {
176
262
  logger.log();
177
263
  }
178
264
 
179
- var program = new commander.Command(); // bug in commander not printing name
180
- // in usage help docs
181
-
182
- program._name = 'cypress';
183
- program.usage('<command> [options]');
265
+ var program = createProgram();
184
266
  program.command('help').description('Shows CLI help and exits').action(function () {
185
267
  program.help();
186
268
  });
187
269
  program.option('-v, --version', text('version')).command('version').description(text('version')).action(showVersions);
188
- program.command('run').usage('[options]').description('Runs Cypress tests from the CLI without the GUI').option('-b, --browser <browser-name-or-path>', text('browserRunMode')).option('--ci-build-id <id>', text('ciBuildId')).option('-c, --config <config>', text('config')).option('-C, --config-file <config-file>', text('configFile')).option('-e, --env <env>', text('env')).option('--group <name>', text('group')).option('-k, --key <record-key>', text('key')).option('--headed', text('headed')).option('--headless', text('headless')).option('--no-exit', text('exit')).option('--parallel', text('parallel')).option('-p, --port <port>', text('port')).option('-P, --project <project-path>', text('project')).option('-q, --quiet', text('quiet')).option('--record [bool]', text('record'), coerceFalse).option('-r, --reporter <reporter>', text('reporter')).option('-o, --reporter-options <reporter-options>', text('reporterOptions')).option('-s, --spec <spec>', text('spec')).option('-t, --tag <tag>', text('tag')).option('--dev', text('dev'), coerceFalse).action(function () {
189
- for (var _len = arguments.length, fnArgs = new Array(_len), _key = 0; _key < _len; _key++) {
190
- fnArgs[_key] = arguments[_key];
270
+ addCypressRunCommand(program).action(function () {
271
+ for (var _len2 = arguments.length, fnArgs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
272
+ fnArgs[_key2] = arguments[_key2];
191
273
  }
192
274
 
193
275
  debug('running Cypress with args %o', fnArgs);
package/lib/cypress.js CHANGED
@@ -13,6 +13,8 @@ var _run = require('./exec/run');
13
13
 
14
14
  var util = require('./util');
15
15
 
16
+ var cli = require('./cli');
17
+
16
18
  var cypressModuleApi = {
17
19
  /**
18
20
  * Opens Cypress GUI
@@ -53,6 +55,21 @@ var cypressModuleApi = {
53
55
  });
54
56
  });
55
57
  });
58
+ },
59
+ cli: {
60
+ /**
61
+ * Parses CLI arguments into an object that you can pass to "cypress.run"
62
+ * @example
63
+ * const cypress = require('cypress')
64
+ * const cli = ['cypress', 'run', '--browser', 'firefox']
65
+ * const options = await cypress.cli.parseRunArguments(cli)
66
+ * // options is {browser: 'firefox'}
67
+ * await cypress.run(options)
68
+ * @see https://on.cypress.io/module-api
69
+ */
70
+ parseRunArguments: function parseRunArguments(args) {
71
+ return cli.parseRunCommand(args);
72
+ }
56
73
  }
57
74
  };
58
75
  module.exports = cypressModuleApi;
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
1
  {
2
2
  "name": "cypress",
3
- "version": "4.9.0",
3
+ "version": "4.12.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "postinstall": "node index.js --exec install",
7
7
  "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";"
8
8
  },
9
9
  "dependencies": {
10
- "@cypress/listr-verbose-renderer": "0.4.1",
11
- "@cypress/request": "2.88.5",
12
- "@cypress/xvfb": "1.2.4",
13
- "@types/sinonjs__fake-timers": "6.0.1",
14
- "@types/sizzle": "2.3.2",
15
- "arch": "2.1.2",
16
- "bluebird": "3.7.2",
17
- "cachedir": "2.3.0",
18
- "chalk": "2.4.2",
19
- "check-more-types": "2.24.0",
20
- "cli-table3": "0.5.1",
21
- "commander": "4.1.1",
22
- "common-tags": "1.8.0",
23
- "debug": "4.1.1",
24
- "eventemitter2": "6.4.2",
25
- "execa": "1.0.0",
26
- "executable": "4.1.1",
27
- "extract-zip": "1.7.0",
28
- "fs-extra": "8.1.0",
29
- "getos": "3.2.1",
30
- "is-ci": "2.0.0",
31
- "is-installed-globally": "0.3.2",
32
- "lazy-ass": "1.6.0",
33
- "listr": "0.14.3",
34
- "lodash": "4.17.15",
35
- "log-symbols": "3.0.0",
36
- "minimist": "1.2.5",
37
- "moment": "2.26.0",
38
- "ospath": "1.2.2",
39
- "pretty-bytes": "5.3.0",
40
- "ramda": "0.26.1",
41
- "request-progress": "3.0.0",
42
- "supports-color": "7.1.0",
43
- "tmp": "0.1.0",
44
- "untildify": "4.0.0",
45
- "url": "0.11.0",
46
- "yauzl": "2.10.0"
10
+ "@cypress/listr-verbose-renderer": "^0.4.1",
11
+ "@cypress/request": "^2.88.5",
12
+ "@cypress/xvfb": "^1.2.4",
13
+ "@types/sinonjs__fake-timers": "^6.0.1",
14
+ "@types/sizzle": "^2.3.2",
15
+ "arch": "^2.1.2",
16
+ "bluebird": "^3.7.2",
17
+ "cachedir": "^2.3.0",
18
+ "chalk": "^2.4.2",
19
+ "check-more-types": "^2.24.0",
20
+ "cli-table3": "~0.5.1",
21
+ "commander": "^4.1.1",
22
+ "common-tags": "^1.8.0",
23
+ "debug": "^4.1.1",
24
+ "eventemitter2": "^6.4.2",
25
+ "execa": "^1.0.0",
26
+ "executable": "^4.1.1",
27
+ "extract-zip": "^1.7.0",
28
+ "fs-extra": "^8.1.0",
29
+ "getos": "^3.2.1",
30
+ "is-ci": "^2.0.0",
31
+ "is-installed-globally": "^0.3.2",
32
+ "lazy-ass": "^1.6.0",
33
+ "listr": "^0.14.3",
34
+ "lodash": "^4.17.19",
35
+ "log-symbols": "^3.0.0",
36
+ "minimist": "^1.2.5",
37
+ "moment": "^2.27.0",
38
+ "ospath": "^1.2.2",
39
+ "pretty-bytes": "^5.3.0",
40
+ "ramda": "~0.26.1",
41
+ "request-progress": "^3.0.0",
42
+ "supports-color": "^7.1.0",
43
+ "tmp": "~0.1.0",
44
+ "untildify": "^4.0.0",
45
+ "url": "^0.11.0",
46
+ "yauzl": "^2.10.0"
47
47
  },
48
48
  "files": [
49
49
  "bin",
@@ -6,7 +6,7 @@
6
6
  // in the future the NPM module itself will be in TypeScript
7
7
  // but for now describe it as an ambient module
8
8
 
9
- declare module 'cypress' {
9
+ declare namespace CypressCommandLine {
10
10
  /**
11
11
  * All options that one can pass to "cypress.run"
12
12
  * @see https://on.cypress.io/module-api#cypress-run
@@ -306,6 +306,27 @@ declare module 'cypress' {
306
306
  message: string
307
307
  }
308
308
 
309
+ /**
310
+ * Methods allow parsing given CLI arguments the same way Cypress CLI does it.
311
+ */
312
+ interface CypressCliParser {
313
+ /**
314
+ * Parses the given array of string arguments to "cypress run"
315
+ * just like Cypress CLI does it.
316
+ * @see https://on.cypress.io/module-api
317
+ * @example
318
+ * const cypress = require('cypress')
319
+ * const args = ['cypress', 'run', '--browser', 'chrome']
320
+ * const options = await cypress.cli.parseRunArguments(args)
321
+ * // options is {browser: 'chrome'}
322
+ * // pass the options to cypress.run()
323
+ * const results = await cypress.run(options)
324
+ */
325
+ parseRunArguments(args: string[]): Promise<Partial<CypressRunOptions>>
326
+ }
327
+ }
328
+
329
+ declare module 'cypress' {
309
330
  /**
310
331
  * Cypress NPM module interface.
311
332
  * @see https://on.cypress.io/module-api
@@ -330,13 +351,19 @@ declare module 'cypress' {
330
351
  })
331
352
  ```
332
353
  */
333
- run(options?: Partial<CypressRunOptions>): Promise<CypressRunResult | CypressFailedRunResult>,
354
+ run(options?: Partial<CypressCommandLine.CypressRunOptions>): Promise<CypressCommandLine.CypressRunResult | CypressCommandLine.CypressFailedRunResult>,
334
355
  /**
335
356
  * Opens Cypress GUI. Resolves with void when the
336
357
  * GUI is closed.
337
358
  * @see https://on.cypress.io/module-api#cypress-open
338
359
  */
339
- open(options?: Partial<CypressOpenOptions>): Promise<void>
360
+ open(options?: Partial<CypressCommandLine.CypressOpenOptions>): Promise<void>
361
+
362
+ /**
363
+ * Utility functions for parsing CLI arguments the same way
364
+ * Cypress does
365
+ */
366
+ cli: CypressCommandLine.CypressCliParser
340
367
  }
341
368
 
342
369
  // export Cypress NPM module interface