# abuser

> 🤕 Create modifiers to require cache based on path (e.g. `__dirname`)

Latest version **2.0.3** (published 2020-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install abuser
pnpm add abuser
yarn add abuser
bun add abuser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2020-07-07 |
| First published | 2019-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.12.0 |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | omrilotan |
| Maintainers | omrilotan |
| Keywords | require, clean, cleanup, override, mock, reset, test, 🤕 |

## Links

- npm: https://www.npmjs.com/package/abuser
- Repository: https://github.com/omrilotan/abuser
- Homepage: https://omrilotan.com/abuser/
- Issues: https://github.com/omrilotan/abuser/issues
- npm.io page: https://npm.io/package/abuser

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2020-07-07
- 2.0.2 — 2019-07-21
- 2.0.1 — 2019-05-13
- 2.0.0 — 2019-04-30
- 1.0.0 — 2019-04-23
- 0.0.0 — 2019-04-23

## README

# abuser [![](https://img.shields.io/npm/v/abuser.svg)](https://www.npmjs.com/package/abuser) [![](https://img.shields.io/badge/source--000000.svg?logo=github&style=social)](https://github.com/omrilotan/abuser)

## 🤕 Create modifiers to require cache based on file path (e.g. `__filename`)

> Supported from node 10.12.0

The `abuser` function accepts routes from which to resolve the modules as arguments
```js
const abuser = require('abuser');
const {clean, override, reset} = abuser(__filename);
```

### `override`: Override module exports value with any given thing (other than `undefined`)
```js
const {override} = require('abuser')(__filename);

override('modulename', () => 'return value');
```

### `reset`: Reset module cache to intended values, recursively
```js
const {reset} = require('abuser')(__filename);

const myThing = reset('.');
```


### `clean`: Clean module and its dependencies from memory
```js
const {clean} = require('abuser')(__filename);

clean('.');
```

```js
const {override, clean} = require('abuser')(__filename);

describe('my suite', () => {
	const dependency = stub();
	let mine;
	before(() => {
		override('dependency', dependency);
		mine = require('.');
	});
	afterEach(() => stub.reset());
	after(() => clean('.'));

	it('Should call "dependency"', () => {
		mine();
		assert(dependency.called);
	});
});
```

---
_Source: https://npm.io/package/abuser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
