BlanketJS + Jasmine 2.0无效 [英] BlanketJS + Jasmine 2.0 not working

查看:136
本文介绍了BlanketJS + Jasmine 2.0无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Jasmine 2.0.0进行测试,它没有任何问题。
但是当我将BlanketJS附加到我的代码时出现问题。

I have been testing with Jasmine 2.0.0 and it works without any problem. But there's a problem when I append BlanketJS to my code.

我使用了specRunner( https://github.com/alex-seville/blanket/blob/master/test/jasmine-requirejs/runner.html )适用于Jasmine 1.3.1。但是当我用Jasmine 2.0.0替换Jasmine 1.3.1时它不起作用,

I used a specRunner(https://github.com/alex-seville/blanket/blob/master/test/jasmine-requirejs/runner.html) that works with Jasmine 1.3.1. But It does not work when I replace Jasmine 1.3.1 with Jasmine 2.0.0,

这是来自BlanketJS repo的原始代码:

Here's original code from 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文件并更改了以下代码:

and I added Jasmine 2.0.0 files and changed this code like below:

....
<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页面的情况下运行问题?请给我一个解决方案。谢谢。

How can I run this specRunner page without problems? Please give me a solution. thanks.

推荐答案

Blanket适配器使用currentRunner,但2.0中不再存在。
Blanket Jasmine适配器需要更新,因为这个和报告器界面都已更改。

the Blanket adapter uses currentRunner but that doesn't exist in 2.0 anymore. The Blanket Jasmine adapter needs to be updated as both this and the reporter interface has changed.

打开你的jasmine-blanket.js文件并替换代码在底部有这个:

Open up your jasmine-blanket.js file and replace the code at the bottom with this:

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

然后它将如预期的那样。

Then it will should as intended.

ETA - 我个人转而去伊斯坦布尔,因为Blanket现在似乎很少更新(如果有的话)。伊斯坦布尔拥有更完整的覆盖统计数据(不仅仅是线路 - 分支机构等),还可以将代码气候等工具导出到lcov。它适用于Jasmine或任何测试框架,完美无缺。

这篇关于BlanketJS + Jasmine 2.0无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆