9

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?

Dan
  • 1,136
  • 10
  • 24
  • What output do you get from Puma when you run your tests? Does it include "Puma starting in single mode" and "Environment: test" – Thomas Walpole Jun 20 '17 at 02:12
  • 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. – Dan Jun 20 '17 at 04:09
  • 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). – Thomas Walpole Jun 20 '17 at 17:04
  • Thanks for posting your question with code, which helped me to resolve one of other problems with ES6 and Uglifier. – Ravindra M Jul 06 '17 at 06:05
  • How did you solve the problem? I have the same issue – marimaf Jul 24 '19 at 01:04
  • 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. – Dan Jul 24 '19 at 06:24

1 Answers1

1

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.

jbielick
  • 2,800
  • 17
  • 28