Last active
August 29, 2015 13:57
-
-
Save naganowl/9775483 to your computer and use it in GitHub Desktop.
Add a toggle to enable/disable Blanket coverage on Mocha browser test page with cov parameter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if window.PHANTOMJS or window.location.search.indexOf('cov=true') >= 0 | |
# Synchronously get Blanket. | |
request = new XMLHttpRequest() | |
request.open 'GET', '../vendor/bower/blanket/dist/qunit/blanket.js', no | |
request.send() | |
script = document.createElement 'script' | |
script.type = 'text/javascript' | |
# There is no event fired when HTML report is added to tests. | |
script.text = request.responseText + | |
""" | |
(function() { | |
var report = blanket.report; | |
blanket.report = function() { | |
report.apply(blanket, arguments); | |
$("#blanket-main .rs:contains('100 %')") | |
.parent(":not('.grand-total')").hide(); | |
$(".bl-success:not(.grand-total) > .rs:nth-child(4)").each(function() { | |
var statements = this.innerHTML.split('/'); | |
if (statements[1] != 0 && statements[0]/statements[1] !== 1) { | |
$(this.parentNode).show(); | |
} | |
}); | |
} | |
})(); | |
""" | |
script.setAttribute( | |
'data-cover-adapter' | |
'../node_modules/grunt-blanket-mocha/support/mocha-blanket.js' | |
) | |
script.setAttribute 'data-cover-flags', 'branchTracking' | |
script.setAttribute 'data-cover-never', '[\'templates\']' | |
script.setAttribute( | |
'data-cover-only' | |
'//src/(controllers|ext|lib|mixins|models|views)/' | |
) | |
(document.body || document.head).appendChild script |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Mocha Tests</title> | |
<link rel="stylesheet" href="../vendor/bower/mocha/mocha.css" /> | |
<script src="../vendor/bower/mocha/mocha.js"></script> | |
<script data-main="../src/test/require-specs.js" src="../vendor/bower/requirejs/require.js"></script> | |
<script src="../src/test/check-coverage.js"></script> | |
</head> | |
<body> | |
<div id="mocha"> | |
<p> | |
<a href="/test/">Run All</a> | |
| | |
<a href="/test/?cov=true">Coverage</a> | |
| | |
<a href="/">Back</a> | |
</p> | |
</div> | |
<label> | |
<input id="change-coverage" type="checkbox"> Show fully covered files | |
</label> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require ['config'], -> | |
mocha.setup ui: 'bdd' | |
if window.PHANTOMJS | |
blanket.options "reporter", | |
"../node_modules/grunt-blanket-mocha/support/grunt-reporter.js" | |
if window.location.search.indexOf('cov=true') >= 0 | |
$('#change-coverage').on 'change', -> | |
$("#blanket-main .rs:contains('100 %')") | |
.parent(":not('.grand-total')").toggle() | |
else | |
$('label').hide() | |
require [ | |
'controller-test' | |
'model-test' | |
'view-test' | |
], -> | |
mocha.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to display missing branch coverage files.