CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jasmine-reporters

A collection of JavaScript reporter classes for the Jasmine BDD testing framework that output test results in various formats including JUnit XML, NUnit XML, TAP, TeamCity, AppVeyor, and Terminal

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

xml-reporters.mddocs/

XML Reporters

File-based reporters that generate structured XML output for CI/CD integration and test result analysis. Supports JUnit and NUnit XML formats with extensive configuration options for file organization and content customization.

Capabilities

JUnit XML Reporter

Generates JUnit XML format test reports with configurable file organization and content customization. Supports both consolidated and individual file output patterns.

/**
 * Creates a JUnit XML reporter instance
 * @param options - Configuration options for XML generation and file output
 * @returns Reporter instance implementing Jasmine reporter interface
 */
function JUnitXmlReporter(options?: JUnitOptions): Reporter;

interface JUnitOptions {
  /** Directory to save the files (default: '') */
  savePath?: string;
  /** Whether to save all test results in a single file (default: true) */
  consolidateAll?: boolean;
  /** Whether to save nested describes within same file as parent (default: true) */
  consolidate?: boolean;
  /** Whether to separate suite names with dots instead of spaces (default: true) */
  useDotNotation?: boolean;
  /** Whether to use fully qualified test name for TestCase name attribute (default: false) */
  useFullTestName?: boolean;
  /** String prepended to xml output file (default: 'junitresults-' or 'junitresults') */
  filePrefix?: string;
  /** Base package for all test suites (default: none) */
  package?: string;
  /** Delegate for modifying suite names in the junit report */
  modifySuiteName?: (fullName: string, suite: Suite) => string;
  /** Delegate for modifying report filenames */
  modifyReportFileName?: (suggestedName: string, suite: Suite) => string;
  /** Path to XSLT stylesheet to add to XML file (default: none) */
  stylesheetPath?: string;
  /** If true, will not include disabled attribute in XML output (default: false) */
  suppressDisabled?: boolean;
  /** Delegate for adding content to system-out tag as part of each testcase spec output */
  systemOut?: (spec: Spec, qualifiedName: string) => string;
  /** Enables capturing all stdout as spec output in xml-output elements (default: false) */
  captureStdout?: boolean;
}

Usage Examples:

// Basic usage with default options
const junitReporter = new jasmineReporters.JUnitXmlReporter();
jasmine.getEnv().addReporter(junitReporter);

// Consolidated output to specific directory
const junitReporter = new jasmineReporters.JUnitXmlReporter({
    savePath: './test-results',
    consolidateAll: true,
    filePrefix: 'junit-results'
});

// Separate files per suite with custom naming
const junitReporter = new jasmineReporters.JUnitXmlReporter({
    savePath: './test-results',
    consolidateAll: false,
    consolidate: false,
    useDotNotation: true,
    modifySuiteName: function(generatedSuiteName, suite) {
        return 'MyApp.' + generatedSuiteName;
    }
});

// Protractor multi-capability setup
const junitReporter = new jasmineReporters.JUnitXmlReporter({
    consolidateAll: true,
    savePath: 'testresults',
    filePrefix: browserName + '-xmloutput',
    modifySuiteName: function(generatedSuiteName, suite) {
        return browserName + '.' + generatedSuiteName;
    }
});

NUnit XML Reporter

Generates NUnit XML format test reports with simpler configuration focused on single-file output and custom report naming.

/**
 * Creates an NUnit XML reporter instance  
 * @param options - Configuration options for NUnit XML generation
 * @returns Reporter instance implementing Jasmine reporter interface
 */
function NUnitXmlReporter(options?: NUnitOptions): Reporter;

interface NUnitOptions {
  /** Directory to save the files (default: '') */
  savePath?: string;
  /** Name of xml output file (default: 'nunitresults.xml') */
  filename?: string;
  /** Name for parent test-results node (default: 'Jasmine Results') */
  reportName?: string;
}

Usage Examples:

// Basic usage with default options
const nunitReporter = new jasmineReporters.NUnitXmlReporter();
jasmine.getEnv().addReporter(nunitReporter);

// Custom filename and location
const nunitReporter = new jasmineReporters.NUnitXmlReporter({
    savePath: './build/test-results',
    filename: 'nunit-test-results.xml',
    reportName: 'MyApplication Test Results'
});

File Writing Methods

Both XML reporters provide file writing capabilities across different environments.

/**
 * Writes XML content to file using environment-appropriate method
 * @param filename - Name of file to write (extension added automatically if missing)
 * @param text - XML content to write to file
 */
writeFile(filename: string, text: string): void;

Environment Support:

  • Node.js: Uses fs module with mkdirp for directory creation
  • PhantomJS: Uses injected __phantom_writeFile method
  • Error Handling: Logs warnings if file writing fails in both environments

Reporter Lifecycle Methods

All XML reporters implement the complete Jasmine reporter interface.

/** Called when Jasmine starts running */
jasmineStarted(summary?: Summary): void;

/** Called when a test suite starts */
suiteStarted(suite: Suite): void;

/** Called when a test spec starts */  
specStarted(spec: Spec): void;

/** Called when a test spec completes */
specDone(spec: Spec): void;

/** Called when a test suite completes */
suiteDone(suite: Suite): void;

/** Called when all tests have completed */
jasmineDone(): void;

XML Output Formats

JUnit XML Structure

<?xml version="1.0" encoding="UTF-8" ?>
<testsuites disabled="0" errors="0" failures="1" tests="3" time="0.123">
  <testsuite name="Suite Name" timestamp="2023-01-01T12:00:00" hostname="localhost" 
             time="0.123" errors="0" tests="2" skipped="0" disabled="0" failures="1">
    <testcase classname="Suite Name" name="should pass" time="0.001" />
    <testcase classname="Suite Name" name="should fail" time="0.122">
      <failure type="exception" message="Expected true to be false">
        <![CDATA[Error: Expected true to be false
        at Object.<anonymous> (spec.js:10:5)]]>
      </failure>
    </testcase>
  </testsuite>
</testsuites>

NUnit XML Structure

<?xml version="1.0" encoding="utf-8" ?>
<test-results name="Jasmine Results" total="2" failures="1" not-run="0" 
              date="2023-01-01" time="12:00:00">
  <test-suite name="Suite Name" executed="true" success="false" time="0.123">
    <results>
      <test-case name="should pass" executed="true" success="true" time="0.001" />
      <test-case name="should fail" executed="true" success="false" time="0.122">
        <failure>
          <message><![CDATA[Expected true to be false]]></message>
          <stack-trace><![CDATA[Error: Expected true to be false
          at Object.<anonymous> (spec.js:10:5)]]></stack-trace>
        </failure>
      </test-case>
    </results>
  </test-suite>
</test-results>

docs

ci-integration.md

console-reporters.md

index.md

xml-reporters.md

tile.json