andersekdahl / karma-common-js

Test CommonJS modules without using Browserify
MIT License
2 stars 4 forks source link

Browserify-shim ? #3

Open stuff opened 9 years ago

stuff commented 9 years ago

I have a couple of good old js script I'm requiring with browserify-shim in my code. It's working when bundling with browserify (obvously) but my build failed with karma-common-js.

I don't know if it's supposed to work, or if I did it wrong :(

someone could help ?

andersekdahl commented 9 years ago

Shims are unfortunately something I haven't implemented yet but should be pretty simple. What you can do as a workaround is to create a wrapper module that just returns the global.

stuff commented 9 years ago

In fact, browserify-shim is a transform stream, and you already handle that, but I think you have a bug in your code... You're using a loop to go thought all the declared transforms and get the result in a var called 'processedContent' then you immediately use it to add your wrapper.

The problem is that transforms are async, so your loop calls them concurrently to change the same var. The worse case is the transforms are not totally finished and the processedContent var you are using is still processed.

I've fixed my browserify-shim problem in karma-common-js by using async.js to run all transforms one after the other and wait until they all ended to continue.

I've planned to submit a pull request when I've cleaned my code If you are interrested.

andersekdahl commented 9 years ago

Oh, right, I forgot about the shims as streams part. A PR is most welcome!