How to stub "global" module variables in node.js with Coffeescript without --bare?

I have some environment variables from Heroku and for readability, I tend to assign them to global variables for readability:

ACCESS_TOKEN = process.env.ACCESS_TOKEN

Now I'd like change value for that in tests. I have tried rewire and sandboxed-module. However, they are both setting global variables directly, whereas coffeescript variables are wrapped in anonymous function.

Is there any way around this, or do I really have to use --bare if I want to test my code?

I'm not familiar with node, but the approach I'd use, and that I've used in other technologies is wrap up globals or external dependencies in an object which can be swapped out for a stub or mock object when needed in test.

Say rather than storing the value in ACCESS_TOKEN you made a herokuEnvironment object and gave it the method accessToken(). Wherever you need to use the properties you inject the object. Then in production that method calls process.env.ACCESS_TOKEN. If you need a safe version to inject into a test situation, you just supply { accessToken: function () {return 'foo';}}