Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(net-stubbing): experimental full network mocking support #4176

Merged
merged 204 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
ac6f78e
wip
flotwig May 10, 2019
843d9f0
basic cy.route setup for HTTP interception
flotwig May 10, 2019
6838e44
tsconfig so runner uses our typescript config
flotwig May 10, 2019
e109aea
down with xhr, up with net_stubbing
flotwig May 10, 2019
7602b40
basic event wiring
flotwig May 10, 2019
431c8bb
extend type annotation test
flotwig May 10, 2019
0e9befe
cleanup
flotwig May 10, 2019
2ca2c8b
server received route:added; route matching code
flotwig May 13, 2019
aea33ef
add server tests for route matching
flotwig May 13, 2019
ee5f21b
static responses work
flotwig May 13, 2019
409c480
wip: callbacks
flotwig May 13, 2019
1d7f208
flesh out req.reply, req.redirect interfaces
flotwig May 14, 2019
a77d081
more plumbing
flotwig May 14, 2019
6e9a88d
wip: response interception
flotwig May 15, 2019
b1c323e
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig May 17, 2019
c7bd42a
can modify and intercept req and res bodies
flotwig May 17, 2019
7d0763c
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 25, 2019
b57f454
lil cleanup
flotwig Jun 25, 2019
153e6dc
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jul 8, 2019
c1fe21e
channel -> ws
flotwig Jul 9, 2019
8ffd326
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Aug 12, 2019
340e270
wip
flotwig Aug 12, 2019
b6c2599
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Aug 23, 2019
f393371
remove .only, cleanup
flotwig Aug 26, 2019
eccb488
intercept HTTP errors
flotwig Aug 27, 2019
7b7870a
modify request body; add tests; add cleanup
flotwig Aug 27, 2019
4846450
wip: res.throttle, res.delay
flotwig Aug 27, 2019
0694c8b
wip: throttle works except for on large proxy responses
flotwig Aug 29, 2019
dcd2581
Support modification, throttling of proxied responses
flotwig Sep 9, 2019
c4ef393
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Sep 9, 2019
fb2df89
add warnings, error messages
flotwig Sep 9, 2019
876fe5b
Improve middleware flow
flotwig Sep 9, 2019
6806534
Change server specs to typescript
flotwig Sep 11, 2019
10a7d7e
Typescriptify driver tests, improve types everywhere
flotwig Sep 11, 2019
22515d9
remove old cy.route types
flotwig Sep 11, 2019
37649d9
fix cypress.sinon type
flotwig Sep 11, 2019
8a9ec90
wip: add aliasing, waiting, logging
flotwig Sep 18, 2019
8972c13
escaped type hell, partial wait support
flotwig Sep 19, 2019
da07b42
Revert "escaped type hell, partial wait support"
flotwig Sep 19, 2019
dafc61a
aliasing and waiting works
flotwig Sep 19, 2019
5b8ccab
remove dupe ts file
flotwig Sep 23, 2019
0886a72
wip: refactor net_stubbing into own package
flotwig Sep 23, 2019
ab801ce
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Dec 9, 2019
3bd6a7c
wip: integrate net stubbing with proxy refactor
flotwig Sep 23, 2019
23f85d4
wip: continue to integrate net stubbing with proxy refactor
flotwig Sep 23, 2019
b373a5a
remedy ts woes
flotwig Sep 24, 2019
aa070fb
-
flotwig Sep 24, 2019
6ac9891
convert interception to middlewares
flotwig Sep 24, 2019
206e870
eslint --fix
flotwig Dec 9, 2019
349e5d5
fix types
flotwig Dec 9, 2019
5551e81
remove xhr_ws_server
flotwig Dec 9, 2019
11c6474
fix types
flotwig Dec 9, 2019
ca41d51
correctly pass request
flotwig Dec 11, 2019
e3c299f
add some types
flotwig Dec 17, 2019
6b8d80f
deprecate cy.server
flotwig Dec 17, 2019
16d6bf5
add type for cy.route(method, url, response)
flotwig Dec 17, 2019
725d1c6
add Cypress.utils.warning typedef
flotwig Dec 17, 2019
df68350
ws
flotwig Dec 17, 2019
c9bff77
add XMLHttpRequest
flotwig Dec 17, 2019
164aeea
add old xhr_spec
flotwig Dec 17, 2019
1de0470
remove old xhr_spec
flotwig Dec 17, 2019
673a4e3
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Dec 17, 2019
90d1a7d
cleanup
flotwig Dec 17, 2019
aa7eb87
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Feb 4, 2020
82a7cbc
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Feb 24, 2020
0dd0714
remove postinstall-postinstall for now
flotwig Feb 24, 2020
a5c3045
Revert "remove postinstall-postinstall for now"
flotwig Feb 24, 2020
b1dd636
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig May 14, 2020
9257537
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig May 18, 2020
9ac575b
clean up internal types
flotwig May 18, 2020
2cd8ab8
restore old cy.route types
flotwig May 18, 2020
975ff8e
move exp net-stubbing types to ambient import
flotwig May 18, 2020
293dfd0
add experimentalNetworkMocking switch
flotwig May 18, 2020
345e60a
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig May 18, 2020
c633dbd
restore old waiting + experimental waiting
flotwig May 20, 2020
7aecf8e
run net_stubbing_spec with experimental flag on
flotwig May 20, 2020
4fad34f
skip running old xhr specs
flotwig May 20, 2020
48274a9
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig May 21, 2020
2127c6f
fix type issues
flotwig May 21, 2020
bea66ea
fix building, unit tests
flotwig May 21, 2020
9a8dcf2
sorta clean up types
flotwig May 21, 2020
724398f
try updating net-stubbing files
flotwig May 21, 2020
c28e641
stub net-stubbing test command
flotwig May 21, 2020
acef0a5
fix Socket constructor
flotwig May 21, 2020
0867714
add lodash dep
flotwig May 21, 2020
fe6ca58
revert expectedResultCount
flotwig May 22, 2020
daf6d8b
restore Cypress.Server
flotwig May 22, 2020
e92c2d1
fix intercept-request-spec
flotwig May 22, 2020
820a326
cleanup
flotwig May 22, 2020
a3c940e
fix driver spec types
flotwig May 28, 2020
69fa789
get rid of mocha.opts
flotwig May 28, 2020
518313c
fix proxy tests
flotwig May 28, 2020
bbcb1e0
fix missing toDriver crash
flotwig May 28, 2020
d556cec
fix error util usage
flotwig May 28, 2020
86b9404
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig May 28, 2020
85b5866
chore: add transform-async-to-promises to webpack
flotwig May 29, 2020
402931c
Revert "chore: add transform-async-to-promises to webpack"
flotwig May 29, 2020
a9d3254
use regenerator-runtime for async/await
flotwig May 29, 2020
7b9ac9e
waiting fixes
flotwig Jun 1, 2020
0fb1ee3
fix aliasing/waiting
flotwig Jun 2, 2020
3fbccf6
uncomment old xhr tests
flotwig Jun 2, 2020
df2a91e
fix method, url, handler invocation
flotwig Jun 3, 2020
0a6beef
fix sending regexes w flags to match
flotwig Jun 3, 2020
1f16642
remove .server mentions
flotwig Jun 3, 2020
aed8edf
cy.route2 instead of cy.route
flotwig Jun 4, 2020
f7a89b8
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 4, 2020
da10ace
fix route2 waiting
flotwig Jun 4, 2020
3616c2c
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 8, 2020
9445183
update specs to route2
flotwig Jun 9, 2020
79d7aaa
add fixture support in cy.route2
flotwig Jun 9, 2020
25cd213
establish desired level of cy.route compatibility for experimental
flotwig Jun 9, 2020
ddf0809
move driver-specific code to driver pkg
flotwig Jun 9, 2020
9ab5207
add a readme for net-stubbing pkg
flotwig Jun 9, 2020
25181aa
cleanup net-stubbing pkg structure, requires
flotwig Jun 9, 2020
0c07bdd
loosen delay timeout spec
flotwig Jun 9, 2020
1e5377e
cleanup
flotwig Jun 9, 2020
0a930aa
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 9, 2020
2443eb4
fix tests, types
flotwig Jun 9, 2020
8fd2071
use "req", not "stubbed route"
flotwig Jun 10, 2020
1b472e0
organize specs
flotwig Jun 10, 2020
ccb72cf
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 10, 2020
c6f77de
fix settings.json merge
flotwig Jun 10, 2020
a5ace76
remove CompatXHRHandler
flotwig Jun 10, 2020
9e13849
catch errors thrown in req/res handlers
flotwig Jun 10, 2020
e97ac8e
fail test instead of warning on strange behavior
flotwig Jun 10, 2020
d0bf365
fix type exports hopefully
flotwig Jun 10, 2020
cfdf71f
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 11, 2020
7d01521
chore: add docker command for server
flotwig Jun 11, 2020
aa1063b
fix proxy tests
flotwig Jun 11, 2020
355329a
put cy.visit proxying behind flag
flotwig Jun 11, 2020
16a2c79
fix proxying
flotwig Jun 11, 2020
3b1d388
streamline net stubbing state reset
flotwig Jun 11, 2020
16439a5
use net-stubbing.d.ts
flotwig Jun 11, 2020
5d98fcf
flag
flotwig Jun 11, 2020
43dfe24
fix resetting net stubbin state
flotwig Jun 11, 2020
135845f
fix route not existing
flotwig Jun 11, 2020
eab9fce
expect 9 unit test results
flotwig Jun 11, 2020
ac1b2a9
Revert "use net-stubbing.d.ts"
flotwig Jun 11, 2020
7bee5ea
bundle net-stubbing types in cypress package
flotwig Jun 11, 2020
efeed4a
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 12, 2020
0c33b71
use string union over enum for RequestState
flotwig Jun 12, 2020
dc89a3b
clear up old TODOs
flotwig Jun 12, 2020
cd91ab8
organize driver code
flotwig Jun 12, 2020
39e26d5
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 12, 2020
552b191
fix spec
flotwig Jun 12, 2020
261200f
fix printing stack in firefox
flotwig Jun 15, 2020
d4cecc7
clean up debug statements
flotwig Jun 15, 2020
65fd97a
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 15, 2020
70eb84a
chore: make NODE_OPTIONS fork with --inspect args
flotwig Jun 15, 2020
f2a19c3
implement staticresponse shorthand for req.reply
flotwig Jun 16, 2020
aec4140
tighten up server fixture code
flotwig Jun 16, 2020
34dad27
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 16, 2020
456a34b
add reply return types
flotwig Jun 16, 2020
891515c
clean up getBackendStaticResponse
flotwig Jun 17, 2020
cf9ebd0
cleanup types
flotwig Jun 17, 2020
1288ecf
make Request more like WaitXHR
flotwig Jun 17, 2020
2e5834d
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 17, 2020
421009a
remove method, url props from root request obj
flotwig Jun 17, 2020
4b20b47
destroySocket => forceNetworkError
flotwig Jun 17, 2020
643a5a4
fail test if intercepted res has net error
flotwig Jun 18, 2020
0b01b6f
merge res.send args with real response
flotwig Jun 19, 2020
b99d2e5
add more forceNetworkError tests
flotwig Jun 19, 2020
ba859d8
use Promises instead of next() for req handler chaining
flotwig Jun 23, 2020
359b662
add timeouts for req.reply, res.send, req handler
flotwig Jun 23, 2020
67dad62
clean up error definitions
flotwig Jun 23, 2020
d7d3f27
fixture support for req.reply and res.send
flotwig Jun 23, 2020
ddf32c5
appease dtslint
flotwig Jun 23, 2020
e47e77c
skip weird FF test
flotwig Jun 23, 2020
c2d28b6
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 24, 2020
0dfaa35
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 25, 2020
2717897
remove outdated xhr specs
flotwig Jun 30, 2020
57adeff
clarify interceptRequest flow
flotwig Jun 30, 2020
00ca86a
add comment
flotwig Jun 30, 2020
efd5a1b
cleanup
flotwig Jun 30, 2020
bcafe74
registerCommands -> addCommand
flotwig Jun 30, 2020
4f43104
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jun 30, 2020
419a526
add querystring test/fix passing stubbed responses
flotwig Jun 30, 2020
61a786c
remove/resolve TODOs, skipped tests....
flotwig Jun 30, 2020
ccf1d09
clean up how errors are thrown
flotwig Jun 30, 2020
a47f1b4
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jul 8, 2020
f073c6d
bump max zip size
flotwig Jul 8, 2020
ffa8c9e
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Jul 13, 2020
9218632
do not prevent 304's when intercepting
flotwig Jul 16, 2020
3671bb3
cleanup
flotwig Jul 16, 2020
cf1432e
add tests that redirects are interceptable at each stage
flotwig Jul 16, 2020
9e4a034
Merge branch 'develop' into issue-687-net-mocking
flotwig Jul 22, 2020
c8fb349
fix 301 test
flotwig Jul 23, 2020
351a4aa
skip ff test
flotwig Jul 23, 2020
50a45c1
fix ff test
flotwig Jul 24, 2020
898e59e
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Aug 13, 2020
0d60f7c
fix type
flotwig Aug 13, 2020
cc98ebd
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Aug 14, 2020
15e34b5
Revert "use regenerator-runtime for async/await"
flotwig Aug 25, 2020
aeeec2d
update yarn.lock
flotwig Aug 25, 2020
72607ee
add regenerator-runtime to runner
flotwig Aug 25, 2020
e6f70e5
pin regenerator-runtime
flotwig Aug 26, 2020
a677a9d
make @packages/driver imports relative
flotwig Aug 26, 2020
cd7d332
remove empty tests
flotwig Aug 26, 2020
a6faf22
clean up getAllStringMatcherFields
flotwig Aug 26, 2020
f5a4cb2
update validateRouteMatcherOptions to return validation result
flotwig Aug 26, 2020
080a396
clean up validateStaticResponse errors
flotwig Aug 26, 2020
10dd14d
use `fromSpec` to attribute errors, use cy.fail
flotwig Aug 27, 2020
75fe8f9
Merge remote-tracking branch 'origin/develop' into issue-687-net-mocking
flotwig Aug 27, 2020
cc357f9
fix tests, clean up error messages
flotwig Aug 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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