npm package: @ppwcode/mocha-ssst
Description: A Mocha reporter that hides what is written to `console` during tests, unless a test fails.
Author: Marc Trudel
Latest version: 2.0.4

# mocha-ssst

A [Mocha] reporter that hides what is written to `console` during tests, unless a test fails.

## Installation

```shell
npm install -D @ppwcode/mocha-ssst
```

In `package.json`:

```json
{
  "...": "…",
  "mocha": {
    "...": "…",
    "reporter": ["@ppwcode/mocha-ssst"]
  },
  "....": "…"
}
```

## Why

There are ample reasons to use `console.log(…)` in production code, e.g., to easily use the structured logging provided
by AWS Lambdas. And even if you don’t do that, some of your dependencies might.

Furthermore, we like to `console.log(…)` progress, results, and intermediate results in our [Mocha] test code. It gives
a warm confidence while developing, e.g., using WebStorm. The JetBrains reporter shows these logs clean and isolated.
And these logs help enormously when something goes wrong later, in CI. _This is not meant to replace automated
validation of your results._

We like the [Mocha Spec] reporter a lot. It gives us a clear view of what is happening and how the tests progress. The
other reporters, to us, are less informative.

But if you combine these 2, the output of production code and test code `console.log(…)` calls is immediate, and messes
up the report.

## What

This reporter alleviates that. It behaves like the [Mocha Spec] reporter, but `console.log(…)` outputs are buffered.

<!--suppress CheckImageSize -->
<img src="./screenshots/log-capture.png" alt="Log capture" width="600px" />

Logs are only shown when the test fails or when the DEBUG environment variable is set, and are shown below the test
title.

```shell
DEBUG=true npm run test
```

<!--suppress CheckImageSize -->
<img src="./screenshots/debug.png" alt="Debug output" width="600px" />

Test errors are presented readably, _and it doesn’t crash when test errors contain circular data structures_.

<!--suppress CheckImageSize -->
<img src="./screenshots/pretty-errors.png" alt="Pretty errors" width="600px" />

Optionally, you may also add the following at the entrypoint of your test suite (it needs to be placed before any other
Mocha-related calls):

```javascript
require('@ppwcode/mocha-ssst').hook()
```

This will add an extra line containing the file name and line number of the test upon error.

## ESM

This package is still CommonJS, because

> Custom reporters and custom interfaces can only be CommonJS files

See [Mocha, “Node.JS native ESM support”; “Current Limitations”](https://mochajs.org/#current-limitations).

## Where

The `npm` package is at
[https://www.npmjs.com/package/@ppwcode/mocha-ssst](https://www.npmjs.com/package/@ppwcode/mocha-ssst).

The code is maintained in a [Bitbucket repository].

Bug reports and other feedback should be directed at [the repository’s issue management system at Bitbucket].

## License

[MIT]

## AI Agents

This repository contains special instructions for AI agents.

- `agents.md`: This file contains repository-specific behavioral requirements, code style rules, and communication
  protocols. Any AI agent working on this project must read and follow these guidelines.
- `.junie/`: This folder contains persistent configuration and instructions for the **Junie** AI agent (developed by
  JetBrains). It ensures that Junie-specific behaviors and lessons learned are carried over between sessions.

## Fork

This started out as a fork of [Wizcorp/mocha-reporter].

[Wizcorp/mocha-reporter] is unmaintained. The last commit is d.d. 2017-12-13. That version contains an annoying [bug]
that results in false positive tests in cases where the error contains circular data structures.

After some years without a response, and since this is still our favorite reporter, this fork was created to fix the bug
ourselves. The code has changed much. It is cleaned, modernized, and now the reporter has tests with 100% coverage.

## Issues

```zsh
npm audit
```

There are currently some moderate vulnerabilities reported in dependencies. All of them can be traced back to `eslint`
(via `ajv`) and `mocha` (via `diff`/`jsdiff`).

Upgrading `eslint` to v10 would resolve the `ajv` issue, but this is currently blocked because several plugins have not
yet evolved to support v10. Similarly, `mocha` depends on a version of `diff` with a known issue.

These are monitored and will be resolved as soon as the upstream dependencies provide compatible, secure versions.

[Mocha]: https://mochajs.org/
[Mocha Spec]: https://mochajs.org/#spec
[Bitbucket repository]: https://bitbucket.org/peopleware/mocha-ssst
[the repository’s issue management system at Bitbucket]: https://bitbucket.org/peopleware/mocha-ssst/issues
[MIT]: https://opensource.org/license/mit/
[Wizcorp/mocha-reporter]: https://github.com/Wizcorp/mocha-reporter
[bug]: https://github.com/Wizcorp/mocha-reporter/issues/5