BlanketJS + Jasmine 2.0 not working

前端 未结 2 1416
春和景丽
春和景丽 2021-02-08 11:40

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

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 12:08

    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.

提交回复
热议问题