Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Blanket.js

Tags:

I am testing some code programmatically using Jasmine from Node. To do this, I've setup the following:

function runTests() {     var Jasmine = require('jasmine');     var jasmine = new Jasmine();          jasmine.loadConfig({         spec_dir: 'unit-tests',         spec_files: [             'tests-*.js'         ]     });      var blanket = require('blanket')();      var TerminalReporter = require('jasmine-terminal-reporter');     var reporter = new TerminalReporter({});     jasmine.addReporter(reporter);            jasmine.execute();   }  runTests(); 

When those tests run, I would like to get the code coverage details. While attempting this, I stumbled upon blanket.js. My question is, how do I programmatically output the code coverage results? Using the code above, I get an error. The error simply says:

Error: Bad file instrument indicator.  Must be a string, regex, function, or array. 

Why? What am I doing wrong?

Update

In my package.son file, I have the following section:

"config": {   "blanket": {           "data-cover-flags": {       "engineOnly":true     }   }       } 

I have updated my runTests function to look like this:

function runTests() {     var Jasmine = require('jasmine');     var jasmine = new Jasmine();          jasmine.loadConfig({         spec_dir: 'unit-tests',         spec_files: [             'tests-*.js'         ]     });      // Setup the coverage reporter     var blanket = require("blanket")();     var blanketReporter = function(coverageData) {         console.log(coverageData);     };     blanket.customReporter = blanketReporter;      blanket.instrument({         inputFile: 'library.js'     }, function(result) { });      var TerminalReporter = require('jasmine-terminal-reporter');     var reporter = new TerminalReporter({});     jasmine.addReporter(reporter);            jasmine.execute();   } 

library.js

'use strict';  class Processor {     execute(vals) {       let result = 0;       vals.forEach(function(v) {         result += v;       });       return result;     } } module.exports = Processor; 

The code above is in a file called "main.js" which I run by calling node main.js from the console window. "library.js" is at the same level and the tests are in a child directory at "./unit-tests/tests.js". When the above runs, the customerReporter code is never called. I don't understand why.

like image 326
xam developer Avatar asked Dec 17 '15 02:12

xam developer


1 Answers

https://github.com/alex-seville/blanket/issues/248

If you don't specify the below in your package.json, blanket throws a "Bad file instrument indicator. Must be a string, regex, function, or array." error. As soon as you require('blanket'); from anywhere within node.

  "scripts": {     "blanket": {       "data-cover-flags": {         "engineOnly":true       }     }   } 
like image 70
Tim Avatar answered Apr 05 '23 21:04

Tim