cancel
Showing results for 
Search instead for 
Did you mean: 

UI5: Karma Config, 404 on UI5 resource load

wridgeu
Participant
927

Hi everyone,

I scaffolded a UI5 Fiori Freestyle application using BAS with the LTS UI5 version 1.71.XX(33 in this case). Because the LTS version is not "natively" supported by the tooling (see: https://github.com/SAP/ui5-tooling/issues/265), BAS adds the "fiori-tools-proxy" to `ui5.yaml`.

Now to the Karma part. I added a basic "karma.conf.js" file according to https://github.com/SAP/karma-ui5#configuration. I removed the "ui5.url" property as I wanted to utilize the UI5 tooling including it's already configured proxy to the correct UI5 version.

Now to the issue, the requested UI5 resources (i.e. in "opaTests.qunit.html" → "../../resource/sap/ui/thirdparty/qunit-2.js") can't be found by Karma and the respective requests results in a 404. The resources are requested from "http://localhost:9876/base/webapp/resources/sap-ui-core.js" while they're actually served at "http://localhost:9876/resources/sap-ui-core.js".

This (obviously :D) results in a few issues:

The Karma-UI5 Plugin already does some URL rewriting (https://github.com/SAP/karma-ui5/blob/6aadede1a68f8abd22b9114f02f0d840dbdc00ba/lib/framework.js#L377-L390) but that is (if I interpreted that correctly) just for forwarding the requests to the Tooling(?).

Possible "Workaround(s)"

Just some workarounds/alternatives I've tried/figured out so far ... not sure how good "solid" they are.

- A "standard" UI5 tooling configuration without such a proxy will work fine but wouldn't be the LTS UI5 version then

- Adjusting the requested resources to go two folders "up", where the UI5 resources apparently reside i.e. "../../resource/sap/ui/thirdparty/qunit-2.js" → "../../../../resource/sap/ui/thirdparty/qunit-2.js" would work (also when running the unit/opa5 tests by themselves) but I feel like this isn't the "best/cleanest?" option, or maybe it is?

- Using the ui5.url option within Karma.conf.js including a specific Version: ui5: { url: "https://ui5.sap.com/1.71.33/" }

Q:

Is there a better or "proper" way of making this setup work? Maybe the 'adjusting the resource path everywhere' was already fine? Any suggestions welcome. Appreciate everyone that took the time even reading all that.

Demo App (@github)

This is just a demo application, purely generated by BAS with added Karma config.

https://github.com/wridgeu/UI5-resource-404-karma

Accepted Solutions (0)

Answers (1)

Answers (1)

mauriciolauffer
Product and Topic Expert
Product and Topic Expert

Hi, hard to tell without a look at the karma and ui5 config files. However, it seems to be an issue in either or both files.

I'd try creating a "clean" ui5 config, eg, ui5-karma.yaml with no fiori-tools-proxy and others, and use it to run karma.

Have a look here: https://github.com/SAP/karma-ui5#configpath

wridgeu
Participant

Hey Mauricio, thanks for your reply! 🙂

"...with no fiori-tools-proxy and others, and use it to run karma." - That's the thing, with a clean config (i.e. no fiori-tools-proxy etc.) it works just fine and I agree that a seperate config just for karma would probably be a good/clean way of doing this, however this doesn't work for me as the tooling is not able to serve the UI5 LTS version 1.71.xx (in my case) without a proxy (https://github.com/SAP/ui5-tooling/issues/265). In all other cases your approach is probably the better one.

For now I went with the last option mentioned in my "workarounds" and added the versioned cdn link to the karma config. I'll leave this question open for just a few more days, maybe some other ideas come to mind. 🙂