Search code examples
javascriptunit-testingtfscode-coveragechutzpah

How to Make reference paths relative when chutzpah generate html harness for code coverage


I am using chutzpah to integrate my javascript unit tests with TFS 2015 and it's done perfectly.

But when enabling code coverage I get errors related to file paths

e.g.

Error: Blanket.js encountered a cross origin request error while instrumenting the source files. This is likely caused by the source files being referenced locally (using the file:// protocol).

Because when chutzpah generate html file for each test file, the references paths are NOT relative :

<script type="text/javascript" src="file:///C:/_work/7b9b5f73/MyProject/packages/Chutzpah.4.2.3/tools/TestFiles/chutzpah_boot.js"></script>

I did research about how I can configure chutzpah settings to make the path relative and the best matched answer was Customizable HTML harness generation which says how to override the whole template not override placeholders inside default template.

So is there any way to configure chutzpah to make reference path relative to be able to link client code coverage result with tfs.

my chutzpah.json file looks like this :

{
"Framework": "mocha",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"RootReferencePathMode": "SettingsFileDirectory",
"EnableCodeCoverage": "true",
"CodeCoverageExcludes": [
    "bower_components\\*",
    "node_modules\\*"
],
"References": [
    {
        "Path": "node_modules/mocha/mocha.js"
    },
    {
        "Path": "node_modules/chai/chai.js"
    },
    {
        "Path": "node_modules/sinon-chai/lib/sinon-chai.js"
    },
    {
        "Path": "src/client/app/mochaConstrutor.js"
    },
    {
        "Path": "bower_components/jquery/dist/jquery.js"
    },
    {
        "Path": "bower_components/angular/angular.js"
    },
    {
        "Path": "bower_components/angular-sanitize/angular-sanitize.js"
    },
    {
        "Path": "bower_components/bootstrap/dist/js/bootstrap.js"
    },
    {
        "Path": "bower_components/extras.angular.plus/ngplus-overlay.js"
    },
    {
        "Path": "bower_components/moment/moment.js"
    },
    {
        "Path": "bower_components/angular-ui-router/release/angular-ui-router.js"
    },
    {
        "Path": "bower_components/toastr/toastr.js"
    },
    {
        "Path": "bower_components/angular-animate/angular-animate.js"
    },
    {
        "Path": "bower_components/angular-bootstrap/ui-bootstrap-tpls.js"
    },
    {
        "Path": "bower_components/angular-mocks/angular-mocks.js"
    },
    {
        "Path": "bower_components/sinon/index.js"
    },
    {
        "Path": "bower_components/bardjs/dist/bard.js"
    },
    {
        "Path": "bower_components/bardjs/dist/bard-ngRouteTester.js"
    },
     ...
],
"Tests": [
    {
        "Path": "src/client/app/admin/admin.controller.spec.js"
    },
    {
        "Path": "src/client/app/admin/admin.route.spec.js"
    },
    ...
]
}

this is the build task on tfs


Solution

  • Currently, there is not a way for Chutzpah to make relative paths. However, I am currently working on a change that will let it run with a embedded web server which will make tools like Blanket work much smoother.