Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

abuser

2.0.2 • Public • Published

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

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

override: Override module exports value with any given thing (other than undefined)

const {override} = require('abuser')(__filename);
 
override('modulename', () => 'return value');

reset: Reset module cache to intended values, recursively

const {reset} = require('abuser')(__filename);
 
const myThing = reset('.');

clean: Clean module and its dependencies from memory

const {clean} = require('abuser')(__filename);
 
clean('.');
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);
    });
});

Install

npm i abuser

DownloadsWeekly Downloads

11

Version

2.0.2

License

MIT

Unpacked Size

5 kB

Total Files

4

Last publish

Collaborators

  • avatar