Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Created March 17, 2017 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloaj/b13823064cd215ecc5f2b8835df581cf to your computer and use it in GitHub Desktop.
Save juanpabloaj/b13823064cd215ecc5f2b8835df581cf to your computer and use it in GitHub Desktop.
var assert = require('assert');
var fs = require('fs');
var util = require('util');
var vm = require('vm');
var sinon = require('sinon');
var source = fs.readFileSync('./to_call.js').toString();
var script = new vm.Script(source);
var sandbox = {};
var context = new vm.createContext(sandbox);
script.runInContext(context);
var stubfakeFunction = sinon.stub(context, 'fakeFunction');
//console.log(util.inspect(sandbox, false, null));
it('hello from vm', function() {
assert.equal(sandbox.hello() , 'hello world');
});
var fakeFunction = function () {
throw 'fakeFunction was called';
};
var hello = function() {
fakeFunction();
return 'hello world';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment