thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
152 stars 24 forks source link

Breaks with es6ify or any other compile to js language #5

Closed EggDice closed 10 years ago

EggDice commented 10 years ago

because it runs before the transforms it will throw syntax error

thlorenz commented 10 years ago

Most likely this is due to the prelude not being overridden in these cases. Could you copy and paste the prelude in your resulting bundle?

Also a more detailed error including stacktrace will help.

Ideally if you can put it up on a github repo so I can reproduce by just cloning it and running npm start, that'd be great.

Thanks.

EggDice commented 10 years ago

Thanks for the quick answer! The repo is here: https://github.com/EggDice/proxyquireify-break-example npm start will runs the build and it will break because of the syntax error of foo.test.js file which is written in es6. es6 runtime is not added jet to the build because I think it breaks because of a different problem hope it "works"!

thlorenz commented 10 years ago

I PRd on your repo with the fix needed (mainly updating proxyquireify to the latest version). I updated detective in there so you won't get that esprima error anymore.

However I noticed none of the files in your repo are actually es6, so you should add one to confirm that it works even with that. I'm a little afraid that it won't since the es6 may not be transformed before proxyquireify sees it which would cause it to fail.

In that case we have to find another solution.

Please let me know how it goes, thanks.

EggDice commented 10 years ago

Thanks really it works!

It is in es6, just hard to catch:

var proxyquire = require('proxyquireify')(require);

var stubs = { 
  //this part:
  './bar': { 
      wunder() { return 'wirklich wunderbar'; }
    , kinder() { return 'schokolade'; }
  }
};

var foo = proxyquire('./foo', stubs);

console.log(foo()); 

I tested it, and it works on the app I tried to use! Thanks for the quick help! Have a nice week!