Are you loading your tests asynchronously? I am using requirejs for modular javascript. It is also used to download test specifications:
<script data-main='SpecRunner' src='/test/scripts/libs/require.js'></script>
When using JSCover run-jscover-jasmine.js script does not take this asynchronous mode into account, so the DOM nodes referenced by the request do not yet exist. I modified the script to delay the call waiting for 1 second:
page.open(system.args[1], function(status){ if (status !== "success") { console.log("Unable to access network"); phantom.exit(); } else { // Added 1s delay here window.setTimeout(function() { waitFor(function(){ return page.evaluate(function(){ return document.body.querySelector('.symbolSummary .pending') === null }); }, function(){ var exitCode = page.evaluate(function(){ console.log(''); console.log(document.body.querySelector('.description').innerText); var list = document.body.querySelectorAll('.results > #details > .specDetail.failed'); if (list && list.length > 0) { console.log(''); console.log(list.length + ' test(s) FAILED:'); for (i = 0; i < list.length; ++i) { var el = list[i], desc = el.querySelector('.description'), msg = el.querySelector('.resultMessage.fail'); console.log(''); console.log(desc.innerText); console.log(msg.innerText); console.log(''); } return 1; } else { console.log(document.body.querySelector('.alert > .passingAlert.bar').innerText); return 0; } }); page.evaluate(function(){ jscoverage_report('phantom'); }); phantom.exit(exitCode); }); }, 1000); } });
Depending on the amount of code downloaded, you may need to increase the delay.
source share