[
  {
    "path": ".gitignore",
    "content": "node_modules/\n.DS_store\n"
  },
  {
    "path": ".prettierrc",
    "content": "{\n  \"proseWrap\": \"always\",\n  \"singleQuote\": true,\n  \"trailingComma\": \"es5\"\n}\n"
  },
  {
    "path": "LICENSE.md",
    "content": "MIT License\n\nCopyright (c) 2018 Rick Hanlon II\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<h1 align=\"center\">\n  <img src=\"https://user-images.githubusercontent.com/2440089/188526466-f9934af0-bd67-4d03-ad84-8ff0a41761e8.png\" height=\"150\"/>\n  <p>Jest Silent Reporter</p>\n</h1>\n<p align=\"center\">\n  Custom <a href=\"https://jestjs.io/docs/en/configuration#reporters-array-modulename-modulename-options\">reporter</a>\n  for <a href=\"https://jestjs.io\">Jest</a> that only prints failed tests.</p>\n<p align=\"center\">\n  <img src=\"https://user-images.githubusercontent.com/2440089/188526149-afb2600a-ddb3-49ec-83e8-dfdc2fb975d2.png\" height=\"200\"/>\n</p>\n\n## Installation\n\nUsing [npm](https://www.npmjs.com/):\n\n```sh\n$ npm i --save-dev jest-silent-reporter\n```\n\nUsing [yarn](https://yarnpkg.com/):\n\n```sh\n$ yarn add --dev jest-silent-reporter\n```\n\n## Usage\n\nJest CLI:\n\n```bash\njest --reporters=jest-silent-reporter\n```\n\nJest config:\n\n```json\n{\n  \"reporters\": [\"jest-silent-reporter\"]\n}\n```\n\n## Options\n\n### useDots: boolean\n\nFor large test suites, `jest-silent-reporter` can cause CI to fail due to having\nno output for some configured amount of time. Using the `useDots` option will\noutput dots for each test file, similar to a dot reporter.\n\n```json\n{\n  \"reporters\": [[\"jest-silent-reporter\", { \"useDots\": true }]]\n}\n```\n\nNote: this config is also available as an environment variable `JEST_SILENT_REPORTER_DOTS=true`.\n\n### showWarnings: boolean\n\nWarnings are supressed by default, use `showWarnings` to log them.\n\n```json\n{\n  \"reporters\": [[\"jest-silent-reporter\", { \"showWarnings\": true }]]\n}\n```\n\nNote: this config is also available as an environment variable `JEST_SILENT_REPORTER_SHOW_WARNINGS=true`.\n\n\n### showPaths: boolean\n\nSometimes it might come in handy to display the test suites' paths (i.e. when\nrunning tests in a terminal inside IDE for quicker file navigation).\n\n```json\n{\n  \"reporters\": [[\"jest-silent-reporter\", { \"showPaths\": true }]]\n}\n```\n\nNote: this config is also available as  an environment variable `JEST_SILENT_REPORTER_SHOW_PATHS=true`.\n\n## Screenshots\n\n#### All tests passed\n\n![Screenshot: all tests passed](https://user-images.githubusercontent.com/2440089/188526258-3d352067-d0c4-4999-9e22-5613981c8887.png)\n\n#### Tests failed\n\n![Screenshot: some tests failed](https://user-images.githubusercontent.com/2440089/188526185-4b3e217c-0228-4e3d-930a-5e508e4770b3.png)\n\n## Licence\n\nMIT\n"
  },
  {
    "path": "SilentReporter.js",
    "content": "const jestUtils = require('jest-util');\nconst helpers = require('./helpers');\nconst StdIo = require('./StdIo');\n\nclass SilentReporter {\n  constructor(globalConfig, options = {}) {\n    this._globalConfig = globalConfig;\n    this.stdio = new StdIo();\n    this.useDots = !!process.env.JEST_SILENT_REPORTER_DOTS || !!options.useDots;\n    this.showPaths =\n      !!process.env.JEST_SILENT_REPORTER_SHOW_PATHS || !!options.showPaths;\n    this.showWarnings =\n      !!process.env.JEST_SILENT_REPORTER_SHOW_WARNINGS ||\n      !!options.showWarnings;\n    this.showSeed = !!globalConfig.showSeed\n  }\n\n  onRunStart() {\n    if (jestUtils.isInteractive) {\n      jestUtils.clearLine(process.stderr);\n    }\n  }\n\n  onRunComplete() {\n    if (this.useDots) {\n      this.stdio.log('\\n');\n    }\n    if (this.showSeed) {\n      this.stdio.log(`Seed: ${this._globalConfig.seed}`)\n    }\n    this.stdio.close();\n  }\n\n  onTestResult(test, testResult) {\n    if (this.useDots) {\n      this.stdio.logInline('.');\n    }\n\n    if (!testResult.skipped) {\n      const didUpdate = this._globalConfig.updateSnapshot === 'all';\n      let hasSnapshotFailures = false;\n      if (testResult.snapshot) {\n        if (!didUpdate && testResult.snapshot.unchecked) {\n          hasSnapshotFailures = true;\n        }\n        if (testResult.snapshot.unmatched) {\n          hasSnapshotFailures = true;\n        }\n      }\n\n      const hasFailures = testResult.failureMessage || hasSnapshotFailures;\n\n      if (this.showPaths && hasFailures) {\n        this.stdio.log('\\n' + test.path);\n      }\n      if (testResult.failureMessage)\n        this.stdio.log('\\n' + testResult.failureMessage);\n      if (testResult.console && this.showWarnings) {\n        testResult.console\n          .filter(entry => ['error', 'warn'].includes(entry.type) && entry.message)\n          .map(entry => entry.message)\n          .forEach(this.stdio.log);\n      }\n      const snapshotStatuses = helpers.getSnapshotStatus(\n        testResult.snapshot,\n        didUpdate\n      );\n      snapshotStatuses.forEach(this.stdio.log);\n    }\n  }\n}\n\nmodule.exports = SilentReporter;\n"
  },
  {
    "path": "StdIo.js",
    "content": "class StdIo {\n  constructor() {\n    this._out = process.stdout.write.bind(process.stdout);\n    this._err = process.stderr.write.bind(process.stderr);\n    this._bufferedOutput = new Set();\n    this._wrapStdio(process.stdout);\n    this._wrapStdio(process.stderr);\n  }\n\n  log(message) {\n    process.stderr.write(message + '\\n');\n  }\n\n  logInline(message) {\n    process.stderr.write(message);\n  }\n\n  close() {\n    this._forceFlushBufferedOutput();\n    process.stdout.write = this._out;\n    process.stderr.write = this._err;\n  }\n\n  // Don't wait for the debounced call and flush all output immediately.\n  _forceFlushBufferedOutput() {\n    for (const flushBufferedOutput of this._bufferedOutput) {\n      flushBufferedOutput();\n    }\n  }\n\n  _wrapStdio(stream) {\n    const originalWrite = stream.write;\n\n    let buffer = [];\n    let timeout = null;\n\n    const flushBufferedOutput = () => {\n      const string = buffer.join('');\n      buffer = [];\n\n      if (string) {\n        originalWrite.call(stream, string);\n      }\n\n      this._bufferedOutput.delete(flushBufferedOutput);\n    };\n\n    this._bufferedOutput.add(flushBufferedOutput);\n\n    const debouncedFlush = () => {\n      // If the process blows up no errors would be printed.\n      // There should be a smart way to buffer stderr, but for now\n      // we just won't buffer it.\n      if (stream === process.stderr) {\n        flushBufferedOutput();\n      } else {\n        if (!timeout) {\n          timeout = setTimeout(() => {\n            flushBufferedOutput();\n            timeout = null;\n          }, 100);\n        }\n      }\n    };\n\n    stream.write = chunk => {\n      buffer.push(chunk);\n      debouncedFlush();\n      return true;\n    };\n  }\n}\n\nmodule.exports = StdIo;\n"
  },
  {
    "path": "helpers.js",
    "content": "const chalk = require('chalk');\n\nconst ARROW = ' \\u203A ';\nconst FAIL_COLOR = chalk.bold.red;\nconst SNAPSHOT_ADDED = chalk.bold.green;\nconst SNAPSHOT_REMOVED = chalk.bold.red;\nconst SNAPSHOT_UPDATED = chalk.bold.green;\n\nconst pluralize = (word, count) => `${count} ${word}${count === 1 ? '' : 's'}`;\n\nconst getSnapshotStatus = (snapshot, afterUpdate) => {\n  const statuses = [];\n\n  if (snapshot.added) {\n    statuses.push(\n      SNAPSHOT_ADDED(ARROW + pluralize('snapshot', snapshot.added)) +\n        ' written.'\n    );\n  }\n\n  if (snapshot.updated) {\n    statuses.push(\n      SNAPSHOT_UPDATED(ARROW + pluralize('snapshot', snapshot.updated)) +\n        ` updated.`\n    );\n  }\n\n  if (snapshot.unchecked) {\n    statuses.push(\n      FAIL_COLOR(ARROW + pluralize('obsolete snapshot', snapshot.unchecked)) +\n        (afterUpdate ? ' removed' : ' found') +\n        '.'\n    );\n  }\n\n  if (snapshot.fileDeleted) {\n    statuses.push(\n      SNAPSHOT_REMOVED(ARROW + 'Obsolete snapshot file') + ` removed.`\n    );\n  }\n\n  if (snapshot.unmatched) {\n    statuses.push(\n      FAIL_COLOR(ARROW + pluralize('snapshot test', snapshot.unmatched)) +\n        ' failed.'\n    );\n  }\n  return statuses;\n};\n\nmodule.exports = {\n  getSnapshotStatus,\n};\n"
  },
  {
    "path": "index.js",
    "content": "const SilentReporter = require('./SilentReporter');\n\nmodule.exports = SilentReporter;\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"jest-silent-reporter\",\n  \"version\": \"0.6.0\",\n  \"description\": \"A silent reporter for Jest\",\n  \"main\": \"index.js\",\n  \"repository\": \"https://github.com/rickhanlonii/jest-silent-reporter\",\n  \"author\": \"rickhanlonii <rickhanlonii@gmail.com>\",\n  \"license\": \"MIT\",\n  \"scripts\": {\n    \"prettier\": \"prettier --write **/**.js **/**.md\"\n  },\n  \"dependencies\": {\n    \"chalk\": \"^4.0.0\",\n    \"jest-util\": \"^26.0.0\"\n  },\n  \"devDependencies\": {\n    \"prettier\": \"^1.10.2\"\n  }\n}\n"
  }
]