-
Notifications
You must be signed in to change notification settings - Fork 3.4k
automatically polyfill window.fetch with XMLHttpRequest #7597
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3f5b69c
automatically polyfill window.fetch with XMLHttpRequest
bahmutov 414cdea
yarn lock
bahmutov 969069f
Merge branch 'develop' into polyfill-fetch
bahmutov 254cc50
Revert "yarn lock"
bahmutov 81e97aa
Merge branch 'develop' into polyfill-fetch
bahmutov 5b579ea
yarn lock for has-binary2
bahmutov eb4ea44
add test polyfill recipe PR
bahmutov f96bdeb
Merge branch 'develop' into polyfill-fetch
bahmutov 2ce27ce
removing eval, using this.XMLHttpRequest to inject proper XMLHttpRequ…
JessicaSachs 8f7c9a9
fixing build
JessicaSachs 89cda9a
dev patches
JessicaSachs 0990b4e
try patching differently, doubt it would work
bahmutov dbbd1a0
merge develop
bahmutov 60063ab
last merge conflict
bahmutov f2e8988
Merge branch 'develop' into polyfill-fetch
bahmutov 89d13a8
Merge branch 'develop' into polyfill-fetch
bahmutov 30bba54
bind fetch polyfill to content window
bahmutov 10ae257
remake unfetch patch
bahmutov 7902378
Merge branch 'polyfill-fetch' of github.com:cypress-io/cypress into p…
bahmutov 2a85c31
add e2e tests for fetch polyfill
bahmutov 9f59760
switch to fetch constructor away from this
bahmutov d6aa5b7
update patch file
bahmutov 4494913
Update packages/driver/README.md
bahmutov 6aee0c7
Merge branch 'develop' into polyfill-fetch
bahmutov 2f2e2b7
removed unfetch from root level
bahmutov d318fb7
adding experimentalFetchPolyfill
bahmutov 135e262
only drop fetch polyfill if experimentalFetchPolyfill is true
bahmutov 4386f7b
enable experimentalFetchPolyfill in the e2e test
bahmutov df44bdb
set state and add test for no polyfill
bahmutov 28f3e03
add experimentalFetchPolyfill to cypress.json schema
bahmutov 62a8b53
update unit test
bahmutov 05e89b1
Merge branch 'develop' into polyfill-fetch
bahmutov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| const e2e = require('../support/helpers/e2e').default | ||
| const { stripIndent } = require('common-tags') | ||
| const bodyParser = require('body-parser') | ||
|
|
||
| const onServer = function (app) { | ||
| app.use(bodyParser.json({ extended: false })) | ||
|
|
||
| app.get('/get-json', (req, res) => { | ||
| return res.json([1, 2, 3]) | ||
| }) | ||
|
|
||
| app.get('/get-text', (req, res) => { | ||
| return res.send('pong') | ||
| }) | ||
|
|
||
| app.post('/add', (req, res) => { | ||
| if (req.body.method !== 'add') { | ||
| throw new Error('wrong body method') | ||
| } | ||
|
|
||
| return res.json({ answer: req.body.a + req.body.b }) | ||
| }) | ||
|
|
||
| // page posts a JSON object | ||
| app.get('/addition', (req, res) => { | ||
| return res.send(stripIndent` | ||
| <body> | ||
| <div id="result"></div> | ||
| <script> | ||
| const data = { | ||
| method: 'add', | ||
| a: 2, | ||
| b: 15 | ||
| } | ||
| fetch('/add', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify(data) | ||
| }).then((response) => { | ||
| if (!response) { | ||
| throw new Error('no response') | ||
| } | ||
| if (!response.ok) { | ||
| throw new Error('response is not ok') | ||
| } | ||
| return response.json() | ||
| }).then(j => { | ||
| // either answer from the server | ||
| // or from the network stub | ||
| if (j.answer !== 17 && j.answer !== 193) { | ||
| throw new Error('wrong answer') | ||
| } | ||
| document.getElementById('result').innerText = 'answer: ' + j.answer | ||
| }) | ||
| </script> | ||
| </body> | ||
| `) | ||
| }) | ||
|
|
||
| // page fetches JSON array | ||
| app.get('/first', (req, res) => { | ||
| return res.send(stripIndent` | ||
| <body> | ||
| <script> | ||
| fetch('/get-json') | ||
| .then((response) => { | ||
| if (!response) { | ||
| throw new Error('no response') | ||
| } | ||
| if (!response.ok) { | ||
| throw new Error('response is not ok') | ||
| } | ||
| return response.json() | ||
| }) | ||
| .then((list) => { | ||
| if (list.length !== 3) { | ||
| throw new Error('Wrong number of items') | ||
| } | ||
| if (list[0] !== 1) { | ||
| throw new Error('Wrong first item') | ||
| } | ||
| if (list[1] !== 2) { | ||
| throw new Error('Wrong second item') | ||
| } | ||
| if (list[2] !== 3) { | ||
| throw new Error('Wrong third item') | ||
| } | ||
| }) | ||
| </script> | ||
| <a href="/second">second</a> | ||
| </body> | ||
| `) | ||
| }) | ||
|
|
||
| // page fetches text | ||
| app.get('/second', (req, res) => { | ||
| return res.send(stripIndent` | ||
| <body> | ||
| <div id="result"></div> | ||
| <script> | ||
| fetch('/get-text') | ||
| .then((response) => { | ||
| if (!response) { | ||
| throw new Error('no response') | ||
| } | ||
| if (!response.ok) { | ||
| throw new Error('response is not ok') | ||
| } | ||
| if (response.status !== 200) { | ||
| throw new Error('response status not 200') | ||
| } | ||
| return response.text() | ||
| }) | ||
| .then((text) => { | ||
| // allow response from the server | ||
| // or stub response | ||
| if (text !== 'pong' && text !== 'mock pong') { | ||
| throw new Error('Wrong text response') | ||
| } | ||
| document.getElementById('result').innerText = 'text: ' + text | ||
| }) | ||
| </script> | ||
| </body> | ||
| `) | ||
| }) | ||
| } | ||
|
|
||
| describe('e2e fetch polyfill', () => { | ||
| e2e.setup({ | ||
| servers: { | ||
| port: 1818, | ||
| onServer, | ||
| }, | ||
| }) | ||
|
|
||
| e2e.it('passes', { | ||
| spec: 'fetch_spec.coffee', | ||
| snapshot: false, | ||
| }) | ||
| }) |
39 changes: 39 additions & 0 deletions
39
packages/server/test/support/fixtures/projects/e2e/cypress/integration/fetch_spec.coffee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| describe "fetch works", -> | ||
| it "spies on fetch requests", -> | ||
| cy.server() | ||
| cy.route("/get-json").as("get-json") | ||
| cy.visit("http://localhost:1818/first") | ||
| cy.wait("@get-json") | ||
|
|
||
| it "spies on fetch requests from second page", -> | ||
| cy.server() | ||
| cy.route("/get-text").as("get-text") | ||
| cy.visit("http://localhost:1818/first") | ||
| cy.contains("a", "second").click() | ||
| cy.wait("@get-text") | ||
| # confirm the real response from the server is shown | ||
| cy.contains("text: pong").should("be.visible") | ||
|
|
||
| it "stubs GET fetch text", -> | ||
| cy.server() | ||
| cy.route("/get-text", "mock pong") | ||
| cy.visit("http://localhost:1818/second") | ||
| # confirm the stub response is shown | ||
| cy.contains("text: mock pong").should("be.visible") | ||
|
|
||
| it "spies on fetch POST", -> | ||
| cy.server() | ||
| cy.route("POST", "/add").as("add") | ||
| cy.visit("http://localhost:1818/addition") | ||
| cy.wait("@add") | ||
| # confirm the response from the server is displayed | ||
| cy.contains("answer: 17").should('be.visible') | ||
|
|
||
| it "stubs fetch POST", -> | ||
| cy.server() | ||
| cy.route("POST", "/add", {answer: 193}).as("add") | ||
| cy.visit("http://localhost:1818/addition") | ||
| cy.wait("@add") | ||
| # confirm the stub was used | ||
| cy.contains("answer: 193").should('be.visible') | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24721,6 +24721,11 @@ undertaker@^1.2.1: | |
| object.reduce "^1.0.0" | ||
| undertaker-registry "^1.0.0" | ||
|
|
||
| [email protected]: | ||
| 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" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.