SAP / karma-ui5

A Karma plugin for UI5
Apache License 2.0
69 stars 26 forks source link

karma-openui5 does not load properly #3

Closed aitos closed 5 years ago

aitos commented 8 years ago

Hi I am using karma 0.13.15.

Attempting to load openUI5 and I get the following error: Uncaught Error: sap-ui-core.js: could not identify script tag! at C:/resources/sap-ui-core.js:25

I only see the script tags that load openUI5 when going into the Karma debug runner.

Here is my config file; what am I doing wrong? ( I have stripped out my code and tests, while trying to narrow down the problem. The result is the same with my code and test files included.)

// Karma configuration // Generated on Fri Nov 06 2015 16:48:28 GMT-0500 (Eastern Standard Time)

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

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: './',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["openui5"],

  files: [

      { pattern: 'build/tmp/bootRun/unpackedOpenuiRuntimeDependencies/resources/**/*', served: true, included: false, watched: false },

  ],

openui5: {
  path: 'build/tmp/bootRun/unpackedOpenuiRuntimeDependencies/resources/sap-ui-core.js',
  useMockServer: false
},

client: {
  openui5: {
      config: {
          theme: 'sap_bluecrystal',
          libs: 'sap.m',
          resourceroots: {
              'sap.m': 'build/tmp/bootRun/unpackedOpenuiRuntimeDependencies/resources/sap/m',
              //'my.namespace': '/base/src/my/namespace'
          },
          themeroots: {
              'sap_bluecrystal': 'build/tmp/bootRun/unpackedOpenuiRuntimeDependencies/resources/sap/m/themes/sap_bluecrystal'
          }

      }
  }
},

// list of files to exclude
exclude: [
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
    //'spec/sapui.html' : 'html2js'
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity

})

}

matz3 commented 8 years ago

Did you already try to run this without the resourceroots/ themeroots configuration? If you are using the extacted zip from http://openui5.org/download.html it should find the libraries and themes without any further configuration.

resourceroots: {
    'sap.m': 'build/tmp/bootRun/unpackedOpenuiRuntimeDependencies/resources/sap/m',
    //'my.namespace': '/base/src/my/namespace'
},
themeroots: {
    'sap_bluecrystal': 'build/tmp/bootRun/unpackedOpenuiRuntimeDependencies/resources/sap/m/themes/sap_bluecrystal'
}

I could not reproduce the issue mentioned by you locally using the openui5-runtime-1.32.5.zip (after removing the configuration above).

matz3 commented 8 years ago

Closing this for now. Please feel free to add comments if the issue is still relevant.

themasch commented 6 years ago

I got the same issue just now. It happens because karma-openui5 appends a cachebuster string to the sap-ui-core.js script tag and the regex used in the lookup does not expect that:

mMatch = sSrc.match(/(.*\/)sap-ui-core\.js$/i)

actual script tag karma generates:

<script type="text/javascript" src="/base/node_modules/@openui5/sap.ui.core/src/sap-ui-core.js?c130a88260d05608009c66b87e5a6c57c4f9fab0" crossorigin="anonymous"></script>

I'm not really shure why this does not happen in our other projects. Will investigate and keep you updated.

Update: Other project is running karma 1.7, the one throwing the error is using 2.0 Update2: Okay, the real difference is one project is loading the sap-ui-core.js from cdn (works fine) and one from local (adds sha1 hash to url, fails).

matz3 commented 6 years ago

My assumption would also be that this is not related to karma, but to our bootstrap check which tries to identify the script which boots UI5. Usually this is done with an ID sap-ui-bootstrap, but karma doesn't allow adding those to the inserted script tags. Also the folder isn't called resources but src, which would also be an indication.

Even when our detection would work, you would still have trouble loading the other libraries from their npm packages, as by default the loader will try to load it relative to the sap.ui.core package.

To solve this, and to ease the use of the npm packages, we introduced a file system abstraction which is able to bring several npm packages (and potentially other sources) together for a local server and during build steps. All this is part of our new UI5 Tooling. You might have a look into our Quick start: OpenUI5 Sample App which uses Karma with the ui5 serve command.

themasch commented 6 years ago

Thanks for the hint to the sample app. Nice to see the ui5 tooling in action. I'd see if I can rework our build scripts to use that. Seems to be the correct choice for new projects.

Thanks!

cevou commented 6 years ago

Hi @matz3,

in my optinion this is a bug. It is valid to load the sap-ui-core.js file directly from the node_modules directory. Karma appends the ?abcdef01234567 string for cache busting. Of course, this doesn't happen if you load UI5 from a different server like ui5 serve but for small tests it might be overkill to start a server just to execute some small tests.

I'm using this in the openui5-redux-model and can't execute the tests because of that. If I modify the regex the tests run fine.

matz3 commented 5 years ago

@cevou fair enough. This needs to be addressed in the https://github.com/SAP/openui5 project. Feel free to file a pull-request.

sebbi08 commented 5 years ago

I just had the same problem and noticed that this only happens with "self-contained" builds if i build the normal build dose not have this script check

EDIT : So running ui5 build self-contained --all --include-task=* fixed the problem for me