# jhnns/rewire

Easy monkey-patching for node.js unit tests

Repository: https://github.com/jhnns/rewire
Canonical: https://ross.abutalabs.com/products/rewire
Language: JavaScript
License: MIT
License Family: permissive
Topics: mock, testing, unit-testing, monkey-patching
Last push: 2025-12-11T21:43:31+00:00

## Health v2 (maintenance only)
Score: 56/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 56, release rhythm 31, longevity 100
- inputs: {"age_days": 5204, "days_push": 265, "days_rel": 383, "gap_med": 36.0, "n_releases_24m": 3}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 3093, forks 128 (observed 2026-08-28T04:07:42.430479+00:00)

## What it is
rewire is a Node.js library that adds special setter and getter methods to CommonJS modules so tests can inject mocks, override private variables, and patch globals. It acts like require() but exposes __set__, __get__, and __with__ for modifying module internals during unit tests.

## Use cases
- inject mocks for required modules like fs in unit tests
- inspect and override private variables of a module
- mock globals like process or console within a single module
- revert monkey-patched changes after a test runs
- test node.js modules with hard-to-mock dependencies

## When to choose
- you test CommonJS Node.js modules and need to stub their internal dependencies
- you want to access or override module-private variables in tests
- you need scoped global mocking that doesn't leak to other modules

## When to avoid
- your project uses ES modules, which rewire does not support
- you prefer dependency injection via constructor parameters or a DI framework
- you want modern alternatives like proxyquire or esm mocking

## Facets
- artifact type: library
- maturity: active
- function: mocking, testing
- domain: testing, developer-tools, backend
- platform: -
- tags: monkey-patching, dependency-injection, unit-testing, commonjs, nodejs, javascript

## Member repositories
- jhnns/rewire (main) score 56

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:07:42.430479+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T07:27:19.162116+00:00, confidence not recorded.
  - readme: https://github.com/jhnns/rewire (fetched 2026-08-28T04:07:42.430479+00:00, sha 7690f364a408)
  - registry_npm: https://registry.npmjs.org/rewire (fetched 2026-08-29T09:42:46.436705+00:00, sha bf9c7b9aadeb)
- Data as of 2026-08-30T08:39:29.467469+00:00.
