CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jasmine-node

DOM-less simple JavaScript BDD testing framework for Node.js

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

reporters.mddocs/

Reporters and Output

Multiple reporter formats and output options for different environments including terminal output, CI integration, XML reports, and desktop notifications.

Capabilities

Terminal Reporter

Basic terminal output reporter with pass/fail indicators and summary information.

/**
 * Basic terminal reporter with colored output and failure details
 * @param config - Reporter configuration object
 */
class TerminalReporter {
  constructor(config: ReporterConfig);
  reportRunnerStarting(runner: jasmine.Runner): void;
  reportRunnerResults(runner: jasmine.Runner): void;
  reportSuiteResults(suite: jasmine.Suite): void;
  reportSpecResults(spec: jasmine.Spec): void;
}

interface ReporterConfig {
  /** Function for output printing (defaults to process.stdout.write) */
  print?: (str: string) => void;
  /** Enable colored output (green/red for pass/fail) */
  color?: boolean;
  /** Callback function when test run completes */
  onComplete?: (passed: boolean) => void;
  /** Include stack traces in failure output */
  includeStackTrace?: boolean;
  /** Function to filter stack trace lines */
  stackFilter?: (trace: string) => string;
}

Usage Examples:

const jasmine = require("jasmine-node");

// Basic terminal reporter
const reporter = new jasmine.TerminalReporter({
  color: true,
  includeStackTrace: true
});

jasmine.getEnv().addReporter(reporter);

// Custom print function
const reporter2 = new jasmine.TerminalReporter({
  print: function(str) {
    console.log("[TEST] " + str);
  },
  color: false
});

// With completion callback
const reporter3 = new jasmine.TerminalReporter({
  color: true,
  onComplete: function(passed) {
    if (passed) {
      console.log("All tests passed!");
      process.exit(0);
    } else {
      console.log("Some tests failed!");
      process.exit(1);
    }
  }
});

Verbose Terminal Reporter

Extended terminal reporter with detailed progress information and timing data.

/**
 * Verbose terminal reporter with detailed test progress and timing
 * @param config - Reporter configuration object
 */
class TerminalVerboseReporter {
  constructor(config: VerboseReporterConfig);
  reportRunnerStarting(runner: jasmine.Runner): void;
  reportRunnerResults(runner: jasmine.Runner): void;
  reportSuiteResults(suite: jasmine.Suite): void;
  reportSpecStarting(spec: jasmine.Spec): void;
  reportSpecResults(spec: jasmine.Spec): void;
}

interface VerboseReporterConfig extends ReporterConfig {
  /** Additional configuration for verbose reporter (extends basic ReporterConfig) */
}

Usage Examples:

const jasmine = require("jasmine-node");

// Verbose reporter with color support
const verboseReporter = new jasmine.TerminalVerboseReporter({
  color: true,
  onComplete: function(passed) {
    console.log("Verbose test run completed: " + (passed ? "PASSED" : "FAILED"));
  }
});

jasmine.getEnv().addReporter(verboseReporter);

// Custom stack filtering
const verboseReporter2 = new jasmine.TerminalVerboseReporter({
  color: true,
  stackFilter: function(trace) {
    // Remove node_modules lines from stack trace
    return trace.split('\n')
      .filter(line => !line.includes('node_modules'))
      .join('\n');
  }
});

TeamCity Reporter

Specialized reporter for JetBrains TeamCity continuous integration platform.

/**
 * TeamCity-compatible reporter with service messages
 * @param config - TeamCity reporter configuration
 */
class TeamcityReporter {
  constructor(config: TeamcityReporterConfig);
  reportRunnerStarting(runner: jasmine.Runner): void;
  reportRunnerResults(runner: jasmine.Runner): void;
  reportSuiteStarting(suite: jasmine.Suite): void;
  reportSuiteResults(suite: jasmine.Suite): void;
  reportSpecStarting(spec: jasmine.Spec): void;
  reportSpecResults(spec: jasmine.Spec): void;
}

interface TeamcityReporterConfig {
  /** Callback function when test run completes */
  onComplete?: (passed: boolean) => void;
  /** Custom print function for service messages */
  print?: (str: string) => void;
}

Usage Examples:

const jasmine = require("jasmine-node");

// Basic TeamCity reporter
const teamcityReporter = new jasmine.TeamcityReporter({
  onComplete: function(passed) {
    process.exit(passed ? 0 : 1);
  }
});

jasmine.getEnv().addReporter(teamcityReporter);

// TeamCity with custom output
const teamcityReporter2 = new jasmine.TeamcityReporter({
  print: function(message) {
    // Log to file or custom output stream
    fs.appendFileSync('teamcity-output.log', message + '\n');
  }
});

JUnit XML Reporter

Generate JUnit-compatible XML reports for CI/CD integration and test result archiving.

/**
 * JUnit XML reporter for CI/CD integration
 * @param savePath - Directory to save XML reports
 * @param consolidate - Combine all results into single XML file
 * @param useDotNotation - Use dot notation for nested describe blocks
 */
class JUnitXmlReporter {
  constructor(savePath: string, consolidate?: boolean, useDotNotation?: boolean);
  reportRunnerStarting(runner: jasmine.Runner): void;
  reportRunnerResults(runner: jasmine.Runner): void;
  reportSuiteResults(suite: jasmine.Suite): void;
  reportSpecResults(spec: jasmine.Spec): void;
}

Usage Examples:

const jasmine = require("jasmine-node");

// Basic JUnit XML reporter
const junitReporter = new jasmine.JUnitXmlReporter('./reports/');
jasmine.getEnv().addReporter(junitReporter);

// Consolidated single XML file
const junitReporter2 = new jasmine.JUnitXmlReporter(
  './reports/',
  true,  // consolidate into single file
  true   // use dot notation for test names
);

// Multiple reporters combination
jasmine.getEnv().addReporter(new jasmine.TerminalReporter({ color: true }));
jasmine.getEnv().addReporter(junitReporter2);

Growl Reporter

Desktop notification reporter using Growl for test result summaries.

/**
 * Growl notification reporter for desktop alerts
 * Requires Growl to be installed on the system
 */
class GrowlReporter {
  constructor();
  reportRunnerResults(runner: jasmine.Runner): void;
}

Usage Examples:

const jasmine = require("jasmine-node");

// Basic Growl notifications
const growlReporter = new jasmine.GrowlReporter();
jasmine.getEnv().addReporter(growlReporter);

// Combined with terminal output
jasmine.getEnv().addReporter(new jasmine.TerminalReporter({ color: true }));
jasmine.getEnv().addReporter(growlReporter);

Custom Reporter Implementation

Create custom reporters by implementing the reporter interface.

/**
 * Custom reporter interface - implement any or all methods
 */
interface CustomReporter {
  /** Called when test runner starts */
  reportRunnerStarting?(runner: jasmine.Runner): void;
  /** Called when test runner completes */
  reportRunnerResults?(runner: jasmine.Runner): void;
  /** Called when a test suite starts */
  reportSuiteStarting?(suite: jasmine.Suite): void;
  /** Called when a test suite completes */
  reportSuiteResults?(suite: jasmine.Suite): void;
  /** Called when a test spec starts */
  reportSpecStarting?(spec: jasmine.Spec): void;
  /** Called when a test spec completes */
  reportSpecResults?(spec: jasmine.Spec): void;
  /** Called for general log messages */
  log?(str: string): void;
}

// Jasmine runner and suite objects
interface jasmine.Runner {
  topLevelSuites(): jasmine.Suite[];
  results(): jasmine.NestedResults;
  specs(): jasmine.Spec[];
}

interface jasmine.Suite {
  id: number;
  description: string;
  parentSuite: jasmine.Suite | null;
  children(): (jasmine.Suite | jasmine.Spec)[];
  results(): jasmine.NestedResults;
}

interface jasmine.Spec {
  id: number;
  description: string;
  suite: jasmine.Suite;
  results(): jasmine.NestedResults;
}

interface jasmine.NestedResults {
  passed(): boolean;
  totalCount: number;
  passedCount: number;
  failedCount: number;
  skippedCount: number;
  getItems(): jasmine.Result[];
}

Usage Examples:

// Custom JSON reporter
const JsonReporter = function() {
  let testResults = [];
  
  this.reportSpecResults = function(spec) {
    const result = {
      id: spec.id,
      description: spec.description,
      suite: spec.suite.description,
      passed: spec.results().passed(),
      runtime: spec.results().runtime || 0
    };
    testResults.push(result);
  };
  
  this.reportRunnerResults = function(runner) {
    const summary = {
      total: runner.results().totalCount,
      passed: runner.results().passedCount,
      failed: runner.results().failedCount,
      results: testResults
    };
    
    require('fs').writeFileSync(
      './test-results.json',
      JSON.stringify(summary, null, 2)
    );
  };
};

jasmine.getEnv().addReporter(new JsonReporter());

// Custom console reporter with emojis
const EmojiReporter = function() {
  this.reportSpecResults = function(spec) {
    const emoji = spec.results().passed() ? '✅' : '❌';
    console.log(`${emoji} ${spec.description}`);
  };
  
  this.reportRunnerResults = function(runner) {
    const results = runner.results();
    console.log(`\n🎯 Total: ${results.totalCount}`);
    console.log(`✅ Passed: ${results.passedCount}`);
    console.log(`❌ Failed: ${results.failedCount}`);
  };
};

jasmine.getEnv().addReporter(new EmojiReporter());

// Database logging reporter
const DatabaseReporter = function(database) {
  this.reportRunnerResults = function(runner) {
    const testRun = {
      timestamp: new Date(),
      total: runner.results().totalCount,
      passed: runner.results().passedCount,
      failed: runner.results().failedCount,
      duration: Date.now() - this.startTime
    };
    
    database.saveTestRun(testRun);
  };
  
  this.reportRunnerStarting = function(runner) {
    this.startTime = Date.now();
  };
};

const db = require('./test-database');
jasmine.getEnv().addReporter(new DatabaseReporter(db));

Reporter Color Configuration

// ANSI color codes used by reporters
interface ANSIColors {
  pass(): string;        // Green - '\033[32m'
  fail(): string;        // Red - '\033[31m'
  specTiming(): string;  // Blue - '\033[34m'
  suiteTiming(): string; // Yellow - '\033[33m'
  ignore(): string;      // Light Gray - '\033[37m'
  neutral(): string;     // Normal - '\033[0m'
}

interface NoColors {
  pass(): string;        // Empty string ''
  fail(): string;        // Empty string ''
  specTiming(): string;  // Empty string ''
  suiteTiming(): string; // Empty string ''
  ignore(): string;      // Empty string ''
  neutral(): string;     // Empty string ''
}

Multi-Reporter Configuration

const jasmine = require("jasmine-node");

// Configure multiple reporters for comprehensive output
const env = jasmine.getEnv();

// Terminal output for development
env.addReporter(new jasmine.TerminalVerboseReporter({
  color: true,
  showTiming: true
}));

// JUnit XML for CI/CD
env.addReporter(new jasmine.JUnitXmlReporter('./reports/', true, true));

// Growl notifications for desktop alerts
env.addReporter(new jasmine.GrowlReporter());

// Custom completion handler
env.addReporter({
  reportRunnerResults: function(runner) {
    const passed = runner.results().passed();
    console.log(`\n🎯 Test run ${passed ? 'PASSED' : 'FAILED'}`);
    process.exit(passed ? 0 : 1);
  }
});

docs

advanced-features.md

cli-usage.md

index.md

reporters.md

test-writing.md

tile.json