felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
MIT License
342 stars 42 forks source link

Having trouble with new version #36

Open tandrewnichols opened 10 years ago

tandrewnichols commented 10 years ago

I've always used 0.3.0 in the past, so maybe there's just some upgrade thing I'm missing, but using 1.0.1, some (at least) of my stubs are not working. I'm using this wrapper:

SandboxedModule = require('sandboxed-module')

global.requireSubject = (path, requires, globals) ->
  console.log requires
  SandboxedModule.require("./../../#{path}",  {requires, globals})

This is in spec/helpers, so the path part isn't the problem (it does try to load the module), but then it throws [Error: Cannot find module 'ftoggleDir/.ftoggle.config'] code: 'MODULE_NOT_FOUND', but the console.log in the code above is logging (amongst other things):

'ftoggleDir/.ftoggle.config': 
   { environments: [ 'production' ],
     configDir: 'config',
     production: { path: 'ftoggle.json' } }

This is a json file, and I see that some of the recent improvements are around json files. I have tried it also with .json on the end. Is there something else I need to do to get 1.0.1 working?

domenic commented 10 years ago

Can you produce an example project, preferably of minimal size, that I can use to reproduce this? I can't really debug it just from your description.

darthmarcos commented 10 years ago

I too had tests written using 0.3.0 of sandboxed-module but am unable to get them to run successfully using 1.0.1

Are there any changes to how I am supposed to use this sandboxed-module library in the version 1.0.1 compared with 0.3.0?

domenic commented 10 years ago

So, it might be that we now recursively sandbox by default. In that, either your tests are explicitly written in a way incompatible with that behavior, or we have bugs in that new feature.

To turn that off, use the singleOnly: true options. (Huh, that's a weird name for an option.) Let me know if it works for you.

In any case, a small example project would again be extremely helpful. We don't want to cause regressions.

tandrewnichols commented 10 years ago

Sorry, I had actually forgotten about this issue, by virtue of working on something else. I'll see if I can put a gist together sometime soon.

darthmarcos commented 9 years ago

Apologies for the very late reply. I have just tried the singleOnly: true option as you suggested and yes this is the solution to my problem. Thank you very much for the assistance. Much appreciated.