cypress 16.2.1 → 16.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/angular/dist/index.js +4 -5
  2. package/dist/bin/cypress +8 -8
  3. package/dist/{cli-DoJnc1F1.js → cli-y9Bb9Y77.js} +212 -38
  4. package/dist/cli.js +6 -6
  5. package/dist/{cypress-BTgp4zGi.js → cypress-CvEs5adm.js} +2 -2
  6. package/dist/cypress.js +8 -8
  7. package/dist/exec/spawn.js +4 -4
  8. package/dist/exec/xvfb.js +7 -4
  9. package/dist/index.js +8 -8
  10. package/dist/{spawn-zPuxj7Kz.js → spawn-Bx99tBTm.js} +527 -67
  11. package/dist/{tap-D2mHgoNE.js → tap-BMFGLoCT.js} +108 -26
  12. package/dist/{xvfb-CbW2_YXR.js → xvfb-DxbcANVl.js} +238 -25
  13. package/mount-utils/dist/index.js +1 -0
  14. package/mount-utils/package.json +1 -0
  15. package/package.json +4 -4
  16. package/react/dist/cypress-react.cjs.js +4 -1
  17. package/react/dist/cypress-react.esm-bundler.js +4 -1
  18. package/svelte/dist/cypress-svelte.cjs.js +3 -1
  19. package/svelte/dist/cypress-svelte.esm-bundler.js +3 -1
  20. package/types/cy-bluebird.d.ts +1 -0
  21. package/types/cypress.d.ts +8 -1
  22. package/types/net-stubbing.d.ts +1 -1
  23. package/vue/dist/cypress-vue.cjs.js +3 -0
  24. package/vue/dist/cypress-vue.esm-bundler.js +3 -0
  25. package/vue/dist/index.d.ts +3 -3
  26. package/vue/package.json +1 -1
  27. package/angular/angular/README.md +0 -18
  28. package/angular/angular/dist/index.d.ts +0 -120
  29. package/angular/angular/dist/index.js +0 -478
  30. package/angular/angular/package.json +0 -67
  31. package/mount-utils/mount-utils/README.md +0 -140
  32. package/mount-utils/mount-utils/dist/index.d.ts +0 -12
  33. package/mount-utils/mount-utils/dist/index.js +0 -40
  34. package/mount-utils/mount-utils/package.json +0 -52
  35. package/react/react/README.md +0 -19
  36. package/react/react/dist/cypress-react.cjs.js +0 -292
  37. package/react/react/dist/cypress-react.esm-bundler.js +0 -267
  38. package/react/react/dist/index.d.ts +0 -95
  39. package/react/react/package.json +0 -93
  40. package/svelte/svelte/README.md +0 -19
  41. package/svelte/svelte/dist/cypress-svelte.cjs.js +0 -121
  42. package/svelte/svelte/dist/cypress-svelte.esm-bundler.js +0 -119
  43. package/svelte/svelte/dist/index.d.ts +0 -31
  44. package/svelte/svelte/package.json +0 -65
  45. package/vue/vue/README.md +0 -14
  46. package/vue/vue/dist/cypress-vue.cjs.js +0 -8691
  47. package/vue/vue/dist/cypress-vue.esm-bundler.js +0 -8670
  48. package/vue/vue/dist/index.d.ts +0 -1413
  49. package/vue/vue/package.json +0 -90
@@ -69,6 +69,7 @@ const getContainerEl = () => {
69
69
  * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
70
70
  * @param optionalCallback Callback to be called before the next test runs
71
71
  */
72
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type -- published API; narrowing the parameter would break callers that pass a `Function`
72
73
  function setupHooks(optionalCallback) {
73
74
  // We don't want CT side effects to run when e2e
74
75
  // testing so we early return.
@@ -320,9 +321,8 @@ function setupComponent(config, fixture) {
320
321
  component = Object.assign(component, config.componentProperties);
321
322
  }
322
323
  getComponentInputs(fixture.componentRef.componentType).forEach((key) => {
323
- var _a;
324
324
  // only assign props if they are passed into the component
325
- if ((_a = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(key)) {
325
+ if ((config === null || config === void 0 ? void 0 : config.componentProperties) && Object.hasOwn(config.componentProperties, key)) {
326
326
  // @ts-expect-error key is a string, not keyof T, so it can't index componentProperties
327
327
  const passedInValue = config === null || config === void 0 ? void 0 : config.componentProperties[key];
328
328
  registerSignalEventsIfNeeded(key, passedInValue, component[key], injector, fixture);
@@ -331,14 +331,13 @@ function setupComponent(config, fixture) {
331
331
  }
332
332
  });
333
333
  getComponentOutputs(fixture.componentRef.componentType).forEach((key) => {
334
- var _a, _b;
335
334
  const property = component[key];
336
335
  // With the introduction of https://github.com/cypress-io/cypress/pull/31993, we want to make sure that component inputs are reference safe inside cy.mount().
337
336
  // However, the exception to this is if the user passes in a Cypress output spy as a property in order to maintain backwards compatibility.
338
337
  // @ts-expect-error key is a string, not keyof T, so it can't index componentProperties
339
- if (property instanceof EventEmitter || (((_a = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(key)) && (config === null || config === void 0 ? void 0 : config.componentProperties[key]) instanceof EventEmitter)) {
338
+ if (property instanceof EventEmitter || ((config === null || config === void 0 ? void 0 : config.componentProperties) && Object.hasOwn(config.componentProperties, key) && (config === null || config === void 0 ? void 0 : config.componentProperties[key]) instanceof EventEmitter)) {
340
339
  // only assign props if they are passed into the component
341
- if ((_b = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _b === void 0 ? void 0 : _b.hasOwnProperty(key)) {
340
+ if ((config === null || config === void 0 ? void 0 : config.componentProperties) && Object.hasOwn(config.componentProperties, key)) {
342
341
  // @ts-expect-error key is a string, not keyof T, so it can't index componentProperties
343
342
  const passedInValue = config === null || config === void 0 ? void 0 : config.componentProperties[key];
344
343
  component[key] = passedInValue;
package/dist/bin/cypress CHANGED
@@ -1,21 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var cli = require('../cli-DoJnc1F1.js');
5
- require('../xvfb-CbW2_YXR.js');
4
+ var cli = require('../cli-y9Bb9Y77.js');
5
+ require('../xvfb-DxbcANVl.js');
6
+ require('lodash');
6
7
  require('os');
8
+ require('path');
9
+ require('child_process');
10
+ require('fs-extra');
7
11
  require('bluebird');
8
12
  require('@cypress/xvfb');
9
13
  require('common-tags');
10
14
  require('debug');
11
15
  require('chalk');
12
- require('lodash');
13
16
  require('assert');
14
17
  require('arch');
15
18
  require('ospath');
16
19
  require('hasha');
17
20
  require('tty');
18
- require('path');
19
21
  require('ci-info');
20
22
  require('execa');
21
23
  require('systeminformation');
@@ -25,19 +27,17 @@ require('executable');
25
27
  require('process');
26
28
  require('supports-color');
27
29
  require('is-installed-globally');
28
- require('fs-extra');
29
30
  require('fs');
30
31
  require('untildify');
31
32
  require('commander');
32
33
  require('cli-table3');
33
34
  require('dayjs');
34
35
  require('dayjs/plugin/relativeTime');
35
- require('../spawn-zPuxj7Kz.js');
36
- require('child_process');
36
+ require('../spawn-Bx99tBTm.js');
37
+ require('string_decoder');
37
38
  require('listr2');
38
39
  require('readline');
39
40
  require('stream');
40
- require('string_decoder');
41
41
  require('node:string_decoder');
42
42
  require('timers/promises');
43
43
  require('fs/promises');
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var xvfb = require('./xvfb-CbW2_YXR.js');
3
+ var xvfb = require('./xvfb-DxbcANVl.js');
4
4
  var _ = require('lodash');
5
5
  var commander = require('commander');
6
6
  var commonTags = require('common-tags');
@@ -13,8 +13,8 @@ var dayjs = require('dayjs');
13
13
  var relativeTime = require('dayjs/plugin/relativeTime');
14
14
  var chalk = require('chalk');
15
15
  var Bluebird = require('bluebird');
16
- var spawn = require('./spawn-zPuxj7Kz.js');
17
16
  var os = require('os');
17
+ var spawn = require('./spawn-Bx99tBTm.js');
18
18
  var listr2 = require('listr2');
19
19
  var timers = require('timers/promises');
20
20
  var fsp = require('fs/promises');
@@ -112,6 +112,14 @@ function requireTapErrors () {
112
112
  description: `Could not find a ${exports.TAP_TARGET} to tap into.`,
113
113
  solution: 'Start Cypress with `cypress open`, select a testing type and launch a browser, then try again.',
114
114
  },
115
+ /**
116
+ * Raised when Cypress is running but its project could not load, so there is no
117
+ * session to drive. Starting Cypress again would only run a second one.
118
+ */
119
+ PROJECT_NOT_LOADED: {
120
+ description: `Cypress is running, but its project could not load, so there is no ${exports.TAP_TARGET} to tap into.`,
121
+ solution: 'Run `cypress tap status` to see why. Fix the cause, then stop Cypress and start it again.',
122
+ },
115
123
  /**
116
124
  * Raised when `--session` named a pid no record on disk matches.
117
125
  *
@@ -309,7 +317,9 @@ function requireTapErrors () {
309
317
  *
310
318
  * @deprecated - raise it with new MissingCompanionOptionTapError(), which writes its copy
311
319
  */
312
- MISSING_COMPANION_OPTION: {},
320
+ MISSING_COMPANION_OPTION: {
321
+ attachHelp: true,
322
+ },
313
323
  /**
314
324
  * Raised when a known input was given a value of the wrong type or range.
315
325
  *
@@ -459,8 +469,9 @@ function requireTapErrors () {
459
469
  exports.SnapshotNotFoundTapError = SnapshotNotFoundTapError;
460
470
  /**
461
471
  * A flag that only means something alongside another one. Both are named here;
462
- * `remedy` is the throw site's, because what dropping either one leaves you with
463
- * is particular to the pair — a spec-wide view rather than one test's attempt.
472
+ * `remedy` comes from the dependency's `requires` in the command schema, because
473
+ * what dropping either one leaves you with is particular to the pair — a
474
+ * spec-wide view rather than one test's attempt.
464
475
  */
465
476
  class MissingCompanionOptionTapError extends DetailedTapError {
466
477
  constructor(given, required, remedy) {
@@ -659,11 +670,28 @@ function requireTapContract () {
659
670
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
660
671
  };
661
672
  Object.defineProperty(exports, "__esModule", { value: true });
662
- exports.KNOWN_COMMANDS = exports.TAP_NATIVE_COMMANDS = exports.buildTapSchema = exports.TAP_COMMANDS = exports.TAP_EXEC_METHOD = exports.TAP_SCHEMA_METHOD = exports.TAP_BINDING_GLOBAL = exports.TAP_SCHEMA_VERSION = void 0;
673
+ exports.KNOWN_COMMANDS = exports.TAP_NATIVE_COMMANDS = exports.buildTapSchema = exports.TAP_COMMANDS = exports.PIN_TARGET_REMEDY = exports.unmetDependency = exports.TAP_EXEC_METHOD = exports.TAP_SCHEMA_METHOD = exports.TAP_BINDING_GLOBAL = exports.TAP_SCHEMA_VERSION = void 0;
674
+ const tap_errors_1 = requireTapErrors();
663
675
  exports.TAP_SCHEMA_VERSION = 1;
664
676
  exports.TAP_BINDING_GLOBAL = '__CYPRESS_TAP_BINDING__';
665
677
  exports.TAP_SCHEMA_METHOD = 'getSchema';
666
678
  exports.TAP_EXEC_METHOD = 'exec';
679
+ /**
680
+ * The first option `supplied` passes without the companion it requires, raised as
681
+ * the failure both sides answer it with. `supplied` holds only the options the
682
+ * caller actually gave, keyed by schema name; a switch given as false was not
683
+ * really given.
684
+ */
685
+ const unmetDependency = (options, supplied) => {
686
+ const given = (name) => supplied[name] !== undefined && supplied[name] !== false;
687
+ for (const { name, requires } of options) {
688
+ if (requires && given(name) && !given(requires.option) && !(requires.unless && given(requires.unless))) {
689
+ return new tap_errors_1.MissingCompanionOptionTapError(`--${name}`, `--${requires.option}`, requires.remedy);
690
+ }
691
+ }
692
+ return undefined;
693
+ };
694
+ exports.unmetDependency = unmetDependency;
667
695
  // Options that recur across commands, defined once so their name, type, and help
668
696
  // text can't drift between the commands that expose them. `test-id` and
669
697
  // `command-id` are required in some commands and optional in others, so each use
@@ -704,18 +732,22 @@ wrong. Add --attempt to view an earlier retry.`,
704
732
  params: [],
705
733
  options: [
706
734
  { ...testIdField, required: false },
707
- attemptField,
735
+ { ...attemptField, requires: { option: 'test-id', remedy: 'Pass `--test-id` to specify the test, or omit `--attempt` to review the latest attempt for every test in the spec.' } },
708
736
  ],
709
737
  };
738
+ // What a pin needs, said once for the call that names half a target and the one
739
+ // that names none.
740
+ exports.PIN_TARGET_REMEDY = 'Pass `--test-id` and `--command-id`, as listed by `cypress tap reporter`, or `--clear` to release the current pin.';
710
741
  const pinMeta = {
711
742
  name: 'pin',
712
743
  description: 'pin a command’s DOM snapshot into the live application-under-test frame',
713
744
  details: `Pins a command's DOM snapshot into the live application-under-test frame so the
714
- dom/aria/inspect commands can read it. Pass --clear to release.`,
745
+ dom/aria/inspect commands can read it. Name the command with --test-id and
746
+ --command-id, or pass --clear to release the current pin.`,
715
747
  params: [],
716
748
  options: [
717
- { ...testIdField, required: false },
718
- { ...commandIdField, required: false },
749
+ { ...testIdField, required: false, requires: { option: 'command-id', unless: 'clear', remedy: exports.PIN_TARGET_REMEDY } },
750
+ { ...commandIdField, required: false, requires: { option: 'test-id', unless: 'clear', remedy: exports.PIN_TARGET_REMEDY } },
719
751
  attemptField,
720
752
  { name: 'at', type: 'string', required: false, description: 'which snapshot to pin: a name like "before"/"after" or a 1-based index; defaults to the last (the command’s final state). Re-run on the pinned command to switch snapshots without releasing the pin' },
721
753
  { name: 'clear', type: 'boolean', required: false, description: 'release the current pin and restore the app to its pre-pin state' },
@@ -798,10 +830,13 @@ tap command refuses it.`,
798
830
  description: 'report where a Cypress session is in its lifecycle',
799
831
  details: `Reports where a Cypress session is in its lifecycle, as JSON — for polling and
800
832
  "where am I?" checks. Always exits 0 for a determinable stage (including "not
801
- connected"); a poller branches on the \`status\` field.
833
+ connected" and "error"); a poller branches on the \`status\` field.
802
834
 
803
835
  Stages:
804
836
  - not connected: Cypress cannot be reached.
837
+ - error: Cypress is running but could not load the project, for example because
838
+ its configuration file is invalid. \`error\` carries the reason; fix the
839
+ project, then stop Cypress and start it again.
805
840
  - browser not selected: Cypress does not have a supported browser open.
806
841
  - spec not selected: Cypress has a browser open but no spec is selected.
807
842
  - loading: Cypress is loading the spec.
@@ -1009,7 +1044,7 @@ function requireDist () {
1009
1044
  return (mod && mod.__esModule) ? mod : { "default": mod };
1010
1045
  };
1011
1046
  Object.defineProperty(exports, "__esModule", { value: true });
1012
- exports.isCompatibleRecord = exports.tapGraphqlPath = exports.sessionProbePath = exports.recordPath = exports.cypressSessionsDir = exports.parseRecordPid = exports.recordFileName = exports.isTapSupportedBrowser = exports.TAP_SUPPORTED_BROWSER_FAMILY = exports.LEGACY_TAP_GRAPHQL_PATH = exports.TAP_GRAPHQL_ROUTE_PREFIX = exports.SESSION_ID_HEADER = exports.SESSIONS_ROUTE_PREFIX = exports.SESSIONS_DIRNAME = exports.MIN_SCHEMA_VERSION = exports.SCHEMA_VERSION = void 0;
1047
+ exports.isCompatibleRecord = exports.tapGraphqlPath = exports.sessionProbePath = exports.recordPath = exports.cypressSessionsDir = exports.parseRecordPid = exports.recordFileName = exports.isStartingRecord = exports.isTapSupportedBrowser = exports.TAP_SUPPORTED_BROWSER_FAMILY = exports.LEGACY_TAP_GRAPHQL_PATH = exports.TAP_GRAPHQL_ROUTE_PREFIX = exports.SESSION_ID_HEADER = exports.SESSIONS_ROUTE_PREFIX = exports.SESSIONS_DIRNAME = exports.MIN_SCHEMA_VERSION = exports.SCHEMA_VERSION = void 0;
1013
1048
  const path_1 = __importDefault(path);
1014
1049
  __exportStar(requireTapContract(), exports);
1015
1050
  __exportStar(requireTapOperations(), exports);
@@ -1033,6 +1068,10 @@ function requireDist () {
1033
1068
  return browserFamily === null || browserFamily === exports.TAP_SUPPORTED_BROWSER_FAMILY;
1034
1069
  };
1035
1070
  exports.isTapSupportedBrowser = isTapSupportedBrowser;
1071
+ const isStartingRecord = (record) => {
1072
+ return record.status === 'starting';
1073
+ };
1074
+ exports.isStartingRecord = isStartingRecord;
1036
1075
  const recordFileName = (pid) => {
1037
1076
  return `${pid}${RECORD_EXTENSION}`;
1038
1077
  };
@@ -1065,6 +1104,7 @@ function requireDist () {
1065
1104
  return value === 'e2e' || value === 'component' || value === null;
1066
1105
  };
1067
1106
  const isCompatibleRecord = (record) => {
1107
+ var _a;
1068
1108
  return Boolean(record)
1069
1109
  && typeof record.schemaVersion === 'number'
1070
1110
  && record.schemaVersion >= exports.MIN_SCHEMA_VERSION
@@ -1073,7 +1113,11 @@ function requireDist () {
1073
1113
  && Number.isInteger(record.serverPort)
1074
1114
  && typeof record.sessionId === 'string'
1075
1115
  && record.sessionId.length > 0
1076
- && isValidTestingType(record.testingType);
1116
+ && isValidTestingType(record.testingType)
1117
+ && (record.status === undefined || record.status === 'starting')
1118
+ && (record.serverPort !== 0 || record.status === 'starting')
1119
+ && (record.loadError === undefined || typeof ((_a = record.loadError) === null || _a === void 0 ? void 0 : _a.message) === 'string')
1120
+ && (record.status !== 'starting' || record.loadError !== undefined);
1077
1121
  };
1078
1122
  exports.isCompatibleRecord = isCompatibleRecord;
1079
1123
 
@@ -1182,14 +1226,22 @@ const readCompatibleRecord = (filePath) => xvfb.__awaiter(void 0, void 0, void 0
1182
1226
  return record;
1183
1227
  });
1184
1228
  // Reaps a record whose writer process is gone, returning whether it was dead.
1229
+ // A pid that fails the signal check is not proof of death: a caller in another
1230
+ // PID namespace cannot see the writer's pid, so a record whose server still
1231
+ // answers its probe is kept. A record we could not read has no probe to try, so
1232
+ // its pid check stands alone.
1185
1233
  // Removal is best-effort: a file we can't delete (permissions, a Windows lock)
1186
1234
  // must not abort discovery of the other, live sessions, so the failure is
1187
1235
  // swallowed and the record is still reported dead.
1188
- const reapIfDead = (file) => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1236
+ const reapIfDead = (file, record) => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1189
1237
  const { path, pid } = file;
1190
1238
  if (isPidAlive(pid)) {
1191
1239
  return false;
1192
1240
  }
1241
+ // A starting record names no server to ask, so its pid check stands alone.
1242
+ if (record && !distExports.isStartingRecord(record) && (yield verifySessionRecord(record))) {
1243
+ return false;
1244
+ }
1193
1245
  yield fs.remove(path).catch((err) => {
1194
1246
  debug$7('failed to reap dead cypress sessions record %s: %o', path, err);
1195
1247
  });
@@ -1206,16 +1258,33 @@ const readLiveSessions = () => xvfb.__awaiter(void 0, void 0, void 0, function*
1206
1258
  if (!record) {
1207
1259
  return null;
1208
1260
  }
1209
- if (yield reapIfDead(file)) {
1261
+ if (yield reapIfDead(file, record)) {
1210
1262
  return null;
1211
1263
  }
1212
1264
  return record;
1213
1265
  })));
1214
1266
  return records.filter((record) => record !== null);
1215
1267
  });
1268
+ /**
1269
+ * Reads the records of projects that could not load, whose writer process is still running.
1270
+ * They are not live sessions: they name no server.
1271
+ */
1272
+ const readStartingSessions = () => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1273
+ const files = yield listRecordFiles(getSessionsDir());
1274
+ const records = yield Promise.all(files.map((file) => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1275
+ const record = yield readCompatibleRecord(file.path);
1276
+ if (!record || !distExports.isStartingRecord(record)) {
1277
+ return null;
1278
+ }
1279
+ return (yield reapIfDead(file, record)) ? null : record;
1280
+ })));
1281
+ return records.filter((record) => record !== null);
1282
+ });
1216
1283
  const pruneDeadSessionRecords = () => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1217
1284
  const files = yield listRecordFiles(getSessionsDir());
1218
- const pruned = yield Promise.all(files.map((file) => reapIfDead(file)));
1285
+ const pruned = yield Promise.all(files.map((file) => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1286
+ return reapIfDead(file, yield readCompatibleRecord(file.path));
1287
+ })));
1219
1288
  const removed = pruned.filter(Boolean).length;
1220
1289
  debug$7('pruned %d dead cypress sessions record(s)', removed);
1221
1290
  return removed;
@@ -1454,13 +1523,27 @@ const processOpenOptions = (options = {}) => {
1454
1523
  return args;
1455
1524
  };
1456
1525
  const start$3 = (...args_1) => xvfb.__awaiter(void 0, [...args_1], void 0, function* (options = {}) {
1526
+ // Some agent hosts export ELECTRON_RUN_AS_NODE, which would start the app as
1527
+ // plain Node with no window and no session. The smoke test that verifies the
1528
+ // binary needs the same environment, or it fails the same way.
1529
+ let env;
1530
+ // Electron treats the variable as set when it exists, even empty. Only Windows names are case-insensitive.
1531
+ const isRunAsNode = (key) => (os.platform() === 'win32' ? key.toUpperCase() : key) === 'ELECTRON_RUN_AS_NODE';
1532
+ if (!options.dev && Object.keys(process.env).some(isRunAsNode)) {
1533
+ xvfb.loggerModule.warn('ELECTRON_RUN_AS_NODE is set and was ignored because `cypress open` needs the app window.');
1534
+ env = _.omitBy(process.env, (_value, key) => isRunAsNode(key));
1535
+ }
1457
1536
  function open() {
1458
1537
  try {
1459
1538
  const args = processOpenOptions(options);
1460
- return spawn.start$1(args, {
1539
+ const spawnOptions = {
1461
1540
  dev: options.dev,
1462
1541
  detached: Boolean(options.detached),
1463
- });
1542
+ };
1543
+ if (env) {
1544
+ spawnOptions.env = env;
1545
+ }
1546
+ return spawn.start$1(args, spawnOptions);
1464
1547
  }
1465
1548
  catch (err) {
1466
1549
  if (err.details) {
@@ -1472,7 +1555,7 @@ const start$3 = (...args_1) => xvfb.__awaiter(void 0, [...args_1], void 0, funct
1472
1555
  if (options.dev) {
1473
1556
  return open();
1474
1557
  }
1475
- yield spawn.start();
1558
+ yield spawn.start({ env });
1476
1559
  return open();
1477
1560
  });
1478
1561
  var openModule = {
@@ -1648,6 +1731,29 @@ const runModule = {
1648
1731
  const debug$4 = Debug('cypress:cli');
1649
1732
  const defaultBaseUrl = 'https://download.cypress.io/';
1650
1733
  const defaultMaxRedirects = 10;
1734
+ const maxDownloadAttempts = 3;
1735
+ const defaultRetryDelayMs = 1000;
1736
+ // How long the connection or the transfer can go quiet, so a network that drops packets fails and is retried instead of waiting for the operating system to give up
1737
+ const defaultTimeoutMs = 60000;
1738
+ const retryableErrorCodes = new Set([
1739
+ 'ECONNRESET',
1740
+ 'ETIMEDOUT',
1741
+ 'ECONNREFUSED',
1742
+ 'EAI_AGAIN',
1743
+ 'EPIPE',
1744
+ 'ESOCKETTIMEDOUT',
1745
+ ]);
1746
+ const isRetryableDownloadError = (err) => {
1747
+ if (err === null || err === void 0 ? void 0 : err.statusCode) {
1748
+ return err.statusCode === 408 || err.statusCode === 429 || err.statusCode >= 500;
1749
+ }
1750
+ return retryableErrorCodes.has(err === null || err === void 0 ? void 0 : err.code);
1751
+ };
1752
+ // Jitter keeps concurrent installs from retrying in lockstep
1753
+ const getRetryDelay = (attempt, baseDelayMs) => {
1754
+ const backoff = baseDelayMs * 2 ** (attempt - 1);
1755
+ return Math.round(backoff * (0.5 + Math.random() / 2));
1756
+ };
1651
1757
  const getProxyForUrlWithNpmConfig = (url) => {
1652
1758
  return proxyFromEnv.getProxyForUrl(url) ||
1653
1759
  process.env.npm_config_https_proxy ||
@@ -1784,7 +1890,7 @@ const verifyDownloadedFile = (filename, expectedSize, expectedChecksum) => xvfb.
1784
1890
  // downloads from given url
1785
1891
  // return an object with
1786
1892
  // {filename: ..., downloaded: true}
1787
- const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redirectTTL = defaultMaxRedirects }) => {
1893
+ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redirectTTL = defaultMaxRedirects, timeoutMs = defaultTimeoutMs }) => {
1788
1894
  if (redirectTTL <= 0) {
1789
1895
  return Promise.reject(new Error(commonTags.stripIndent `
1790
1896
  Failed downloading the Cypress binary.
@@ -1802,10 +1908,19 @@ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redi
1802
1908
  if (ca) {
1803
1909
  debug$4('using custom CA details from npm config');
1804
1910
  }
1805
- const reqOptions = Object.assign(Object.assign(Object.assign({ uri: url }, (proxy ? { proxy } : {})), (ca ? { agentOptions: { ca } } : {})), { method: 'GET', followRedirect: false });
1911
+ const reqOptions = Object.assign(Object.assign(Object.assign({ uri: url }, (proxy ? { proxy } : {})), (ca ? { agentOptions: { ca } } : {})), { method: 'GET', followRedirect: false, timeout: timeoutMs });
1806
1912
  const req = request(reqOptions);
1807
1913
  // closure
1808
1914
  let started = null;
1915
+ let bodyComplete = false;
1916
+ let redirected = false;
1917
+ let writeFailed = false;
1918
+ let fileStream;
1919
+ // A failed attempt closes the file it was writing, so a retry does not leave it open behind it
1920
+ const fail = (err) => {
1921
+ fileStream === null || fileStream === void 0 ? void 0 : fileStream.destroy();
1922
+ reject(err);
1923
+ };
1809
1924
  let expectedSize;
1810
1925
  let expectedChecksum;
1811
1926
  requestProgress(req, {
@@ -1835,7 +1950,8 @@ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redi
1835
1950
  const redirectUrl = response.headers.location;
1836
1951
  debug$4('redirect version:', redirectVersion);
1837
1952
  debug$4('redirect url:', redirectUrl);
1838
- downloadFromUrl({ url: redirectUrl, progress, ca, downloadDestination, version: redirectVersion, redirectTTL: redirectTTL - 1 })
1953
+ redirected = true;
1954
+ downloadFromUrl({ url: redirectUrl, progress, ca, downloadDestination, version: redirectVersion, redirectTTL: redirectTTL - 1, timeoutMs })
1839
1955
  .then(resolve).catch(reject);
1840
1956
  // if our status code does not start with 200
1841
1957
  }
@@ -1846,18 +1962,42 @@ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redi
1846
1962
  Response code: ${response.statusCode}
1847
1963
  Response message: ${response.statusMessage}
1848
1964
  `);
1849
- reject(err);
1965
+ err.statusCode = response.statusCode;
1966
+ err.statusMessage = response.statusMessage;
1967
+ fail(err);
1850
1968
  // status codes here are all 2xx
1851
1969
  }
1852
1970
  else {
1971
+ const writeStream = fs.createWriteStream(downloadDestination);
1972
+ fileStream = writeStream;
1973
+ // An unhandled 'error' event would crash the CLI. A failed write, such as on a
1974
+ // full disk, leaves a truncated file that would keep holding that disk space.
1975
+ writeStream.on('error', (err) => {
1976
+ debug$4('failed writing %s: %s', downloadDestination, err.message);
1977
+ writeFailed = true;
1978
+ response.destroy();
1979
+ writeStream.once('close', () => {
1980
+ fs.remove(downloadDestination)
1981
+ .catch((removeErr) => debug$4('failed removing %s: %s', downloadDestination, removeErr.message))
1982
+ .finally(() => reject(err));
1983
+ });
1984
+ });
1853
1985
  // We only enable this pipe connection when we know we've got a successful return
1854
1986
  // and handle the completion with verify and resolve
1855
1987
  // there was a possible race condition between end of request and close of writeStream
1856
1988
  // that is made ordered with this Promise.all
1989
+ response.on('end', () => {
1990
+ bodyComplete = true;
1991
+ });
1857
1992
  Bluebird.all([new Bluebird((r) => {
1858
- return response.pipe(fs.createWriteStream(downloadDestination).on('close', r));
1993
+ return response.pipe(writeStream.on('close', r));
1859
1994
  }), new Bluebird((r) => response.on('end', r))])
1860
1995
  .then(() => {
1996
+ // The error handler is deleting the partial file and rejects with the
1997
+ // write error, so verifying the file here would race that deletion.
1998
+ if (writeFailed) {
1999
+ return;
2000
+ }
1861
2001
  debug$4('downloading finished');
1862
2002
  verifyDownloadedFile(downloadDestination, expectedSize, expectedChecksum)
1863
2003
  .then(() => debug$4('verified'))
@@ -1867,9 +2007,15 @@ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redi
1867
2007
  }
1868
2008
  })
1869
2009
  .on('error', (e) => {
1870
- if (e.code === 'ECONNRESET')
1871
- return; // sometimes proxies give ECONNRESET but we don't care
1872
- reject(e);
2010
+ // The connection can reset after the whole file arrived. The file is complete, and
2011
+ // verifying it decides the outcome, so downloading it all again would be wasted.
2012
+ // A failed write stops the response itself, and the connection error that causes
2013
+ // must not turn the write error into a retry.
2014
+ if (bodyComplete || redirected || writeFailed) {
2015
+ debug$4('ignoring error after the download completed or moved on: %s', e.message);
2016
+ return;
2017
+ }
2018
+ fail(e);
1873
2019
  })
1874
2020
  .on('progress', (state) => {
1875
2021
  // total time we've elapsed
@@ -1889,7 +2035,7 @@ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redi
1889
2035
  * @param [string] downloadDestination Local filename to save as
1890
2036
  */
1891
2037
  const start$2 = (opts) => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1892
- const { version, downloadDestination, redirectTTL } = opts;
2038
+ const { version, downloadDestination, redirectTTL, retryDelayMs = defaultRetryDelayMs, timeoutMs = defaultTimeoutMs } = opts;
1893
2039
  let { progress } = opts;
1894
2040
  if (!downloadDestination) {
1895
2041
  assert.ok(_.isString(downloadDestination) && !_.isEmpty(downloadDestination), 'missing download dir');
@@ -1901,7 +2047,7 @@ const start$2 = (opts) => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1901
2047
  }
1902
2048
  const arch = yield xvfb.util.getRealArch();
1903
2049
  const versionUrl = getUrl(arch, version);
1904
- progress.throttle = 100;
2050
+ progress.throttle = xvfb.util.progressThrottleMs;
1905
2051
  debug$4('needed Cypress version: %s', version);
1906
2052
  debug$4('source url %s', versionUrl);
1907
2053
  debug$4(`downloading cypress.zip to "${downloadDestination}"`);
@@ -1909,7 +2055,21 @@ const start$2 = (opts) => xvfb.__awaiter(void 0, void 0, void 0, function* () {
1909
2055
  // ensure download dir exists
1910
2056
  yield fs.ensureDir(path.dirname(downloadDestination));
1911
2057
  const ca = yield getCA();
1912
- return downloadFromUrl(Object.assign({ url: versionUrl, downloadDestination, progress, ca, version }, (redirectTTL ? { redirectTTL } : {})));
2058
+ for (let attempt = 1;; attempt++) {
2059
+ try {
2060
+ return yield downloadFromUrl(Object.assign({ url: versionUrl, downloadDestination, progress, ca, version,
2061
+ timeoutMs }, (redirectTTL ? { redirectTTL } : {})));
2062
+ }
2063
+ catch (err) {
2064
+ if (attempt >= maxDownloadAttempts || !isRetryableDownloadError(err)) {
2065
+ throw err;
2066
+ }
2067
+ const delay = getRetryDelay(attempt, retryDelayMs);
2068
+ debug$4('download attempt %d of %d failed (%s), retrying in %dms', attempt, maxDownloadAttempts, err.code || err.statusCode, delay);
2069
+ progress.onProgress(0, 0);
2070
+ yield Bluebird.delay(delay);
2071
+ }
2072
+ }
1913
2073
  }
1914
2074
  catch (err) {
1915
2075
  return prettyDownloadErr(err, versionUrl);
@@ -2095,22 +2255,37 @@ const unzip = (_a) => xvfb.__awaiter(void 0, [_a], void 0, function* ({ zipFileP
2095
2255
  debug$3('zipFile entries count', total);
2096
2256
  // Close the count-only handle — the Node fallback re-opens the zip for extraction.
2097
2257
  zipFile.close();
2098
- const started = new Date();
2258
+ let started = Date.now();
2099
2259
  let percent = 0;
2100
2260
  let count = 0;
2261
+ let lastNotifiedPercent;
2262
+ let lastNotifiedAt = 0;
2101
2263
  const notify = (percent) => {
2102
- const elapsed = +new Date() - +started;
2103
- const eta = xvfb.util.calculateEta(percent, elapsed);
2264
+ const now = Date.now();
2265
+ lastNotifiedPercent = percent;
2266
+ lastNotifiedAt = now;
2267
+ const eta = xvfb.util.calculateEta(percent, now - started);
2104
2268
  progress.onProgress(percent, xvfb.util.secsRemaining(eta));
2105
2269
  };
2270
+ // Extractors tick for every entry or chunk of tool output, far more
2271
+ // often than the shown percent changes.
2106
2272
  const tick = () => {
2107
2273
  count += 1;
2108
2274
  percent = ((count / total) * 100);
2109
- const displayPercent = percent.toFixed(0);
2110
- return notify(Number(displayPercent));
2275
+ const displayPercent = Math.round(percent);
2276
+ if (displayPercent === lastNotifiedPercent && Date.now() - lastNotifiedAt < xvfb.util.progressThrottleMs) {
2277
+ return;
2278
+ }
2279
+ return notify(displayPercent);
2111
2280
  };
2112
2281
  const unzipWithNode = () => xvfb.__awaiter(void 0, void 0, void 0, function* () {
2113
2282
  debug$3('unzipping with node.js (slow)');
2283
+ // When this is the fallback, the OS tool may already have ticked part
2284
+ // of the archive and used up time, but extraction starts over from the
2285
+ // first entry, so the progress and the ETA must too.
2286
+ count = 0;
2287
+ started = Date.now();
2288
+ lastNotifiedPercent = undefined;
2114
2289
  try {
2115
2290
  yield unzipTools.extractWithYauzl(zipFilePath, installDir, tick);
2116
2291
  debug$3('node unzip finished');
@@ -2439,7 +2614,6 @@ function downloadArchive(version, downloadDestination) {
2439
2614
  version,
2440
2615
  downloadDestination,
2441
2616
  progress: {
2442
- throttle: 100,
2443
2617
  onProgress: (percentComplete, remaining) => {
2444
2618
  task.title = progressTitle(inProgressTitle, percentComplete, remaining);
2445
2619
  },
@@ -3089,7 +3263,7 @@ const cliModule = {
3089
3263
  .action(function (opts, args) {
3090
3264
  return xvfb.__awaiter(this, void 0, void 0, function* () {
3091
3265
  try {
3092
- const { default: tapModule } = yield Promise.resolve().then(function () { return require('./tap-D2mHgoNE.js'); });
3266
+ const { default: tapModule } = yield Promise.resolve().then(function () { return require('./tap-BMFGLoCT.js'); });
3093
3267
  const code = yield tapModule.start(args || [], _.pick(opts, ['session', 'json', 'timeout']));
3094
3268
  process.exit(code);
3095
3269
  }
@@ -3142,8 +3316,8 @@ const cliModule = {
3142
3316
  exports.cliModule = cliModule;
3143
3317
  exports.distExports = distExports;
3144
3318
  exports.installModule = installModule;
3145
- exports.isPidAlive = isPidAlive;
3146
3319
  exports.openModule = openModule;
3147
3320
  exports.readLiveSessions = readLiveSessions;
3321
+ exports.readStartingSessions = readStartingSessions;
3148
3322
  exports.runModule = runModule;
3149
3323
  exports.verifySessionRecord = verifySessionRecord;
package/dist/cli.js CHANGED
@@ -2,15 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('./xvfb-CbW2_YXR.js');
5
+ require('./xvfb-DxbcANVl.js');
6
6
  require('lodash');
7
7
  require('commander');
8
8
  require('common-tags');
9
9
  require('log-symbols');
10
10
  require('debug');
11
- var cli = require('./cli-DoJnc1F1.js');
12
- require('./spawn-zPuxj7Kz.js');
11
+ var cli = require('./cli-y9Bb9Y77.js');
12
+ require('./spawn-Bx99tBTm.js');
13
13
  require('os');
14
+ require('path');
15
+ require('child_process');
16
+ require('fs-extra');
14
17
  require('bluebird');
15
18
  require('@cypress/xvfb');
16
19
  require('chalk');
@@ -19,7 +22,6 @@ require('arch');
19
22
  require('ospath');
20
23
  require('hasha');
21
24
  require('tty');
22
- require('path');
23
25
  require('ci-info');
24
26
  require('execa');
25
27
  require('systeminformation');
@@ -28,7 +30,6 @@ require('executable');
28
30
  require('process');
29
31
  require('supports-color');
30
32
  require('is-installed-globally');
31
- require('fs-extra');
32
33
  require('fs');
33
34
  require('untildify');
34
35
  require('cli-table3');
@@ -40,7 +41,6 @@ require('fs/promises');
40
41
  require('@cypress/request');
41
42
  require('request-progress');
42
43
  require('proxy-from-env');
43
- require('child_process');
44
44
  require('yauzl');
45
45
  require('util');
46
46
  require('stream');
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var xvfb = require('./xvfb-CbW2_YXR.js');
3
+ var xvfb = require('./xvfb-DxbcANVl.js');
4
4
  var tmp = require('tmp');
5
5
  var fs = require('fs-extra');
6
- var cli$1 = require('./cli-DoJnc1F1.js');
6
+ var cli$1 = require('./cli-y9Bb9Y77.js');
7
7
 
8
8
  /**
9
9
  * Opens Cypress GUI