cypress 4.12.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/lib/errors.js CHANGED
@@ -121,7 +121,7 @@ function _templateObject6() {
121
121
  }
122
122
 
123
123
  function _templateObject5() {
124
- var data = _taggedTemplateLiteral(["\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n "], ["\\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n "]);
124
+ var data = _taggedTemplateLiteral(["\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n\n You can also try clearing the cache with 'cypress cache clear' and reinstalling. \n "], ["\\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n\n You can also try clearing the cache with 'cypress cache clear' and reinstalling. \n "]);
125
125
 
126
126
  _templateObject5 = function _templateObject5() {
127
127
  return data;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
3
5
  function _templateObject7() {
4
6
  var data = _taggedTemplateLiteral(["\n ", " Warning: Forcing a binary version different than the default.\n\n The CLI expected to install version: ", "\n\n Instead we will install version: ", "\n\n These versions may not work properly together.\n "]);
5
7
 
@@ -20,6 +22,18 @@ function _templateObject6() {
20
22
  return data;
21
23
  }
22
24
 
25
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
26
+
27
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
28
+
29
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
30
+
31
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
32
+
33
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
34
+
35
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
36
+
23
37
  function _templateObject5() {
24
38
  var data = _taggedTemplateLiteral(["\n Failed to access ", ":\n\n ", "\n "]);
25
39
 
@@ -72,10 +86,32 @@ function _templateObject() {
72
86
 
73
87
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
74
88
 
89
+ function _wrapRegExp(re, groups) { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _RegExp = _wrapNativeSuper(RegExp); var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = _RegExp.call(this, re, flags); _groups.set(_this, groups || _groups.get(re)); return _this; } _inherits(BabelRegExp, _RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = []; args.push.apply(args, arguments); if (_typeof(args[args.length - 1]) !== "object") { args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
90
+
91
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
92
+
93
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
94
+
95
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
96
+
97
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
98
+
99
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
100
+
101
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
102
+
103
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
104
+
105
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
106
+
107
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
108
+
75
109
  var _ = require('lodash');
76
110
 
77
111
  var os = require('os');
78
112
 
113
+ var url = require('url');
114
+
79
115
  var path = require('path');
80
116
 
81
117
  var chalk = require('chalk');
@@ -109,6 +145,102 @@ var _require2 = require('../errors'),
109
145
  throwFormErrorText = _require2.throwFormErrorText,
110
146
  errors = _require2.errors;
111
147
 
148
+ var getNpmArgv = function getNpmArgv() {
149
+ var json = process.env.npm_config_argv;
150
+
151
+ if (!json) {
152
+ return;
153
+ }
154
+
155
+ debug('found npm argv json %o', json);
156
+
157
+ try {
158
+ return JSON.parse(json).original || [];
159
+ } catch (e) {
160
+ return [];
161
+ }
162
+ }; // attempt to discover the version specifier used to install Cypress
163
+ // for example: "^5.0.0", "https://cdn.cypress.io/...", ...
164
+
165
+
166
+ var getVersionSpecifier = function getVersionSpecifier() {
167
+ var startDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : path.resolve(__dirname, '../..');
168
+ var argv = getNpmArgv();
169
+
170
+ if (argv) {
171
+ var tgz = _.find(argv, function (t) {
172
+ return t.endsWith('cypress.tgz');
173
+ });
174
+
175
+ if (tgz) {
176
+ return tgz;
177
+ }
178
+ }
179
+
180
+ var getVersionSpecifierFromPkg = function getVersionSpecifierFromPkg(dir) {
181
+ debug('looking for versionSpecifier %o', {
182
+ dir: dir
183
+ });
184
+
185
+ var tryParent = function tryParent() {
186
+ var parentPath = path.resolve(dir, '..');
187
+
188
+ if (parentPath === dir) {
189
+ debug('reached FS root with no versionSpecifier found');
190
+ return;
191
+ }
192
+
193
+ return getVersionSpecifierFromPkg(parentPath);
194
+ };
195
+
196
+ return fs.readJSON(path.join(dir, 'package.json'))["catch"](function () {
197
+ return {};
198
+ }).then(function (pkg) {
199
+ var specifier = _.chain(['dependencies', 'devDependencies', 'optionalDependencies']).map(function (prop) {
200
+ return _.get(pkg, "".concat(prop, ".cypress"));
201
+ }).compact().first().value();
202
+
203
+ return specifier || tryParent();
204
+ });
205
+ }; // recurse through parent directories until package.json with `cypress` is found
206
+
207
+
208
+ return getVersionSpecifierFromPkg(startDir).then(function (versionSpecifier) {
209
+ debug('finished looking for versionSpecifier', {
210
+ versionSpecifier: versionSpecifier
211
+ });
212
+ return versionSpecifier;
213
+ });
214
+ };
215
+
216
+ var betaNpmUrlRe = /*#__PURE__*/_wrapRegExp(/^\/beta\/npm\/([\.0-9]+)\/([\0-\.0-\uFFFF]+)\/cypress\.tgz$/, {
217
+ version: 1,
218
+ artifactSlug: 2
219
+ }); // convert a prerelease NPM package .tgz URL to the corresponding binary .zip URL
220
+
221
+
222
+ var getBinaryUrlFromPrereleaseNpmUrl = function getBinaryUrlFromPrereleaseNpmUrl(npmUrl) {
223
+ var parsed;
224
+
225
+ try {
226
+ parsed = url.parse(npmUrl);
227
+ } catch (e) {
228
+ return;
229
+ }
230
+
231
+ var matches = betaNpmUrlRe.exec(parsed.pathname);
232
+
233
+ if (parsed.hostname !== 'cdn.cypress.io' || !matches) {
234
+ return;
235
+ }
236
+
237
+ var _matches$groups = matches.groups,
238
+ version = _matches$groups.version,
239
+ artifactSlug = _matches$groups.artifactSlug;
240
+ parsed.pathname = "/beta/binary/".concat(version, "/").concat(os.platform(), "-").concat(os.arch(), "/").concat(artifactSlug, "/cypress.zip");
241
+ return parsed.format();
242
+ };
243
+
112
244
  var alreadyInstalledMsg = function alreadyInstalledMsg() {
113
245
  if (!util.isPostInstall()) {
114
246
  logger.log(stripIndent(_templateObject(), chalk.yellow('--force')));
@@ -204,6 +336,7 @@ var start = function start() {
204
336
 
205
337
  var pkgVersion = util.pkgVersion();
206
338
  var needVersion = pkgVersion;
339
+ var binaryUrlOverride;
207
340
  debug('version in package.json is', needVersion); // let this environment variable reset the binary version we need
208
341
 
209
342
  if (util.getEnv('CYPRESS_INSTALL_BINARY')) {
@@ -218,14 +351,9 @@ var start = function start() {
218
351
  logger.log(stripIndent(_templateObject3(), chalk.yellow('Note:')));
219
352
  logger.log();
220
353
  return Promise.resolve();
221
- } // if this doesn't match the expected version
222
- // then print warning to the user
223
-
224
-
225
- if (envVarVersion !== needVersion) {
226
- // reset the version to the env var version
227
- needVersion = envVarVersion;
228
354
  }
355
+
356
+ binaryUrlOverride = envVarVersion;
229
357
  }
230
358
 
231
359
  if (util.getEnv('CYPRESS_CACHE_FOLDER')) {
@@ -242,14 +370,32 @@ var start = function start() {
242
370
  }, function (err) {
243
371
  return throwFormErrorText(errors.invalidCacheDirectory)(stripIndent(_templateObject5(), chalk.cyan(cacheDir), err.message));
244
372
  }).then(function () {
245
- return state.getBinaryPkgVersionAsync(binaryDir);
246
- }).then(function (binaryVersion) {
373
+ return Promise.all([state.getBinaryPkgVersionAsync(binaryDir), getVersionSpecifier()]);
374
+ }).then(function (_ref2) {
375
+ var _ref3 = _slicedToArray(_ref2, 2),
376
+ binaryVersion = _ref3[0],
377
+ versionSpecifier = _ref3[1];
378
+
379
+ if (!binaryUrlOverride && versionSpecifier) {
380
+ var computedBinaryUrl = getBinaryUrlFromPrereleaseNpmUrl(versionSpecifier);
381
+
382
+ if (computedBinaryUrl) {
383
+ debug('computed binary url from version specifier %o', {
384
+ computedBinaryUrl: computedBinaryUrl,
385
+ needVersion: needVersion
386
+ });
387
+ binaryUrlOverride = computedBinaryUrl;
388
+ }
389
+ }
390
+
391
+ needVersion = binaryUrlOverride || needVersion;
392
+ debug('installed version is', binaryVersion, 'version needed is', needVersion);
393
+
247
394
  if (!binaryVersion) {
248
395
  debug('no binary installed under cli version');
249
396
  return true;
250
397
  }
251
398
 
252
- debug('installed version is', binaryVersion, 'version needed is', needVersion);
253
399
  logger.log();
254
400
  logger.log(stripIndent(_templateObject6(), chalk.green(binaryVersion), chalk.cyan(installDir)));
255
401
  logger.log();
@@ -332,14 +478,16 @@ var start = function start() {
332
478
  };
333
479
 
334
480
  module.exports = {
335
- start: start
481
+ start: start,
482
+ _getVersionSpecifier: getVersionSpecifier,
483
+ _getBinaryUrlFromPrereleaseNpmUrl: getBinaryUrlFromPrereleaseNpmUrl
336
484
  };
337
485
 
338
- var unzipTask = function unzipTask(_ref2) {
339
- var zipFilePath = _ref2.zipFilePath,
340
- installDir = _ref2.installDir,
341
- progress = _ref2.progress,
342
- rendererOptions = _ref2.rendererOptions;
486
+ var unzipTask = function unzipTask(_ref4) {
487
+ var zipFilePath = _ref4.zipFilePath,
488
+ installDir = _ref4.installDir,
489
+ progress = _ref4.progress,
490
+ rendererOptions = _ref4.rendererOptions;
343
491
  return {
344
492
  title: util.titleize('Unzipping Cypress'),
345
493
  task: function task(ctx, _task3) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress",
3
- "version": "4.12.0",
3
+ "version": "5.2.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "postinstall": "node index.js --exec install",
@@ -13,26 +13,27 @@
13
13
  "@types/sinonjs__fake-timers": "^6.0.1",
14
14
  "@types/sizzle": "^2.3.2",
15
15
  "arch": "^2.1.2",
16
+ "blob-util": "2.0.2",
16
17
  "bluebird": "^3.7.2",
17
18
  "cachedir": "^2.3.0",
18
- "chalk": "^2.4.2",
19
+ "chalk": "^4.1.0",
19
20
  "check-more-types": "^2.24.0",
20
- "cli-table3": "~0.5.1",
21
+ "cli-table3": "~0.6.0",
21
22
  "commander": "^4.1.1",
22
23
  "common-tags": "^1.8.0",
23
24
  "debug": "^4.1.1",
24
25
  "eventemitter2": "^6.4.2",
25
- "execa": "^1.0.0",
26
+ "execa": "^4.0.2",
26
27
  "executable": "^4.1.1",
27
28
  "extract-zip": "^1.7.0",
28
- "fs-extra": "^8.1.0",
29
+ "fs-extra": "^9.0.1",
29
30
  "getos": "^3.2.1",
30
31
  "is-ci": "^2.0.0",
31
32
  "is-installed-globally": "^0.3.2",
32
33
  "lazy-ass": "^1.6.0",
33
34
  "listr": "^0.14.3",
34
35
  "lodash": "^4.17.19",
35
- "log-symbols": "^3.0.0",
36
+ "log-symbols": "^4.0.0",
36
37
  "minimist": "^1.2.5",
37
38
  "moment": "^2.27.0",
38
39
  "ospath": "^1.2.2",
@@ -40,7 +41,7 @@
40
41
  "ramda": "~0.26.1",
41
42
  "request-progress": "^3.0.0",
42
43
  "supports-color": "^7.1.0",
43
- "tmp": "~0.1.0",
44
+ "tmp": "~0.2.1",
44
45
  "untildify": "^4.0.0",
45
46
  "url": "^0.11.0",
46
47
  "yauzl": "^2.10.0"
@@ -49,13 +50,14 @@
49
50
  "bin",
50
51
  "lib",
51
52
  "index.js",
52
- "types/**/*.d.ts"
53
+ "types/**/*.d.ts",
54
+ "types/net-stubbing.ts"
53
55
  ],
54
56
  "bin": {
55
57
  "cypress": "bin/cypress"
56
58
  },
57
59
  "engines": {
58
- "node": ">=8.0.0"
60
+ "node": ">=10.0.0"
59
61
  },
60
62
  "types": "types",
61
63
  "description": "Cypress.io end to end testing tool",
@@ -3,7 +3,7 @@
3
3
  // so that Cypress can get and use the Blob type
4
4
 
5
5
  // tslint:disable-next-line:no-implicit-dependencies
6
- import * as blobUtil from './blob-util'
6
+ import * as blobUtil from 'blob-util'
7
7
 
8
8
  export = BlobUtil
9
9
  export as namespace BlobUtil
@@ -7,6 +7,12 @@
7
7
  // but for now describe it as an ambient module
8
8
 
9
9
  declare namespace CypressCommandLine {
10
+ type HookName = 'before' | 'beforeEach' | 'afterEach' | 'after'
11
+ interface TestError {
12
+ name: string
13
+ message: string
14
+ stack: string
15
+ }
10
16
  /**
11
17
  * All options that one can pass to "cypress.run"
12
18
  * @see https://on.cypress.io/module-api#cypress-run
@@ -154,39 +160,36 @@ declare namespace CypressCommandLine {
154
160
  // small utility types to better express meaning of other types
155
161
  type dateTimeISO = string
156
162
  type ms = number
157
- type hookId = string
158
- type testId = string
159
163
  type pixels = number
160
164
 
161
165
  /**
162
166
  * Cypress single test result
163
167
  */
164
168
  interface TestResult {
165
- testId: testId
166
169
  title: string[]
167
170
  state: string
168
171
  body: string
169
- /**
170
- * Error stack string if there is an error
171
- */
172
- stack: string | null
173
- /**
174
- * Error message if there is an error
172
+ /**
173
+ * Error string as it's presented in console if the test fails
175
174
  */
176
- error: string | null
177
- timings: any
178
- failedFromHookId: hookId | null
179
- wallClockStartedAt: dateTimeISO
180
- wallClockDuration: ms
175
+ displayError: string | null
176
+ attempts: AttemptResult[]
177
+ }
178
+
179
+ interface AttemptResult {
180
+ state: string
181
+ error: TestError | null
182
+ startedAt: dateTimeISO
183
+ duration: ms
181
184
  videoTimestamp: ms
185
+ screenshots: ScreenshotInformation[]
182
186
  }
183
187
 
184
188
  /**
185
189
  * Information about a single "before", "beforeEach", "afterEach" and "after" hook.
186
190
  */
187
191
  interface HookInformation {
188
- hookId: hookId
189
- hookName: 'before' | 'beforeEach' | 'afterEach' | 'after'
192
+ hookName: HookName
190
193
  title: string[]
191
194
  body: string
192
195
  }
@@ -195,9 +198,7 @@ declare namespace CypressCommandLine {
195
198
  * Information about a single screenshot.
196
199
  */
197
200
  interface ScreenshotInformation {
198
- screenshotId: string
199
201
  name: string
200
- testId: testId
201
202
  takenAt: dateTimeISO
202
203
  /**
203
204
  * Absolute path to the saved image
@@ -221,9 +222,9 @@ declare namespace CypressCommandLine {
221
222
  pending: number
222
223
  skipped: number
223
224
  failures: number
224
- wallClockStartedAt: dateTimeISO
225
- wallClockEndedAt: dateTimeISO
226
- wallClockDuration: ms
225
+ startedAt: dateTimeISO
226
+ endedAt: dateTimeISO
227
+ duration: ms
227
228
  },
228
229
  /**
229
230
  * Reporter name like "spec"
@@ -238,7 +239,6 @@ declare namespace CypressCommandLine {
238
239
  tests: TestResult[]
239
240
  error: string | null
240
241
  video: string | null
241
- screenshots: ScreenshotInformation[]
242
242
  /**
243
243
  * information about the spec test file.
244
244
  */
@@ -1,10 +1,10 @@
1
1
  declare namespace Cypress {
2
2
  type FileContents = string | any[] | object
3
- type HistoryDirection = "back" | "forward"
3
+ type HistoryDirection = 'back' | 'forward'
4
4
  type HttpMethod = string
5
5
  type RequestBody = string | object
6
- type ViewportOrientation = "portrait" | "landscape"
7
- type PrevSubject = "optional" | "element" | "document" | "window"
6
+ type ViewportOrientation = 'portrait' | 'landscape'
7
+ type PrevSubject = 'optional' | 'element' | 'document' | 'window'
8
8
  type PluginConfig = (on: PluginEvents, config: PluginConfigOptions) => void | ConfigOptions | Promise<ConfigOptions>
9
9
 
10
10
  interface CommandOptions {
@@ -26,6 +26,7 @@ declare namespace Cypress {
26
26
  * @see https://on.cypress.io/firefox-gc-issue
27
27
  */
28
28
  (task: 'firefox:force:gc'): Promise<void>
29
+ (task: 'net', eventName: string, frame: any): Promise<void>
29
30
  }
30
31
 
31
32
  type BrowserName = 'electron' | 'chrome' | 'chromium' | 'firefox' | 'edge' | string
@@ -107,6 +108,24 @@ declare namespace Cypress {
107
108
  fromAutWindow: WindowPosition & { x: number, y: number }
108
109
  }
109
110
 
111
+ /**
112
+ * Spec type for the given test. "integration" is the default, but
113
+ * tests run using experimentalComponentTesting will be "component"
114
+ *
115
+ * @see https://on.cypress.io/experiments
116
+ */
117
+ type CypressSpecType = 'integration' | 'component'
118
+
119
+ /**
120
+ * Window type for Application Under Test(AUT)
121
+ */
122
+ type AUTWindow = Window & typeof globalThis & ApplicationWindow
123
+
124
+ /**
125
+ * The interface for user-defined properties in Window object under test.
126
+ */
127
+ interface ApplicationWindow {} // tslint:disable-line
128
+
110
129
  /**
111
130
  * Several libraries are bundled with Cypress by default.
112
131
  *
@@ -211,6 +230,7 @@ declare namespace Cypress {
211
230
  // name: "config_passing_spec.coffee",
212
231
  // relative: "cypress/integration/config_passing_spec.coffee",
213
232
  // absolute: "/users/smith/projects/web/cypress/integration/config_passing_spec.coffee"
233
+ // specType: "integration"
214
234
  // }
215
235
  ```
216
236
  */
@@ -219,6 +239,7 @@ declare namespace Cypress {
219
239
  relative: string // "cypress/integration/config_passing_spec.coffee" or "__all" if clicked all specs button
220
240
  absolute: string
221
241
  specFilter?: string // optional spec filter used by the user
242
+ specType?: CypressSpecType
222
243
  }
223
244
 
224
245
  /**
@@ -324,6 +345,11 @@ declare namespace Cypress {
324
345
  */
325
346
  getFirefoxGcInterval(): number | null | undefined
326
347
 
348
+ /**
349
+ * @returns the number of test retries currently enabled for the run
350
+ */
351
+ getTestRetries(): number | null
352
+
327
353
  /**
328
354
  * Checks if a variable is a valid instance of `cy` or a `cy` chainable.
329
355
  *
@@ -387,7 +413,7 @@ declare namespace Cypress {
387
413
  * Returns a boolean indicating whether an object is a DOM object.
388
414
  */
389
415
  isDom(obj: any): boolean
390
- isType(element: JQuery | HTMLElement , type: string): boolean
416
+ isType(element: JQuery | HTMLElement, type: string): boolean
391
417
  /**
392
418
  * Returns a boolean indicating whether an element is visible.
393
419
  */
@@ -492,7 +518,7 @@ declare namespace Cypress {
492
518
  off: Actions
493
519
  }
494
520
 
495
- type CanReturnChainable = void | Chainable
521
+ type CanReturnChainable = void | Chainable | Promise<unknown>
496
522
  type ThenReturn<S, R> =
497
523
  R extends void ? Chainable<S> :
498
524
  R extends R | undefined ? Chainable<S | Exclude<R, undefined>> :
@@ -1062,7 +1088,7 @@ declare namespace Cypress {
1062
1088
  *
1063
1089
  * @see https://on.cypress.io/go
1064
1090
  */
1065
- go(direction: HistoryDirection | number, options?: Partial<Loggable & Timeoutable>): Chainable<Window>
1091
+ go(direction: HistoryDirection | number, options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>
1066
1092
 
1067
1093
  /**
1068
1094
  * Get the current URL hash of the page that is currently active.
@@ -1399,7 +1425,7 @@ declare namespace Cypress {
1399
1425
  * @example
1400
1426
  * cy.reload()
1401
1427
  */
1402
- reload(options?: Partial<Loggable & Timeoutable>): Chainable<Window>
1428
+ reload(options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>
1403
1429
  /**
1404
1430
  * Reload the page without cache
1405
1431
  *
@@ -1410,7 +1436,7 @@ declare namespace Cypress {
1410
1436
  * cy.visit('http://localhost:3000/admin')
1411
1437
  * cy.reload(true)
1412
1438
  */
1413
- reload(forceReload: boolean): Chainable<Window>
1439
+ reload(forceReload: boolean): Chainable<AUTWindow>
1414
1440
 
1415
1441
  /**
1416
1442
  * Make an HTTP GET request.
@@ -1581,15 +1607,12 @@ declare namespace Cypress {
1581
1607
 
1582
1608
  /**
1583
1609
  * Traverse into an element's shadow root.
1584
- * Requires `experimentalShadowDomSupport: true` config option
1585
1610
  *
1586
- @example
1587
- ```js
1588
- cy.get('.top-level > my-component')
1589
- .shadow()
1590
- .find('.my-button')
1591
- .click()
1592
- ```
1611
+ * @example
1612
+ * cy.get('my-component')
1613
+ * .shadow()
1614
+ * .find('.my-button')
1615
+ * .click()
1593
1616
  * @see https://on.cypress.io/experimental
1594
1617
  */
1595
1618
  shadow(): Chainable<Subject>
@@ -1976,8 +1999,8 @@ declare namespace Cypress {
1976
1999
  * })
1977
2000
  *
1978
2001
  */
1979
- visit(url: string, options?: Partial<VisitOptions>): Chainable<Window>
1980
- visit(options: Partial<VisitOptions> & { url: string }): Chainable<Window>
2002
+ visit(url: string, options?: Partial<VisitOptions>): Chainable<AUTWindow>
2003
+ visit(options: Partial<VisitOptions> & { url: string }): Chainable<AUTWindow>
1981
2004
 
1982
2005
  /**
1983
2006
  * Wait for a number of milliseconds.
@@ -2048,7 +2071,7 @@ declare namespace Cypress {
2048
2071
  })
2049
2072
  ```
2050
2073
  */
2051
- window(options?: Partial<Loggable & Timeoutable>): Chainable<Window>
2074
+ window(options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>
2052
2075
 
2053
2076
  /**
2054
2077
  * Scopes all subsequent cy commands to within this element.
@@ -2177,7 +2200,7 @@ declare namespace Cypress {
2177
2200
  type Agent<T extends sinon.SinonSpy> = SinonSpyAgent<T> & T
2178
2201
 
2179
2202
  interface CookieDefaults {
2180
- whitelist: string | string[] | RegExp | ((cookie: any) => boolean)
2203
+ preserve: string | string[] | RegExp | ((cookie: any) => boolean)
2181
2204
  }
2182
2205
 
2183
2206
  interface Failable {
@@ -2276,7 +2299,7 @@ declare namespace Cypress {
2276
2299
  * @default {@link Timeoutable#timeout}
2277
2300
  * @see https://docs.cypress.io/guides/references/configuration.html#Timeouts
2278
2301
  */
2279
- requestTimeout: number,
2302
+ requestTimeout: number
2280
2303
  /**
2281
2304
  * Time to wait for the response (ms)
2282
2305
  *
@@ -2319,6 +2342,54 @@ declare namespace Cypress {
2319
2342
  * @default false
2320
2343
  */
2321
2344
  multiple: boolean
2345
+ /**
2346
+ * Activates the control key during click
2347
+ *
2348
+ * @default false
2349
+ */
2350
+ ctrlKey: boolean
2351
+ /**
2352
+ * Activates the control key during click
2353
+ *
2354
+ * @default false
2355
+ */
2356
+ controlKey: boolean
2357
+ /**
2358
+ * Activates the alt key (option key for Mac) during click
2359
+ *
2360
+ * @default false
2361
+ */
2362
+ altKey: boolean
2363
+ /**
2364
+ * Activates the alt key (option key for Mac) during click
2365
+ *
2366
+ * @default false
2367
+ */
2368
+ optionKey: boolean
2369
+ /**
2370
+ * Activates the shift key during click
2371
+ *
2372
+ * @default false
2373
+ */
2374
+ shiftKey: boolean
2375
+ /**
2376
+ * Activates the meta key (Windows key or command key for Mac) during click
2377
+ *
2378
+ * @default false
2379
+ */
2380
+ metaKey: boolean
2381
+ /**
2382
+ * Activates the meta key (Windows key or command key for Mac) during click
2383
+ *
2384
+ * @default false
2385
+ */
2386
+ commandKey: boolean
2387
+ /**
2388
+ * Activates the meta key (Windows key or command key for Mac) during click
2389
+ *
2390
+ * @default false
2391
+ */
2392
+ cmdKey: boolean
2322
2393
  }
2323
2394
 
2324
2395
  interface ResolvedConfigOptions {
@@ -2353,7 +2424,12 @@ declare namespace Cypress {
2353
2424
  */
2354
2425
  reporter: string
2355
2426
  /**
2356
- * Whether to take a screenshot on test failure when running headlessly or in CI
2427
+ * Some reporters accept [reporterOptions](https://on.cypress.io/reporters) that customize their behavior
2428
+ * @default "spec"
2429
+ */
2430
+ reporterOptions: { [key: string]: any }
2431
+ /**
2432
+ * Whether Cypress will watch and restart tests on test file changes
2357
2433
  * @default true
2358
2434
  */
2359
2435
  watchForFileChanges: boolean
@@ -2406,7 +2482,7 @@ declare namespace Cypress {
2406
2482
  * If set to `system`, Cypress will try to find a `node` executable on your path to use when executing your plugins. Otherwise, Cypress will use the Node version bundled with Cypress.
2407
2483
  * @default "bundled"
2408
2484
  */
2409
- nodeVersion: "system" | "bundled"
2485
+ nodeVersion: 'system' | 'bundled'
2410
2486
  /**
2411
2487
  * Path to plugins file. (Pass false to disable)
2412
2488
  * @default "cypress/plugins/index.js"
@@ -2494,12 +2570,6 @@ declare namespace Cypress {
2494
2570
  * @default { runMode: 1, openMode: null }
2495
2571
  */
2496
2572
  firefoxGcInterval: Nullable<number | { runMode: Nullable<number>, openMode: Nullable<number> }>
2497
- /**
2498
- * If `true`, Cypress will add `sameSite` values to the objects yielded from `cy.setCookie()`,
2499
- * `cy.getCookie()`, and `cy.getCookies()`. This will become the default behavior in Cypress 5.0.
2500
- * @default false
2501
- */
2502
- experimentalGetCookiesSameSite: boolean
2503
2573
  /**
2504
2574
  * Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement
2505
2575
  * algorithm.
@@ -2507,14 +2577,28 @@ declare namespace Cypress {
2507
2577
  */
2508
2578
  experimentalSourceRewriting: boolean
2509
2579
  /**
2510
- * Enables shadow DOM support. Adds the `cy.shadow()` command and
2511
- * the `includeShadowDom` option to some DOM commands.
2580
+ * Enables `cy.route2`, which can be used to dynamically intercept/stub/await any HTTP request or response (XHRs, fetch, beacons, etc.)
2581
+ * @default false
2582
+ */
2583
+ experimentalNetworkStubbing: boolean
2584
+ /**
2585
+ * Number of times to retry a failed test.
2586
+ * If a number is set, tests will retry in both runMode and openMode.
2587
+ * To enable test retries only in runMode, set e.g. `{ openMode: null, runMode: 2 }`
2588
+ * @default null
2589
+ */
2590
+ retries: Nullable<number | {runMode: Nullable<number>, openMode: Nullable<number>}>
2591
+ /**
2592
+ * Enables including elements within the shadow DOM when using querying
2593
+ * commands (e.g. cy.get(), cy.find()). Can be set globally in cypress.json,
2594
+ * per-suite or per-test in the test configuration object, or programmatically
2595
+ * with Cypress.config()
2596
+ * @default false
2512
2597
  */
2513
- experimentalShadowDomSupport: boolean
2598
+ includeShadowDom: boolean
2514
2599
  }
2515
2600
 
2516
- interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'baseUrl' | 'defaultCommandTimeout' | 'taskTimeout' | 'animationDistanceThreshold' | 'waitForAnimations' | 'viewportHeight' | 'viewportWidth' | 'requestTimeout' | 'execTimeout' | 'env' | 'responseTimeout'>> {
2517
- // retries?: number
2601
+ interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'baseUrl' | 'defaultCommandTimeout' | 'taskTimeout' | 'animationDistanceThreshold' | 'waitForAnimations' | 'viewportHeight' | 'viewportWidth' | 'requestTimeout' | 'execTimeout' | 'env' | 'responseTimeout' | 'retries' | 'includeShadowDom'>> {
2518
2602
  browser?: IsBrowserMatcher | IsBrowserMatcher[]
2519
2603
  }
2520
2604
 
@@ -2614,18 +2698,18 @@ declare namespace Cypress {
2614
2698
  scale: boolean
2615
2699
  onBeforeScreenshot: ($el: JQuery) => void
2616
2700
  onAfterScreenshot: ($el: JQuery, props: {
2617
- path: string,
2618
- size: number,
2701
+ path: string
2702
+ size: number
2619
2703
  dimensions: {
2620
- width: number,
2704
+ width: number
2621
2705
  height: number
2622
- },
2623
- multipart: boolean,
2624
- pixelRatio: number,
2625
- takenAt: string,
2626
- name: string,
2627
- blackout: string[],
2628
- duration: number,
2706
+ }
2707
+ multipart: boolean
2708
+ pixelRatio: number
2709
+ takenAt: string
2710
+ name: string
2711
+ blackout: string[]
2712
+ duration: number
2629
2713
  testAttemptIndex: number
2630
2714
  }) => void
2631
2715
  }
@@ -2646,13 +2730,13 @@ declare namespace Cypress {
2646
2730
  *
2647
2731
  * @default 'swing'
2648
2732
  */
2649
- easing: 'swing' | 'linear',
2733
+ easing: 'swing' | 'linear'
2650
2734
  /**
2651
2735
  * Ensure element is scrollable. Error if element is not scrollable
2652
2736
  *
2653
2737
  * @default true
2654
2738
  */
2655
- ensureScrollable: boolean,
2739
+ ensureScrollable: boolean
2656
2740
  }
2657
2741
 
2658
2742
  interface ScrollIntoViewOptions extends ScrollToOptions {
@@ -2684,7 +2768,7 @@ declare namespace Cypress {
2684
2768
  enable: boolean
2685
2769
  force404: boolean
2686
2770
  urlMatchingOptions: object
2687
- whitelist(xhr: Request): void
2771
+ ignore(xhr: Request): void
2688
2772
  onAnyRequest(route: RouteOptions, proxy: any): void
2689
2773
  onAnyResponse(route: RouteOptions, proxy: any): void
2690
2774
  onAnyAbort(route: RouteOptions, proxy: any): void
@@ -2701,6 +2785,10 @@ declare namespace Cypress {
2701
2785
  sameSite: SameSiteStatus
2702
2786
  }
2703
2787
 
2788
+ interface ShadowDomOptions {
2789
+ includeShadowDom?: boolean
2790
+ }
2791
+
2704
2792
  /**
2705
2793
  * Options that control `cy.type` command
2706
2794
  *
@@ -2783,16 +2871,16 @@ declare namespace Cypress {
2783
2871
  /**
2784
2872
  * Called before your page has loaded all of its resources.
2785
2873
  *
2786
- * @param {Window} contentWindow the remote page's window object
2874
+ * @param {AUTWindow} contentWindow the remote page's window object
2787
2875
  */
2788
- onBeforeLoad(win: Window): void
2876
+ onBeforeLoad(win: AUTWindow): void
2789
2877
 
2790
2878
  /**
2791
2879
  * Called once your page has fired its load event.
2792
2880
  *
2793
- * @param {Window} contentWindow the remote page's window object
2881
+ * @param {AUTWindow} contentWindow the remote page's window object
2794
2882
  */
2795
- onLoad(win: Window): void
2883
+ onLoad(win: AUTWindow): void
2796
2884
 
2797
2885
  /**
2798
2886
  * Cypress will automatically apply the right authorization headers
@@ -2831,6 +2919,12 @@ declare namespace Cypress {
2831
2919
  * @default true
2832
2920
  */
2833
2921
  cancelable: boolean
2922
+ /**
2923
+ * The type of the event you want to trigger
2924
+ *
2925
+ * @default 'Event'
2926
+ */
2927
+ eventConstructor: string
2834
2928
  }
2835
2929
 
2836
2930
  /** Options to change the default behavior of .writeFile */
@@ -4857,9 +4951,9 @@ declare namespace Cypress {
4857
4951
  }
4858
4952
 
4859
4953
  interface BrowserLaunchOptions {
4860
- extensions: string[],
4954
+ extensions: string[]
4861
4955
  preferences: { [key: string]: any }
4862
- args: string[],
4956
+ args: string[]
4863
4957
  }
4864
4958
 
4865
4959
  interface Dimensions {
@@ -4983,12 +5077,12 @@ declare namespace Cypress {
4983
5077
  * Fires as the page begins to load, but before any of your applications JavaScript has executed. This fires at the exact same time as `cy.visit()` `onBeforeLoad` callback. Useful to modify the window on a page transition.
4984
5078
  * @see https://on.cypress.io/catalog-of-events#App-Events
4985
5079
  */
4986
- (action: 'window:before:load', fn: (win: Window) => void): void
5080
+ (action: 'window:before:load', fn: (win: AUTWindow) => void): void
4987
5081
  /**
4988
5082
  * Fires after all your resources have finished loading after a page transition. This fires at the exact same time as a `cy.visit()` `onLoad` callback.
4989
5083
  * @see https://on.cypress.io/catalog-of-events#App-Events
4990
5084
  */
4991
- (action: 'window:load', fn: (win: Window) => void): void
5085
+ (action: 'window:load', fn: (win: AUTWindow) => void): void
4992
5086
  /**
4993
5087
  * Fires when your application is about to navigate away. The real event object is provided to you. Your app may have set a `returnValue` on the event, which is useful to assert on.
4994
5088
  * @see https://on.cypress.io/catalog-of-events#App-Events
@@ -5169,7 +5263,7 @@ declare namespace Cypress {
5169
5263
 
5170
5264
  interface Server extends RouteOptions {
5171
5265
  enable: boolean
5172
- whitelist: (xhr: any) => boolean
5266
+ ignore: (xhr: any) => boolean
5173
5267
  }
5174
5268
 
5175
5269
  interface Viewport {
@@ -5200,10 +5294,10 @@ declare namespace Cypress {
5200
5294
  }
5201
5295
 
5202
5296
  type Encodings = 'ascii' | 'base64' | 'binary' | 'hex' | 'latin1' | 'utf8' | 'utf-8' | 'ucs2' | 'ucs-2' | 'utf16le' | 'utf-16le'
5203
- type PositionType = "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight"
5297
+ type PositionType = 'topLeft' | 'top' | 'topRight' | 'left' | 'center' | 'right' | 'bottomLeft' | 'bottom' | 'bottomRight'
5204
5298
  type ViewportPreset = 'macbook-15' | 'macbook-13' | 'macbook-11' | 'ipad-2' | 'ipad-mini' | 'iphone-xr' | 'iphone-x' | 'iphone-6+' | 'iphone-6' | 'iphone-5' | 'iphone-4' | 'iphone-3' | 'samsung-s10' | 'samsung-note9'
5205
5299
  interface Offset {
5206
- top: number,
5300
+ top: number
5207
5301
  left: number
5208
5302
  }
5209
5303
 
@@ -5236,39 +5330,39 @@ declare namespace Cypress {
5236
5330
  declare namespace Mocha {
5237
5331
  interface TestFunction {
5238
5332
  /**
5239
- * Describe a specification or test-case with the given `title`, TestCptions, and callback `fn` acting
5333
+ * Describe a specification or test-case with the given `title`, TestOptions, and callback `fn` acting
5240
5334
  * as a thunk.
5241
5335
  */
5242
5336
  (title: string, config: Cypress.TestConfigOverrides, fn?: Func): Test
5243
5337
 
5244
5338
  /**
5245
- * Describe a specification or test-case with the given `title`, TestCptions, and callback `fn` acting
5339
+ * Describe a specification or test-case with the given `title`, TestOptions, and callback `fn` acting
5246
5340
  * as a thunk.
5247
5341
  */
5248
5342
  (title: string, config: Cypress.TestConfigOverrides, fn?: AsyncFunc): Test
5249
5343
  }
5250
5344
  interface ExclusiveTestFunction {
5251
5345
  /**
5252
- * Describe a specification or test-case with the given `title`, TestCptions, and callback `fn` acting
5346
+ * Describe a specification or test-case with the given `title`, TestOptions, and callback `fn` acting
5253
5347
  * as a thunk.
5254
5348
  */
5255
5349
  (title: string, config: Cypress.TestConfigOverrides, fn?: Func): Test
5256
5350
 
5257
5351
  /**
5258
- * Describe a specification or test-case with the given `title`, TestCptions, and callback `fn` acting
5352
+ * Describe a specification or test-case with the given `title`, TestOptions, and callback `fn` acting
5259
5353
  * as a thunk.
5260
5354
  */
5261
5355
  (title: string, config: Cypress.TestConfigOverrides, fn?: AsyncFunc): Test
5262
5356
  }
5263
5357
  interface PendingTestFunction {
5264
5358
  /**
5265
- * Describe a specification or test-case with the given `title`, TestCptions, and callback `fn` acting
5359
+ * Describe a specification or test-case with the given `title`, TestOptions, and callback `fn` acting
5266
5360
  * as a thunk.
5267
5361
  */
5268
5362
  (title: string, config: Cypress.TestConfigOverrides, fn?: Func): Test
5269
5363
 
5270
5364
  /**
5271
- * Describe a specification or test-case with the given `title`, TestCptions, and callback `fn` acting
5365
+ * Describe a specification or test-case with the given `title`, TestOptions, and callback `fn` acting
5272
5366
  * as a thunk.
5273
5367
  */
5274
5368
  (title: string, config: Cypress.TestConfigOverrides, fn?: AsyncFunc): Test
@@ -5276,7 +5370,7 @@ declare namespace Mocha {
5276
5370
 
5277
5371
  interface SuiteFunction {
5278
5372
  /**
5279
- * Describe a "suite" with the given `title`, TestCptions, and callback `fn` containing
5373
+ * Describe a "suite" with the given `title`, TestOptions, and callback `fn` containing
5280
5374
  * nested suites.
5281
5375
  */
5282
5376
  (title: string, config: Cypress.TestConfigOverrides, fn: (this: Suite) => void): Suite
@@ -5284,13 +5378,13 @@ declare namespace Mocha {
5284
5378
 
5285
5379
  interface ExclusiveSuiteFunction {
5286
5380
  /**
5287
- * Describe a "suite" with the given `title`, TestCptions, and callback `fn` containing
5381
+ * Describe a "suite" with the given `title`, TestOptions, and callback `fn` containing
5288
5382
  * nested suites. Indicates this suite should be executed exclusively.
5289
5383
  */
5290
5384
  (title: string, config: Cypress.TestConfigOverrides, fn: (this: Suite) => void): Suite
5291
5385
  }
5292
5386
 
5293
5387
  interface PendingSuiteFunction {
5294
- (title: string, config: Cypress.TestConfigOverrides, fn: (this: Suite) => void): Suite | void
5388
+ (title: string, config: Cypress.TestConfigOverrides, fn: (this: Suite) => void): Suite | void
5295
5389
  }
5296
5390
  }
package/types/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  // Mike Woudenberg <https://github.com/mikewoudenberg>
5
5
  // Robbert van Markus <https://github.com/rvanmarkus>
6
6
  // Nicholas Boll <https://github.com/nicholasboll>
7
- // TypeScript Version: 3.0
7
+ // TypeScript Version: 3.4
8
8
  // Updated by the Cypress team: https://www.cypress.io/about/
9
9
 
10
10
  /// <reference path="./cy-blob-util.d.ts" />
@@ -27,6 +27,7 @@
27
27
  // hmm, how to load it better?
28
28
  /// <reference path="./cypress-npm-api.d.ts" />
29
29
 
30
+ /// <reference path="./net-stubbing.ts" />
30
31
  /// <reference path="./cypress.d.ts" />
31
32
  /// <reference path="./cypress-global-vars.d.ts" />
32
33
  /// <reference path="./cypress-type-helpers.d.ts" />
@@ -0,0 +1,257 @@
1
+ /**
2
+ * HTTP request/response types.
3
+ */
4
+ export namespace CyHttpMessages {
5
+ interface BaseMessage {
6
+ // as much stuff from `incomingmessage` as makes sense to serialize and send
7
+ body?: any
8
+ headers: { [key: string]: string }
9
+ url: string
10
+ method?: string
11
+ httpVersion?: string
12
+ }
13
+
14
+ export type IncomingResponse = BaseMessage & {
15
+ statusCode: number
16
+ statusMessage: string
17
+ }
18
+
19
+ export type IncomingHttpResponse = IncomingResponse & {
20
+ /**
21
+ * Continue the HTTP response, merging the supplied values with the real response.
22
+ */
23
+ send(status: number, body?: string | number | object, headers?: { [key: string]: string }): void
24
+ send(body: string | object, headers?: { [key: string]: string }): void
25
+ send(staticResponse: StaticResponse): void
26
+ /**
27
+ * Continue the HTTP response to the browser, including any modifications made to `res`.
28
+ */
29
+ send(): void
30
+ /**
31
+ * Wait for `delayMs` milliseconds before sending the response to the client.
32
+ */
33
+ delay: (delayMs: number) => IncomingHttpResponse
34
+ /**
35
+ * Serve the response at `throttleKbps` kilobytes per second.
36
+ */
37
+ throttle: (throttleKbps: number) => IncomingHttpResponse
38
+ }
39
+
40
+ export type IncomingRequest = BaseMessage & {
41
+ responseTimeout?: number
42
+ /**
43
+ * Set if redirects should be followed when this request is made. By default, requests will
44
+ * not follow redirects before yielding the response (the 3xx redirect is yielded)
45
+ */
46
+ followRedirect?: boolean
47
+ }
48
+
49
+ export interface IncomingHttpRequest extends IncomingRequest {
50
+ destroy(): void
51
+ reply(interceptor?: StaticResponse | HttpResponseInterceptor): void
52
+ reply(body: string | object, headers?: { [key: string]: string }): void
53
+ reply(status: number, body?: string | object, headers?: { [key: string]: string }): void
54
+ redirect(location: string, statusCode: number): void
55
+ }
56
+ }
57
+
58
+ export interface DictMatcher<T> {
59
+ [key: string]: T
60
+ }
61
+
62
+ /**
63
+ * Matches a string using glob (`*`) matching.
64
+ */
65
+ export type GlobPattern = string
66
+
67
+ export type HttpRequestInterceptor = (req: CyHttpMessages.IncomingHttpRequest) => void | Promise<void>
68
+
69
+ export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse, send?: () => void) => void | Promise<void>
70
+
71
+ /**
72
+ * Matches a single number or any of an array of acceptable numbers.
73
+ */
74
+ export type NumberMatcher = number | number[]
75
+
76
+ /**
77
+ * Request/response cycle.
78
+ */
79
+ export interface Request {
80
+ id: string
81
+ /* @internal */
82
+ log: any
83
+ request: CyHttpMessages.IncomingRequest
84
+ /**
85
+ * Was `cy.wait()` used to wait on this request?
86
+ * @internal
87
+ */
88
+ requestWaited: boolean
89
+ response?: CyHttpMessages.IncomingResponse
90
+ /* @internal */
91
+ responseHandler?: HttpResponseInterceptor
92
+ /**
93
+ * Was `cy.wait()` used to wait on the response to this request?
94
+ * @internal
95
+ */
96
+ responseWaited: boolean
97
+ /* @internal */
98
+ state: RequestState
99
+ }
100
+
101
+ export type RequestState =
102
+ 'Received' |
103
+ 'Intercepted' |
104
+ 'ResponseReceived' |
105
+ 'ResponseIntercepted' |
106
+ 'Complete' |
107
+ 'Errored'
108
+
109
+ export interface Route {
110
+ alias?: string
111
+ log: any
112
+ options: RouteMatcherOptions
113
+ handler: RouteHandler
114
+ hitCount: number
115
+ requests: { [key: string]: Request }
116
+ }
117
+
118
+ export interface RouteMap { [key: string]: Route }
119
+
120
+ /**
121
+ * A `RouteMatcher` describes a filter for HTTP requests.
122
+ */
123
+ export type RouteMatcher = StringMatcher | RouteMatcherOptions
124
+
125
+ export interface RouteMatcherCompatOptions {
126
+ response?: string | object
127
+ }
128
+
129
+ export type RouteMatcherOptions = RouteMatcherOptionsGeneric<StringMatcher>
130
+
131
+ export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions {
132
+ /**
133
+ * Match HTTP basic authentication.
134
+ */
135
+ auth?: { username: S, password: S }
136
+ /**
137
+ * Match client request headers.
138
+ */
139
+ headers?: DictMatcher<S>
140
+ /**
141
+ * Match based on requested hostname.
142
+ */
143
+ hostname?: S
144
+ /**
145
+ * Match requests served via HTTPS only.
146
+ */
147
+ https?: boolean
148
+ /**
149
+ * @default 'GET'
150
+ */
151
+ method?: S
152
+ /**
153
+ * Match on request path after the hostname, including query params.
154
+ */
155
+ path?: S
156
+ /**
157
+ * Matches like `path`, but without query params.
158
+ */
159
+ pathname?: S
160
+ /**
161
+ * Match based on requested port.
162
+ */
163
+ port?: NumberMatcher
164
+ /**
165
+ * Match on parsed querystring parameters.
166
+ */
167
+ query?: DictMatcher<S>
168
+ /**
169
+ * Match based on full request URL.
170
+ */
171
+ url?: S
172
+ }
173
+
174
+ export type RouteHandlerController = HttpRequestInterceptor
175
+
176
+ export type RouteHandler = string | StaticResponse | RouteHandlerController | object
177
+
178
+ /**
179
+ * Describes a response that will be sent back to the browser to fulfill the request.
180
+ */
181
+ export type StaticResponse = GenericStaticResponse<string, string | object> & {
182
+ /**
183
+ * If set, `delayMs` will pass before the response is sent.
184
+ */
185
+ delayMs?: number
186
+ }
187
+
188
+ export interface GenericStaticResponse<Fixture, Body> {
189
+ /**
190
+ * If set, serve a fixture as the response body.
191
+ */
192
+ fixture?: Fixture
193
+ /**
194
+ * If set, serve a static string/JSON object as the response body.
195
+ */
196
+ body?: Body
197
+ /**
198
+ * @default {}
199
+ */
200
+ headers?: { [key: string]: string }
201
+ /**
202
+ * @default 200
203
+ */
204
+ statusCode?: number
205
+ /**
206
+ * If `forceNetworkError` is truthy, Cypress will destroy the connection to the browser and send no response. Useful for simulating a server that is not reachable. Must not be set in combination with other options.
207
+ */
208
+ forceNetworkError?: boolean
209
+ /**
210
+ * If set, the `body` will be sent at `throttleKbps` kbps.
211
+ */
212
+ throttleKbps?: number
213
+ }
214
+
215
+ /**
216
+ * Either a `GlobPattern` string or a `RegExp`.
217
+ */
218
+ export type StringMatcher = GlobPattern | RegExp
219
+
220
+ declare global {
221
+ namespace Cypress {
222
+ interface Chainable<Subject = any> {
223
+ /**
224
+ * Use `cy.route2()` to stub and intercept HTTP requests and responses.
225
+ *
226
+ * Note: this command is only available if you have set the `experimentalNetworkStubbing`
227
+ * configuration option to `true`.
228
+ *
229
+ * @see https://on.cypress.io/route2
230
+ * @example
231
+ * cy.route2('https://localhost:7777/users', [{id: 1, name: 'Pat'}])
232
+ * @example
233
+ * cy.route2('https://localhost:7777/protected-endpoint', (req) => {
234
+ * req.headers['authorization'] = 'basic fooabc123'
235
+ * })
236
+ * @example
237
+ * cy.route2('https://localhost:7777/some-response', (req) => {
238
+ * req.reply(res => {
239
+ * res.body = 'some new body'
240
+ * })
241
+ * })
242
+ */
243
+ route2(url: RouteMatcher, response?: RouteHandler): Chainable<null>
244
+ /**
245
+ * Use `cy.route2()` to stub and intercept HTTP requests and responses.
246
+ *
247
+ * Note: this command is only available if you have set the `experimentalNetworkStubbing`
248
+ * configuration option to `true`.
249
+ *
250
+ * @see https://on.cypress.io/route2
251
+ * @example
252
+ * cy.route2('GET', 'http://foo.com/fruits', ['apple', 'banana', 'cherry'])
253
+ */
254
+ route2(method: string, url: RouteMatcher, response?: RouteHandler): Chainable<null>
255
+ }
256
+ }
257
+ }
@@ -1,97 +0,0 @@
1
- // Type definitions for blob-util 1.3
2
- // Project: https://github.com/nolanlawson/blob-util#readme
3
- // Definitions by: Max Battcher <https://github.com/WorldMaker>
4
- // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
- // TypeScript Version: 2.1
6
-
7
- /**
8
- * Shim for new Blob() to support older browsers that use the deprecated BlobBuilder API.
9
- *
10
- * @param parts content of the Blob
11
- * @param options usually just `{ type: mimeType }`
12
- */
13
- export function createBlob(parts: any[], options?: { type: string }): Blob;
14
-
15
- /**
16
- * Shim for URL.createObjectURL() to support browsers that only have the prefixed webkitURL (e.g. Android <4.4).
17
- */
18
- export function createObjectURL(blob: Blob): string;
19
-
20
- /**
21
- * Shim for URL.revokeObjectURL() to support browsers that only have the prefixed webkitURL (e.g. Android <4.4).
22
- */
23
- export function revokeObjectURL(url: string): void;
24
-
25
- /**
26
- * Convert a Blob to a binary string.
27
- */
28
- export function blobToBinaryString(blob: Blob): Promise<string>;
29
-
30
- /**
31
- * Convert a binary string to a Blob.
32
- * @param type the content type
33
- */
34
- export function binaryStringToBlob(binary: string, type?: string): Promise<Blob>;
35
-
36
- /**
37
- * Convert a Blob to a base-64 string.
38
- */
39
- export function blobToBase64String(blob: Blob): Promise<string>;
40
-
41
- /**
42
- * Convert a base-64 string to a Blob.
43
- * @param type the content type
44
- */
45
- export function base64StringToBlob(base64: string, type?: string): Promise<Blob>;
46
-
47
- /**
48
- * Convert a data URL string (e.g. `'data:image/png;base64,iVBORw0KG...'`) to a Blob.
49
- */
50
- export function dataURLToBlob(dataURL: string): Promise<Blob>;
51
-
52
- /**
53
- * Convert a Blob to a data URL string (e.g. `'data:image/png;base64,iVBORw0KG...'`).
54
- */
55
- export function blobToDataURL(blob: Blob): Promise<string>;
56
-
57
- /**
58
- * Convert an image's src URL to a data URL by loading the image and painting it to a canvas.
59
- *
60
- * Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.
61
- *
62
- * @param type the content type (optional, defaults to 'image/png')
63
- * @param crossOrigin for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors
64
- * @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
65
- */
66
- export function imgSrcToDataURL(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<string>;
67
-
68
- /**
69
- * Convert a canvas to a Blob.
70
- *
71
- * @param type the content type (optional, defaults to 'image/png')
72
- * @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
73
- */
74
- export function canvasToBlob(canvas: HTMLCanvasElement, type?: string, quality?: number): Promise<Blob>;
75
-
76
- /**
77
- * Convert an image's src URL to a Blob by loading the image and painting it to a canvas.
78
- *
79
- * Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.
80
- *
81
- * @param type the content type (optional, defaults to 'image/png')
82
- * @param crossOrigin for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors
83
- * @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
84
- */
85
- export function imgSrcToBlob(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<Blob>;
86
-
87
- /**
88
- * Convert an ArrayBuffer to a Blob.
89
- *
90
- * @param type the content type
91
- */
92
- export function arrayBufferToBlob(arrayBuff: ArrayBuffer, type?: string): Promise<Blob>;
93
-
94
- /**
95
- * Convert a Blob to an ArrayBuffer.
96
- */
97
- export function blobToArrayBuffer(blob: Blob): Promise<ArrayBuffer>;