Jasmine Reporters

2.5.2 · active · verified Sun Apr 19

jasmine-reporters is a collection of JavaScript reporter classes designed for the Jasmine BDD testing framework. As of version 2.5.2, it primarily supports Jasmine 2.x, with a dedicated branch and older npm versions available for Jasmine 1.x compatibility. The library offers a variety of output formats, including standard options like JUnit XML, NUnit XML, and TAP (Test Anything Protocol), alongside specialized reporters for build systems such as TeamCity and AppVeyor, and a colorized Terminal Reporter. It differentiates itself by providing robust support for both Node.js environments and in-browser testing via PhantomJS, including mechanisms for local filesystem writes in headless browser contexts. While no explicit release cadence is documented, major versions of jasmine-reporters historically align with significant Jasmine framework updates, requiring users to match the reporter library version to their Jasmine version.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up and use the JUnitXmlReporter with Jasmine in a Node.js environment, showing how to instantiate the reporter and add it to Jasmine, then execute a basic test suite.

const Jasmine = require('jasmine');
const reporters = require('jasmine-reporters');
const path = require('path');

const jasmine = new Jasmine();

// Configure a JUnit XML Reporter
const junitReporter = new reporters.JUnitXmlReporter({
  savePath: path.join(__dirname, 'test-results'), // Directory to save XML files
  filePrefix: 'test-result-',
  consolidateAll: true, // Consolidate all specs into a single XML file per suite
  use misfortunes: true
});

// Add the reporter to Jasmine
jasmine.addReporter(junitReporter);

// Define a simple spec file for demonstration
// In a real project, these would be separate files.
const specCode = `
describe('A suite', function() {
  it('contains spec with an expectation', function() {
    expect(true).toBe(true);
  });
  it('contains another spec', function() {
    expect(1 + 1).toBe(2);
  });
});
`;

// Create a temporary spec file for Jasmine to find
const fs = require('fs');
const specFilePath = path.join(__dirname, 'temp-spec.js');
fs.writeFileSync(specFilePath, specCode);

// Configure Jasmine to find specs
jasmine.specDir = __dirname;
jasmine.specFiles = ['temp-spec.js'];

// Execute the tests
jasmine.execute();

// Clean up temporary file after tests (simplified, should use 'afterAll' in real test suite)
process.on('exit', () => {
  if (fs.existsSync(specFilePath)) {
    fs.unlinkSync(specFilePath);
  }
  console.log('Test execution complete. Check test-results directory.');
});

view raw JSON →