How to use the sandboxed-module.require function in sandboxed-module

To help you get started, we’ve selected a few sandboxed-module examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prey / prey-node-client / tmp / old_tests / cli_spec.js View on Github external
},
      exit                  : myProcessObjExit,
      on                    : process.on
    }

    function myProcessObjExit (code) {
      myStdOutMessages.push('-- process.exit() have been called with the code: ' + code);
    }

    // The last step is overwrite `common` function `present()`
    var myCommon = require(join('..','lib','agent','common'));
    myCommon.config.present = function () { return false; }
    myCommon.logger = myLogger;

    // Create the cli object with dependency injections
    var cli = sandbox.require(modifiedCLIFile, {
      requires              : {
        '/package'          : require(join('..','package.json')),
        'commander'         : require('commander'),
        '../utils/pidfile'  : require('../lib/utils/pidfile'),
        './'                : {
          run               : function fakeRun () { console.log('Fake run!'); },
          shutdown          : function fakeShutDown () { console.log('Fake shutdown!'); }
        },
        './common'          : myCommon
      },
      globals               : {
        process             : myProcessObj
      }
    });

    // The test itself
github ethereum / web3.js / test / ipcprovider.js View on Github external
var chai = require('chai');
var assert = chai.assert;
var SandboxedModule = require('sandboxed-module');

var FakeIpcRequest = require('./helpers/FakeIpcRequest')
var net = new FakeIpcRequest();

SandboxedModule.registerBuiltInSourceTransformer('istanbul');
var IpcProvider = SandboxedModule.require('../packages/web3-providers-ipc', {
    requires: {
        'bn.js': require('bn.js'),
    },
    singleOnly: true
});

describe('web3-providers-ipc', function () {

    // oboe.js DOESNT WORK with FakeIpcProvider
    // describe('send', function () {
    //     it('should send basic async request', function (done) {
    //         var provider = new IpcProvider('', net);
    //         provider.send({id: 1, method: 'eth_test'}, function (err, result) {
    //             assert.isObject(result);
    //             done();
    //         });
github ethereum / web3.js / test / httpprovider.js View on Github external
var chai = require('chai');
var assert = chai.assert;
var SandboxedModule = require('sandboxed-module');

SandboxedModule.registerBuiltInSourceTransformer('istanbul');
var HttpProvider = SandboxedModule.require('../packages/web3-providers-http', {
    requires: {
        'xhr2-cookies': require('./helpers/FakeXHR2'),
        // 'xmlhttprequest': require('./helpers/FakeXMLHttpRequest')
    },
    singleOnly: true
});

describe('web3-providers-http', function () {
    describe('prepareRequest', function () {
        it('should set request header', function () {
            var provider = new HttpProvider('http://localhost:8545', {headers: [{name: 'Access-Control-Allow-Origin',  value: '*'}]});
            var result = provider._prepareRequest();

            assert.equal(typeof result, 'object');
            assert.equal(result.headers['Access-Control-Allow-Origin'], '*');
        });
github serialport / node-serialport / test / mocks / darwin-hardware.js View on Github external
throw new Error('Length extends beyond buffer');
  }

  // node v0.8 doesn't like a slice that is bigger then available data
  length = port.data.length < length ? port.data.length : length;
  var read = port.data.slice(0, length);
  port.data = port.data.slice(length);
  read.copy(buffer, offset);
  callLater(cb, null, read.length, buffer);
};

var hardware = new Hardware();

var SandboxedModule = require('sandboxed-module');

var SerialPort = SandboxedModule.require('../../', {
  requires: {
    fs: {
      read: hardware.fakeRead.bind(hardware)
    },
    './bindings': hardware.mockBinding
  },
  singleOnly: true,
  globals: {
    process: {
      platform: 'darwin',
      nextTick: process.nextTick
    }
  }
});

SerialPort.hardware = hardware;
github weiway / node-serialport-worker / test_mocks / linux-hardware.js View on Github external
throw new Error("Length extends beyond buffer");
  }

  // node v0.8 doesn't like a slice that is bigger then available data
  length = port.data.length < length ? port.data.length : length;
  var read = port.data.slice(0, length);
  port.data = port.data.slice(length);
  read.copy(buffer, offset);
  cb(null, read.length, buffer);
};

var hardware = new Hardware();

var SandboxedModule = require('sandboxed-module');

var serialPort = SandboxedModule.require('../serialport.js', {
  requires: {
    fs: {
      read: hardware.fakeRead.bind(hardware)
    }
  },
  globals: {
    process: {
      platform: 'darwin',
      nextTick: process.nextTick
    }
  }
});

serialPort.hardware = hardware;
serialPort.SerialPortBinding = hardware.mockBinding;
github log4js-node / log4js-api / test / index.js View on Github external
batch.test('when log4js is available', (t) => {
    const log4js = sandbox.require('../lib', {
      requires: {
        log4js: {
          getLogger: () => 'cheese'
        }
      },
      singleOnly: true
    });
    const logger = log4js.getLogger();

    t.equal(logger, 'cheese');
    t.end();
  });
github nomiddlename / flipper / test / persistence.js View on Github external
topic: function() {
                var fs = mockFS(), flipper = sandbox.require('../lib/flipper', { requires: { fs: fs }, globals: { console: mockConsole } });
                flipper.persist('path/to/cheese.json');
                flipper.add("cheeseballs");
                flipper.enable("cheeseballs");
                return fs;
            },
            'should write the updated feature to the file': function(fs) {
github nomiddlename / flipper / test / persistence.js View on Github external
topic: function() {
                var fs = mockFS({ cheeseballs: false }), flipper = sandbox.require('../lib/flipper', { requires: { fs: fs }, globals: { console: mockConsole } });
                flipper.persist('path/to/cheese.json');
                flipper.enable('cheeseballs');
                fs.watchCallback({ mtime: 5 }, { mtime: 1 });
                return flipper;
            },
            'should reload the features': function(flipper) {
github nomiddlename / flipper / test / persistence.js View on Github external
topic: function() {
                var fs = mockFS(), flipper = sandbox.require('../lib/flipper', { requires: { fs: fs }, globals: { console: mockConsole } });
                flipper.persist('path/to/cheese.json');
                flipper.add("cheeseballs");
                flipper.enable("cheeseballs");
                flipper.disable("cheeseballs");
                return fs;
            },
            'should write the updated feature to the file': function(fs) {
github nomiddlename / flipper / test / persistence.js View on Github external
topic: function() {
            var fs = mockFS({ cheeseballs: true }), flipper = sandbox.require('../lib/flipper', { requires: { fs: fs }, globals: { console: mockConsole } });
            flipper.add("baconballs");
            flipper.add("cheeseballs");
            flipper.persist('path/to/cheese.json');
            return flipper;
        },
        'should override existing feature status from file': function(flipper) {

sandboxed-module

A sandboxed Node.js module loader that lets you inject dependencies into your modules.

MIT
Latest version published 5 years ago

Package Health Score

54 / 100
Full package analysis

Popular sandboxed-module functions