Jasmine, disable the default reporter

I have Jasmine with a custom reporter

var myReporter = {
  jasmineStarted: function(suiteInfo) {

    console.log('Running suite with ' + suiteInfo.totalSpecsDefined);
  },

  suiteStarted: function(result) {

    console.log('Suite started: ' + result.description + ' whose full description is: ' + result.fullName);
  },

  specStarted: function(result) {

    console.log('Spec started: ' + result.description + ' whose full description is: ' + result.fullName);
  },

  specDone: function(result) {

    console.log('Spec: ' + result.description + ' was ' + result.status);
    for(var i = 0; i < result.failedExpectations.length; i++) {


      console.log('Failure: ' + result.failedExpectations[i].message);
      console.log(result.failedExpectations[i].stack);
    }
  },

  suiteDone: function(result) {

    console.log('Suite: ' + result.description + ' was ' + result.status);
    for(var i = 0; i < result.failedExpectations.length; i++) {

      console.log('AfterAll ' + result.failedExpectations[i].message);
      console.log(result.failedExpectations[i].stack);
    }
  },
  jasmineDone: function() {
    console.log('Finished suite');
  }
};

jasmine.getEnv().addReporter(myReporter);

describe('Top Level suite', function() {
  it('spec', function() {
    expect(1).toBe(1);
  });

  describe('Nested suite', function() {
    it('nested spec', function() {
      expect(true).toBe(true);
    });
  });
});

      

live: http://jsfiddle.net/wLnmbh88/

The results are now displayed in the html and console, but I need to disable that in the html. How to show test results in console only? Sample code from jasmine documentation.

+3


source to share


2 answers


No need to delete jasmine-html.js

and play with custom boot.js

. Just remove all reporters before adding your reporter of choice:



var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().clearReporters();
jasmine.getEnv().addReporter(new jasmineReporters.TapReporter());

      

+7


source


By default, HTML reporter is added to files jasmine-html.js

and boot.js

in your JSFiddle .

jasmine-html.js

( source ) - actually the reporter itself, implemented through the Jasmine reporter API; boot.js

( source ) - The file that configures the environment for Jasmine and runs it. Also, it activates the HTML reporter by default, because both of these files are considered the core of Jasmine, so by including them in everything, you have a basic Jasmine installation.

In your case, you want to implement a custom reporter +, you want to get rid of the default HTML reporter, so you just need to remove jasmine-html.js

and replace boot.js

with a custom one. The Jasmine docs have a custom upload setup page and an annotated source for it.

A basic custom upload script for Jasmine 2.x without including any reporters should look something like this:

(function() {

  window.jasmine = jasmineRequire.core(jasmineRequire);

  var env = jasmine.getEnv();
  var jasmineInterface = jasmineRequire.interface(jasmine, env);

  extend(window, jasmineInterface);

  window.setTimeout = window.setTimeout;
  window.setInterval = window.setInterval;
  window.clearTimeout = window.clearTimeout;
  window.clearInterval = window.clearInterval;

  var currentWindowOnload = window.onload;

  window.onload = function() {
    if (currentWindowOnload) {
      currentWindowOnload();
    }
    env.execute();
  };

  function extend(destination, source) {
    for (var property in source) destination[property] = source[property];
    return destination;
  }

}());

      



Make sure you include this loading script after jasmine.js

.

After setting up the upload, you can register your reporter as usual:

jasmine.getEnv().addReporter(myReporter);

      

or even better - add it to your boot script.

Check out the JSFiddle: http://jsfiddle.net/wLnmbh88/2/

-1


source







All Articles