简体   繁体   中英

BlanketJS + Jasmine + RequireJS no code coverage

I am trying to get the same setup as this tutorial.

First Off. My file structure is:

/assests
/css
/font
/img
/js
    /collection
    /lib
    /model
    /plugin
    /spec
        -> Tests in here
    /view
    SpecRunner.js
    main.js
/templates
index.html
SpecRunner.html

My SpecRunner.html looks like:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Jasmine Spec Runner v2.2.0</title>

    <link rel="shortcut icon" type="image/png" href="js/lib/jasmine/jasmine_favicon.png">
    <link rel="stylesheet" href="js/lib/jasmine/jasmine.css">

    <!--
    <script type="text/javascript" src="js/lib/blanket/blanket.js"></script>
    <script type="text/javascript" src="js/lib/jasmine/jasmine.js"></script>
    <script type="text/javascript" src="js/lib/jasmine/jasmine-html.js"></script>
    <script type="text/javascript" src="js/lib/jasmine/boot.js"></script>
    <script type="text/javascript" src="js/lib/blanket/blanket_jasmine.js"></script>
    -->

    <script type="text/javascript" src="js/lib/require/require.js" data-main="js/SpecRunner.js">
    </script>   
</head>

<body>
    <!--This div is to allow the views to render. It's filled with the required garbage tags-->
    <div id="sandbox" style="overflow: hidden; height: 1px;">
        <div id="progress-bar-container">
            <div class="main_content">
            </div>
        </div>
    </div>
</body>
</html>

My SpecRunner.js looks like:

require.config({
  paths: {
    'jquery' : 'lib/jqm/jquery-1.11.2.min',
    'underscore' : 'lib/underscore/underscore',
    'backbone' : 'lib/backbone/backbone',
        //Testing Dependencies
        'blanket': 'lib/blanket/blanket',
        'jasmine': 'lib/jasmine/jasmine',
        'jasmine-html': 'lib/jasmine/jasmine-html',
        'jasmine-boot' : 'lib/jasmine/boot',
        'jasmine-blanket' : 'lib/blanket/blanket_jasmine'
  },
  shim: {
        backbone: {
          deps: ['underscore', 'jquery'],
          exports: 'Backbone'
        },
       'jasmine-boot' : {
            deps : [ 'jasmine', 'jasmine-html' ],
            exports : 'jasmine'
        },
        'jasmine-html' : {
            deps : [ 'jasmine' ]
        },
        'jasmine-blanket' : {
            deps : [ 'jasmine-boot', 'blanket' ],
            exports : 'blanket'
        },
    }
});

require(['jquery', 'jasmine-boot', 'jasmine-blanket', 'blanket'], function($, jasmine, blanket){
    blanket.options('filter', '../js/');
    blanket.options('antifilter', [ '../js/lib/', 
                                    '../js/plugin/', 
                                    '../js/spec/',
                                    '../js/SpecRunner.js',
                                    '../js/main.js'  ]);
    blanket.options('branchTracking', true); 

    var jasmineEnv = jasmine.getEnv();
    jasmineEnv.addReporter(new jasmine.BlanketReporter());
    jasmineEnv.updateInterval = 1000;

    var specs = [];
    specs.push('../js/spec/view/DetailView');

    $(document).ready(function() {
      require(specs, function(spec) {
        window.onload();
      });
    });   
});

The problem is that with this current setup I get to the point where the console just displays "waiting for blanket" and hangs.

I can get a version working by removing all the blanket and jasmine dependencies from SpecRunner.js and have them in SpecRunner.html (ie uncomment the script references). However this version is flawed as it does not provide any blanket code coverage.

I have tried the suggestions here with no luck.

Any advice would be appreciated.

It appears jasmine-blanket get's hung in it's reference to jasmine.getEnv().currentRunner. Which is undefined in Jasmine version 2.0+. The last output to console just happens to be 'waiting for blanket...' before it breaks. I replaced the code of my BlanketReporter in my jasmine-blanket with this to resolve the issue.

var BlanketReporter = function(savePath, consolidate, useDotNotation) {

    blanket.setupCoverage();
};
BlanketReporter.finished_at = null; // will be updated after all files have been written

BlanketReporter.prototype = {
    specStarted: function(spec) {
        blanket.onTestStart();
    },

    specDone: function(result) {
        var passed = result.status === "passed" ? 1 : 0;
        blanket.onTestDone(1,passed);
    },

    jasmineDone: function() {
        blanket.onTestsDone();
    },

    log: function(str) {
        var console = jasmine.getGlobal().console;

        if (console && console.log) {
            console.log(str);
        }
    }
};

// export public
jasmine.BlanketReporter = BlanketReporter;

//override existing jasmine execute
var originalJasmineExecute = jasmine.getEnv().execute;
jasmine.getEnv().execute = function(){ console.log("waiting for blanket..."); };


blanket.beforeStartTestRunner({
    checkRequirejs:true,
    callback:function(){
        jasmine.getEnv().addReporter(new jasmine.BlanketReporter());
        jasmine.getEnv().execute = originalJasmineExecute;
        jasmine.getEnv().execute();
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM