Skip to content

Commit

Permalink
feat(net-stubbing): experimental full network mocking support (#4176)
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig authored Aug 31, 2020
1 parent cc5aafc commit c378960
Show file tree
Hide file tree
Showing 78 changed files with 4,418 additions and 214 deletions.
14 changes: 0 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ packages/server/support
packages/server/test/support/fixtures/server/imgs
packages/server/test/support/fixtures/server/libs

# CLI tool
cli/types/blob-util
cli/types/bluebird
cli/types/chai
cli/types/chai-jquery
cli/types/jquery
cli/types/lodash
cli/types/mocha
cli/types/minimatch
cli/types/sinon
cli/types/sinon-chai
# ignore CLI output build folder
cli/build

# Building app binary
scripts/support
package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ jobs:
# run unit tests from each individual package
- run: yarn test
- verify-mocha-results:
expectedResultCount: 8
expectedResultCount: 9
- store_test_results:
path: /tmp/cypress
# CLI tests generate HTML files with sample CLI command output
Expand Down
14 changes: 14 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
types/blob-util
types/bluebird
types/chai
types/chai-jquery
types/jquery
types/lodash
types/mocha
types/minimatch
types/sinon
types/sinon-chai
# copied from net-stubbing package on build
types/net-stubbing.ts
# ignore CLI output build folder
build
3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"bin",
"lib",
"index.js",
"types/**/*.d.ts"
"types/**/*.d.ts",
"types/net-stubbing.ts"
],
"bin": {
"cypress": "bin/cypress"
Expand Down
5 changes: 5 additions & 0 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
"default": false,
"description": "Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm."
},
"experimentalNetworkMocking": {
"type": "boolean",
"default": false,
"description": "Enables `cy.route2`, which can be used to dynamically intercept/stub/await any HTTP request or response (XHRs, fetch, beacons, etc.)"
},
"experimentalShadowDomSupport": {
"type": "boolean",
"default": false,
Expand Down
4 changes: 4 additions & 0 deletions cli/scripts/post-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ makeReferenceTypesCommentRelative('sinon', '../sinon/index.d.ts', sinonChaiFilen

// and an import sinon line to be changed to relative path
shell.sed('-i', 'from \'sinon\';', 'from \'../sinon\';', sinonChaiFilename)

// copy experimental network stubbing type definitions
// so users can import: `import 'cypress/types/net-stubbing'`
shell.cp(resolvePkg('@packages/net-stubbing/lib/external-types.ts'), 'types/net-stubbing.ts')
7 changes: 7 additions & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare namespace Cypress {
* @see https://on.cypress.io/firefox-gc-issue
*/
(task: 'firefox:force:gc'): Promise<void>
(task: 'net', eventName: string, frame: any): Promise<void>
}

type BrowserName = 'electron' | 'chrome' | 'chromium' | 'firefox' | 'edge' | string
Expand Down Expand Up @@ -2578,9 +2579,15 @@ declare namespace Cypress {
* @default false
*/
experimentalSourceRewriting: boolean
/**
* Enables `cy.route2`, which can be used to dynamically intercept/stub/await any HTTP request or response (XHRs, fetch, beacons, etc.)
* @default false
*/
experimentalNetworkMocking: boolean
/**
* Enables shadow DOM support. Adds the `cy.shadow()` command and
* the `includeShadowDom` option to some DOM commands.
* @default false
*/
experimentalShadowDomSupport: boolean
/**
Expand Down
1 change: 1 addition & 0 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// hmm, how to load it better?
/// <reference path="./cypress-npm-api.d.ts" />

/// <reference path="./net-stubbing.ts" />
/// <reference path="./cypress.d.ts" />
/// <reference path="./cypress-global-vars.d.ts" />
/// <reference path="./cypress-type-helpers.d.ts" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"stop-only": "npx stop-only --skip .cy,.publish,.projects,node_modules,dist,dist-test,fixtures,lib,bower_components,src --exclude e2e.ts,cypress-tests.ts",
"stop-only-all": "yarn stop-only --folder packages",
"pretest": "yarn ensure-deps",
"test": "yarn lerna exec yarn test --scope cypress --scope \"'@packages/{electron,extension,https-proxy,launcher,network,proxy,rewriter,reporter,runner,socket}'\"",
"test": "yarn lerna exec yarn test --scope cypress --scope \"'@packages/{electron,extension,https-proxy,launcher,net-stubbing,network,proxy,rewriter,reporter,runner,socket}'\"",
"test-debug": "lerna exec yarn test-debug --ignore \"'@packages/{desktop-gui,driver,root,static,web-config}'\"",
"pretest-e2e": "yarn ensure-deps",
"test-e2e": "lerna exec yarn test-e2e --ignore \"'@packages/{desktop-gui,driver,root,static,web-config}'\"",
Expand Down
1 change: 1 addition & 0 deletions packages/driver/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"reporterOptions": {
"configFile": "../../mocha-reporter-config.json"
},
"experimentalNetworkMocking": true,
"experimentalShadowDomSupport": true
}
Loading

2 comments on commit c378960

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c378960 Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.1.0/linux-x64/circle-develop-c37896089b23bd083c9fae5770ea638f87b0deb8-434398/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.1.0/circle-develop-c37896089b23bd083c9fae5770ea638f87b0deb8-434380/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c378960 Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.1.0/darwin-x64/circle-develop-c37896089b23bd083c9fae5770ea638f87b0deb8-434414/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.1.0/circle-develop-c37896089b23bd083c9fae5770ea638f87b0deb8-434406/cypress.tgz

Please sign in to comment.