Precompiled assets in Rails test environment not used
Asked Answered
C

1

10

I'm using Rails 5.1.1 and for our rspec feature tests we want would like to use precompiled assets before running all feature tests. (The main reason for this is because capybara-webkit doesn't support javascript es6 features)

The assets successfully precompile with RAILS_ENV=test rake assets:precompile however capybara-webkit doesn't appear to use the precompiled assets.

config/environment/test.rb looks like this

config.assets.prefix = "/assets_test"
config.assets.compile = true
config.serve_static_assets = true
config.assets.js_compressor = Uglifier.new(
  harmony: true #es6 support
)

What do I need to add for test to use the precompiled assets?

Cantharides answered 20/6, 2017 at 1:55 Comment(6)
What output do you get from Puma when you run your tests? Does it include "Puma starting in single mode" and "Environment: test"Cyclone
log/test.log seems to skip output of the server starting up and rspec doesn't display any other server logs. However if I add a byebug in a controller action being called and call Rails.env it returns test as to be expected.Cantharides
The puma output should just to be stdout, however I just noticed the "harmony: true" option you're passing to Uglifier. Just precompiling your assets isn't going to make a difference if they still have ES6 features in them. Capybara-webkit doesn't support running any ES6 features without them being transpiled down to ES5 (babel, etc) and polyfilled, which would then mean the harmony option wouldn't be needed when minifying (since there would be no ES6 code left to minify).Cyclone
Thanks for posting your question with code, which helped me to resolve one of other problems with ES6 and Uglifier.Tehee
How did you solve the problem? I have the same issueShop
I'm not sure if I ever found a solution. I'm currently using webpacker to handle JS assets which includes babel to help automatically convert es6 to backwards compatible JS and hence this isn't an issue for me any longer.Cantharides
H
2

You'll need to set config.assets.compile = false in your test.rb to indicate to Rails that it should only use static (precompiled) assets.

Heliotropism answered 9/7, 2020 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.