Repository: rickhanlonii/jest-silent-reporter
Branch: main
Commit: a1ce53d8cc80
Files: 9
Total size: 8.9 KB
Directory structure:
gitextract_v38xw2bw/
├── .gitignore
├── .prettierrc
├── LICENSE.md
├── README.md
├── SilentReporter.js
├── StdIo.js
├── helpers.js
├── index.js
└── package.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
node_modules/
.DS_store
================================================
FILE: .prettierrc
================================================
{
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "es5"
}
================================================
FILE: LICENSE.md
================================================
MIT License
Copyright (c) 2018 Rick Hanlon II
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: README.md
================================================
<h1 align="center">
<img src="https://user-images.githubusercontent.com/2440089/188526466-f9934af0-bd67-4d03-ad84-8ff0a41761e8.png" height="150"/>
<p>Jest Silent Reporter</p>
</h1>
<p align="center">
Custom <a href="https://jestjs.io/docs/en/configuration#reporters-array-modulename-modulename-options">reporter</a>
for <a href="https://jestjs.io">Jest</a> that only prints failed tests.</p>
<p align="center">
<img src="https://user-images.githubusercontent.com/2440089/188526149-afb2600a-ddb3-49ec-83e8-dfdc2fb975d2.png" height="200"/>
</p>
## Installation
Using [npm](https://www.npmjs.com/):
```sh
$ npm i --save-dev jest-silent-reporter
```
Using [yarn](https://yarnpkg.com/):
```sh
$ yarn add --dev jest-silent-reporter
```
## Usage
Jest CLI:
```bash
jest --reporters=jest-silent-reporter
```
Jest config:
```json
{
"reporters": ["jest-silent-reporter"]
}
```
## Options
### useDots: boolean
For large test suites, `jest-silent-reporter` can cause CI to fail due to having
no output for some configured amount of time. Using the `useDots` option will
output dots for each test file, similar to a dot reporter.
```json
{
"reporters": [["jest-silent-reporter", { "useDots": true }]]
}
```
Note: this config is also available as an environment variable `JEST_SILENT_REPORTER_DOTS=true`.
### showWarnings: boolean
Warnings are supressed by default, use `showWarnings` to log them.
```json
{
"reporters": [["jest-silent-reporter", { "showWarnings": true }]]
}
```
Note: this config is also available as an environment variable `JEST_SILENT_REPORTER_SHOW_WARNINGS=true`.
### showPaths: boolean
Sometimes it might come in handy to display the test suites' paths (i.e. when
running tests in a terminal inside IDE for quicker file navigation).
```json
{
"reporters": [["jest-silent-reporter", { "showPaths": true }]]
}
```
Note: this config is also available as an environment variable `JEST_SILENT_REPORTER_SHOW_PATHS=true`.
## Screenshots
#### All tests passed

#### Tests failed

## Licence
MIT
================================================
FILE: SilentReporter.js
================================================
const jestUtils = require('jest-util');
const helpers = require('./helpers');
const StdIo = require('./StdIo');
class SilentReporter {
constructor(globalConfig, options = {}) {
this._globalConfig = globalConfig;
this.stdio = new StdIo();
this.useDots = !!process.env.JEST_SILENT_REPORTER_DOTS || !!options.useDots;
this.showPaths =
!!process.env.JEST_SILENT_REPORTER_SHOW_PATHS || !!options.showPaths;
this.showWarnings =
!!process.env.JEST_SILENT_REPORTER_SHOW_WARNINGS ||
!!options.showWarnings;
this.showSeed = !!globalConfig.showSeed
}
onRunStart() {
if (jestUtils.isInteractive) {
jestUtils.clearLine(process.stderr);
}
}
onRunComplete() {
if (this.useDots) {
this.stdio.log('\n');
}
if (this.showSeed) {
this.stdio.log(`Seed: ${this._globalConfig.seed}`)
}
this.stdio.close();
}
onTestResult(test, testResult) {
if (this.useDots) {
this.stdio.logInline('.');
}
if (!testResult.skipped) {
const didUpdate = this._globalConfig.updateSnapshot === 'all';
let hasSnapshotFailures = false;
if (testResult.snapshot) {
if (!didUpdate && testResult.snapshot.unchecked) {
hasSnapshotFailures = true;
}
if (testResult.snapshot.unmatched) {
hasSnapshotFailures = true;
}
}
const hasFailures = testResult.failureMessage || hasSnapshotFailures;
if (this.showPaths && hasFailures) {
this.stdio.log('\n' + test.path);
}
if (testResult.failureMessage)
this.stdio.log('\n' + testResult.failureMessage);
if (testResult.console && this.showWarnings) {
testResult.console
.filter(entry => ['error', 'warn'].includes(entry.type) && entry.message)
.map(entry => entry.message)
.forEach(this.stdio.log);
}
const snapshotStatuses = helpers.getSnapshotStatus(
testResult.snapshot,
didUpdate
);
snapshotStatuses.forEach(this.stdio.log);
}
}
}
module.exports = SilentReporter;
================================================
FILE: StdIo.js
================================================
class StdIo {
constructor() {
this._out = process.stdout.write.bind(process.stdout);
this._err = process.stderr.write.bind(process.stderr);
this._bufferedOutput = new Set();
this._wrapStdio(process.stdout);
this._wrapStdio(process.stderr);
}
log(message) {
process.stderr.write(message + '\n');
}
logInline(message) {
process.stderr.write(message);
}
close() {
this._forceFlushBufferedOutput();
process.stdout.write = this._out;
process.stderr.write = this._err;
}
// Don't wait for the debounced call and flush all output immediately.
_forceFlushBufferedOutput() {
for (const flushBufferedOutput of this._bufferedOutput) {
flushBufferedOutput();
}
}
_wrapStdio(stream) {
const originalWrite = stream.write;
let buffer = [];
let timeout = null;
const flushBufferedOutput = () => {
const string = buffer.join('');
buffer = [];
if (string) {
originalWrite.call(stream, string);
}
this._bufferedOutput.delete(flushBufferedOutput);
};
this._bufferedOutput.add(flushBufferedOutput);
const debouncedFlush = () => {
// If the process blows up no errors would be printed.
// There should be a smart way to buffer stderr, but for now
// we just won't buffer it.
if (stream === process.stderr) {
flushBufferedOutput();
} else {
if (!timeout) {
timeout = setTimeout(() => {
flushBufferedOutput();
timeout = null;
}, 100);
}
}
};
stream.write = chunk => {
buffer.push(chunk);
debouncedFlush();
return true;
};
}
}
module.exports = StdIo;
================================================
FILE: helpers.js
================================================
const chalk = require('chalk');
const ARROW = ' \u203A ';
const FAIL_COLOR = chalk.bold.red;
const SNAPSHOT_ADDED = chalk.bold.green;
const SNAPSHOT_REMOVED = chalk.bold.red;
const SNAPSHOT_UPDATED = chalk.bold.green;
const pluralize = (word, count) => `${count} ${word}${count === 1 ? '' : 's'}`;
const getSnapshotStatus = (snapshot, afterUpdate) => {
const statuses = [];
if (snapshot.added) {
statuses.push(
SNAPSHOT_ADDED(ARROW + pluralize('snapshot', snapshot.added)) +
' written.'
);
}
if (snapshot.updated) {
statuses.push(
SNAPSHOT_UPDATED(ARROW + pluralize('snapshot', snapshot.updated)) +
` updated.`
);
}
if (snapshot.unchecked) {
statuses.push(
FAIL_COLOR(ARROW + pluralize('obsolete snapshot', snapshot.unchecked)) +
(afterUpdate ? ' removed' : ' found') +
'.'
);
}
if (snapshot.fileDeleted) {
statuses.push(
SNAPSHOT_REMOVED(ARROW + 'Obsolete snapshot file') + ` removed.`
);
}
if (snapshot.unmatched) {
statuses.push(
FAIL_COLOR(ARROW + pluralize('snapshot test', snapshot.unmatched)) +
' failed.'
);
}
return statuses;
};
module.exports = {
getSnapshotStatus,
};
================================================
FILE: index.js
================================================
const SilentReporter = require('./SilentReporter');
module.exports = SilentReporter;
================================================
FILE: package.json
================================================
{
"name": "jest-silent-reporter",
"version": "0.6.0",
"description": "A silent reporter for Jest",
"main": "index.js",
"repository": "https://github.com/rickhanlonii/jest-silent-reporter",
"author": "rickhanlonii <rickhanlonii@gmail.com>",
"license": "MIT",
"scripts": {
"prettier": "prettier --write **/**.js **/**.md"
},
"dependencies": {
"chalk": "^4.0.0",
"jest-util": "^26.0.0"
},
"devDependencies": {
"prettier": "^1.10.2"
}
}
gitextract_v38xw2bw/ ├── .gitignore ├── .prettierrc ├── LICENSE.md ├── README.md ├── SilentReporter.js ├── StdIo.js ├── helpers.js ├── index.js └── package.json
SYMBOL INDEX (17 symbols across 3 files)
FILE: SilentReporter.js
class SilentReporter (line 5) | class SilentReporter {
method constructor (line 6) | constructor(globalConfig, options = {}) {
method onRunStart (line 18) | onRunStart() {
method onRunComplete (line 24) | onRunComplete() {
method onTestResult (line 34) | onTestResult(test, testResult) {
FILE: StdIo.js
class StdIo (line 1) | class StdIo {
method constructor (line 2) | constructor() {
method log (line 10) | log(message) {
method logInline (line 14) | logInline(message) {
method close (line 18) | close() {
method _forceFlushBufferedOutput (line 25) | _forceFlushBufferedOutput() {
method _wrapStdio (line 31) | _wrapStdio(stream) {
FILE: helpers.js
constant ARROW (line 3) | const ARROW = ' \u203A ';
constant FAIL_COLOR (line 4) | const FAIL_COLOR = chalk.bold.red;
constant SNAPSHOT_ADDED (line 5) | const SNAPSHOT_ADDED = chalk.bold.green;
constant SNAPSHOT_REMOVED (line 6) | const SNAPSHOT_REMOVED = chalk.bold.red;
constant SNAPSHOT_UPDATED (line 7) | const SNAPSHOT_UPDATED = chalk.bold.green;
Condensed preview — 9 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
{
"path": ".gitignore",
"chars": 24,
"preview": "node_modules/\n.DS_store\n"
},
{
"path": ".prettierrc",
"chars": 77,
"preview": "{\n \"proseWrap\": \"always\",\n \"singleQuote\": true,\n \"trailingComma\": \"es5\"\n}\n"
},
{
"path": "LICENSE.md",
"chars": 1071,
"preview": "MIT License\n\nCopyright (c) 2018 Rick Hanlon II\n\nPermission is hereby granted, free of charge, to any person obtaining a "
},
{
"path": "README.md",
"chars": 2312,
"preview": "<h1 align=\"center\">\n <img src=\"https://user-images.githubusercontent.com/2440089/188526466-f9934af0-bd67-4d03-ad84-8ff0"
},
{
"path": "SilentReporter.js",
"chars": 2089,
"preview": "const jestUtils = require('jest-util');\nconst helpers = require('./helpers');\nconst StdIo = require('./StdIo');\n\nclass S"
},
{
"path": "StdIo.js",
"chars": 1719,
"preview": "class StdIo {\n constructor() {\n this._out = process.stdout.write.bind(process.stdout);\n this._err = process.stder"
},
{
"path": "helpers.js",
"chars": 1224,
"preview": "const chalk = require('chalk');\n\nconst ARROW = ' \\u203A ';\nconst FAIL_COLOR = chalk.bold.red;\nconst SNAPSHOT_ADDED = cha"
},
{
"path": "index.js",
"chars": 86,
"preview": "const SilentReporter = require('./SilentReporter');\n\nmodule.exports = SilentReporter;\n"
},
{
"path": "package.json",
"chars": 475,
"preview": "{\n \"name\": \"jest-silent-reporter\",\n \"version\": \"0.6.0\",\n \"description\": \"A silent reporter for Jest\",\n \"main\": \"inde"
}
]
About this extraction
This page contains the full source code of the rickhanlonii/jest-silent-reporter GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 9 files (8.9 KB), approximately 2.5k tokens, and a symbol index with 17 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.