stephenmathieson / node-obfuscator

maintainer wanted → Obfuscate your node packages because your boss says so!
216 stars 36 forks source link

Running tests against obfuscated code #21

Open brian-mann opened 9 years ago

brian-mann commented 9 years ago

I was wondering how you would approach running tests against the obfuscated code.

For instance, while all my tests pass prior to obfuscation, after doing so it's possible I broke something. Using __dirname would point to a potentially incorrect path.

To avoid these headaches I was attempting to run all of my unit tests against the obfuscated code, but that doesn't work due to the require paths being completely wrong in the unit tests. I was wondering if you could give me some direction at solving this.

Because the single entry point is exported, it seems impossible to get access to the require'd files from outside of the file.

stephenmathieson commented 9 years ago

i have only run acceptance tests after obfuscating a project. e.g. things that test the "app" directly, not its individual modules.

To avoid these headaches I was attempting to run all of my unit tests against the obfuscated code, but that doesn't work due to the require paths being completely wrong in the unit tests. I was wondering if you could give me some direction at solving this.

depending on how your app/tests are structured, you may be able to put a "phony" entry together which require()s all of your tests:

require('./test/my-test-1')
require('./test/my-test-2')
require('./test/my-test-3')

it seems impossible to get access to the require'd files from outside of the file.

yes, that's (mostly) true. without massive hackery, you no longer have access.


sorry i don't have a good solution for this. i'll think a bit more about tomorrow. :/

brian-mann commented 9 years ago

Okay thanks for the response. I'll have some time to keep hacking on it pretty soon, and I'll let you know if I get anywhere.