karmaExecuteTests always fails in Stage: Additional Unit Tests for SAPUI5 MTA project

Pre-condition:

  1. Generate SAPUI5 MTA project using ‘bash> yo fiori-project’ in SAP BTP Business Application Studio
  2. Pass karma test locally using ‘karma start’
  3. Setup pipeline using https://github.com/SAP/jenkins-library.git
    Issue: karma test failed in pipeline with npm error.

Configuration 1:

  1. By default, npm script is defined as below in $PROJECT_ROOTuipackage.json.
    "scripts": {
    "test": "karma start",
    }

Configuration 2:

  1. Add custom configuration for karmaExecuteTests in .piper/config.yml
    stages:
    karmaExecuteTests:
    runCommand: ‘npm run test’
  2. npm script is defined as below in $PROJECT_ROOTuipackage.json
    "scripts": {
    "test": "karma start",
    }

Error message is as below:
ERROR: (karmaExecuteTests) Step execution failed (category: test). Error: running command ‘npm’ failed: cmd.Run() failed: exit status 1

For segment & # 39; TravelPrpGetHistory in SAPUI5 OData Service & # 39; no resource was found

I'm trying to get data from a service. I've added the target in neo-app.json and also set headers that will be submitted with this service. However, when running the application, the resource for segment & # 39; TravelPrpGetHistory & # 39; not found. Below is my code:

Component.js:

                init: function () {
var das = that;
// call the init function of the base component
UIComponent.prototype.init.apply (arguments);
var sServiceUrl = this.getMetadata (). getManifestEntry ("sap.app"). dataSources.WcfODataServiceForApproval.uri;
var oModel = new sap.ui.model.odata.ODataModel (sServiceUrl, true);
$ .ajax ({
URL: "/ services / userapi / attributes",
Method: & # 39; GET & # 39 ;,
Data type: & # 39; Json & # 39 ;,
Success: Function (Data) {
oModel.setHeaders ({
"User": "70000419"
});

das.setModel (oModel);
sap.ui.getCore (). setModel (oModel, "DataModel");
that.getRouter (). initialize ();
},
Error: Function (error) {}
});
// set the device model
this.setModel (models.createDeviceModel (), "device");

this.detailModel = new sap.ui.model.json.JSONModel ();
sap.ui.getCore (). setModel (this.detailModel, "detailModel");

this.model = new sap.ui.model.json.JSONModel ();
sap.ui.getCore (). setModel (this.model, "btnModel");

}

CreateRequestMaster.view.xml:



        
    

        
            
                
                
                
                
                <! -->
                    
                        
                        
                    
                    
                        
                    

                
            
        
    

        

CreateRequestMaster.controller.js:

sap.ui.define ([
"sap/ui/core/mvc/Controller"
]Function (Controller) {
"strictly use";

return Controller.extend ("hmel.TravelandGuestHouse.controller.CreateRequestMaster"), {

onInit: function () {
this.router = sap.ui.core.UIComponent.getRouterFor (this);
// this.btumodel = sap.ui.getCore (). getModel ("btnModel");

this.listTemp = this.getView (). byId ("objTravelId"). clone ();
this.router.attachRoutePatternMatched (this._handleRouteMatched, this);
},

_handleRouteMatched: Function (evt) {
if (evt.getParameter ("name")! == "CreateRequestMaster") {
Return;
}
var das = that;
//this.getView().byId("travelListId").setMode("SingleSelectMaster ");
//this.getView().byId("accBtnId").setVisible(false);
//this.getView().byId("rejBtnId").setVisible(false);
//this.getView().byId("selectAllBtnId").setVisible(false);
/ * var baseModel = this.getOwnerComponent (). getModel ("DataModel");
this.getView (). setModel (baseModel, "DataModel"); * /
that.getView (). byId ("travelListId"). bindAggregation ("items", {
Path: "/ TravelPrpGetHistory",
Template: that.listTemp
});

this.getView (). byId ("travelListId"). getBinding ("items"). attachDataReceived (function () {
var list = that.getView (). byId ("travelListId");
list.removeSelections ();
/ * var selectedItem = list.getItems ()[0];
if (selectedItem) {
if (! sap.ui.Device.system.phone) {
list.setSelectedItem (selectedItem, true);
var data = selectedItem.getBindingContext (). getObject ();
sap.ui.getCore (). getModel ("detailModel"). setData (data);

that.router.navTo ("TravelDetail"), {
ID: DataID
});
}
} else {
that.router.navTo ("NoData");
var RedirectLocation = window.location.origin;
location.replace (RedirectLocation);
} * /
});
},
});

});

Please help. Thank you.