-
Notifications
You must be signed in to change notification settings - Fork 27
Description
I've spent quite a bit of time off and on trying to get a test suite to work on our app, and after trying several different test runners and a lot of debugging, what I've discovered is that the reason I haven't been able to get it to work is that inject-data is basically breaking anything that uses mocha.
Here is what's happening in my case:
Mocha includes jade, which includes this code in lib/filters.js:
coffeescript: function(str){
str = str.replace(/\\n/g, '\n');
var js = require('coffee-script').compile(str).replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
return '<script type="text/javascript">\\n' + js + '</script>';
}
Jade also includes, in lib/doctypes.js:
module.exports = {
'5': '<!DOCTYPE html>'
, 'default': '<!DOCTYPE html>'
So, when meteor concatenates these files together and serves them, because inject-data is using /<!DOCTYPE html>/.test(chunk)
to determine when it needs to inject, it's attempting to inject into the practicalmeteor_mocha-core.js file.
This actually wouldn't be a huge problem in this particular case, because I don't think there is anything in practicalmeteor:mocha that would actually use that coffeescript filter, so it would just be some unused code bloat. However, since inject-data is loading lib/inject.html as an asset, the template being used for injection ends with a newline, and it's actually the newline that is causing all my failures..
coffeescript: function(str){
str = str.replace(/\\n/g, '\n');
var js = require('coffee-script').compile(str).replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
return '<script type="text/inject-data">%7B%22fast-render-data%22%3A%7B%22collectionData%22%3A%7B%7D%2C%22subscriptions%22%3A%7B%7D%2C%22loginToken%22%3A%...%22%7D%7D</script>
<script type="text/javascript">\\n' + js + '</script>';
}
And in the end, my entire test suite is failing because single-quoted javascript strings can't contain literal new-lines.
Now that I've tracked this down in my own code, I see that several other people have already tried to fix it -- any of the four currently open PR's (#2 #5 #6 #7) would have avoided this problem for me, either by not injecting into that file, or by not including the newline from the template.