|
| 1 | +varfs=require('fs') |
| 2 | +varsuites=require('system').args.slice(1) |
| 3 | + |
| 4 | +functionprint(s){ |
| 5 | +fs.write('/dev/stdout',s,'w') |
| 6 | +} |
| 7 | + |
| 8 | +varpage=require('webpage').create() |
| 9 | +page.onConsoleMessage=function(msg){ |
| 10 | +console.log(msg) |
| 11 | +} |
| 12 | +page.onError=function(msg){ |
| 13 | +console.error('ERROR: '+msg) |
| 14 | +} |
| 15 | + |
| 16 | +vartimeoutId=null |
| 17 | +functiondeferTimeout(){ |
| 18 | +if(timeoutId)clearTimeout(timeoutId) |
| 19 | +timeoutId=setTimeout(function(){ |
| 20 | +console.error('Timeout') |
| 21 | +phantom.exit(1) |
| 22 | +},3000) |
| 23 | +} |
| 24 | + |
| 25 | +varendresult=0 |
| 26 | + |
| 27 | +functionrunSuite(){ |
| 28 | +varsuite=suites.shift() |
| 29 | +if(!suite){ |
| 30 | +phantom.exit(endresult) |
| 31 | +return |
| 32 | +} |
| 33 | + |
| 34 | +page.open(suite,function(){ |
| 35 | +deferTimeout() |
| 36 | + |
| 37 | +varinterval=setInterval(function(){ |
| 38 | +vartests=page.evaluate(function(){ |
| 39 | +varresults=[] |
| 40 | +varels=document.getElementById('qunit-tests').children |
| 41 | + |
| 42 | +for(vari=0;i<els.length;i++){ |
| 43 | +vartest=els[i] |
| 44 | +if(test.className!=='running'&&!test.recorded){ |
| 45 | +test.recorded=true |
| 46 | +if(test.className==='pass')results.push('.') |
| 47 | +elseif(test.className==='fail')results.push('F') |
| 48 | +} |
| 49 | +} |
| 50 | + |
| 51 | +returnresults |
| 52 | +}) |
| 53 | + |
| 54 | +for(vari=0;i<tests.length;i++){ |
| 55 | +deferTimeout() |
| 56 | +print(tests[i]) |
| 57 | +} |
| 58 | + |
| 59 | +varresult=page.evaluate(function(){ |
| 60 | +vartestresult=document.getElementById('qunit-testresult') |
| 61 | +varels=document.getElementById('qunit-tests').children |
| 62 | + |
| 63 | +if(testresult.innerText.match(/completed/)){ |
| 64 | +console.log('') |
| 65 | + |
| 66 | +for(vari=0;i<els.length;i++){ |
| 67 | +vartest=els[i] |
| 68 | +if(test.className==='fail'){ |
| 69 | +console.error(test.innerText) |
| 70 | +} |
| 71 | +} |
| 72 | + |
| 73 | +console.log(testresult.innerText) |
| 74 | +returnparseInt(testresult.getElementsByClassName('failed')[0].innerText) |
| 75 | +} |
| 76 | +}) |
| 77 | + |
| 78 | +if(result!=null){ |
| 79 | +endresult=result |
| 80 | +clearInterval(interval) |
| 81 | +runSuite() |
| 82 | +} |
| 83 | +},100) |
| 84 | +}) |
| 85 | +} |
| 86 | + |
| 87 | +runSuite() |