{"id":11115,"library":"istanbul-threshold-checker","title":"Istanbul Coverage Threshold Checker","description":"This package, `istanbul-threshold-checker`, provides a utility for validating code coverage reports generated by Istanbul against user-defined thresholds. It allows developers to enforce minimum coverage percentages or maximum allowed uncovered entities for statements, branches, lines, and functions. Thresholds can be configured globally for the entire project or on a per-file basis, offering granular control over coverage requirements. Last published in November 2016 at version 0.2.1, this module is considered abandoned. Its core functionality for checking coverage thresholds has since been integrated directly into the `istanbul` project's command-line interface, `nyc`, as well as into popular testing frameworks like Jest. Modern projects are advised to use `nyc`'s native threshold checking capabilities or those provided by their testing framework rather than relying on this standalone, unmaintained package. It strictly uses CommonJS `require` syntax and depends on an older version of `istanbul`, which may lead to compatibility issues with contemporary coverage formats.","status":"abandoned","version":"0.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/peterjwest/istanbul-threshold-checker","tags":["javascript"],"install":[{"cmd":"npm install istanbul-threshold-checker","lang":"bash","label":"npm"},{"cmd":"yarn add istanbul-threshold-checker","lang":"bash","label":"yarn"},{"cmd":"pnpm add istanbul-threshold-checker","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to generate coverage objects for the checker.","package":"istanbul","optional":false}],"imports":[{"note":"This package uses CommonJS `require` syntax exclusively. ESM `import` is not supported.","wrong":"import checker from 'istanbul-threshold-checker';","symbol":"checker","correct":"const checker = require('istanbul-threshold-checker');"},{"note":"Relies on the CommonJS `istanbul` package (older version) for coverage report collection.","wrong":"import { Collector } from 'istanbul';","symbol":"Collector","correct":"const istanbul = require('istanbul');\nconst Collector = istanbul.Collector;"}],"quickstart":{"code":"/* package.json (excerpt) */\n// {\n//   \"dependencies\": {\n//     \"istanbul\": \"^0.4.0\", // Use a compatible istanbul version\n//     \"istanbul-threshold-checker\": \"^0.2.0\"\n//   }\n// }\n\nconst istanbul = require('istanbul');\nconst checker = require('istanbul-threshold-checker');\n\n// Mock a coverage JSON object (replace with actual report)\nconst coverageJsonObject = {\n  '/path/to/my-file.js': {\n    path: '/path/to/my-file.js',\n    s: { '1': 1, '2': 1, '3': 0 }, // Statements\n    b: { '1': [1, 0] },         // Branches\n    f: { '1': 1 },             // Functions\n    l: { '1': 1, '2': 1, '3': 0 }  // Lines\n  }\n};\n\nconst collector = new istanbul.Collector();\ncollector.add(coverageJsonObject);\nconst coverage = collector.getFinalCoverage();\n\nconst thresholds = {\n  global: {\n    statements: 50,\n    branches: 50,\n    lines: 50,\n    functions: 50\n  },\n  each: {\n    statements: 0, // 0% means any file with less than 0% statements coverage fails (always passes if some coverage exists)\n    branches: -5,  // No more than 5 uncovered branches per file\n    lines: 70,\n    functions: 100\n  }\n};\n\nconst results = checker.checkFailures(thresholds, coverage);\n\nif (results.some(r => r.global?.failed || r.each?.failed)) {\n  console.error('Coverage thresholds failed:');\n  console.error(JSON.stringify(results, null, 2));\n  // process.exit(1);\n} else {\n  console.log('Coverage thresholds passed!');\n  console.log(JSON.stringify(results, null, 2));\n}\n\n/* Example of 'results' output:\n[\n  {\n    \"type\": \"statements\",\n    \"global\": {\n      \"failed\": false,\n      \"value\": 66.66666666666667\n    },\n    \"each\": {\n      \"failed\": true,\n      \"failures\": [\n        \"/path/to/my-file.js\"\n      ]\n    }\n  },\n  {\n    \"type\": \"branches\",\n    \"global\": {\n      \"failed\": true,\n      \"value\": 50\n    },\n    \"each\": {\n      \"failed\": false\n    }\n  },\n  {\n    \"type\": \"functions\",\n    \"global\": {\n      \"failed\": false,\n      \"value\": 100\n    },\n    \"each\": {\n      \"failed\": false\n    }\n  },\n  {\n    \"type\": \"lines\",\n    \"global\": {\n      \"failed\": false,\n      \"value\": 66.66666666666667\n    },\n    \"each\": {\n      \"failed\": true,\n      \"failures\": [\n        \"/path/to/my-file.js\"\n      ]\n    }\n  }\n]\n*/\n","lang":"javascript","description":"Demonstrates how to manually collect a coverage report using `istanbul` and then use `istanbul-threshold-checker` to validate it against defined global and per-file thresholds."},"warnings":[{"fix":"Migrate to `nyc` for coverage reporting and threshold checks. See `nyc` documentation for `check-coverage` command and configuration options.","message":"This package, last updated in 2016, is considered abandoned and its functionality has largely been absorbed into the main `istanbul` project's command-line interface, `nyc`. It is highly recommended to use `nyc`'s built-in threshold checking instead.","severity":"deprecated","affected_versions":">=0.2.1"},{"fix":"If direct integration with `istanbul-threshold-checker` is unavoidable, ensure your `istanbul` dependency is pinned to a version compatible with this package (e.g., `^0.4.0`). Otherwise, migrate to `nyc`'s native threshold features.","message":"The package relies on an older version of `istanbul`. Using it with modern versions of `istanbul` (via `nyc`) or coverage reports generated by other tools (like Jest) might lead to compatibility issues or incorrect results due to changes in coverage report formats.","severity":"gotcha","affected_versions":">=0.2.1"},{"fix":"Always use `const checker = require('istanbul-threshold-checker');` when importing this module in a CommonJS environment.","message":"This package is strictly CommonJS and does not support ES Modules (`import`/`export`). Attempting to import it using ESM syntax will result in errors.","severity":"gotcha","affected_versions":">=0.2.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure both `istanbul` (e.g., `npm install istanbul@^0.4.0`) and `istanbul-threshold-checker` (`npm install istanbul-threshold-checker`) are installed. Verify that `require('istanbul')` and `require('istanbul-threshold-checker')` are used, and that the `Collector` and `checkFailures` methods exist on the respective objects for the installed versions.","cause":"The `istanbul` or `istanbul-threshold-checker` packages are not installed or are not imported correctly, or their versions are incompatible.","error":"TypeError: Cannot read properties of undefined (reading 'Collector') or checker.checkFailures is not a function"},{"fix":"Consult the `istanbul` documentation for the correct coverage object structure for versions around `0.4.x`. If using a newer coverage report, consider migrating to `nyc` which handles modern report formats and threshold checking natively.","cause":"The coverage JSON object provided to `istanbul.Collector.add()` or `checker.checkFailures()` is not in the expected format for the `istanbul` version this package depends on.","error":"Error: Invalid coverage object"}],"ecosystem":"npm"}