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

Loading .js.jsx files doesn't work in specs anymore #431

Closed
jipiboily opened this issue Dec 28, 2015 · 11 comments
Closed

Loading .js.jsx files doesn't work in specs anymore #431

jipiboily opened this issue Dec 28, 2015 · 11 comments

Comments

@jipiboily
Copy link

Hey folks,
it looks like there is a little something weird, I am not 100% clear of what it is right now, but here is what I have: I am trying to use TestUtils, I am able to load it perfectly fine in a spec, with jasmine-rails BUT, when I try to use it with code that requires JSX, and change the extension of the spec to .js.jsx, it fails. It is new in 1.4.2, it works in 1.4.1.

I've logged some of my findings in testdouble/jasmine-rails#178, if that can help.

This blog post explains how to do it, and has working code: http://www.calebwoods.com/2015/11/01/testing-react-components-rails/ (example code: https://github.com/calebwoods/react_testing) but it breaks when upgrading to react-rails 1.4.2, see the diff I just created to make sure only react-rails changed here calebwoods/react_testing@master...jipiboily:figure-out-wtf-breaks-it

I know this is issue is not 100% clear, as it's just not clear to me what broke, besides that everything seems to point to a change in v1.4.1...v1.4.2

And it still affects 1.5.0 from my quick test.

Any idea? I am going to use 1.4.1 in the meantime but happy to help on that if I can.

@jipiboily
Copy link
Author

This line is probably why it stopped working: v1.4.1...v1.4.2#diff-db79e062f0a40ceaca64834c6738ee2bR7. Maybe the problem is in jasmine-rails after all?

@rmosolgo
Copy link
Member

Thanks for all the info! It seems like adding support for sprockets 3 also introduced some bugs in other contexts. See also #415 and #423

I think the first step will be to add some failing specs for these cases (maybe need a new Gemfile for appraisal) then fix the bug itself.

I'm working on #430 at the moment but I'll take a look at these sprockets issues next, if nobody gets to them before me!

@mikem
Copy link

mikem commented Jan 4, 2016

@rmosolgo I thought this was an issue with Sprockets so dug in trying to understand it. I didn't solve it, but wrote up what I found in rails/sprockets#209. Maybe that'll help?

Also, if you have any pointers, maybe I'll be able to make some progress.

@jipiboily
Copy link
Author

Thanks for the update @mikem!

@rmosolgo
Copy link
Member

rmosolgo commented Jan 4, 2016

Wow, thanks for that write-up! A great place to start with react-rails would be to write a failing test. Since I don't really understand the bug yet, I can't give a great suggestion, but I could imagine a few possibilities:

If we had a failing test, that could focus the work toward fixing it!

@mikem
Copy link

mikem commented Jan 11, 2016

I finally had some time to put a failing test together. @rmosolgo check out commit b962dae on my fork.

mikem added a commit to mikem/jasmine-rails that referenced this issue Jan 11, 2016
@rmosolgo rmosolgo mentioned this issue Jan 22, 2016
17 tasks
@rmosolgo
Copy link
Member

While hunting down a bug in https://github.com/rmosolgo/react-rails-hot-loader, I discovered a behavior change between Sprockets 2 and Sprockets 3. In Sprockets 3:

assets["my_component.js.jsx"] # => "raw" JSX 
assets["my_component.js"] # => transformed JavaScript

So, what if you try requiring those assets without the .jsx in the extension (.js only)?

@mikem
Copy link

mikem commented Jan 24, 2016

@rmosolgo yes, I've encountered that as well.

Do you know whether that's a documented change of behavior in Sprockets? In my case it's another gem which is calling require_asset.

I'll mention this in testdouble/jasmine-rails#178.

@rmosolgo
Copy link
Member

documented change

I was about to complain that it wasn't, but I figured I should check the upgrade notes again. Technically it is, it's here, under "We can request the file under its original content type". Makes sense, it's a change to support source maps.

@rmosolgo
Copy link
Member

It sounds like this is a bug in jasmine-rails + sprockets 3, please reopen if there's something we should do in react-rails!

@colinrobertbrooks
Copy link

I updated to react-rails 1.8.0 today in conjunction with the following and am no longer facing this issue:

  • jasmine-core (2.4.1)
  • jasmine-rails (0.12.2)
  • sprockets (3.4.0)
  • sprockets-rails (2.3.3)

Prior to that, I was holding at react-rails 1.4; this no longer seems necessary.

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

4 participants