Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inject-data breaks practicalmeteor:mocha (and others) #8

Closed
jasonk opened this issue Sep 26, 2016 · 0 comments
Closed

inject-data breaks practicalmeteor:mocha (and others) #8

jasonk opened this issue Sep 26, 2016 · 0 comments

Comments

@jasonk
Copy link

jasonk commented Sep 26, 2016

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.

@jasonk jasonk closed this as completed Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant