karma config fails to add external project or file in the current project

97 Views Asked by At
I have added unit tests in some frontend projects using karma. I have multiple projects in my Git folder. If I run them individually, they work fine. However if there is a dependency of one project in another project it fails to include it. (failed to load JavaScript resource:) 

If I run the tests using the html file directly, it runs the tests normally and even loads the external projects without any error. following are my resource roots in my unitTest.qunit.html file:

 data-sap-ui-resourceroots='{
                "x.y.projectmain": "../../",
                "test.unit": "./",
                "x.y.project2": "../../../../project2/WebContent"
            }'

If I try to include the project same way in my Karma.conf.js it gives an error: "Failed to resolve dependencies of 'x/y/projectmain/test/unit/AllTests.js' -> 'x/y/projectmain/test/unit/myUnitTest.js' -> 'x.y.project2/util/myfile.js': failed to load 'x.y.project2/util/myfile.js' from ./../../project2/WebContent/util/myfile.js: script load error"

Following are some of my Karma.conf.js settings:

ui5: {
            type: "library",

            paths: {
                src: "projectmain/WebContent",
                test: "projectmain/WebContent/test"
            },

            url: "https://openui5.hana.ondemand.com",
            mode: "script",

            config: {
                async: true,
                bindingSyntax: "complex",
                compatVersion: "edge",

                resourceRoots: {
                    "x.y.projectmain": "./base/projectmain/WebContent",
//                    "x.y.project2": path.resolve('../project2/WebContent')

                    "x.y.project2": "./../../projet2/WebContent"

//                    "x.y.project2": "./base/projectmain/WebContent/test/resources/project2/WebContent"

//                    "x.y.project2.util": "./base/project2/WebContent/util"

                }

            }
            ,
            tests: [
                "x.y.projectmain/test/unit/AllTests"
            ]

        },

  files: [
    'Utils.js',

                { pattern: "../public/Project2/WebContent/utils/myfile.js", included: false, served: true, watched: false, nocache: true  },

                { pattern: '../Project2/WebContent/**/*', watched: true, served: true, included: false }

        ],
//        proxies: {
//            '/project2/': path.resolve('../../project2/WebContent')

//        },

        proxies: {
            '/x.y.project2/': '/absolute/' + path.resolve('../project2/WebContent'),
            '/myfile.js/': '../public/project2/WebContent/util/myfile.js'
        },
1

There are 1 best solutions below

0
On

I have tried many things here. It even refers to the exact file in that external project but it just cant load the file. If I try to load the file manually in the browser it opens fine. But with Karma it gives an error.

My ultimate goal is to add one project as a dependency inside another project. I did check it by copying the whole WebContent folder from Project 2 inside the 'ProjectMain/WebContent/test/Resources/' directory It does work, but that's not appropriate way to include it. There must be some way where we can register or include one project in another either as a resource root or proxies.