From da4f4b6a0f2ff12fdd1013fff70d4195b8eccb7b Mon Sep 17 00:00:00 2001 From: Alan Savage Date: Wed, 2 Sep 2020 09:26:10 -0700 Subject: [PATCH] Clarify Rails test use of config environments fixes rails/webpacker#2654 --- docs/testing.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/testing.md b/docs/testing.md index 573cf66c6..c83192cec 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -134,3 +134,16 @@ Make sure you configure Rails to serve static files from the public directory in # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true ``` + +## Webpacker Configuration Environments and Rails Tests + +Webpacker ships with three configuration files in `config/webpack`: +`test.js`, `development.js`, and `production.js`. `NODE_ENV` determines which +webpack config it will use, i.e., config/webpack/{development,test,production}.js +and will impact behavior in your Babel config, i.e., `babel.config.js`. +`NODE_ENV` is independent of `RAILS_ENV` in Rails. + +This means that by default `rails test` or `rspec` will use `development.js` +_not_ `test.js`, because `NODE_ENV` is `development` by [default](https://github.com/rails/webpacker/blob/bf278f9787704ed0f78038ad7d36c008abc2edfd/lib/install/bin/webpack#L4). + +For more information see [Why doesn't Webpacker use my test config when I run Rails tests?](https://rossta.net/blog/why-doesnt-webpacker-use-my-test-config-when-i-run-rails-tests.html)