-
-
Notifications
You must be signed in to change notification settings - Fork 43
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: add option to ignore urls for auto waiting #575
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3a0445d
feat: add option to ignore urls for auto waiting
sebbi08 0d40993
fix: fetch waiter is only avaiable after 1.114.0
sebbi08 ed1c8f1
chore: typo
sebbi08 ee4132e
chore: added type for new config with documentation
sebbi08 f278361
docs: add documentation for autoWaitUrlIgnoreRegex
sebbi08 39584ed
Update docs/configuration.md
sebbi08 3308eb2
chore: change option naming
sebbi08 e3dca08
Update docs/configuration.md
sebbi08 b33fa1b
chore: remove unused await
sebbi08 93164db
Merge branch 'main' into feature/add-xhr-fetch-ignore
vobu 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 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,55 @@ | ||
async function clientSide_injectXHRPatch(config, browserInstance) { | ||
return await browserInstance.executeAsync((config, done) => { | ||
const originalFetch = window.fetch | ||
|
||
const ignoreAutoWaitUrls = config.wdi5.ignoreAutoWaitUrls | ||
function checkURL(url) { | ||
return ignoreAutoWaitUrls?.map((regex) => new RegExp(regex))?.some((regex) => url.match(regex)) || false | ||
} | ||
const imports = ["sap/ui/thirdparty/sinon", "sap/ui/test/autowaiter/_XHRWaiter"] | ||
if (window.compareVersions.compare(sap.ui.version, "1.114.0", ">")) { | ||
imports.push("sap/ui/test/autowaiter/_fetchWaiter") | ||
} | ||
|
||
//Load the XHRWaiter before our overwrite so we are called first | ||
sap.ui.require(imports, function (sinon, _XHRWaiter, _fetchWaiter) { | ||
// Hook into XHR open for sinon XHRs | ||
const fnOriginalFakeOpen = sinon.FakeXMLHttpRequest.prototype.open | ||
sinon.FakeXMLHttpRequest.prototype.open = function () { | ||
return fnOriginalFakeOpen.apply(this, hooktoXHROpen.apply(this, arguments)) | ||
} | ||
|
||
// Hook into XHR open for regular XHRs | ||
const fnOriginalOpen = XMLHttpRequest.prototype.open | ||
XMLHttpRequest.prototype.open = function () { | ||
return fnOriginalOpen.apply(this, hooktoXHROpen.apply(this, arguments)) | ||
} | ||
|
||
function hooktoXHROpen(method, url, async) { | ||
//The ignore property will force the OPA5 _XHRWaiter to ignore certain calls for auto waiting | ||
//https://github.com/SAP/openui5/blob/45e49887f632d0a8a8ef195bd3edf10eb0be9015/src/sap.ui.core/src/sap/ui/test/autowaiter/_XHRWaiter.js | ||
//This ist the XHR request instance so setting it here will only affect the specific request | ||
this.ignored = checkURL(url) | ||
|
||
return arguments | ||
} | ||
if (_fetchWaiter !== undefined) { | ||
const sapFetch = window.fetch | ||
|
||
window.fetch = function (resource) { | ||
const url = typeof resource === "object" ? resource.url : resource | ||
if (checkURL(url)) { | ||
return originalFetch.apply(this, arguments) | ||
} else { | ||
return sapFetch.apply(this, arguments) | ||
} | ||
} | ||
} | ||
done(true) | ||
}) | ||
}, config) | ||
} | ||
|
||
module.exports = { | ||
clientSide_injectXHRPatch | ||
} |
This file contains 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 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 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 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,13 @@ | ||
const femiddleware = require("@sap-ux/ui5-middleware-fe-mockserver") | ||
|
||
module.exports = async function middleware(middlewareConfig) { | ||
const feMiddleware = await femiddleware(middlewareConfig) | ||
return async (req, res, next) => { | ||
if (req.originalUrl.startsWith("/V2") && req.originalUrl.includes("/Categories")) { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)) | ||
feMiddleware(req, res, next) | ||
return | ||
} | ||
next() | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -10,3 +10,19 @@ server: | |
configuration: | ||
baseUri: "https://services.odata.org/V2" | ||
strictSSL: false | ||
- name: delayed-mockserver | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again: cool idea, well done 😀 |
||
beforeMiddleware: ui5-middleware-simpleproxy | ||
configuration: | ||
service: | ||
urlBasePath: "/V2/Northwind/Northwind.svc" | ||
name: "" | ||
metadataXmlPath: "./webapp/localService/metadata.xml" | ||
generateMockData: true | ||
--- | ||
specVersion: "1.0" | ||
metadata: | ||
name: delayed-mockserver | ||
kind: extension | ||
type: server-middleware | ||
middleware: | ||
path: scripts/delayedMockServer.js |
This file contains 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 |
---|---|---|
|
@@ -27,6 +27,20 @@ sap.ui.define( | |
|
||
// set the device model | ||
this.setModel(models.createDeviceModel(), "device") | ||
|
||
const url = new URL(location.href) | ||
if (url.searchParams.get("isui5toolingTest")?.toLocaleLowerCase() === "true") { | ||
const startXHR = () => { | ||
this.getModel().read("/Categories", { | ||
success: startXHR | ||
}) | ||
} | ||
startXHR() | ||
const startFetch = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i keep my fingers crossed that the gh runners are equipped with enough memory for the CI runs 😁 |
||
fetch("/V2/Northwind/Northwind.svc/Categories").then(startFetch) | ||
} | ||
startFetch() | ||
} | ||
} | ||
}) | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is so cool. well well done!!!