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

automatically polyfill window.fetch with XMLHttpRequest #7597

Merged
merged 32 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3f5b69c
automatically polyfill window.fetch with XMLHttpRequest
bahmutov Jun 5, 2020
414cdea
yarn lock
bahmutov Jun 5, 2020
969069f
Merge branch 'develop' into polyfill-fetch
bahmutov Jun 5, 2020
254cc50
Revert "yarn lock"
bahmutov Jun 5, 2020
81e97aa
Merge branch 'develop' into polyfill-fetch
bahmutov Jun 5, 2020
5b579ea
yarn lock for has-binary2
bahmutov Jun 5, 2020
eb4ea44
add test polyfill recipe PR
bahmutov Jun 5, 2020
f96bdeb
Merge branch 'develop' into polyfill-fetch
bahmutov Jun 5, 2020
2ce27ce
removing eval, using this.XMLHttpRequest to inject proper XMLHttpRequ…
JessicaSachs Jun 5, 2020
8f7c9a9
fixing build
JessicaSachs Jun 5, 2020
89cda9a
dev patches
JessicaSachs Jun 5, 2020
0990b4e
try patching differently, doubt it would work
bahmutov Jun 5, 2020
dbbd1a0
merge develop
bahmutov Jun 9, 2020
60063ab
last merge conflict
bahmutov Jun 9, 2020
f2e8988
Merge branch 'develop' into polyfill-fetch
bahmutov Jun 9, 2020
89d13a8
Merge branch 'develop' into polyfill-fetch
bahmutov Jun 9, 2020
30bba54
bind fetch polyfill to content window
bahmutov Jun 9, 2020
10ae257
remake unfetch patch
bahmutov Jun 9, 2020
7902378
Merge branch 'polyfill-fetch' of github.com:cypress-io/cypress into p…
bahmutov Jun 9, 2020
2a85c31
add e2e tests for fetch polyfill
bahmutov Jun 9, 2020
9f59760
switch to fetch constructor away from this
bahmutov Jun 9, 2020
d6aa5b7
update patch file
bahmutov Jun 9, 2020
4494913
Update packages/driver/README.md
bahmutov Jun 9, 2020
6aee0c7
Merge branch 'develop' into polyfill-fetch
bahmutov Jun 10, 2020
2f2e2b7
removed unfetch from root level
bahmutov Jun 10, 2020
d318fb7
adding experimentalFetchPolyfill
bahmutov Jun 10, 2020
135e262
only drop fetch polyfill if experimentalFetchPolyfill is true
bahmutov Jun 10, 2020
4386f7b
enable experimentalFetchPolyfill in the e2e test
bahmutov Jun 10, 2020
df44bdb
set state and add test for no polyfill
bahmutov Jun 10, 2020
28f3e03
add experimentalFetchPolyfill to cypress.json schema
bahmutov Jun 10, 2020
62a8b53
update unit test
bahmutov Jun 10, 2020
05e89b1
Merge branch 'develop' into polyfill-fetch
bahmutov Jun 15, 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
10 changes: 5 additions & 5 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ commands:
command: |
git fetch origin pull/<< parameters.pull_request_id >>/head:pr-<< parameters.pull_request_id >>
git checkout pr-<< parameters.pull_request_id >>
git log
git log -n 2
- run:
command: npm install
working_directory: /tmp/<<parameters.repo>>
Expand Down Expand Up @@ -1258,8 +1258,8 @@ jobs:
- test-binary-against-repo:
repo: cypress-example-recipes
command: npm run test:ci
pull_request_id: 492
folder: examples/testing-dom__form-interactions
pull_request_id: 503
folder: examples/stubbing-spying__window-fetch

"test-binary-against-kitchensink":
<<: *defaults
Expand Down Expand Up @@ -1574,11 +1574,11 @@ linux-workflow: &linux-workflow
- build-binary
- build-npm-package
- test-binary-against-recipe-pull-request:
name: Test jQuery update recipe
name: Test fetch polyfill
filters:
branches:
only:
- test-recipe-pr
- polyfill-fetch
requires:
- build-binary
- build-npm-package
Expand Down
1 change: 1 addition & 0 deletions packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"text-mask-addons": "3.8.0",
"underscore": "1.9.1",
"underscore.string": "3.3.5",
"unfetch": "4.1.0",
"url-parse": "1.4.7",
"vanilla-text-mask": "5.1.1",
"wait-on": "3.3.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/driver/src/cypress/cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const $CommandQueue = require('./command_queue')
const $VideoRecorder = require('../cy/video-recorder')
const $TestConfigOverrides = require('../cy/testConfigOverrides')

// get the fetch polyfill as a string so we can "eval" it in the app window
const fetchPolyfill = require('unfetch').default.toString()

const privateProps = {
props: { name: 'state', url: true },
privates: { name: 'state', url: false },
Expand Down Expand Up @@ -258,6 +261,11 @@ const create = function (specWindow, Cypress, Cookies, state, config, log) {

contentWindow.CSSStyleSheet.prototype.insertRule = _.wrap(insertRule, cssModificationSpy)
contentWindow.CSSStyleSheet.prototype.deleteRule = _.wrap(deleteRule, cssModificationSpy)

// drop "fetch" polyfill that replaces it with XMLHttpRequest
// by using "eval" we force the polyfill to use XMLHttpRequest objects
// from the app iframe that we wrap for network stubbing
contentWindow.eval(`fetch=${fetchPolyfill}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can pretty easily avoid eval + toString and use the correct XMLHttpRequest object if we patch-package and take in the XMLHttpRequest (or content window) reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ughh, but that would be more complex to set up and maintain. Remember the has-binary2 disaster

} catch (error) {} // eslint-disable-line no-empty
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24724,6 +24724,11 @@ undertaker@^1.2.1:
object.reduce "^1.0.0"
undertaker-registry "^1.0.0"

unfetch@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.1.0.tgz#6ec2dd0de887e58a4dee83a050ded80ffc4137db"
integrity sha512-crP/n3eAPUJxZXM9T80/yv0YhkTEx2K1D3h7D1AJM6fzsWZrxdyRuLN0JH/dkZh1LNH8LxCnBzoPFCPbb2iGpg==

unicode-canonical-property-names-ecmascript@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"
Expand Down