Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including fuxor with all npm packages installed. Try it out:

var fuxor = require("fuxor")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

fuxor v3.0.0

Simple dependency injection by overriding require

Build Status

Fuxor

Very simple DI for node.

const fuxor = require('fuxor');
fuxor.add('fs', {
    readFileSync: function () {
        return 'Not really a file';
    }
});
const fs = require('fs');
console.log(fs.readFileSync('not really', 'anything', { whatever:'you want'}));//'Not really a file'

API

Add

const fuxor = require('fuxor');
// Add one entry to be overridden 
fuxor.add('fs', {
  readFileSync: function () {
    return 'Not really a file';
  }
});
// Add one entry to be overridden 
fuxor.add({ name: 'fs', result: {
  readFileSync: function () {
    return 'Not really a file';
  }
}});
// Add multiple entries at once
fuxor.add([{ name: 'fs', result: {
  readFileSync: function () {
    return 'Not really a file';
  }
}, {
  name: 'request',
  result: function () {
    return 'Not really a file';
  }
}]);

Clear

const fuxor = require('fuxor');
// After items have been added
fuxor.clear(); // All entries have been removed

remove

const fuxor = require('fuxor');
// After items have been added
fuxor.remove('your-module'); // The module has been removed

reset

const fuxor = require('fuxor');
// After items have been added
fuxor.reset(); // require now works back to normal

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free