using browser-based mocha with istanbul

Setting up mocha / chai / testdouble:


<div id="mocha"></div>
<div><a id="coverageLink">Export Coverage</a></div>

<script src="https://unpkg.com/[email protected]/chai.js"></script>
<script src="https://unpkg.com/[email protected]/mocha.js"></script>
<script src="https://unpkg.com/[email protected]/dist/testdouble.js"></script>
<script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script>

<script>mocha.setup({ ui: 'bdd',
globals: ['*'], ignoreLeaks: true
});</script>

<script src="./dist/bundle.js"></script>
<script src="./test/test.js"></script>

<script>
mocha.checkLeaks();
mocha.run();

document.getElementById('coverageLink').onclick = function() {
var json = JSON.stringify(window.__coverage__);
var jsonData = 'data:application/json;charset=utf-8,'
+ encodeURIComponent(json);
this.href = jsonData;
this.target = '_blank';
this.download = 'coverage.json';
};
</script>

Move coverage.json to coverage directory in src tree, then run:
yarn nyc report –temp-directory coverage/ -r lcov

Source: https://www.engineyard.com/blog/measuring-clientside-javascript-test-coverage-with-istanbul

Leave a Reply

Your email address will not be published. Required fields are marked *