Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Nightwatchjs Nightwatch Reporter Hook Interface

From Leeroopedia
Revision as of 11:41, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Nightwatchjs_Nightwatch_Reporter_Hook_Interface.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Testing, Reporting
Last Updated 2026-02-12 00:00 GMT

Overview

Interface specification for the custom reporter hook in Nightwatch.js globals, invoked after test execution with aggregated results.

Description

The reporter function is defined in the globals module and is called after all tests complete. It receives the full results object containing passed, failed, errors, and skipped counts along with per-module details. A callback must be invoked to signal completion. This is a user-defined pattern, not a library API class.

Usage

Define a reporter function in the globals module when you need custom post-test processing such as sending Slack notifications, writing custom report formats, or updating external dashboards.

Code Reference

Source Location

  • Repository: nightwatch
  • File: examples/globalsModule.js (lines 68-70)

Signature

/**
 * Custom reporter hook - called after all tests complete
 * @param {Object} results - aggregated test results
 * @param {Function} cb - callback to signal completion
 */
reporter(results: Object, cb: Function) -> void

Import

// Defined as a property in the globals module (globals.js)
// No import required - Nightwatch calls this automatically

I/O Contract

Inputs

Name Type Required Description
results Object Yes Aggregated test results with passed, failed, errors, skipped counts and module details
cb Function Yes Callback that must be called to signal reporter completion

Outputs

Name Type Description
Custom report output Any User-defined: files, console output, API calls, etc.
cb() invocation void Signals to Nightwatch that reporting is complete

Usage Examples

Basic Reporter

// globals.js
module.exports = {
  reporter(results, cb) {
    console.log('Tests passed:', results.passed);
    console.log('Tests failed:', results.failed);
    console.log('Errors:', results.errors);
    cb();
  }
};

Reporter with External Integration

const https = require('https');

module.exports = {
  reporter(results, cb) {
    // Send results to a dashboard
    const payload = JSON.stringify({
      passed: results.passed,
      failed: results.failed,
      errors: results.errors,
      timestamp: new Date().toISOString()
    });

    const req = https.request({
      hostname: 'dashboard.example.com',
      path: '/api/test-results',
      method: 'POST',
      headers: { 'Content-Type': 'application/json' }
    }, () => cb());

    req.write(payload);
    req.end();
  }
};

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment