Created
March 17, 2017 02:29
-
-
Save juanpabloaj/b13823064cd215ecc5f2b8835df581cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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