antjenkinssonarqube-5.0jscoverage

JSCover - Excluding coverage files


Currently trying to get JSCover to exclude js files that are used as libraries. I have a set of ant scripts below which will

  1. start the JSCover server
  2. Run & Generate Json report
  3. Stop the server

Finally, i have a shell command to convert the Json file to LCov so that i can use it with sonarqube. I also get coverage in jscoverage.html but it includes every file under web/ which is something i do not want. Image below

enter image description here

Ant scripts below:

    <target name="jstest-start">
    <java jar=".../JSCover.jar" fork="true" spawn="true">
        <arg value="-ws"/>
        <arg value="--report-dir=coverage"/>
        <arg value="--document-root=web"/>
        <arg value="--port=8082"/>

        <!-- Aim is to exclude folder js under web/ as it contains libraries, not source code. Currently does not work -->
        <arg value="--no-instrument=web/js/"/>
        <arg value="--no-instrument=js/"/>
    </java>

    <waitfor maxwait="5" maxwaitunit="second" checkevery="250" checkeveryunit="millisecond" timeoutproperty="failed">
        <http url="http://localhost:8082/jscoverage.html"/>
    </waitfor>
    <fail if="failed"/>

</target>

<target name="jstest-run">
    <exec dir="/usr/local/CI/phantomjs/bin/" executable="phantomjs" failonerror="true">
        <arg line=".../run-jscover-qunit.js http://localhost:8082/index.html"/>
    </exec>
</target>

<target name="jstest-stop">
    <get src="http://localhost:8082/stop" dest="stop.txt" />
</target>

<target name="jstest" description="Run javascript tests">
    <antcall target="jstest-start"/>
    <antcall target="jstest-run"/>
    <antcall target="jstest-stop"/>
</target>

My folder structure is:

enter image description here

And finally, my sonar standalone analysis settings:

enter image description here

So, what seems to be happening is that JSCover is recursively reading for all js files and i cannot prevent that from sonar or ant.

Can anyone shed some light?


Solution

  • i have resolved my own issue by correcting the shell command which generates an LCOV report.

    java -cp JSCover.jar  jscover.report.Main --format=LCOV  /usr/local/CI/jenkins/workspace/PhantomJS/coverage/phantom/ /usr/local/CI/jenkins/workspace/PhantomJS/web/
    

    Prior to this, the SRC-DIR and REPORT-DIR were the same which was an error on my part. As far as i can understand, SRC-DIR should point to the source folder and REPORT-DIR should point to where the lcov file exists.

    I hope this helps someone