Skip to content

Custom Mocha reporter with spinners and progress reporting ability

Notifications You must be signed in to change notification settings

ramtinsoltani/mocha-progress-reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mocha Progress Reporter

Custom Mocha reporter with extra logging abilities. This reporter shows spinners for test cases while running and allows reporting progress mid-test for cases that take too long and need more context. Logs are also handled very well and stylized correctly, as opposed to the default Mocha reporter where console logs break the report style.

terminal-recording

Installation

npm install mocha-progress-reporter --save-dev

TypeScript import (for typings only):

// Globally available in all tests with one import in main spec
import 'mocha-progress-reporter';

Usage

Configure the reporter (if needed):

// In main spec file
import 'mocha-progress-reporter';

reporter.config({ hooks: false });

NOTE: You can reconfigure the reporter mid-case or in hooks when needed. Using this can form a debug mode where logs are off globally but toggled on inside specific test cases for debugging.

Use the reporter for progress and logs:

// In any spec file that is imported in main spec
describe('Suite', function() {

  beforeEach(function() {

    reporter.progress('Preparing stuff');

    // Prepare stuff

    reporter.warn('Stuff not fully prepared, but we should be good nonetheless!');

  });

  it('should pass this', function() {

    reporter.progress('Doing stuff');

    // Do stuff

    reporter.progress('Doing more stuff');

    // Do more stuff

    reporter.log('Important log that should stay');

  });

});

Running Mocha:

mocha ./main.spec --reporter mocha-progress-reporter

API

The following methods are defined on the reporter object:

  • .progress(message) Sends a progress message to the reporter for the current test.
  • .clear() Clears the last progress message. This is automatically called at the end of every test case and therefore not manually used very often.
  • .log(message[, ...additionalMessages]) Logs a message without breaking the spinners.
  • .warn(message[, ...additionalMessages]) Logs a warning message without breaking the spinners.
  • .error(message[, ...additionalMessages]) Logs an error message without breaking the spinners.
  • .config(options) Configures the reporter with the following options:
    • hooks When true, running hooks will be shown in the terminal. Default true.
    • colors When false all logs will be plain white. Default true.
    • logs When false, .log(), .warn(), and .error() logs will be ignored. Default true.

About

Custom Mocha reporter with spinners and progress reporting ability

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published