bullet-train-co / magic_test

MIT License
437 stars 23 forks source link

Rack-based Javascript Injection #16

Open tleish opened 3 years ago

tleish commented 3 years ago

I've seen other gems which use Rack to inject javascript into head of an html request (e.g rack-livereload).

The user would then add:

# config/environments/test.rb
if ENV['MAGIC_TEST']
  config.middleware.insert_after ActionDispatch::Static, Rack::MagicTest
end

This approach might be a bit cleaner than modifying layouts to include the javascript.

Would you be interested in this approach?

andrewculver commented 3 years ago

@tleish Yes, 100%. Seems like this would be a major improvement!

andrewculver commented 3 years ago

@tleish Hey, I just realized this probably won't work. You can't inject the JS until you're ready to start recording, which shouldn't happen until the user has actually hit magic_test in the test. Otherwise, it will re-record actions that the earlier Capybara code is triggering.

andrewculver commented 3 years ago

Actually, I take that back... it could work, we just need to add a method to activate the recording, vs. it happening automatically, then issue that command via JS when they hit magic_test. I think this will help solve some of the jitteriness that happens right now on full page refreshes.

andrewculver commented 3 years ago

We've got an update on the JS side coming that will help support this.

tleish commented 3 years ago

Meaning you are working on the injection, or refactoring the JS to make injection easier?

andrewculver commented 3 years ago

@tleish Hey, sorry to drop the ball on this. Forget what I said before! I would definitely be interested in your approach. Want to take a stab at it?

gazayas commented 1 year ago

I've seen other gems which use Rack to inject javascript into head of an html request (e.g rack-livereload).

Found the line: https://github.com/jaredmdobson/rack-livereload/blob/42ab828ca73dcbebbc516b95b2f4b24541c228a5/README.md?plain=1#L29

Will have to think about how to implement this one moving forward.