Heroku, Webpacker and Failing Tests
In the past weeks, I had troubles running Rails 6 tests on Heroku CI due to the following Webpacker error
ActionView::Template::Error: Webpacker can't find application in /app/public/packs-test/manifest.json. Possible causes: 1. You want to set webpacker.yml value of compile to true for your environment unless you are using the `webpack -w` or the webpack-dev-server. 2. webpack has not yet re-run to reflect updates. 3. You have misconfigured Webpacker's config/webpacker.yml file. 4. Your webpack configuration is not creating a manifest. Your manifest contains: { }
Tests worked on my local machine but failed on Heroku CI and my webpacker.yml was properly configured with compile: true in the test section.
Turns out, the compile: true directive is ignored on Heroku while running tests. The issue is simply that webpacker:compile was/is never launched. Surprisingly, it is launched on production deploy.
To fix the error above, force Heroku CI to precompile your assets in the test-setup step of your app.json. Something like
{ "environments": { "test": { ... "scripts": { "test-setup": "bin/rails assets:precompile" } } } }












