Comments (18)
We had this discussion on CoffeeScript in issue #8 and were talking about whether rewire should support compiling to CoffeeScript or not. I don't think that rewire should support every language in the node.js community (e.g. what about IcedCoffeeScript?). I think that anyone who is using a compile-to-js-language needs to take care of compiling it to JavaScript.
Personally I don't use CoffeeScript, so I don't know much about tools and typical workflows. Is there a possibility to add the CoffeeScript(Redux)-Compiler to require.extensions
?
from rewire.
The extension of CSR is still .coffee and so an addition to require.extensions is not needed.
I see that you are doing a require("coffee-script") in
Line 58 in 6040974
This "coffee-script" is a module name. In my case, Coffee-script-redux is a different (stricter) compiler for .coffee files. It would be good if there was a json file for settings where the compiler can be specified and the specified compiler can be required. I believe this is how mocha does it..
from rewire.
Could you give me a link to a readme or something where the behavior of mocha is described?
If rewire didn't modify require.extensions
would you be able to use CoffeeScriptRedux by modifying require.extensions
before starting your tests?
from rewire.
The readme is on http://visionmedia.github.io/mocha/. Please go to the link and Ctrl+F for --compilers
from rewire.
Are you calling mocha
with --compilers coffee:coffee-script
?
It seems to me that the CS "feature" of rewire #8 prevents you from using other CS compilers which means that the feature should be regressed.
from rewire.
Are you calling mocha with --compilers coffee:coffee-script?
No, I call it with --compilers coffee:coffee-script-redux. But you have the correct understanding of it.
It seems to me that the CS "feature" of rewire #8 prevents you from using other CS compilers
I think so too. Though, I did try to get rewire to work with CSR but failed. I haven't looked at it enough to see where the problem lies. In short, let me share the gist of what I did https://gist.github.com/gprasant/7399548
from rewire.
Mhmmm k. And if you remove the whole CS-compile thing of rewire and start mocha with --compilers coffee:coffee-script
it still works? If this is the case, I'll remove CS-support so everybody can choose his favorite CS-compiler.
from rewire.
Let me check if that will work.
On Nov 11, 2013 2:29 PM, "Johannes Ewald" [email protected] wrote:
Mhmmm k. And if you remove the whole CS-compile thing of rewire and start
mocha with --compilers coffee:coffee-script it still works? If this is
the case, I'll remove CS-support so everybody can choose his favorite
CS-compiler.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/21#issuecomment-28182217
.
from rewire.
Hello, I tried this today. I have a commit up at https://github.com/gprasant/rewire/tree/anycompiler
commit : gprasant@9518cc4.
Here is what I found out - One test fails it("should also work with CoffeeScript")
. But it looks like the coffeescript file is read. But rewire is not able to set a variable . I thought it could be because of an outer closure introduced when compiling the file, but that doesn't look like it. You probably know more about how this works. Can you try to see if the way I have removed the coffeescript functionality is right and see whats causing rewire to not work in this case?
UPDATE It looks like coffeeModule.readFileSync is resulting in calling the actual fs.readFileSync even though we have stubbed it out.
UPDATE-2 Looks like it is the outer closure that was the problem. So, I compiled module.coffee with --bare and then ran the test against the compiled js file . This time, the test ran successfully. I don't know of a way to include this --bare switch in the mocha command line. yet.
from rewire.
Yep, the bare
-option is needed as pointed out in this issue #8.
rewire can't invalidate the way how JavaScript closures work. Variables hidden "behind" a closure can never be accessed.
Your commit looks good, I think I'll regress the feature and bump the major version. @00Davo @djthread @es128
from rewire.
Wait, so why the need for the regress? This issue boiled down to an oversight of the requirement to use bare
, which is good practice in node apps anyway since the module system does its own encapsulation.
Please... leave it alone.
from rewire.
The problem is that rewire's CoffeeScript-feature prevents other users from using another CoffeeScript-dialect because rewire will always compile files ending on .coffee
with the original CoffeeScript compiler. If you compiled all your CoffeeScript to JavaScript and then run your tests it should be no problem.
If you're using mocha you just need to use the --compilers coffee:coffee-script
argument.
The main problem here is that rewire does not know anything about CoffeeScript or other compilers (and in fact it should not care about). It just enhances node's require so you have private access to your modules.
from rewire.
But the feature as it stands works fine - allowing testing without a compilation step for the specific use-case.
For anyone else, they can precompile, which they'll have to do either way.
from rewire.
Seems like everyone who's using CoffeeScript doesn't like to pre-compile... ^^
from rewire.
Actually, TBH, I usually do run the tests on precompiled code as it's noticeably faster. But I like the option of not having to, perhaps for smaller projects/experiments. And I'm just not understanding the benefit gained by removing the existing, working feature, by imposing the workaround on everyone instead of just outliers.
Btw, since I haven't expressed this before - thank you for rewire, it is absolutely awesome. I will continue using it whether you decide to remove the built-in coffee-script support or not.
from rewire.
@gprasant is pre-compiling an option for you?
@es128 thx! 😄
from rewire.
I can manage precompiling
from rewire.
Cool! 👍
from rewire.
Related Issues (20)
- global variable is not available in the module HOT 8
- Injected mocks add functionality rather than replace it HOT 1
- rewiring any function executes every line that isn't in any function
- Rewired function is not instanceof Function in Jest context HOT 1
- Rewire doesn't work with typescript HOT 3
- Rewire does not seem to work with flow HOT 1
- mocking fs when using rewire
- Rewire dosn't mock function
- A behaviour that could have HOT 1
- Update the vulnerable packages HOT 6
- type error when rewire'ing const HOT 4
- Vulnerable dependancy eslint 7.32.0 HOT 1
- Vulnerability in dependency eslint HOT 2
- Feature request: ESM support
- Special handling for process.env? HOT 2
- Rewire on node module with shebang doesn't work.
- Eslint need to be updated to at least version 8.15.0 HOT 1
- Rewire is great, but it doesn't work for SonarQube HOT 1
- unpexpected : due to type definition in TS HOT 1
- nconf values are undefined when a module is rewire
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rewire.