Skip to content

Commit

Permalink
fix: alter test to verify module context
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed May 10, 2023
1 parent fb71483 commit cbd42bc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions test/nodevm.js
Expand Up @@ -233,16 +233,25 @@ describe('modules', () => {
require: {
external: {
modules: ['mocha', 'module1'],
transitive: true,
},
context(module) {
if (module === 'mocha') return 'host';
if (module === 'module1') return 'sandbox';
if (module.includes('mocha')) return 'host';
return 'sandbox';
}
}
});

assert.ok(vm.run("require('module1')", __filename));
assert.ok(vm.run("require('mocha')", __filename));
function isVMProxy(obj) {
const key = {};
const proto = Object.getPrototypeOf(obj);
if (!proto) return undefined;
proto.isVMProxy = key;
const proxy = obj.isVMProxy !== key;
delete proto.isVMProxy;
return proxy;
}
assert.equal(isVMProxy(vm.run("module.exports = require('mocha')", __filename)), false, 'Mocha is a proxy');
assert.equal(isVMProxy(vm.run("module.exports = require('module1')", __filename)), true, 'Module1 is not a proxy');
});

it('can resolve paths based on a custom resolver', () => {
Expand Down

0 comments on commit cbd42bc

Please sign in to comment.