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