# @voxpelli/node-test-pretty-reporter

> Reporter for node:test that supports colorful diffs etc

Latest version **1.1.2** (published 2024-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @voxpelli/node-test-pretty-reporter
pnpm add @voxpelli/node-test-pretty-reporter
yarn add @voxpelli/node-test-pretty-reporter
bun add @voxpelli/node-test-pretty-reporter
```

## Health

**Score 50/100 (C)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2024-06-24 |
| First published | 2023-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18.0.0 |
| Dependencies | 3 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 19 |
| Author | Pelle Wessman |
| Keywords | node:test |

## Links

- npm: https://www.npmjs.com/package/@voxpelli/node-test-pretty-reporter
- Repository: https://github.com/voxpelli/node-test-pretty-reporter
- Homepage: http://github.com/voxpelli/node-test-pretty-reporter
- Issues: https://github.com/voxpelli/node-test-pretty-reporter/issues
- npm.io page: https://npm.io/package/@voxpelli/node-test-pretty-reporter

## Dependencies (3)

- [jest-diff](https://npm.io/package/jest-diff.md) ^29.7.0
- [clean-stack](https://npm.io/package/clean-stack.md) ^5.2.0
- [markdown-or-chalk](https://npm.io/package/markdown-or-chalk.md) ^0.2.0

## Recent versions

- 1.1.2 (latest) — 2024-06-24
- 1.1.1 — 2023-07-31
- 1.1.0 — 2023-07-26
- 1.0.3 — 2023-07-26
- 1.0.2 — 2023-07-25
- 1.0.1 — 2023-07-24
- 1.0.0 — 2023-07-24

## README

# @voxpelli/node-test-pretty-reporter

Reporter for [node:test](https://nodejs.org/api/test.html#custom-reporters) that supports colorful diffs etc

[![npm version](https://img.shields.io/npm/v/@voxpelli/node-test-pretty-reporter.svg?style=flat)](https://www.npmjs.com/package/@voxpelli/node-test-pretty-reporter)
[![npm downloads](https://img.shields.io/npm/dm/@voxpelli/node-test-pretty-reporter.svg?style=flat)](https://www.npmjs.com/package/@voxpelli/node-test-pretty-reporter)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-7fffff?style=flat&labelColor=ff80ff)](https://github.com/neostandard/neostandard)
[![Module type: ESM](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
[![Types in JS](https://img.shields.io/badge/types_in_js-yes-brightgreen)](https://github.com/voxpelli/types-in-js)
[![Follow @voxpelli@mastodon.social](https://img.shields.io/mastodon/follow/109247025527949675?domain=https%3A%2F%2Fmastodon.social&style=social)](https://mastodon.social/@voxpelli)

## Usage

```sh
npm install -D @voxpelli/node-test-pretty-reporter
```

```sh
node --test --test-reporter=@voxpelli/node-test-pretty-reporter
```

## Why another test reporter?

This one is similar to the built-in `spec` reporter but differs in some ways which I personally prefer.

### Rendering diffs from assertions

Outputs colored diffs when a test is failed with an `Error` that has `expected` and `actual` properties (respecting a `showDiff` property set to `false`).

Diff is generated by [`jest-diff`](https://www.npmjs.com/package/jest-diff) (no other part of `jest` is used in this reporter).

Assertion libraries that outputs compatible errors:
  * [`node:assert`](https://nodejs.org/api/assert.html#assert)
  * [`chai`](https://www.chaijs.com/) (**note:** `chai.should()` breaks error presentation since `18.17.0`, see: [voxpelli/node-test-pretty-reporter#6](https://github.com/voxpelli/node-test-pretty-reporter/issues/6), [nodejs/node#48918](https://github.com/nodejs/node/issues/48918), [chaijs/chai#1530](https://github.com/chaijs/chai/issues/1530))

As with other changes, this makes the reporter on par [with Mocha](https://mochajs.org/#diffs).

### Output styling

The output styling aligns more with Mocha's [`spec` reporter](https://mochajs.org/#spec):

* ~~Errors are presented at the end instead of in the list of tests~~ _(also done in built in since [nodejs/node#47164](https://github.com/nodejs/node/pull/47164))_
* Less visually intense, eg. no `▶` in front of names and only failed tests gets colored
* Durations are only reported if considered slow (using same default [as Mocha](https://mochajs.org/#test-duration): 75ms)
* No redundant mentioning of a test suite after the suite has completed – opts for a clean tree from top to bottom instead

### Outputting the full `cause` chain of an `Error`

When used with at least Node `18.17.0` or `20.2.0` this is supported (see [issue #2](https://github.com/voxpelli/node-test-pretty-reporter/issues/2)).

Since those same versions the cause chain is also printed in the built in `spec` reporter, but done through `util.inspect()` there rather than the custom output here.

### Example output

![CLI output](docs/cli-output.png)

## Similar modules

I have not tested any of these myself yet so can't say if they work well or not, but adding here for reference.

* [`MoLow/reporters`](https://github.com/MoLow/reporters) – many custom reporters for `node:test`
* [`nearform/node-test-github-reporter`](https://github.com/nearform/node-test-github-reporter) – another custom report for `node:test`, this one from [@nearform](https://github.com/nearform) and geared towards GitHub Actions

## See also

* [`node:test`](https://nodejs.org/api/test.html) – the full documentation for the `node:test` module that shipped in Node.js 18
* [`nodejs/node-core-test`](https://github.com/nodejs/node-core-test) – a userland port of `node:test` making it available in Node.js 14 and later (this reporter has not been tested with this userland port)
* [`@matteo.collina/tspl`](https://github.com/mcollina/tspl) – test planner for `node:test` and `node:assert`

---
_Source: https://npm.io/package/@voxpelli/node-test-pretty-reporter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
