Warm tip: This article is reproduced from stackoverflow.com, please click
sapui5 karma-runner

UI5

发布于 2020-03-27 10:28:10

I just started with karma runner, would like to use it to run my unit tests. The structure of my application is pretty standard, yet I have trouble setting up the karma.conf.js file. I try to direct karma to my allTests.js file which references all unit test files (when tested through unitTests.qunit.html file, all works as expected). Path to my allTests.js file

webapp/test/unit/allTests.js

And this is how the relevant section of karma.conf.js file looks like:

config.set({    
    openui5: {
      path: 'https://openui5.hana.ondemand.com/1.65.1/resources/sap-ui-core.js'
    },

    client: {
      openui5: {
        tests: [
          'test/unit/allTests'
        ],
        config: {
          language: 'EN',
          resourceroots: {
            'test': './webapp/test'
          }
        } 
      }
    },

    basePath: 'webapp',

    frameworks: ['qunit', 'openui5'],

    files: [
      { pattern: '**', included: false, served: true, watched: true }
    ],

When executed, I assumed that karma would be able to find the allTests.js file, however, it throws this error.

03 07 2019 14:50:48.462:WARN [web-server]: 404: /webapp/test/unit/allTests.js
Firefox 66.0.0 (Ubuntu 0.0.0) ERROR
Error: failed to load 'test/unit/allTests.js' from ./webapp/test/unit/allTests.js: 404 - Not Found at https://openui5.hana.ondemand.com/1.65.1/resources/sap-ui-core.js:86:37

Does someone see where is the problem? Is the fact that I am using CDN for sap-ui-core.js somehow messing with the paths and is the system looking for the AllTests.js file on the openui.hana server. And if yes, how to fix it?

Questioner
Jozef
Viewed
59
Jozef 2019-07-04 15:41

Solved. All I had to do was to folow the tutorial - https://help.sap.com/viewer/468a97775123488ab3345a0c48cadd8f/7.52.3/en-US/ae448243822448d8ba04b4784f4b09a0.html

The problem was that the /base/ route used in the tutorial is actually the route to the basePath in the conf file, I haven't found explained it anywhere but it seems to work. So I had to update the resourceroots section and use base in it. So now the file looks like this

config.set({    
    openui5: {
      path: 'https://openui5.hana.ondemand.com/1.65.1/resources/sap-ui-core.js'
    },

    client: {
      openui5: {
        tests: [
          'test/unit/allTests'
        ],
        config: {
          language: 'EN',
          resourceroots: {
            'test': './base/test'
          }
        } 
      }
    },

    basePath: 'webapp',

    frameworks: ['qunit', 'openui5'],

    files: [
      { pattern: '**', included: false, served: true, watched: true }
    ],