1 desc "Generate JavaScript code coverage report in ./covershot"
6 coverage:instrumentation
7 coverage:write_manifest
13 namespace :coverage do
15 unless File.exist?(base_path.join('node_modules'))
16 if %x[which npm].strip.length == 0
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
23 cmd = "npm install && bundle exec #{$0} #{ARGV.join ' '}"
24 puts "Executing the following command:"
35 rm_rf base_path.join('covershot')
36 rm_rf base_path.join('tmp')
40 manifest = sprockets['gl-matrix-manifest.js']
41 coverage_path = base_path.join('tmp/coverage')
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|
52 task :instrumentation do
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
58 unless system *[bin, opts, input, output].flatten
59 raise "Instrumentation failure. Please make sure `jscoverage` is installed."
63 task :write_manifest do
64 manifest = sprockets['gl-matrix-manifest.js']
65 coverage_path = base_path.join('tmp/coverage')
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);
73 var exps = csrequire(str);
79 global.GLMAT_EPSILON = 0.000001;
80 global.GLMAT_ARRAY_TYPE = Float32Array;
83 manifest.dependencies.each do |part|
84 path = coverage_path.join('lib-cov').join(part.pathname.basename)
85 manifest_out.puts "pull('#{path}');"
87 manifest_out.puts <<-end_script
88 function CoverageReporter() {
89 this.reportRunnerResults = function(suite) {
90 covershot.writeCoverage();
94 jasmine.getEnv().addReporter(new CoverageReporter());
100 jasmine_node = base_path.join('node_modules/jasmine-node/bin/jasmine-node').to_s
101 spec = base_path.join('spec').to_s
103 unless system jasmine_node, spec
104 raise "jasmine-node tests failed. Coverage report not generated."
109 covershot = base_path.join('node_modules/covershot/bin/covershot').to_s
110 data_dir = base_path.join('covershot/data').to_s
113 unless system covershot, data_dir, '-f', format
114 raise "Execution of covershot failed. Coverage report not generated."
119 rm_rf base_path.join('tmp')
122 puts "Coverage report generated in: #{base_path.join("covershot/index.html")}"