Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlanketJS + Jasmine 2.0 not working

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.

like image 815
SJ Baek Avatar asked Jan 29 '14 01:01

SJ Baek


1 Answers

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.

like image 112
abritinthebay Avatar answered Sep 28 '22 05:09

abritinthebay