cancel
Showing results for 
Search instead for 
Did you mean: 

How to define the "data-sap-ui-resource-roots" of OPA qunit test for MTA project (Fiori freestyle)

minjie_lao
Product and Topic Expert
Product and Topic Expert
0 Kudos
147

Hi,

We are building a testing modules for existing full stack SAP UI5 project, our project structure looks like this..

project
-app
--node_modules
--webapp
---myAppInst
----controller
----views
----resources(my question is here)
----test
------Test.qunit.js
----manifest
---xs-app.json
---package.json
-db
-srv
-xs-security.json
-node_modules
-package.json

i found SAPUI5 and OPENUI5 is using different resources folder, like the sap/ui/test modules,  when i tried to install the modules, files were created in my node_modules folder, but when i running the Test.qunit.html, it is always referring to the resources folder. Therefore, to make it work, i copied the openUI module file from node_modules to /webapp/myAppInst/resource folder. 

here is my Test.qunit.html

<!DOCTYPE html>
<html>
<head>
	
	<!-- src="../../../../node_modules/@openui5/sap.ui.core/src/sap/ui/test/starter/runTest.js" -->
	<meta charset="utf-8">
	<script
	src="../resources/sap/ui/test/starter/runTest.js"
		data-sap-ui-resource-roots='{
			"test-resources.myAppInst": "./"
		}'
	></script>
</head>
<body class="sapUiBody">
	<div id="qunit"></div>
	<div id="qunit-fixture"></div>
</body>
</html>

But after that, the qunit test journey having following error, looks like the qunit test is looking up all the UI5 modules from my resources folder, instead the node_modules folder

Unable to load the component with the name: myAppInst
Failure in Opa check function
Exception thrown by the testcode:'Error: Error while waiting for promise scheduled on flow, details: ModuleError: failed to load 'sap/m/library.js' from ../resources/sap/m/library.js: script load error
ModuleError: failed to load 'sap/m/library.js' from ../resources/sap/m/library.js: script load error
    at we (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:6833)
    at ge.failWith (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:4709)
    at HTMLScriptElement.i (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:10686)
Caused by: Error: script load error
    at HTMLScriptElement.i (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:10728)
Error: Error while waiting for promise scheduled on flow, details: ModuleError: failed to load 'sap/m/library.js' from ../resources/sap/m/library.js: script load error
ModuleError: failed to load 'sap/m/library.js' from ../resources/sap/m/library.js: script load error
    at we (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:6833)
    at ge.failWith (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:4709)
    at HTMLScriptElement.i (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:10686)
Caused by: Error: script load error
    at HTMLScriptElement.i (http://localhost:5001/myAppInst/webapp/resources/ui5loader.js:6:10728)
    at oOptions.check (http://localhost:5001/myAppInst/webapp/resources/sap/ui/test/Opa.js:677:12)
    at Opa5._executeCheck (http://localhost:5001/myAppInst/webapp/resources/sap/ui/test/Opa5.js:1278:26)
    at oOptionsPassedToOpa.check (http://localhost:5001/myAppInst/webapp/resources/sap/ui/test/Opa5.js:820:18)
    at fnClass.<anonymous> (http://localhost:5001/myAppInst/webapp/resources/sap/ui/test/Opa.js:591:37)
    at opaCheck (http://localhost:5001/myAppInst/webapp/resources/sap/ui/test/Opa.js:54:18)
    at wrappedCallback (http://localhost:5001/myAppInst/webapp/resources/sap/ui/test/autowaiter/_timeoutWaiter.js:120:17)'

can anyone give some suggestion?

 

 

 

View Entire Topic
Dinu
Active Contributor
0 Kudos

The standard SAPUI5 project expects you to use UI5 tools (ui5 serve) to run the application and tests. If you are using CAP, the middleware for UI5 server is not by default used. It is this middleware that serves '../resources'. When using cds (serve or watch) for running your application, the standard practice is to refer to CDN for UI5 resources; replace '../resources' with 'https://ui5.sap.com/1.120.24/resources' (adjust the version as per your needs). This, additionally, allows for the resources to be cached in the browser. Especially when using BAS, it makes no sense to serve the resources from the local server (in BAS).  

An alternate approach is to run two dev servers, one using cap and another using ui5 tools and configure the backend for ui5 server to point to the CAP server. This is necessary if the application requires access to multiple backends. Even then, I prefer to use CDN unless I am on an island or a plane. 

PS: There is a community plugin (cds-plugin-ui5) that plugs in the UI5 middleware into CAP.  I never used it.

minjie_lao
Product and Topic Expert
Product and Topic Expert
0 Kudos
Thanks for the response Dinu, do you have some article for my reference? i am not so familiar with ui5 serve. My objective just to build a automated testing framework of fiori free style application.