我一直在使用Jasmine 2.0.0进行测试,它没有任何问题。 但是当我将BlanketJS附加到我的代码时会出现问题。
我使用了与Jasmine 1.3.1一起使用的specRunner(https://github.com/alex-seville/blanket/blob/master/test/jasmine-requirejs/runner.html)。但是当我用Jasmine 2.0.0替换Jasmine 1.3.1时,它不起作用,
以下是BlanketJS repo的原始代码:
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="../vendor/jasmine.css">
<script type="text/javascript" src="../vendor/jasmine.js"></script>
<script type="text/javascript" src="../vendor/jasmine-html.js"></script>
<script type="text/javascript" src="../helpers/console_runner.js"></script>
<script type="text/javascript" src="../../node_modules/requirejs/require.js"></script>
<script type="text/javascript" data-cover-only="code/" data-cover-never="['all.tests','code/tests']"
src="../../dist/qunit/blanket.js"> </script>
<script type="text/javascript" src="../../src/adapters/jasmine-blanket.js"></script>
<script type="text/javascript">
if (window.require && typeof (window.require.config) === 'function') {
require.config({
baseUrl: './code'
});
}
</script>
<script type="text/javascript" src="code/all.tests.jasmine.js"></script>
<script type="text/javascript">
(function () {
window.blanketTestJasmineExpected=2;
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
var oldResult = htmlReporter.reportRunnerResults;
jasmineEnv.addReporter(htmlReporter);
/* this is just for our automated tests */
window.jasmine_phantom_reporter = new jasmine.ConsoleReporter;
jasmineEnv.addReporter(jasmine_phantom_reporter);
/* */
jasmineEnv.specFilter = function (spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>
我添加了Jasmine 2.0.0文件并更改了以下代码:
....
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="../vendor/jasmine.css">
<script type="text/javascript" src="../vendor/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="../vendor/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="../vendor/jasmine-2.0.0/boot.js"></script>
<script type="text/javascript" src="../helpers/console_runner.js"></script>
....
打印出错误消息:
Uncaught TypeError: Cannot read property 'env' of undefined jasmine-html.js:38
Uncaught TypeError: Object #<Env> has no method 'currentRunner' jasmine-blanket.js:76
如何正常运行此specRunner页面?请给我一个解决方案。感谢。
答案 0 :(得分:19)
Blanket适配器使用currentRunner,但2.0中不再存在。 Blanket Jasmine适配器需要更新,因为它和记者界面都已更改。
打开你的jasmine-blanket.js文件并用下面的代码替换底部的代码:
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();
}
});
然后它将按预期进行。
ETA - 我个人转而去伊斯坦布尔,因为Blanket现在似乎很少更新(如果有的话)。伊斯坦布尔拥有更完整的覆盖统计数据(不仅仅是线路 - 分支机构等),还可以将代码气候等工具导出到lcov。它适用于Jasmine或任何测试框架,完美无缺。
答案 1 :(得分:4)
所以现在实际上有一个2.x版本的茉莉花适配器。但是我仍然在配置它时遇到了一些麻烦。最终我确实把一切都配置好了,这就是我得到的:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tests</title>
<link rel="stylesheet" href="components/jasmine.css">
<script src="components/jasmine.js"></script>
<script src="components/jasmine-html.js"></script>
<script src="components/boot.js"></script>
<script type="text/javascript" data-cover-only="app/" src="components/blanket.js" data-cover-adapter="components/jasmine-2.x-blanket.js"></script>
<script src="components/blanket_browser.js"></script>
<script src="components/jasmine-2.x-blanket.js"></script>
<!-- sources -->
<script src="components/angular.js"></script>
<script src="components/angular-mocks.js"></script>
<script src="app/custom-forms.js"></script>
<script src="app/route-selector.js"></script>
<!-- tests -->
<script src="tests/custom-forms-tests.js"></script>
<script src="tests/route-selector-tests.js"></script>
</head>
<body>
</body>
</html>
注意:我使用bower来检索茉莉花和毯子,但是对于我必须引用的毯子文件存在一些混淆,所以:
“components / blanket.js” - &gt;我从dist / qunit / blanket.js
“components / blanket_browser.js” - &gt; SRC / blanket_browser.js
“components / jasmine-2.x-blanket.js” - &gt; SRC /适配器/茉莉2.x的-blanket.js
请注意,我也使用jasmine附带的boot.js,它工作正常。希望这些信息对某人有所帮助。