yo easy-ui5
npm install ui5-middleware-code-coverage --save-dev
Now add the config to the package.json file and ui5.yaml(Bear in mind that i'm using the easy-ui5 package as it comes and the webapp folder is in a uimodule subfolder. If you are adding to an existing project, you might have the webapp folder in the root and therefore don't need the uimodule prefix)
<mvc:View controllerName="com.myorg.myUI5App.controller.MainView"
displayBlock="true"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<App id="idAppControl" >
<pages>
<Page title="{i18n>title}">
<content>
<Button id="btnPress" text="Press me" press="onPress" />
</content>
</Page>
</pages>
</App>
</mvc:View>
sap.ui.define([
"com/myorg/myUI5App/controller/BaseController",
"sap/m/Dialog",
"sap/m/Button",
"sap/m/Text"
], function(Controller, Dialog, Button, Text) {
"use strict";
return Controller.extend("com.myorg.myUI5App.controller.MainView", {
/**
* Event handler for the button on the mainview using async/await
* @returns {void}
*/
onPress: async function(){
const text = await this.delayedResponse();
if (!this.oDefaultMessageDialog) {
this.oDefaultMessageDialog = new Dialog("myDialog", {
type: "Message",
title: text,
content: new Text({ text: "Test" }),
beginButton: new Button({
type: "Emphasized",
text: "OK",
press: function () {
this.oDefaultMessageDialog.close();
}.bind(this)
})
});
}
this.oDefaultMessageDialog.open();
},
/**
* Promise to return back a text after 3 seconds
* @returns {Promise} Promise with a timeout to send hello world
*/
delayedResponse: function(){
return new Promise((resolve, reject) =>
setTimeout(() => {
resolve("Hello world");
}, 3000));
}
});
});
exports.config = {
profile: 'integration',
baseUrl: 'https://localhost:8080/index.html',
};
describe('test' , function () {
it('Test 0', function () {
var button = element(by.control({ id: /idAppControl--btnPress$/}));
button.click();
browser.sleep(4000);
var title = element(by.control({ id: /myDialog-title$/}));
expect(title.getText()).toBe("Hello world");
});
});
afterAll(() => {
browser.executeScript(`$.ajax({
type: "POST",
url: 'http://localhost:3000/coverage/client',
data: JSON.stringify(window.__coverage__),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});`);
});
"test": "cd uimodule/webapp/test && uiveri5 && nyc report",
nyc report --reporter=html
nyc report --reporter=lcov
$.ajax({
type: "POST",
url: 'http://localhost:3000/coverage/client',
data: JSON.stringify(window.__coverage__),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
36 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |