-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix testing issues with Rails hot reloading setup
Configured testing so that: * If we're not running a webpack process to watch the client JS files, then we build the client or server files. * Test will let you know if it's skipping building. Expression used to see if a watch process is running: `pgrep -fl '\\-w \\-\\-config webpack\\.#{type}\\.rails\\.build\\.config\\.js'` * Renamed asset helpers so usage is like this: <%= env_stylesheet_link_tag 'application_prod', 'application_dev', media: 'all', 'data-turbolinks-track' => true %> <%= env_javascript_include_tag nil, 'http://localhost:3500/vendor-bundle.js' %> <%= env_javascript_include_tag nil, 'http://localhost:3500/app-bundle.js' %> <%= env_javascript_include_tag 'application_prod', 'application_dev', 'data-turbolinks-track' => true %> TODO: Should we consider having tests use the Rails hot reload server?
- Loading branch information
Showing
19 changed files
with
103 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
web: rails s | ||
|
||
# Run the hot reload server for client development | ||
client: sh -c 'rm app/assets/webpack/* || true && cd client && HOT_RAILS_PORT=3500 npm run build:dev:client' | ||
|
||
# Keep the JS fresh for specs | ||
client-spec: sh -c 'cd client && npm run build:test:client' | ||
|
||
# Keep the JS fresh for server rendering | ||
server: sh -c 'cd client && npm run build:dev:server' | ||
hot: sh -c 'cd client && HOT_PORT=4000 npm start' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
module ApplicationHelper | ||
def javascript_include_env_tag(asset, dev_asset, params = {}) | ||
asset_file = Rails.env.production? ? asset : dev_asset | ||
# TODO: MOVE TO helper in react_on_rails | ||
# See application.html.erb for usage example | ||
def env_javascript_include_tag(prod_asset, dev_asset, params = {}) | ||
asset_file = !Rails.env.development? ? prod_asset : dev_asset | ||
return javascript_include_tag(asset_file, params) if asset_file | ||
end | ||
|
||
def stylesheet_link_env_tag(asset, dev_asset, params = {}) | ||
asset_file = Rails.env.production? ? asset : dev_asset | ||
# TODO: MOVE TO helper in react_on_rails | ||
def env_stylesheet_link_tag(prod_asset, dev_asset, params = {}) | ||
asset_file = !Rails.env.development? ? prod_asset : dev_asset | ||
return stylesheet_link_tag(asset_file, params) if asset_file | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Testing | ||
|
||
1. `rake` runs the test suite | ||
2. To test production with precompiled assets: | ||
|
||
```sh | ||
export SECRET_KEY_BASE=`rake secret` | ||
alias test-prod='rake assets:clobber && RAILS_ENV=production bin/rake assets:precompile \ | ||
&& rails s -e production' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# TODO: Move to react_on_rails | ||
class EnsureAssetsCompiled | ||
def self.check_built_assets | ||
return if @checked_built_assets | ||
build_all_assets | ||
end | ||
|
||
def self.running_webpack_watch?(type) | ||
running = `pgrep -fl '\\-w \\-\\-config webpack\\.#{type}\\.rails\\.build\\.config\\.js'` | ||
if running.present? | ||
puts "Found process, so skipping rebuild => #{running.ai}" | ||
return true | ||
end | ||
end | ||
|
||
def self.build_assets_for_type(type) | ||
unless running_webpack_watch?(type) | ||
build_output = `cd client && npm run build:#{type}` | ||
if build_output =~ /error/i | ||
fail "Error in building assets!\n#{build_output}" | ||
else | ||
puts "Webpack build completed." | ||
end | ||
end | ||
end | ||
|
||
def self.build_all_assets | ||
build_assets_for_type("client") | ||
build_assets_for_type("server") | ||
@checked_built_assets = true | ||
end | ||
end |