最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Running Blanket.js - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Jan 5, 2016 at 19:51 xam developer asked Dec 17, 2015 at 2:37 xam developerxam developer 1,9836 gold badges29 silver badges39 bronze badges 4
  • Instructions for using the Jasmine test runner. – approxiblue Commented Dec 19, 2015 at 20:31
  • Still no luck running blanket from Node. – xam developer Commented Dec 22, 2015 at 15:35
  • What does library.js look like? – edin-m Commented Jan 5, 2016 at 14:08
  • @EdinM library.js is very basic. I included it above. I attempted to isolate the issue so I reduced it down to the above. – xam developer Commented Jan 5, 2016 at 19:52
Add a comment  | 

3 Answers 3

Reset to default 8 +50

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
      }
    }
  }

It would seem that you need to add the reporter to the Jasmine environment.

jasmine.getEnv().addReporter(reporter);

Source: http://jasmine.github.io/2.1/custom_reporter.html

Try custom reporter https://github.com/alex-seville/blanket/blob/master/docs/advanced_browser.md#reporters

blanket.customReporter=function(coverage_results){
    console.log(coverage_results);
};
发布评论

评论列表(0)

  1. 暂无评论