簡體   English   中英

BlanketJS +茉莉花+ RequireJS沒有代碼覆蓋

[英]BlanketJS + Jasmine + RequireJS no code coverage

我正在嘗試獲得與教程相同的設置。

首先。 我的文件結構是:

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

我的SpecRunner.html看起來像:

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

我的SpecRunner.js看起來像:

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();
      });
    });   
});

問題在於,使用當前的設置,控制台將顯示“正在等待毯子”並掛起。

我可以通過刪除SpecRunner.js中的所有毯子和茉莉花依賴項並將它們包含在SpecRunner.html中(即取消注釋腳本引用)來使版本工作。 但是,此版本存在缺陷,因為它沒有提供任何覆蓋范圍的代碼。

我在這里沒有運氣嘗試過這些建議。

任何意見,將不勝感激。

似乎jasmine-blanket get掛在對jasmine.getEnv()。currentRunner的引用中。 在Jasmine 2.0+版本中未定義。 在中斷之前,控制台的最后一個輸出恰好是“正在等待...”。 我用茉莉花毯替換了BlanketReporter的代碼,以解決此問題。

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();
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM