Skip to Content
0
Nov 18 at 12:03 PM

Reference Library and Karma config

148 Views Last edit Nov 18 at 12:04 PM 2 rev

Hi,

I have a project where I use a custom UI5 library with some custom types.

VSC Workspace:

- zui5lib (com.ui5.zui5lib),

- zui5mainproject (com.ui5.zui5mainproject)

I added a library to the main project using a Fiori Tools task. I see some servestatic path have been added to the yaml files. In the manifest I also can see the library is referenced.

I load some custom types in my controller by resolving a dependency:

"com/ui5/zui5lib/types/CustomDateFormat".

Everything seems to work when I preview the app locally. The same when I launch my unit tests, integration test or test suite.

The problem occurs when I try to configure a karma test suite.

I started with a simple config:

module.exports = function(config) {
  config.set({

    frameworks: ["ui5"],

    ui5: {
      url: "https://openui5.hana.ondemand.com"
    },

    browsers: ["Chrome"]

  });
};

but looks like my library types cannot be loaded:

Uncaught ModuleError: Failed to resolve dependencies of 'com/ui5/zui5mainproject/test/unit/AllTests.js'

...

'com/ui5/zui5lib/types/CustomDateFormat.js': failed to load 'com/ui5/zui5lib/types/CustomDateFormat.js' from ../../resources/com/ui5/zui5lib/types/CustomDateFormat.js: 404

- Not Found

at webapp/resources/sap-ui-core.js:69:764

The request URL, which ends up with 404 is:

http://localhost:9876/base/webapp/resources/com/ui5/zui5lib/types/CustomDateFormat.js

which doesn't look correct. I thought it can be resolved with yaml file, which routes the static resources, but it doesn't work.

I tried to align the resource roots in the karma.config.js, also tried to play with the base path, but nothings works.

It would be nice if you can share your experiences with using custom libraries with karma and provide me some hints how I can load them correctly.

BR,

Adrian