npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mocha-detailed-json-reporter

v1.0.0

Published

Detailed JSON reporter for Mocha with DRY approach, works in Node.js and browser

Downloads

19

Readme

Mocha Detailed JSON Reporter

A comprehensive Mocha reporter that provides detailed test results in JSON format. Works in both Node.js and browser environments, with advanced features like console output capture, stack trace parsing, and source code inclusion.

npm version License: MIT

Features

  • Detailed test results in a structured JSON format
  • Works in both Node.js and browser environments
  • Captures console output during tests (configurable)
  • Collects source code context for errors and test files
  • Stack trace parsing and formatting
  • Flexible output options (file, variable, window object)
  • No external dependencies beyond Mocha
  • TypeScript support

Installation

npm install mocha-detailed-json-reporter --save-dev

Usage

Node.js Environment

Command Line

mocha tests/ --reporter mocha-detailed-json-reporter

With options:

mocha tests/ --reporter mocha-detailed-json-reporter --reporter-options outputToFile=true,outputFilePath=results.json

Programmatic Usage

const Mocha = require('mocha');
const { DetailedJsonReporter } = require('mocha-detailed-json-reporter');

const mocha = new Mocha({
  reporter: DetailedJsonReporter,
  reporterOptions: {
    outputToFile: true,
    outputFilePath: 'results/test-results.json'
  }
});

// Add files and run
mocha.addFile('test/test.js');
mocha.run(failures => {
  process.exitCode = failures ? 1 : 0;
});

Browser Environment

<script src="node_modules/mocha/mocha.js"></script>
<script src="node_modules/mocha-detailed-json-reporter/dist/browser.js"></script>
<script>
  mocha.setup({
    ui: 'bdd',
    reporter: MochaDetailedReporter.DetailedJsonReporter
  });
</script>

<!-- Your tests -->
<script src="tests.js"></script>

<script>
  mocha.run();
  // Results will be available in window.detailedTestResults
</script>

Configuration Options

| Option | Default | Description | | ------ | ------- | ----------- | | outputToFile | true (Node) / false (Browser) | Whether to write results to a file | | outputFilePath | "detailed-test-results.json" | Path to output file relative to CWD | | outputDir | "test-results" | Directory to store test results | | useTimestampDir | true | Create timestamped subdirectories for each run | | splitOutput | false | Split output into multiple files by type | | outputToVariable | false | Store results in a global variable | | variableName | "detailedTestResults" | Name of the variable to store results | | outputToWindow | false (Node) / true (Browser) | Store results in window object | | windowVariableName | "detailedTestResults" | Name of window property to store results | | captureConsoleLogs | true | Capture console output during test execution | | captureConsoleTypes | ["log", "info", "warn", "error"] | Which console methods to capture | | maxConsoleLogSize | 100000 | Maximum size of captured console logs in characters |

Output Format

The reporter generates a detailed JSON structure with test results, environment info, source code, console logs, and more. See the Output Format Documentation for details.

Example Output

{
  "stats": {
    "suites": 1,
    "tests": 3,
    "passes": 2,
    "failures": 1,
    "pending": 0,
    "duration": 15,
    "start": "2023-06-01T12:30:45.678Z",
    "end": "2023-06-01T12:30:45.693Z"
  },
  "environment": {
    "node": "v16.15.0",
    "platform": "darwin",
    "mocha": "10.2.0"
  },
  "rootSuiteId": "root-suite",
  // ... More detailed structure (see documentation)
}

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.

License

MIT