OLD | NEW |
(Empty) | |
| 1 desc "Generate JavaScript code coverage report in ./covershot" |
| 2 task :coverage => %w( |
| 3 coverage:dependencies |
| 4 coverage:clean |
| 5 coverage:prepare |
| 6 coverage:instrumentation |
| 7 coverage:write_manifest |
| 8 coverage:execute |
| 9 coverage:generate |
| 10 coverage:done |
| 11 ) |
| 12 |
| 13 namespace :coverage do |
| 14 task :dependencies do |
| 15 unless File.exist?(base_path.join('node_modules')) |
| 16 if %x[which npm].strip.length == 0 |
| 17 raise <<-end_error |
| 18 Could not execute `npm`! Please make sure node.js and the Node Package |
| 19 Manager (NPM) are available and can be executed without root |
| 20 permissions. |
| 21 end_error |
| 22 else |
| 23 cmd = "npm install && bundle exec #{$0} #{ARGV.join ' '}" |
| 24 puts "Executing the following command:" |
| 25 puts |
| 26 puts " #{cmd}" |
| 27 puts |
| 28 puts |
| 29 Kernel.exec cmd |
| 30 end |
| 31 end |
| 32 end |
| 33 |
| 34 task :clean do |
| 35 rm_rf base_path.join('covershot') |
| 36 rm_rf base_path.join('tmp') |
| 37 end |
| 38 |
| 39 task :prepare do |
| 40 manifest = sprockets['gl-matrix-manifest.js'] |
| 41 coverage_path = base_path.join('tmp/coverage') |
| 42 |
| 43 manifest.dependencies.each do |part| |
| 44 path = coverage_path.join('lib').join(part.pathname.basename) |
| 45 mkdir_p(path.dirname) unless File.directory?(path.dirname) |
| 46 File.open(path, 'w') do |f| |
| 47 f.print part.body |
| 48 end |
| 49 end |
| 50 end |
| 51 |
| 52 task :instrumentation do |
| 53 bin = 'jscoverage' |
| 54 opts = [ '--no-highlight' ] |
| 55 input = base_path.join('tmp/coverage/lib').to_s |
| 56 output = base_path.join('tmp/coverage/lib-cov').to_s |
| 57 |
| 58 unless system *[bin, opts, input, output].flatten |
| 59 raise "Instrumentation failure. Please make sure `jscoverage` is installed
." |
| 60 end |
| 61 end |
| 62 |
| 63 task :write_manifest do |
| 64 manifest = sprockets['gl-matrix-manifest.js'] |
| 65 coverage_path = base_path.join('tmp/coverage') |
| 66 |
| 67 File.open(coverage_path.join('manifest.js'), 'w') do |manifest_out| |
| 68 manifest_out.puts <<-end_script |
| 69 var covershot = require('covershot'); |
| 70 var csrequire = covershot.require.bind(null, require); |
| 71 |
| 72 function pull(str) { |
| 73 var exps = csrequire(str); |
| 74 for (var i in exps) { |
| 75 global[i] = exps[i]; |
| 76 } |
| 77 } |
| 78 |
| 79 global.GLMAT_EPSILON = 0.000001; |
| 80 global.GLMAT_ARRAY_TYPE = Float32Array; |
| 81 |
| 82 end_script |
| 83 manifest.dependencies.each do |part| |
| 84 path = coverage_path.join('lib-cov').join(part.pathname.basename) |
| 85 manifest_out.puts "pull('#{path}');" |
| 86 end |
| 87 manifest_out.puts <<-end_script |
| 88 function CoverageReporter() { |
| 89 this.reportRunnerResults = function(suite) { |
| 90 covershot.writeCoverage(); |
| 91 }; |
| 92 }; |
| 93 |
| 94 jasmine.getEnv().addReporter(new CoverageReporter()); |
| 95 end_script |
| 96 end |
| 97 end |
| 98 |
| 99 task :execute do |
| 100 jasmine_node = base_path.join('node_modules/jasmine-node/bin/jasmine-node').
to_s |
| 101 spec = base_path.join('spec').to_s |
| 102 |
| 103 unless system jasmine_node, spec |
| 104 raise "jasmine-node tests failed. Coverage report not generated." |
| 105 end |
| 106 end |
| 107 |
| 108 task :generate do |
| 109 covershot = base_path.join('node_modules/covershot/bin/covershot').to_s |
| 110 data_dir = base_path.join('covershot/data').to_s |
| 111 format = 'html' |
| 112 |
| 113 unless system covershot, data_dir, '-f', format |
| 114 raise "Execution of covershot failed. Coverage report not generated." |
| 115 end |
| 116 end |
| 117 |
| 118 task :done do |
| 119 rm_rf base_path.join('tmp') |
| 120 puts |
| 121 puts |
| 122 puts "Coverage report generated in: #{base_path.join("covershot/index.html")
}" |
| 123 puts |
| 124 end |
| 125 end |
OLD | NEW |