-
-
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
Changes from 5 commits
3a0445d
0d40993
ed1c8f1
ee4132e
f278361
39584ed
3308eb2
e3dca08
b33fa1b
93164db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 autoWaitUrlIgnoreRegex = config.wdi5.autoWaitUrlIgnoreRegex | ||
function checkURL(url) { | ||
return autoWaitUrlIgnoreRegex?.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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ exports.config = { | |
logLevel: "verbose", // [optional] error | verbose | silent, default: "error" | ||
skipInjectUI5OnStart: false, // [optional] {boolean}, default: false; true when UI5 is not on the start page, you need to later call <wdioUI5service>.injectUI5() manually | ||
waitForUI5Timeout: 15000, // [optional] {number}, default: 15000; maximum waiting time in milliseconds while checking for UI5 availability | ||
btpWorkZoneEnablement: false // [optional] {boolean}, default: false; whether to instruct wdi5 to inject itself in both the SAP Build Workzone, standard edition, shell and app | ||
btpWorkZoneEnablement: false, // [optional] {boolean}, default: false; whether to instruct wdi5 to inject itself in both the SAP Build Workzone, standard edition, shell and app | ||
autoWaitUrlIgnoreRegex: [] // [optional] {string[]}, default: []; Array of regex to ignore certain XHR/Fetch calls wile autowaiting | ||
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. see my other comment about renaming this setting, please |
||
} | ||
// ... | ||
} | ||
|
@@ -133,6 +134,12 @@ Number in milliseconds (default: `15000`) to wait for UI5-related operations wit | |
Boolean setting to trigger injecting `wdi5` into both the shell and the app when used with the SAP Build Workzone, standard edition. | ||
Recommended complement is to also [configure IAS Authentication](authentication?id=sap-cloud-identity-services-identity-authentication): as SAP Build requires its own Identity Provider (most likely provided by using an IAS tenant), you'll have to configure authentication against that as well in `wdi5`. | ||
|
||
### `autoWaitUrlIgnoreRegex` | ||
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. see my rename comment |
||
|
||
Ignore list in form of regex. Those will be used to ignore certain XHR/Fetch call from beeing waited for by the OPA5 Waiters. This can be used in combination with longpolling requests to continusly update your app. | ||
sebbi08 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
!> Be carefull adding to many requests or to general regex here as this might make the tests more instable by advancing in the test before you expect it. | ||
sebbi08 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## `package.json` | ||
|
||
Not required, but as a convention, put a `test` or `wdi5` script into your UI5.app's `package.json` to start `wdi5/wdio`. | ||
|
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) { | ||
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. this is so cool. well well done!!! |
||
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() | ||
} | ||
} |
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 |
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() | ||
} | ||
} | ||
}) | ||
} | ||
|
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.
see my other comment with the renaming suggestion