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/util.js DELETED
@@ -1,448 +0,0 @@
1
- "use strict";
2
-
3
- const _ = require('lodash');
4
- const arch = require('arch');
5
- const os = require('os');
6
- const ospath = require('ospath');
7
- const hasha = require('hasha');
8
- const la = require('lazy-ass');
9
- const is = require('check-more-types');
10
- const tty = require('tty');
11
- const path = require('path');
12
- const isCi = require('ci-info').isCI;
13
- const execa = require('execa');
14
- const si = require('systeminformation');
15
- const chalk = require('chalk');
16
- const Promise = require('bluebird');
17
- const cachedir = require('cachedir');
18
- const logSymbols = require('log-symbols');
19
- const executable = require('executable');
20
- const {
21
- stripIndent
22
- } = require('common-tags');
23
- const supportsColor = require('supports-color');
24
- const isInstalledGlobally = require('is-installed-globally');
25
- const logger = require('./logger');
26
- const debug = require('debug')('cypress:cli');
27
- const fs = require('./fs');
28
- const pkg = require(path.join(__dirname, '..', 'package.json'));
29
- const issuesUrl = 'https://github.com/cypress-io/cypress/issues';
30
-
31
- /**
32
- * Returns SHA512 of a file
33
- */
34
- const getFileChecksum = filename => {
35
- la(is.unemptyString(filename), 'expected filename', filename);
36
- return hasha.fromFile(filename, {
37
- algorithm: 'sha512'
38
- });
39
- };
40
- const getFileSize = filename => {
41
- la(is.unemptyString(filename), 'expected filename', filename);
42
- return fs.statAsync(filename).get('size');
43
- };
44
- const isBrokenGtkDisplayRe = /Gtk: cannot open display/;
45
- const stringify = val => {
46
- return _.isObject(val) ? JSON.stringify(val) : val;
47
- };
48
- function normalizeModuleOptions(options = {}) {
49
- return _.mapValues(options, stringify);
50
- }
51
-
52
- /**
53
- * Returns true if the platform is Linux. We do a lot of different
54
- * stuff on Linux (like Xvfb) and it helps to has readable code
55
- */
56
- const isLinux = () => {
57
- return os.platform() === 'linux';
58
- };
59
-
60
- /**
61
- * If the DISPLAY variable is set incorrectly, when trying to spawn
62
- * Cypress executable we get an error like this:
63
- ```
64
- [1005:0509/184205.663837:WARNING:browser_main_loop.cc(258)] Gtk: cannot open display: 99
65
- ```
66
- */
67
- const isBrokenGtkDisplay = str => {
68
- return isBrokenGtkDisplayRe.test(str);
69
- };
70
- const isPossibleLinuxWithIncorrectDisplay = () => {
71
- return isLinux() && process.env.DISPLAY;
72
- };
73
- const logBrokenGtkDisplayWarning = () => {
74
- debug('Cypress exited due to a broken gtk display because of a potential invalid DISPLAY env... retrying after starting Xvfb');
75
-
76
- // if we get this error, we are on Linux and DISPLAY is set
77
- logger.warn(stripIndent`
78
-
79
- ${logSymbols.warning} Warning: Cypress failed to start.
80
-
81
- This is likely due to a misconfigured DISPLAY environment variable.
82
-
83
- DISPLAY was set to: "${process.env.DISPLAY}"
84
-
85
- Cypress will attempt to fix the problem and rerun.
86
- `);
87
- logger.warn();
88
- };
89
- function stdoutLineMatches(expectedLine, stdout) {
90
- const lines = stdout.split('\n').map(val => val.trim());
91
- return lines.some(line => line === expectedLine);
92
- }
93
-
94
- /**
95
- * Confirms if given value is a valid CYPRESS_INTERNAL_ENV value. Undefined values
96
- * are valid, because the system can set the default one.
97
- *
98
- * @param {string} value
99
- * @example util.isValidCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
100
- */
101
- function isValidCypressInternalEnvValue(value) {
102
- if (_.isUndefined(value)) {
103
- // will get default value
104
- return true;
105
- }
106
-
107
- // names of config environments, see "packages/server/config/app.json"
108
- const names = ['development', 'test', 'staging', 'production'];
109
- return _.includes(names, value);
110
- }
111
-
112
- /**
113
- * Confirms if given value is a non-production CYPRESS_INTERNAL_ENV value.
114
- * Undefined values are valid, because the system can set the default one.
115
- *
116
- * @param {string} value
117
- * @example util.isNonProductionCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
118
- */
119
- function isNonProductionCypressInternalEnvValue(value) {
120
- return !_.isUndefined(value) && value !== 'production';
121
- }
122
-
123
- /**
124
- * Prints NODE_OPTIONS using debug() module, but only
125
- * if DEBUG=cypress... is set
126
- */
127
- function printNodeOptions(log = debug) {
128
- if (!log.enabled) {
129
- return;
130
- }
131
- if (process.env.NODE_OPTIONS) {
132
- log('NODE_OPTIONS=%s', process.env.NODE_OPTIONS);
133
- } else {
134
- log('NODE_OPTIONS is not set');
135
- }
136
- }
137
-
138
- /**
139
- * Removes double quote characters
140
- * from the start and end of the given string IF they are both present
141
- *
142
- * @param {string} str Input string
143
- * @returns {string} Trimmed string or the original string if there are no double quotes around it.
144
- * @example
145
- ```
146
- dequote('"foo"')
147
- // returns string 'foo'
148
- dequote('foo')
149
- // returns string 'foo'
150
- ```
151
- */
152
- const dequote = str => {
153
- la(is.string(str), 'expected a string to remove double quotes', str);
154
- if (str.length > 1 && str[0] === '"' && str[str.length - 1] === '"') {
155
- return str.substr(1, str.length - 2);
156
- }
157
- return str;
158
- };
159
- const parseOpts = opts => {
160
- opts = _.pick(opts, 'autoCancelAfterFailures', 'browser', 'cachePath', 'cacheList', 'cacheClear', 'cachePrune', 'ciBuildId', 'ct', 'component', 'config', 'configFile', 'cypressVersion', 'destination', 'detached', 'dev', 'e2e', 'exit', 'env', 'force', 'global', 'group', 'headed', 'headless', 'inspect', 'inspectBrk', 'key', 'path', 'parallel', 'port', 'project', 'quiet', 'reporter', 'reporterOptions', 'record', 'runnerUi', 'runProject', 'spec', 'tag');
161
- if (opts.exit) {
162
- opts = _.omit(opts, 'exit');
163
- }
164
-
165
- // some options might be quoted - which leads to unexpected results
166
- // remove double quotes from certain options
167
- const cleanOpts = {
168
- ...opts
169
- };
170
- const toDequote = ['group', 'ciBuildId'];
171
- for (const prop of toDequote) {
172
- if (_.has(opts, prop)) {
173
- cleanOpts[prop] = dequote(opts[prop]);
174
- }
175
- }
176
- debug('parsed cli options %o', cleanOpts);
177
- return cleanOpts;
178
- };
179
-
180
- /**
181
- * Copy of packages/server/lib/browsers/utils.ts
182
- * because we need same functionality in CLI to show the path :(
183
- */
184
- const getApplicationDataFolder = (...paths) => {
185
- const {
186
- env
187
- } = process;
188
-
189
- // allow overriding the app_data folder
190
- let folder = env.CYPRESS_CONFIG_ENV || env.CYPRESS_INTERNAL_ENV || 'development';
191
- const PRODUCT_NAME = pkg.productName || pkg.name;
192
- const OS_DATA_PATH = ospath.data();
193
- const ELECTRON_APP_DATA_PATH = path.join(OS_DATA_PATH, PRODUCT_NAME);
194
- if (process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF) {
195
- folder = `${folder}-e2e-test`;
196
- }
197
- const p = path.join(ELECTRON_APP_DATA_PATH, 'cy', folder, ...paths);
198
- return p;
199
- };
200
- const util = {
201
- normalizeModuleOptions,
202
- parseOpts,
203
- isValidCypressInternalEnvValue,
204
- isNonProductionCypressInternalEnvValue,
205
- printNodeOptions,
206
- isCi() {
207
- return isCi;
208
- },
209
- getEnvOverrides(options = {}) {
210
- return _.chain({}).extend(util.getEnvColors()).extend(util.getForceTty()).omitBy(_.isUndefined) // remove undefined values
211
- .mapValues(value => {
212
- // stringify to 1 or 0
213
- return value ? '1' : '0';
214
- }).extend(util.getOriginalNodeOptions()).value();
215
- },
216
- getOriginalNodeOptions() {
217
- const opts = {};
218
- if (process.env.NODE_OPTIONS) {
219
- opts.ORIGINAL_NODE_OPTIONS = process.env.NODE_OPTIONS;
220
- }
221
- return opts;
222
- },
223
- getForceTty() {
224
- return {
225
- FORCE_STDIN_TTY: util.isTty(process.stdin.fd),
226
- FORCE_STDOUT_TTY: util.isTty(process.stdout.fd),
227
- FORCE_STDERR_TTY: util.isTty(process.stderr.fd)
228
- };
229
- },
230
- getEnvColors() {
231
- const sc = util.supportsColor();
232
- return {
233
- FORCE_COLOR: sc,
234
- DEBUG_COLORS: sc,
235
- MOCHA_COLORS: sc ? true : undefined
236
- };
237
- },
238
- isTty(fd) {
239
- return tty.isatty(fd);
240
- },
241
- supportsColor() {
242
- // if we've been explicitly told not to support
243
- // color then turn this off
244
- if (process.env.NO_COLOR) {
245
- return false;
246
- }
247
-
248
- // https://github.com/cypress-io/cypress/issues/1747
249
- // always return true in CI providers
250
- if (process.env.CI) {
251
- return true;
252
- }
253
-
254
- // ensure that both stdout and stderr support color
255
- return Boolean(supportsColor.stdout) && Boolean(supportsColor.stderr);
256
- },
257
- cwd() {
258
- return process.cwd();
259
- },
260
- pkgBuildInfo() {
261
- return pkg.buildInfo;
262
- },
263
- pkgVersion() {
264
- return pkg.version;
265
- },
266
- exit(code) {
267
- process.exit(code);
268
- },
269
- logErrorExit1(err) {
270
- logger.error(err.message);
271
- process.exit(1);
272
- },
273
- dequote,
274
- titleize(...args) {
275
- // prepend first arg with space
276
- // and pad so that all messages line up
277
- args[0] = _.padEnd(` ${args[0]}`, 24);
278
-
279
- // get rid of any falsy values
280
- args = _.compact(args);
281
- return chalk.blue(...args);
282
- },
283
- calculateEta(percent, elapsed) {
284
- // returns the number of seconds remaining
285
-
286
- // if we're at 100% already just return 0
287
- if (percent === 100) {
288
- return 0;
289
- }
290
-
291
- // take the percentage and divide by one
292
- // and multiple that against elapsed
293
- // subtracting what's already elapsed
294
- return elapsed * (1 / (percent / 100)) - elapsed;
295
- },
296
- convertPercentToPercentage(num) {
297
- // convert a percent with values between 0 and 1
298
- // with decimals, so that it is between 0 and 100
299
- // and has no decimal places
300
- return Math.round(_.isFinite(num) ? num * 100 : 0);
301
- },
302
- secsRemaining(eta) {
303
- // calculate the seconds reminaing with no decimal places
304
- return (_.isFinite(eta) ? eta / 1000 : 0).toFixed(0);
305
- },
306
- setTaskTitle(task, title, renderer) {
307
- // only update the renderer title when not running in CI
308
- if (renderer === 'default' && task.title !== title) {
309
- task.title = title;
310
- }
311
- },
312
- isInstalledGlobally() {
313
- return isInstalledGlobally;
314
- },
315
- isSemver(str) {
316
- return /^(\d+\.)?(\d+\.)?(\*|\d+)$/.test(str);
317
- },
318
- isExecutableAsync(filePath) {
319
- return Promise.resolve(executable(filePath));
320
- },
321
- isLinux,
322
- getOsVersionAsync() {
323
- return Promise.try(() => {
324
- return si.osInfo().then(osInfo => {
325
- if (osInfo.distro && osInfo.release) {
326
- return `${osInfo.distro} - ${osInfo.release}`;
327
- }
328
- return os.release();
329
- }).catch(() => {
330
- return os.release();
331
- });
332
- });
333
- },
334
- async getPlatformInfo() {
335
- const [version, osArch] = await Promise.all([util.getOsVersionAsync(), this.getRealArch()]);
336
- return stripIndent`
337
- Platform: ${os.platform()}-${osArch} (${version})
338
- Cypress Version: ${util.pkgVersion()}
339
- `;
340
- },
341
- _cachedArch: undefined,
342
- /**
343
- * Attempt to return the real system arch (not process.arch, which is only the Node binary's arch)
344
- */
345
- async getRealArch() {
346
- if (this._cachedArch) return this._cachedArch;
347
- async function _getRealArch() {
348
- const osPlatform = os.platform();
349
- // eslint-disable-next-line no-restricted-syntax
350
- const osArch = os.arch();
351
- debug('detecting arch %o', {
352
- osPlatform,
353
- osArch
354
- });
355
- if (osArch === 'arm64') return 'arm64';
356
- if (osPlatform === 'darwin') {
357
- // could possibly be x64 node on arm64 darwin, check if we are being translated by Rosetta
358
- // https://stackoverflow.com/a/65347893/3474615
359
- const {
360
- stdout
361
- } = await execa('sysctl', ['-n', 'sysctl.proc_translated']).catch(() => '');
362
- debug('rosetta check result: %o', {
363
- stdout
364
- });
365
- if (stdout === '1') return 'arm64';
366
- }
367
- if (osPlatform === 'linux') {
368
- // could possibly be x64 node on arm64 linux, check the "machine hardware name"
369
- // list of names for reference: https://stackoverflow.com/a/45125525/3474615
370
- const {
371
- stdout
372
- } = await execa('uname', ['-m']).catch(() => '');
373
- debug('arm uname -m result: %o ', {
374
- stdout
375
- });
376
- if (['aarch64_be', 'aarch64', 'armv8b', 'armv8l'].includes(stdout)) return 'arm64';
377
- }
378
-
379
- // eslint-disable-next-line no-restricted-syntax
380
- const pkgArch = arch();
381
- if (pkgArch === 'x86') return 'ia32';
382
- return pkgArch;
383
- }
384
- return this._cachedArch = await _getRealArch();
385
- },
386
- // attention:
387
- // when passing relative path to NPM post install hook, the current working
388
- // directory is set to the `node_modules/cypress` folder
389
- // the user is probably passing relative path with respect to root package folder
390
- formAbsolutePath(filename) {
391
- if (path.isAbsolute(filename)) {
392
- return filename;
393
- }
394
- return path.join(process.cwd(), '..', '..', filename);
395
- },
396
- getEnv(varName, trim) {
397
- la(is.unemptyString(varName), 'expected environment variable name, not', varName);
398
- const configVarName = `npm_config_${varName}`;
399
- const configVarNameLower = configVarName.toLowerCase();
400
- const packageConfigVarName = `npm_package_config_${varName}`;
401
- let result;
402
- if (process.env.hasOwnProperty(varName)) {
403
- debug(`Using ${varName} from environment variable`);
404
- result = process.env[varName];
405
- } else if (process.env.hasOwnProperty(configVarName)) {
406
- debug(`Using ${varName} from npm config`);
407
- result = process.env[configVarName];
408
- } else if (process.env.hasOwnProperty(configVarNameLower)) {
409
- debug(`Using ${varName.toLowerCase()} from npm config`);
410
- result = process.env[configVarNameLower];
411
- } else if (process.env.hasOwnProperty(packageConfigVarName)) {
412
- debug(`Using ${varName} from package.json config`);
413
- result = process.env[packageConfigVarName];
414
- }
415
-
416
- // environment variables are often set double quotes to escape characters
417
- // and on Windows it can lead to weird things: for example
418
- // set FOO="C:\foo.txt" && node -e "console.log('>>>%s<<<', process.env.FOO)"
419
- // will print
420
- // >>>"C:\foo.txt" <<<
421
- // see https://github.com/cypress-io/cypress/issues/4506#issuecomment-506029942
422
- // so for sanity sake we should first trim whitespace characters and remove
423
- // double quotes around environment strings if the caller is expected to
424
- // use this environment string as a file path
425
- return trim ? dequote(_.trim(result)) : result;
426
- },
427
- getCacheDir() {
428
- return cachedir('Cypress');
429
- },
430
- isPostInstall() {
431
- return process.env.npm_lifecycle_event === 'postinstall';
432
- },
433
- exec: execa,
434
- stdoutLineMatches,
435
- issuesUrl,
436
- isBrokenGtkDisplay,
437
- logBrokenGtkDisplayWarning,
438
- isPossibleLinuxWithIncorrectDisplay,
439
- getGitHubIssueUrl(number) {
440
- la(is.positive(number), 'github issue should be a positive number', number);
441
- la(_.isInteger(number), 'github issue should be an integer', number);
442
- return `${issuesUrl}/${number}`;
443
- },
444
- getFileChecksum,
445
- getFileSize,
446
- getApplicationDataFolder
447
- };
448
- module.exports = util;