gpt4 book ai didi

javascript - BlanketJS + Jasmine + RequireJS 无代码覆盖率

转载 作者:行者123 更新时间:2023-11-28 07:24:42 25 4
gpt4 key购买 nike

我正在尝试获得与 this 相同的设置教程。

首先。我的文件结构是:

/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 中删除所有毯子和 jasmine 依赖项并将它们放在 SpecRunner.html 中(即取消注释脚本引用)来获得一个可用的版本。然而这个版本是有缺陷的,因为它不提供任何全面的代码覆盖。

我已尝试过建议here运气不好。

如有任何建议,我们将不胜感激。

最佳答案

看起来 jasmine-blanket get 卡在了对 jasmine.getEnv().currentRunner 的引用中。 Jasmine 2.0+ 版本中未定义。控制台的最后一个输出恰好是在中断之前“等待毯子...”。我用这个替换了 jasmine-blanket 中 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();
}
});

关于javascript - BlanketJS + Jasmine + RequireJS 无代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29820793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com