ui5-uiveri5
ui5-uiveri5 copied to clipboard
Uiveri5 with Karma
Hi,
I'm looking into code coverage and want to get coverage for my uiveri5 tests.
I've done it with a "hack" now using ui5-middleware-code-coverage which does work. I'm the author of this npm package as well and are currently refactoring it to get it working with NYC instead of istanbul. But this is causing me some grief.
Then I thought we could use Karma to generate the reporting using existing plugins. I can see that jasmine can run using karma. But I'm not sure about uiveri5. Hence the question.
Can uiveri5 run with Karma or is there any intention of building that functionality?
Alright so a small update from my own side. I've added this to my karma.conf.js file `module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'),
],
files: [
'*spec.js'
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};`
I have my sample test.spec.js file in my root. I can now run the test, but i get the error that element is not defined.
This is the output of my tests
3 12 2020 22:23:14.381:WARN [karma]: No captured browser, open http://localhost:9876/
03 12 2020 22:23:14.417:INFO [karma-server]: Karma v5.2.3 server started at http://localhost:9876/
03 12 2020 22:23:14.418:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
03 12 2020 22:23:14.425:INFO [launcher]: Starting browser Chrome
03 12 2020 22:23:18.293:INFO [Chrome 87.0.4280.88 (Linux x86_64)]: Connected on socket DzhWJtbWYBQy5dtfAAAA with id 83672388
Chrome 87.0.4280.88 (Linux x86_64) test Test 0 FAILED
ReferenceError: element is not defined
at UserContext.
This is my test.spec.js ` describe('test' , function () {
it('Test 0', function () {
var title = element(by.control( { controlType : "sap.m.Title", id : /title$/ }));
expect(title.asControl().getProperty("text")).toBe("myUI5App");
});
it('Test 1', function () {
var button = element(by.control( { id : /idAppControl--idAppControl$/ })).element(by.control( { controlType : "sap.m.Page" })).element(by.control( { controlType : "sap.m.Button" }));
button.click();
});
}); `
Hi Jacob, So far we did not invest time to implement code coverage in uiveri5 mainly due to lack of interest. But as you have implemented this, I will glad to have a look and possibly merge and/or help you by reviewing the code and advertising it as "officially supported plugin". Event further, we can plan and implement some hooks that maybe you need. As for karma. Karma is a test launcher - it opens the browser and executes the test code in the browser context. In contrast uiveri5 is an e2e testing tool - it opens the browser, loads the app from real system and interacts with it. And so the question is - what would be the value to execute those same tests in one more browser as they will control a second browser that will load the app ? As for the error, it means that the "element API" is missing and this is obvious as it is a nodejs module we reuse from protractor.