Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Wrapper to require() js files in a custom context

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
Octocat-spinner-32 readme.md
readme.md

RequireInContext

Allows you to do a require() with a custom context.

Installing:

npm install requireincontext

Using:

Useful for emulating a browser environment in Node:

var requireInContext = require('requireincontext');
var myclient = requireInContext('./myclient.js', {
  window: {},
  io: require('socket.io')
});

Or for specifying mock objects for running tests:

var requireInContext = require('requireincontext');
var mycode = requireInContext('./mycode.js', {
  mydependency: require('./dependency_mock.js')
});
Something went wrong with that request. Please try again.