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

Testing workflow? #318

Closed
mockdeep opened this issue May 2, 2017 · 14 comments
Closed

Testing workflow? #318

mockdeep opened this issue May 2, 2017 · 14 comments
Assignees

Comments

@mockdeep
Copy link

mockdeep commented May 2, 2017

We're trying to set up Webpacker in our Rails 4.2 project and we've more or less got it working, but we've got some unanswered questions. In particular, if we're trying to run Capybara feature tests locally, do we always need to run RAILS_ENV=test ./bin/rails webpacker:compile beforehand? Or is there some other workflow that makes sense for this? One option we're considering is doing that on CI, but when we're developing locally having the tests fall back to relying on the dev server.

@jackjennings
Copy link

The assets are being compiled in the test environment during controller and system tests: https://github.com/rails/webpacker/blob/master/lib/tasks/webpacker/compile.rake#L30-L31

It seems like it would also make sense that this would happen when bare rails test is run, given that this command includes that invocation as well.

My workaround at this point is to add the following to the Rakefile:

Rake::Task["test"].enhance(["webpacker:compile_before_test"])

Does it make sense to include this by default?

@mockdeep
Copy link
Author

mockdeep commented May 3, 2017

Ah, I see. We're still on Rails 4.2, but I guess we could add that to our Rakefile as well. We were actually taking an approach where we require webpack-dev-server to be running for the tests when testing locally, which also allows us to use rspec spec/features/whatever_spec.rb and not needing to go via rake/rails.

@jackjennings
Copy link

I noticed that works too, but having to run a separate process to get tests working is a very non-ideal developer experience.

@jackjennings
Copy link

The above workaround doesn't work with rspec (frustratingly). Not sure what to do there, and not familiar enough with rspec to recommend an avenue to support it, unfortunately.

@mockdeep
Copy link
Author

mockdeep commented May 4, 2017

Being that we're more likely than not to have the dev server already running, it isn't too much a pain on our end, and there's the upshot that it will also speed up spec runs by not needing to compile assets on each run. But it would be nice to have something that's a little more transparent.

@p0wl
Copy link
Contributor

p0wl commented May 4, 2017

maybe you can benefit from this issue: #59. Especially with the latest version of webpacker, you may not be able to use the running webpack-dev-server in your test environment, because webpacker will search for manifest-test.json in RAILS_ENV=test (see https://github.com/rails/webpacker/blob/master/lib/install/config/webpack/paths.yml#L30)

@gauravtiwari
Copy link
Member

gauravtiwari commented May 4, 2017

No that should work because the manifest is written to file regardless of what binstub you use 👍 Will probably setup a base test helper to address this

@mockdeep
Copy link
Author

mockdeep commented May 4, 2017

We changed paths.yml not to override manifest in test mode, so all environments write to manifest.json. This works out so that when testing locally the tests just use the dev server endpoint. On CI we precompile and set Capybara.server_port = 8080 so that the Rails server serves up the assets from the public directory.

@returnlytom
Copy link
Contributor

thanks @mockdeep, removing the manifest rule and adding this worked:

RSpec.configure do |config|
  config.before(:each, selenium: true) do
    Capybara.server_port = 8080
  end
end

@gauravtiwari
Copy link
Member

After #360 this seems like a non-issue. Feel free to open another ticket if something else pops up 👍

@mockdeep
Copy link
Author

Awesome, thanks @javan, @gauravtiwari! This looks like it'll do the trick.

@gauravtiwari
Copy link
Member

Document this in README/guide - #372

@mcmire
Copy link

mcmire commented May 18, 2017

While the documentation gets updated, can someone tell me what the conclusion here is in terms of using Webpacker to write Capybara tests that rely on JavaScript? Is it as simple as running RAILS_ENV=test bin/webpack-dev-server in a separate process? Or do you have to configure Webpacker to do something fancy? (EDIT: running JavaScript tests is something separate, so ignore that)

@toadkicker
Copy link

I just fought with this rspec and CircleCI. It came down to simply adding - run: bin/webpack to circle.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants