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/lib/errors.js DELETED
@@ -1,392 +0,0 @@
1
- "use strict";
2
-
3
- const chalk = require('chalk');
4
- const {
5
- stripIndent,
6
- stripIndents
7
- } = require('common-tags');
8
- const la = require('lazy-ass');
9
- const is = require('check-more-types');
10
- const util = require('./util');
11
- const state = require('./tasks/state');
12
- const docsUrl = 'https://on.cypress.io';
13
- const requiredDependenciesUrl = `${docsUrl}/required-dependencies`;
14
- const runDocumentationUrl = `${docsUrl}/cypress-run`;
15
-
16
- // TODO it would be nice if all error objects could be enforced via types
17
- // to only have description + solution properties
18
-
19
- const hr = '----------';
20
- const genericErrorSolution = stripIndent`
21
- Search for an existing issue or open a GitHub issue at
22
-
23
- ${chalk.blue(util.issuesUrl)}
24
- `;
25
-
26
- // common errors Cypress application can encounter
27
- const unknownError = {
28
- description: 'Unknown Cypress CLI error',
29
- solution: genericErrorSolution
30
- };
31
- const invalidRunProjectPath = {
32
- description: 'Invalid --project path',
33
- solution: stripIndent`
34
- Please provide a valid project path.
35
-
36
- Learn more about ${chalk.cyan('cypress run')} at:
37
-
38
- ${chalk.blue(runDocumentationUrl)}
39
- `
40
- };
41
- const invalidOS = {
42
- description: 'The Cypress App could not be installed. Your machine does not meet the operating system requirements.',
43
- solution: stripIndent`
44
-
45
- ${chalk.blue('https://on.cypress.io/app/get-started/install-cypress#System-requirements')}`
46
- };
47
- const failedDownload = {
48
- description: 'The Cypress App could not be downloaded.',
49
- solution: stripIndent`
50
- Does your workplace require a proxy to be used to access the Internet? If so, you must configure the HTTP_PROXY environment variable before downloading Cypress. Read more: https://on.cypress.io/proxy-configuration
51
-
52
- Otherwise, please check network connectivity and try again:`
53
- };
54
- const failedUnzip = {
55
- description: 'The Cypress App could not be unzipped.',
56
- solution: genericErrorSolution
57
- };
58
- const failedUnzipWindowsMaxPathLength = {
59
- description: 'The Cypress App could not be unzipped.',
60
- solution: `This is most likely because the maximum path length is being exceeded on your system.
61
-
62
- Read here for solutions to this problem: https://on.cypress.io/win-max-path-length-error`
63
- };
64
- const missingApp = binaryDir => {
65
- return {
66
- description: `No version of Cypress is installed in: ${chalk.cyan(binaryDir)}`,
67
- solution: stripIndent`
68
- \nPlease reinstall Cypress by running: ${chalk.cyan('cypress install')}
69
- `
70
- };
71
- };
72
- const binaryNotExecutable = executable => {
73
- return {
74
- description: `Cypress cannot run because this binary file does not have executable permissions here:\n\n${executable}`,
75
- solution: stripIndent`\n
76
- Reasons this may happen:
77
-
78
- - node was installed as 'root' or with 'sudo'
79
- - the cypress npm package as 'root' or with 'sudo'
80
-
81
- Please check that you have the appropriate user permissions.
82
-
83
- You can also try clearing the cache with 'cypress cache clear' and reinstalling.
84
- `
85
- };
86
- };
87
- const notInstalledCI = executable => {
88
- return {
89
- description: 'The cypress npm package is installed, but the Cypress binary is missing.',
90
- solution: stripIndent`\n
91
- We expected the binary to be installed here: ${chalk.cyan(executable)}
92
-
93
- Reasons it may be missing:
94
-
95
- - You're caching 'node_modules' but are not caching this path: ${util.getCacheDir()}
96
- - You ran 'npm install' at an earlier build step but did not persist: ${util.getCacheDir()}
97
-
98
- Properly caching the binary will fix this error and avoid downloading and unzipping Cypress.
99
-
100
- Alternatively, you can run 'cypress install' to download the binary again.
101
-
102
- ${chalk.blue('https://on.cypress.io/not-installed-ci-error')}
103
- `
104
- };
105
- };
106
- const nonZeroExitCodeXvfb = {
107
- description: 'Xvfb exited with a non zero exit code.',
108
- solution: stripIndent`
109
- There was a problem spawning Xvfb.
110
-
111
- This is likely a problem with your system, permissions, or installation of Xvfb.
112
- `
113
- };
114
- const missingXvfb = {
115
- description: 'Your system is missing the dependency: Xvfb',
116
- solution: stripIndent`
117
- Install Xvfb and run Cypress again.
118
-
119
- Read our documentation on dependencies for more information:
120
-
121
- ${chalk.blue(requiredDependenciesUrl)}
122
-
123
- If you are using Docker, we provide containers with all required dependencies installed.
124
- `
125
- };
126
- const smokeTestFailure = (smokeTestCommand, timedOut) => {
127
- return {
128
- description: `Cypress verification ${timedOut ? 'timed out' : 'failed'}.`,
129
- solution: stripIndent`
130
- This command failed with the following output:
131
-
132
- ${smokeTestCommand}
133
-
134
- `
135
- };
136
- };
137
- const invalidSmokeTestDisplayError = {
138
- code: 'INVALID_SMOKE_TEST_DISPLAY_ERROR',
139
- description: 'Cypress verification failed.',
140
- solution(msg) {
141
- return stripIndent`
142
- Cypress failed to start after spawning a new Xvfb server.
143
-
144
- The error logs we received were:
145
-
146
- ${hr}
147
-
148
- ${msg}
149
-
150
- ${hr}
151
-
152
- This may be due to a missing library or dependency. ${chalk.blue(requiredDependenciesUrl)}
153
-
154
- Please refer to the error above for more detail.
155
- `;
156
- }
157
- };
158
- const missingDependency = {
159
- description: 'Cypress failed to start.',
160
- // this message is too Linux specific
161
- solution: stripIndent`
162
- This may be due to a missing library or dependency. ${chalk.blue(requiredDependenciesUrl)}
163
-
164
- Please refer to the error below for more details.
165
- `
166
- };
167
- const invalidCacheDirectory = {
168
- description: 'Cypress cannot write to the cache directory due to file permissions',
169
- solution: stripIndent`
170
- See discussion and possible solutions at
171
- ${chalk.blue(util.getGitHubIssueUrl(1281))}
172
- `
173
- };
174
- const versionMismatch = {
175
- description: 'Installed version does not match package version.',
176
- solution: 'Install Cypress and verify app again'
177
- };
178
- const incompatibleHeadlessFlags = {
179
- description: '`--headed` and `--headless` cannot both be passed.',
180
- solution: 'Either pass `--headed` or `--headless`, but not both.'
181
- };
182
- const solutionUnknown = stripIndent`
183
- Please search Cypress documentation for possible solutions:
184
-
185
- ${chalk.blue(docsUrl)}
186
-
187
- Check if there is a GitHub issue describing this crash:
188
-
189
- ${chalk.blue(util.issuesUrl)}
190
-
191
- Consider opening a new issue.
192
- `;
193
- const unexpected = {
194
- description: 'An unexpected error occurred while verifying the Cypress executable.',
195
- solution: solutionUnknown
196
- };
197
- const invalidCypressEnv = {
198
- description: chalk.red('The environment variable with the reserved name "CYPRESS_INTERNAL_ENV" is set.'),
199
- solution: chalk.red('Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.'),
200
- exitCode: 11
201
- };
202
- const invalidTestingType = {
203
- description: 'Invalid testingType',
204
- solution: `Please provide a valid testingType. Valid test types are ${chalk.cyan('\'e2e\'')} and ${chalk.cyan('\'component\'')}.`
205
- };
206
- const incompatibleTestTypeFlags = {
207
- description: '`--e2e` and `--component` cannot both be passed.',
208
- solution: 'Either pass `--e2e` or `--component`, but not both.'
209
- };
210
- const incompatibleTestingTypeAndFlag = {
211
- description: 'Set a `testingType` and also passed `--e2e` or `--component` flags.',
212
- solution: 'Either set `testingType` or pass a testing type flag, but not both.'
213
- };
214
- const invalidConfigFile = {
215
- description: '`--config-file` cannot be false.',
216
- solution: 'Either pass a relative path to a valid Cypress config file or remove this option.'
217
- };
218
-
219
- /**
220
- * This error happens when CLI detects that the child Test Runner process
221
- * was killed with a signal, like SIGBUS
222
- * @see https://github.com/cypress-io/cypress/issues/5808
223
- * @param {'close'|'event'} eventName Child close event name
224
- * @param {string} signal Signal that closed the child process, like "SIGBUS"
225
- */
226
- const childProcessKilled = (eventName, signal) => {
227
- return {
228
- description: `The Test Runner unexpectedly exited via a ${chalk.cyan(eventName)} event with signal ${chalk.cyan(signal)}`,
229
- solution: solutionUnknown
230
- };
231
- };
232
- const CYPRESS_RUN_BINARY = {
233
- notValid: value => {
234
- const properFormat = `**/${state.getPlatformExecutable()}`;
235
- return {
236
- description: `Could not run binary set by environment variable: CYPRESS_RUN_BINARY=${value}`,
237
- solution: `Ensure the environment variable is a path to the Cypress binary, matching ${properFormat}`
238
- };
239
- }
240
- };
241
- function addPlatformInformation(info) {
242
- return util.getPlatformInfo().then(platform => {
243
- return {
244
- ...info,
245
- platform
246
- };
247
- });
248
- }
249
-
250
- /**
251
- * Given an error object (see the errors above), forms error message text with details,
252
- * then resolves with Error instance you can throw or reject with.
253
- * @param {object} errorObject
254
- * @returns {Promise<Error>} resolves with an Error
255
- * @example
256
- ```js
257
- // inside a Promise with "resolve" and "reject"
258
- const errorObject = childProcessKilled('exit', 'SIGKILL')
259
- return getError(errorObject).then(reject)
260
- ```
261
- */
262
- function getError(errorObject) {
263
- return formErrorText(errorObject).then(errorMessage => {
264
- const err = new Error(errorMessage);
265
- err.known = true;
266
- return err;
267
- });
268
- }
269
-
270
- /**
271
- * Forms nice error message with error and platform information,
272
- * and if possible a way to solve it. Resolves with a string.
273
- */
274
- function formErrorText(info, msg, prevMessage) {
275
- return addPlatformInformation(info).then(obj => {
276
- const formatted = [];
277
- function add(msg) {
278
- formatted.push(stripIndents(msg));
279
- }
280
- la(is.unemptyString(obj.description), 'expected error description to be text', obj.description);
281
-
282
- // assuming that if there the solution is a function it will handle
283
- // error message and (optional previous error message)
284
- if (is.fn(obj.solution)) {
285
- const text = obj.solution(msg, prevMessage);
286
- la(is.unemptyString(text), 'expected solution to be text', text);
287
- add(`
288
- ${obj.description}
289
-
290
- ${text}
291
-
292
- `);
293
- } else {
294
- la(is.unemptyString(obj.solution), 'expected error solution to be text', obj.solution);
295
- add(`
296
- ${obj.description}
297
-
298
- ${obj.solution}
299
-
300
- `);
301
- if (msg) {
302
- add(`
303
- ${hr}
304
-
305
- ${msg}
306
-
307
- `);
308
- }
309
- }
310
- add(`
311
- ${hr}
312
-
313
- ${obj.platform}
314
- `);
315
- if (obj.footer) {
316
- add(`
317
-
318
- ${hr}
319
-
320
- ${obj.footer}
321
- `);
322
- }
323
- return formatted.join('\n\n');
324
- });
325
- }
326
- const raise = info => {
327
- return text => {
328
- const err = new Error(text);
329
- if (info.code) {
330
- err.code = info.code;
331
- }
332
- err.known = true;
333
- throw err;
334
- };
335
- };
336
- const throwFormErrorText = info => {
337
- return (msg, prevMessage) => {
338
- return formErrorText(info, msg, prevMessage).then(raise(info));
339
- };
340
- };
341
-
342
- /**
343
- * Forms full error message with error and OS details, prints to the error output
344
- * and then exits the process.
345
- * @param {ErrorInformation} info Error information {description, solution}
346
- * @example return exitWithError(errors.invalidCypressEnv)('foo')
347
- */
348
- const exitWithError = info => {
349
- return msg => {
350
- return formErrorText(info, msg).then(text => {
351
- // eslint-disable-next-line no-console
352
- console.error(text);
353
- process.exit(info.exitCode || 1);
354
- });
355
- };
356
- };
357
- module.exports = {
358
- raise,
359
- exitWithError,
360
- // formError,
361
- formErrorText,
362
- throwFormErrorText,
363
- getError,
364
- hr,
365
- errors: {
366
- unknownError,
367
- nonZeroExitCodeXvfb,
368
- missingXvfb,
369
- missingApp,
370
- notInstalledCI,
371
- missingDependency,
372
- invalidOS,
373
- invalidSmokeTestDisplayError,
374
- versionMismatch,
375
- binaryNotExecutable,
376
- unexpected,
377
- failedDownload,
378
- failedUnzip,
379
- failedUnzipWindowsMaxPathLength,
380
- invalidCypressEnv,
381
- invalidCacheDirectory,
382
- CYPRESS_RUN_BINARY,
383
- smokeTestFailure,
384
- childProcessKilled,
385
- incompatibleHeadlessFlags,
386
- invalidRunProjectPath,
387
- invalidTestingType,
388
- incompatibleTestTypeFlags,
389
- incompatibleTestingTypeAndFlag,
390
- invalidConfigFile
391
- }
392
- };
package/lib/exec/info.js DELETED
@@ -1,92 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable no-console */
4
- const spawn = require('./spawn');
5
- const util = require('../util');
6
- const state = require('../tasks/state');
7
- const os = require('os');
8
- const chalk = require('chalk');
9
- const prettyBytes = require('pretty-bytes');
10
- const _ = require('lodash');
11
-
12
- // color for numbers and show values
13
- const g = chalk.green;
14
- // color for paths
15
- const p = chalk.cyan;
16
- const red = chalk.red;
17
- // urls
18
- const link = chalk.blue.underline;
19
-
20
- // to be exported
21
- const methods = {};
22
- methods.findProxyEnvironmentVariables = () => {
23
- return _.pick(process.env, ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY']);
24
- };
25
- const maskSensitiveVariables = obj => {
26
- const masked = {
27
- ...obj
28
- };
29
- if (masked.CYPRESS_RECORD_KEY) {
30
- masked.CYPRESS_RECORD_KEY = '<redacted>';
31
- }
32
- return masked;
33
- };
34
- methods.findCypressEnvironmentVariables = () => {
35
- const isCyVariable = (val, key) => key.startsWith('CYPRESS_');
36
- return _.pickBy(process.env, isCyVariable);
37
- };
38
- const formatCypressVariables = () => {
39
- const vars = methods.findCypressEnvironmentVariables();
40
- return maskSensitiveVariables(vars);
41
- };
42
- methods.start = async (options = {}) => {
43
- const args = ['--mode=info'];
44
- await spawn.start(args, {
45
- dev: options.dev
46
- });
47
- console.log();
48
- const proxyVars = methods.findProxyEnvironmentVariables();
49
- if (_.isEmpty(proxyVars)) {
50
- console.log('Proxy Settings: none detected');
51
- } else {
52
- console.log('Proxy Settings:');
53
- _.forEach(proxyVars, (value, key) => {
54
- console.log('%s: %s', key, g(value));
55
- });
56
- console.log();
57
- console.log('Learn More: %s', link('https://on.cypress.io/proxy-configuration'));
58
- console.log();
59
- }
60
- const cyVars = formatCypressVariables();
61
- if (_.isEmpty(cyVars)) {
62
- console.log('Environment Variables: none detected');
63
- } else {
64
- console.log('Environment Variables:');
65
- _.forEach(cyVars, (value, key) => {
66
- console.log('%s: %s', key, g(value));
67
- });
68
- }
69
- console.log();
70
- console.log('Application Data:', p(util.getApplicationDataFolder()));
71
- console.log('Browser Profiles:', p(util.getApplicationDataFolder('browsers')));
72
- console.log('Binary Caches: %s', p(state.getCacheDir()));
73
- console.log();
74
- const osVersion = await util.getOsVersionAsync();
75
- const buildInfo = util.pkgBuildInfo();
76
- const isStable = buildInfo && buildInfo.stable;
77
- console.log('Cypress Version: %s', g(util.pkgVersion()), isStable ? g('(stable)') : red('(pre-release)'));
78
- console.log('System Platform: %s (%s)', g(os.platform()), g(osVersion));
79
- console.log('System Memory: %s free %s', g(prettyBytes(os.totalmem())), g(prettyBytes(os.freemem())));
80
- if (!buildInfo) {
81
- console.log();
82
- console.log('This is the', red('development'), '(un-built) Cypress CLI.');
83
- } else if (!isStable) {
84
- console.log();
85
- console.log('This is a', red('pre-release'), 'build of Cypress.');
86
- console.log('Build info:');
87
- console.log(' Commit SHA:', g(buildInfo.commitSha));
88
- console.log(' Commit Branch:', g(buildInfo.commitBranch));
89
- console.log(' Commit Date:', g(buildInfo.commitDate));
90
- }
91
- };
92
- module.exports = methods;
package/lib/exec/open.js DELETED
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- const debug = require('debug')('cypress:cli');
4
- const util = require('../util');
5
- const spawn = require('./spawn');
6
- const verify = require('../tasks/verify');
7
- const {
8
- processTestingType,
9
- checkConfigFile
10
- } = require('./shared');
11
- const {
12
- exitWithError
13
- } = require('../errors');
14
-
15
- /**
16
- * Maps options collected by the CLI
17
- * and forms list of CLI arguments to the server.
18
- *
19
- * Note: there is lightweight validation, with errors
20
- * thrown synchronously.
21
- *
22
- * @returns {string[]} list of CLI arguments
23
- */
24
- const processOpenOptions = (options = {}) => {
25
- // In addition to setting the project directory, setting the project option
26
- // here ultimately decides whether cypress is run in global mode or not.
27
- // It's first based off whether it's installed globally by npm/yarn (-g).
28
- // A global install can be overridden by the --project flag, putting Cypress
29
- // in project mode. A non-global install can be overridden by the --global
30
- // flag, putting it in global mode.
31
- if (!util.isInstalledGlobally() && !options.global && !options.project) {
32
- options.project = process.cwd();
33
- }
34
- const args = [];
35
- if (options.config) {
36
- args.push('--config', options.config);
37
- }
38
- if (options.configFile !== undefined) {
39
- checkConfigFile(options);
40
- args.push('--config-file', options.configFile);
41
- }
42
- if (options.browser) {
43
- args.push('--browser', options.browser);
44
- }
45
- if (options.env) {
46
- args.push('--env', options.env);
47
- }
48
- if (options.port) {
49
- args.push('--port', options.port);
50
- }
51
- if (options.project) {
52
- args.push('--project', options.project);
53
- }
54
- if (options.global) {
55
- args.push('--global', options.global);
56
- }
57
- if (options.inspect) {
58
- args.push('--inspect');
59
- }
60
- if (options.inspectBrk) {
61
- args.push('--inspectBrk');
62
- }
63
- args.push(...processTestingType(options));
64
- debug('opening from options %j', options);
65
- debug('command line arguments %j', args);
66
- return args;
67
- };
68
- module.exports = {
69
- processOpenOptions,
70
- start(options = {}) {
71
- function open() {
72
- try {
73
- const args = processOpenOptions(options);
74
- return spawn.start(args, {
75
- dev: options.dev,
76
- detached: Boolean(options.detached)
77
- });
78
- } catch (err) {
79
- if (err.details) {
80
- return exitWithError(err.details)();
81
- }
82
- throw err;
83
- }
84
- }
85
- if (options.dev) {
86
- return open();
87
- }
88
- return verify.start().then(open);
89
- }
90
- };