Name: js-handler/node_modules/nodeunit/test/test-sandbox.js
| 1: | var nodeunit = require('../lib/nodeunit'); |
| 2: | var sandbox = require('../lib/utils').sandbox; |
| 3: | var testCase = nodeunit.testCase; |
| 4: | |
| 5: | exports.testSimpleSandbox = function (test) { |
| 6: | var raw_jscode1 = sandbox(__dirname + '/fixtures/raw_jscode1.js'); |
| 7: | test.equal(raw_jscode1.hello_world('foo'), '_foo_', 'evaluation ok'); |
| 8: | test.done(); |
| 9: | }; |
| 10: | |
| 11: | exports.testSandboxContext = function (test) { |
| 12: | var a_variable = 42; // should not be visible in the sandbox |
| 13: | var raw_jscode2 = sandbox(__dirname + '/fixtures/raw_jscode2.js'); |
| 14: | a_variable = 42; // again for the win |
| 15: | test.equal( |
| 16: | raw_jscode2.get_a_variable(), |
| 17: | 'undefined', |
| 18: | 'the variable should not be defined' |
| 19: | ); |
| 20: | test.done(); |
| 21: | }; |
| 22: | |
| 23: | exports.testSandboxMultiple = function (test) { |
| 24: | var raw_jscode3 = sandbox([ |
| 25: | __dirname + '/fixtures/raw_jscode3.js', |
| 26: | __dirname + '/fixtures/raw_jscode3.js', |
| 27: | __dirname + '/fixtures/raw_jscode3.js' |
| 28: | ]); |
| 29: | test.equal(raw_jscode3.t, 3, 'two files loaded'); |
| 30: | test.done(); |
| 31: | }; |
