cypress 5.1.0 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +6 -6
- package/lib/cli.js +114 -107
- package/lib/cypress.js +21 -21
- package/lib/errors.js +233 -276
- package/lib/exec/info.js +29 -32
- package/lib/exec/open.js +7 -8
- package/lib/exec/run.js +20 -20
- package/lib/exec/spawn.js +53 -49
- package/lib/exec/versions.js +18 -17
- package/lib/exec/xvfb.js +43 -37
- package/lib/fs.js +1 -1
- package/lib/logger.js +24 -50
- package/lib/tasks/cache.js +96 -36
- package/lib/tasks/download.js +113 -133
- package/lib/tasks/get-folder-size.js +41 -0
- package/lib/tasks/install.js +225 -161
- package/lib/tasks/state.js +54 -56
- package/lib/tasks/unzip.js +72 -69
- package/lib/tasks/verify.js +112 -147
- package/lib/util.js +172 -176
- package/package.json +3 -3
- package/types/cypress-npm-api.d.ts +13 -5
- package/types/cypress.d.ts +51 -48
- package/types/mocha/index.d.ts +123 -308
- package/types/net-stubbing.ts +169 -19
package/index.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
|
3
|
+
const minimist = require('minimist');
|
4
4
|
|
5
|
-
|
5
|
+
const debug = require('debug')('cypress:cli');
|
6
6
|
|
7
|
-
|
7
|
+
const args = minimist(process.argv.slice(2));
|
8
8
|
|
9
|
-
|
9
|
+
const util = require('./lib/util'); // we're being used from the command line
|
10
10
|
|
11
11
|
|
12
12
|
switch (args.exec) {
|
@@ -15,7 +15,7 @@ switch (args.exec) {
|
|
15
15
|
|
16
16
|
require('./lib/tasks/install').start({
|
17
17
|
force: args.force
|
18
|
-
})
|
18
|
+
}).catch(util.logErrorExit1);
|
19
19
|
|
20
20
|
break;
|
21
21
|
|
@@ -26,7 +26,7 @@ switch (args.exec) {
|
|
26
26
|
require('./lib/tasks/verify').start({
|
27
27
|
force: true
|
28
28
|
}) // always force verification
|
29
|
-
|
29
|
+
.catch(util.logErrorExit1);
|
30
30
|
|
31
31
|
break;
|
32
32
|
|
package/lib/cli.js
CHANGED
@@ -1,53 +1,33 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
|
3
|
+
const _ = require('lodash');
|
4
4
|
|
5
|
-
|
5
|
+
const R = require('ramda');
|
6
6
|
|
7
|
-
|
7
|
+
const commander = require('commander');
|
8
8
|
|
9
|
-
|
9
|
+
const {
|
10
|
+
stripIndent
|
11
|
+
} = require('common-tags');
|
10
12
|
|
11
|
-
|
13
|
+
const logSymbols = require('log-symbols');
|
12
14
|
|
13
|
-
|
15
|
+
const debug = require('debug')('cypress:cli:cli');
|
14
16
|
|
15
|
-
|
17
|
+
const util = require('./util');
|
16
18
|
|
17
|
-
|
19
|
+
const logger = require('./logger');
|
18
20
|
|
19
|
-
|
21
|
+
const errors = require('./errors');
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
var _ = require('lodash');
|
24
|
-
|
25
|
-
var R = require('ramda');
|
26
|
-
|
27
|
-
var commander = require('commander');
|
28
|
-
|
29
|
-
var _require = require('common-tags'),
|
30
|
-
stripIndent = _require.stripIndent;
|
31
|
-
|
32
|
-
var logSymbols = require('log-symbols');
|
33
|
-
|
34
|
-
var debug = require('debug')('cypress:cli:cli');
|
35
|
-
|
36
|
-
var util = require('./util');
|
37
|
-
|
38
|
-
var logger = require('./logger');
|
39
|
-
|
40
|
-
var errors = require('./errors');
|
41
|
-
|
42
|
-
var cache = require('./tasks/cache'); // patch "commander" method called when a user passed an unknown option
|
23
|
+
const cache = require('./tasks/cache'); // patch "commander" method called when a user passed an unknown option
|
43
24
|
// we want to print help for the current command and exit with an error
|
44
25
|
|
45
26
|
|
46
|
-
function unknownOption(flag) {
|
47
|
-
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'option';
|
27
|
+
function unknownOption(flag, type = 'option') {
|
48
28
|
if (this._allowUnknownOption) return;
|
49
29
|
logger.error();
|
50
|
-
logger.error(
|
30
|
+
logger.error(` error: unknown ${type}:`, flag);
|
51
31
|
logger.error();
|
52
32
|
this.outputHelp();
|
53
33
|
util.exit(1);
|
@@ -55,19 +35,36 @@ function unknownOption(flag) {
|
|
55
35
|
|
56
36
|
commander.Command.prototype.unknownOption = unknownOption;
|
57
37
|
|
58
|
-
|
38
|
+
const coerceFalseOrString = arg => {
|
39
|
+
return arg !== 'false' ? arg : false;
|
40
|
+
};
|
41
|
+
|
42
|
+
const coerceFalse = arg => {
|
59
43
|
return arg !== 'false';
|
60
44
|
};
|
61
45
|
|
62
|
-
|
46
|
+
const coerceAnyStringToInt = arg => {
|
63
47
|
return typeof arg === 'string' ? parseInt(arg) : arg;
|
64
48
|
};
|
65
49
|
|
66
|
-
|
67
|
-
|
50
|
+
const spaceDelimitedArgsMsg = (flag, args) => {
|
51
|
+
let msg = `
|
52
|
+
${logSymbols.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
|
+
`;
|
68
61
|
|
69
62
|
if (flag === 'spec') {
|
70
|
-
msg +=
|
63
|
+
msg += `
|
64
|
+
The most common cause of this warning is using an unescaped glob pattern. If you are
|
65
|
+
trying to pass a glob pattern, escape it using quotes:
|
66
|
+
cypress run --spec "**/*.spec.js"
|
67
|
+
`;
|
71
68
|
}
|
72
69
|
|
73
70
|
logger.log();
|
@@ -75,30 +72,28 @@ var spaceDelimitedArgsMsg = function spaceDelimitedArgsMsg(flag, args) {
|
|
75
72
|
logger.log();
|
76
73
|
};
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
opts = _fnArgs[0],
|
81
|
-
unknownArgs = _fnArgs[1];
|
75
|
+
const parseVariableOpts = (fnArgs, args) => {
|
76
|
+
const [opts, unknownArgs] = fnArgs;
|
82
77
|
|
83
78
|
if (unknownArgs && unknownArgs.length && (opts.spec || opts.tag)) {
|
84
79
|
// this will capture space-delimited args after
|
85
80
|
// flags that could have possible multiple args
|
86
81
|
// but before the next option
|
87
82
|
// --spec spec1 spec2 or --tag foo bar
|
88
|
-
|
83
|
+
const multiArgFlags = _.compact([opts.spec ? 'spec' : opts.spec, opts.tag ? 'tag' : opts.tag]);
|
89
84
|
|
90
|
-
_.forEach(multiArgFlags,
|
91
|
-
|
85
|
+
_.forEach(multiArgFlags, flag => {
|
86
|
+
const argIndex = _.indexOf(args, `--${flag}`) + 2;
|
92
87
|
|
93
|
-
|
88
|
+
const nextOptOffset = _.findIndex(_.slice(args, argIndex), arg => {
|
94
89
|
return _.startsWith(arg, '--');
|
95
90
|
});
|
96
91
|
|
97
|
-
|
92
|
+
const endIndex = nextOptOffset !== -1 ? argIndex + nextOptOffset : args.length;
|
98
93
|
|
99
|
-
|
94
|
+
const maybeArgs = _.slice(args, argIndex, endIndex);
|
100
95
|
|
101
|
-
|
96
|
+
const extraArgs = _.intersection(maybeArgs, unknownArgs);
|
102
97
|
|
103
98
|
if (extraArgs.length) {
|
104
99
|
opts[flag] = [opts[flag]].concat(extraArgs);
|
@@ -109,18 +104,20 @@ var parseVariableOpts = function parseVariableOpts(fnArgs, args) {
|
|
109
104
|
}
|
110
105
|
|
111
106
|
debug('variable-length opts parsed %o', {
|
112
|
-
args
|
113
|
-
opts
|
107
|
+
args,
|
108
|
+
opts
|
114
109
|
});
|
115
110
|
return util.parseOpts(opts);
|
116
111
|
};
|
117
112
|
|
118
|
-
|
113
|
+
const descriptions = {
|
119
114
|
browserOpenMode: 'path to a custom browser to be added to the list of available browsers in Cypress',
|
120
115
|
browserRunMode: '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.',
|
121
116
|
cacheClear: 'delete all cached binaries',
|
117
|
+
cachePrune: 'deletes all cached binaries except for the version currently in use',
|
122
118
|
cacheList: 'list cached binary versions',
|
123
119
|
cachePath: 'print the path to the binary cache',
|
120
|
+
cacheSize: 'Used with the list command to show the sizes of the cached folders',
|
124
121
|
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',
|
125
122
|
config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.',
|
126
123
|
configFile: 'path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.',
|
@@ -145,11 +142,11 @@ var descriptions = {
|
|
145
142
|
tag: 'named tag(s) for recorded runs in the Cypress Dashboard',
|
146
143
|
version: 'prints Cypress version'
|
147
144
|
};
|
148
|
-
|
145
|
+
const knownCommands = ['cache', 'help', '-h', '--help', 'install', 'open', 'run', 'verify', '-v', '--version', 'version', 'info'];
|
149
146
|
|
150
|
-
|
147
|
+
const text = description => {
|
151
148
|
if (!descriptions[description]) {
|
152
|
-
throw new Error(
|
149
|
+
throw new Error(`Could not find description for: ${description}`);
|
153
150
|
}
|
154
151
|
|
155
152
|
return descriptions[description];
|
@@ -161,16 +158,15 @@ function includesVersion(args) {
|
|
161
158
|
|
162
159
|
function showVersions() {
|
163
160
|
debug('printing Cypress version');
|
164
|
-
return require('./exec/versions').getVersions().then(
|
165
|
-
|
166
|
-
logger.always('Cypress package version:', versions["package"]);
|
161
|
+
return require('./exec/versions').getVersions().then((versions = {}) => {
|
162
|
+
logger.always('Cypress package version:', versions.package);
|
167
163
|
logger.always('Cypress binary version:', versions.binary);
|
168
164
|
process.exit(0);
|
169
|
-
})
|
165
|
+
}).catch(util.logErrorExit1);
|
170
166
|
}
|
171
167
|
|
172
|
-
|
173
|
-
|
168
|
+
const createProgram = () => {
|
169
|
+
const program = new commander.Command(); // bug in commander not printing name
|
174
170
|
// in usage help docs
|
175
171
|
|
176
172
|
program._name = 'cypress';
|
@@ -178,7 +174,7 @@ var createProgram = function createProgram() {
|
|
178
174
|
return program;
|
179
175
|
};
|
180
176
|
|
181
|
-
|
177
|
+
const addCypressRunCommand = program => {
|
182
178
|
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
179
|
};
|
184
180
|
/**
|
@@ -190,13 +186,13 @@ var addCypressRunCommand = function addCypressRunCommand(program) {
|
|
190
186
|
*/
|
191
187
|
|
192
188
|
|
193
|
-
|
189
|
+
const castCypressRunOptions = opts => {
|
194
190
|
// only properties that have type "string | false" in our TS definition
|
195
191
|
// require special handling, because CLI parsing takes care of purely
|
196
192
|
// boolean arguments
|
197
|
-
|
193
|
+
const result = R.evolve({
|
198
194
|
port: coerceAnyStringToInt,
|
199
|
-
configFile:
|
195
|
+
configFile: coerceFalseOrString
|
200
196
|
})(opts);
|
201
197
|
return result;
|
202
198
|
};
|
@@ -209,8 +205,8 @@ module.exports = {
|
|
209
205
|
* const options = parseRunCommand(['cypress', 'run', '--browser', 'chrome'])
|
210
206
|
* // options is {browser: 'chrome'}
|
211
207
|
*/
|
212
|
-
parseRunCommand
|
213
|
-
return new Promise(
|
208
|
+
parseRunCommand(args) {
|
209
|
+
return new Promise((resolve, reject) => {
|
214
210
|
if (!Array.isArray(args)) {
|
215
211
|
return reject(new Error('Expected array of arguments'));
|
216
212
|
} // make a copy of the input arguments array
|
@@ -218,19 +214,15 @@ module.exports = {
|
|
218
214
|
// also remove "cypress" keyword at the start if present
|
219
215
|
|
220
216
|
|
221
|
-
|
217
|
+
const cliArgs = args[0] === 'cypress' ? [...args.slice(1)] : [...args];
|
222
218
|
cliArgs.unshift(null, null);
|
223
219
|
debug('creating program parser');
|
224
|
-
|
225
|
-
addCypressRunCommand(program).action(
|
226
|
-
for (var _len = arguments.length, fnArgs = new Array(_len), _key = 0; _key < _len; _key++) {
|
227
|
-
fnArgs[_key] = arguments[_key];
|
228
|
-
}
|
229
|
-
|
220
|
+
const program = createProgram();
|
221
|
+
addCypressRunCommand(program).action((...fnArgs) => {
|
230
222
|
debug('parsed Cypress run %o', fnArgs);
|
231
|
-
|
223
|
+
const options = parseVariableOpts(fnArgs, cliArgs);
|
232
224
|
debug('parsed options %o', options);
|
233
|
-
|
225
|
+
const casted = castCypressRunOptions(options);
|
234
226
|
debug('casted options %o', casted);
|
235
227
|
resolve(casted);
|
236
228
|
});
|
@@ -242,76 +234,90 @@ module.exports = {
|
|
242
234
|
/**
|
243
235
|
* Parses the command line and kicks off Cypress process.
|
244
236
|
*/
|
245
|
-
init
|
237
|
+
init(args) {
|
246
238
|
if (!args) {
|
247
239
|
args = process.argv;
|
248
240
|
}
|
249
241
|
|
250
|
-
|
242
|
+
const {
|
243
|
+
CYPRESS_INTERNAL_ENV
|
244
|
+
} = process.env;
|
251
245
|
|
252
246
|
if (!util.isValidCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
|
253
247
|
debug('invalid CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
|
254
|
-
return errors.exitWithError(errors.errors.invalidCypressEnv)(
|
248
|
+
return errors.exitWithError(errors.errors.invalidCypressEnv)(`CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}`);
|
255
249
|
}
|
256
250
|
|
257
251
|
if (util.isNonProductionCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
|
258
252
|
debug('non-production CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
|
259
|
-
|
253
|
+
let msg = `
|
254
|
+
${logSymbols.warning} Warning: It looks like you're passing CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}
|
255
|
+
|
256
|
+
The environment variable "CYPRESS_INTERNAL_ENV" is reserved and should only be used internally.
|
257
|
+
|
258
|
+
Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.
|
259
|
+
`;
|
260
260
|
logger.log();
|
261
261
|
logger.warn(stripIndent(msg));
|
262
262
|
logger.log();
|
263
263
|
}
|
264
264
|
|
265
|
-
|
266
|
-
program.command('help').description('Shows CLI help and exits').action(
|
265
|
+
const program = createProgram();
|
266
|
+
program.command('help').description('Shows CLI help and exits').action(() => {
|
267
267
|
program.help();
|
268
268
|
});
|
269
269
|
program.option('-v, --version', text('version')).command('version').description(text('version')).action(showVersions);
|
270
|
-
addCypressRunCommand(program).action(
|
271
|
-
for (var _len2 = arguments.length, fnArgs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
272
|
-
fnArgs[_key2] = arguments[_key2];
|
273
|
-
}
|
274
|
-
|
270
|
+
addCypressRunCommand(program).action((...fnArgs) => {
|
275
271
|
debug('running Cypress with args %o', fnArgs);
|
276
272
|
|
277
|
-
require('./exec/run').start(parseVariableOpts(fnArgs, args)).then(util.exit)
|
273
|
+
require('./exec/run').start(parseVariableOpts(fnArgs, args)).then(util.exit).catch(util.logErrorExit1);
|
278
274
|
});
|
279
|
-
program.command('open').usage('[options]').description('Opens Cypress in the interactive GUI.').option('-b, --browser <browser-path>', text('browserOpenMode')).option('-c, --config <config>', text('config')).option('-C, --config-file <config-file>', text('configFile')).option('-d, --detached [bool]', text('detached'), coerceFalse).option('-e, --env <env>', text('env')).option('--global', text('global')).option('-p, --port <port>', text('port')).option('-P, --project <project-path>', text('project')).option('--dev', text('dev'), coerceFalse).action(
|
275
|
+
program.command('open').usage('[options]').description('Opens Cypress in the interactive GUI.').option('-b, --browser <browser-path>', text('browserOpenMode')).option('-c, --config <config>', text('config')).option('-C, --config-file <config-file>', text('configFile')).option('-d, --detached [bool]', text('detached'), coerceFalse).option('-e, --env <env>', text('env')).option('--global', text('global')).option('-p, --port <port>', text('port')).option('-P, --project <project-path>', text('project')).option('--dev', text('dev'), coerceFalse).action(opts => {
|
280
276
|
debug('opening Cypress');
|
281
277
|
|
282
|
-
require('./exec/open').start(util.parseOpts(opts))
|
278
|
+
require('./exec/open').start(util.parseOpts(opts)).catch(util.logErrorExit1);
|
283
279
|
});
|
284
|
-
program.command('install').usage('[options]').description('Installs the Cypress executable matching this package\'s version').option('-f, --force', text('forceInstall')).action(
|
285
|
-
require('./tasks/install').start(util.parseOpts(opts))
|
280
|
+
program.command('install').usage('[options]').description('Installs the Cypress executable matching this package\'s version').option('-f, --force', text('forceInstall')).action(opts => {
|
281
|
+
require('./tasks/install').start(util.parseOpts(opts)).catch(util.logErrorExit1);
|
286
282
|
});
|
287
|
-
program.command('verify').usage('[options]').description('Verifies that Cypress is installed correctly and executable').option('--dev', text('dev'), coerceFalse).action(
|
288
|
-
|
283
|
+
program.command('verify').usage('[options]').description('Verifies that Cypress is installed correctly and executable').option('--dev', text('dev'), coerceFalse).action(opts => {
|
284
|
+
const defaultOpts = {
|
289
285
|
force: true,
|
290
286
|
welcomeMessage: false
|
291
287
|
};
|
292
|
-
|
288
|
+
const parsedOpts = util.parseOpts(opts);
|
293
289
|
|
294
|
-
|
290
|
+
const options = _.extend(parsedOpts, defaultOpts);
|
295
291
|
|
296
|
-
require('./tasks/verify').start(options)
|
292
|
+
require('./tasks/verify').start(options).catch(util.logErrorExit1);
|
297
293
|
});
|
298
|
-
program.command('cache').usage('[command]').description('Manages the Cypress binary cache').option('list', text('cacheList')).option('path', text('cachePath')).option('clear', text('cacheClear')).action(function (opts, args) {
|
294
|
+
program.command('cache').usage('[command]').description('Manages the Cypress binary cache').option('list', text('cacheList')).option('path', text('cachePath')).option('clear', text('cacheClear')).option('prune', text('cachePrune')).option('--size', text('cacheSize')).action(function (opts, args) {
|
299
295
|
if (!args || !args.length) {
|
300
296
|
this.outputHelp();
|
301
297
|
util.exit(1);
|
302
298
|
}
|
303
299
|
|
304
|
-
|
305
|
-
command = _args[0];
|
300
|
+
const [command] = args;
|
306
301
|
|
307
|
-
if (!_.includes(['list', 'path', 'clear'], command)) {
|
308
|
-
unknownOption.call(this,
|
302
|
+
if (!_.includes(['list', 'path', 'clear', 'prune'], command)) {
|
303
|
+
unknownOption.call(this, `cache ${command}`, 'command');
|
304
|
+
}
|
305
|
+
|
306
|
+
if (command === 'list') {
|
307
|
+
debug('cache command %o', {
|
308
|
+
command,
|
309
|
+
size: opts.size
|
310
|
+
});
|
311
|
+
return cache.list(opts.size).catch(e => {
|
312
|
+
debug('cache list command failed with "%s"', e.message);
|
313
|
+
util.logErrorExit1(e);
|
314
|
+
});
|
309
315
|
}
|
310
316
|
|
311
317
|
cache[command]();
|
312
318
|
});
|
313
|
-
program.command('info').usage('[command]').description('Prints Cypress and system information').option('--dev', text('dev'), coerceFalse).action(
|
314
|
-
require('./exec/info').start(opts).then(util.exit)
|
319
|
+
program.command('info').usage('[command]').description('Prints Cypress and system information').option('--dev', text('dev'), coerceFalse).action(opts => {
|
320
|
+
require('./exec/info').start(opts).then(util.exit).catch(util.logErrorExit1);
|
315
321
|
});
|
316
322
|
debug('cli starts with arguments %j', args);
|
317
323
|
util.printNodeOptions(); // if there are no arguments
|
@@ -321,11 +327,11 @@ module.exports = {
|
|
321
327
|
program.help(); // exits
|
322
328
|
}
|
323
329
|
|
324
|
-
|
330
|
+
const firstCommand = args[2];
|
325
331
|
|
326
332
|
if (!_.includes(knownCommands, firstCommand)) {
|
327
333
|
debug('unknown command %s', firstCommand);
|
328
|
-
logger.error('Unknown command', "
|
334
|
+
logger.error('Unknown command', `"${firstCommand}"`);
|
329
335
|
program.outputHelp();
|
330
336
|
return util.exit(1);
|
331
337
|
}
|
@@ -341,6 +347,7 @@ module.exports = {
|
|
341
347
|
debug('program parsing arguments');
|
342
348
|
return program.parse(args);
|
343
349
|
}
|
350
|
+
|
344
351
|
};
|
345
352
|
|
346
353
|
if (!module.parent) {
|
package/lib/cypress.js
CHANGED
@@ -1,51 +1,49 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
// https://github.com/cypress-io/cypress/issues/316
|
4
|
-
|
4
|
+
const Promise = require('bluebird');
|
5
5
|
|
6
|
-
|
6
|
+
const tmp = Promise.promisifyAll(require('tmp'));
|
7
7
|
|
8
|
-
|
8
|
+
const fs = require('./fs');
|
9
9
|
|
10
|
-
|
10
|
+
const open = require('./exec/open');
|
11
11
|
|
12
|
-
|
12
|
+
const run = require('./exec/run');
|
13
13
|
|
14
|
-
|
14
|
+
const util = require('./util');
|
15
15
|
|
16
|
-
|
16
|
+
const cli = require('./cli');
|
17
17
|
|
18
|
-
|
18
|
+
const cypressModuleApi = {
|
19
19
|
/**
|
20
20
|
* Opens Cypress GUI
|
21
21
|
* @see https://on.cypress.io/module-api#cypress-open
|
22
22
|
*/
|
23
|
-
open
|
24
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
23
|
+
open(options = {}) {
|
25
24
|
options = util.normalizeModuleOptions(options);
|
26
|
-
return
|
25
|
+
return open.start(options);
|
27
26
|
},
|
28
27
|
|
29
28
|
/**
|
30
29
|
* Runs Cypress tests in the current project
|
31
30
|
* @see https://on.cypress.io/module-api#cypress-run
|
32
31
|
*/
|
33
|
-
run
|
34
|
-
|
35
|
-
|
36
|
-
if (!_run.isValidProject(options.project)) {
|
37
|
-
return Promise.reject(new Error("Invalid project path parameter: ".concat(options.project)));
|
32
|
+
run(options = {}) {
|
33
|
+
if (!run.isValidProject(options.project)) {
|
34
|
+
return Promise.reject(new Error(`Invalid project path parameter: ${options.project}`));
|
38
35
|
}
|
39
36
|
|
40
37
|
options = util.normalizeModuleOptions(options);
|
41
|
-
return tmp.fileAsync().then(
|
38
|
+
return tmp.fileAsync().then(outputPath => {
|
42
39
|
options.outputPath = outputPath;
|
43
|
-
return
|
40
|
+
return run.start(options).then(failedTests => {
|
44
41
|
return fs.readJsonAsync(outputPath, {
|
45
|
-
|
46
|
-
}).then(
|
42
|
+
throws: false
|
43
|
+
}).then(output => {
|
47
44
|
if (!output) {
|
48
45
|
return {
|
46
|
+
status: 'failed',
|
49
47
|
failures: failedTests,
|
50
48
|
message: 'Could not find Cypress test run results'
|
51
49
|
};
|
@@ -56,6 +54,7 @@ var cypressModuleApi = {
|
|
56
54
|
});
|
57
55
|
});
|
58
56
|
},
|
57
|
+
|
59
58
|
cli: {
|
60
59
|
/**
|
61
60
|
* Parses CLI arguments into an object that you can pass to "cypress.run"
|
@@ -67,9 +66,10 @@ var cypressModuleApi = {
|
|
67
66
|
* await cypress.run(options)
|
68
67
|
* @see https://on.cypress.io/module-api
|
69
68
|
*/
|
70
|
-
parseRunArguments
|
69
|
+
parseRunArguments(args) {
|
71
70
|
return cli.parseRunCommand(args);
|
72
71
|
}
|
72
|
+
|
73
73
|
}
|
74
74
|
};
|
75
75
|
module.exports = cypressModuleApi;
|