Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
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
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();
// });
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'], '*');
});
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;
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;
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();
});
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) {
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) {
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) {
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) {