Domanda

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.

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,

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>

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

The error messages printed:

Uncaught TypeError: Cannot read property 'env' of undefined jasmine-html.js:38
Uncaught TypeError: Object #<Env> has no method 'currentRunner' jasmine-blanket.js:76

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

È stato utile?

Soluzione

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.

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 - personally I'd switch to Istanbul instead, as Blanket seems to be sparsely updated (if at all) right now. Istanbul has more complete coverage stats (not just lines - branches, etc) and can export to lcov for tools like Code Climate. It works with Jasmine, or any test framework, flawlessly.

Altri suggerimenti

So now there is actually an adapter for 2.x version of jasmine. But I still had some trouble configuring it. Eventually I did configure everything right, so that is what I got:

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

Note: I used bower to retrieve jasmine and blanket, but there is some confusion towards what blanket files I had to reference, so:

  • "components/blanket.js" -> I got this file from dist/qunit/blanket.js

  • "components/blanket_browser.js" -> src/blanket_browser.js

  • "components/jasmine-2.x-blanket.js" -> src/adapters/jasmine-2.x-blanket.js

Note that I also use boot.js that comes with jasmine and it works fine. Hope this information helps someone.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top