Skip to content

Commit

Permalink
Handle case of no webpacker installed
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Aug 19, 2018
1 parent b2868ce commit 6fad1af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/react_on_rails/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
puts
@printed_once = true

if ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?
if ReactOnRails::WebpackerUtils.using_webpacker? &&
ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?
msg = <<-MSG.strip_heredoc
WARNING: Define config.webpacker.yml to include sourcePath to configure
the location of your JavaScript source for React on Rails.
Expand Down
4 changes: 3 additions & 1 deletion lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def self.source_path
end
end

def self.source_path_is_not_defined_and_custom_node_modules?
def self.using_webpacker_source_path_is_not_defined_and_custom_node_modules?
return false unless ReactOnRails::WebpackerUtils.using_webpacker?

!ReactOnRails::WebpackerUtils.webpacker_source_path_explicit? &&
ReactOnRails.configuration.node_modules_location.present?
end
Expand Down
46 changes: 24 additions & 22 deletions spec/react_on_rails/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,34 @@ module ReactOnRails
end
end

describe ".source_path_is_not_defined_and_custom_node_modules?" do
it "returns false if node_modules is blank" do
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
.and_return("")
allow(Webpacker).to receive_message_chain("config.send").with(:data)
.and_return({})

expect(ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?).to eq(false)
end
if ReactOnRails::WebpackerUtils.using_webpacker?
describe ".source_path_is_not_defined_and_custom_node_modules?" do
it "returns false if node_modules is blank" do
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
.and_return("")
allow(Webpacker).to receive_message_chain("config.send").with(:data)
.and_return({})

it "returns false if source_path is defined in the config/webpacker.yml and node_modules defined" do
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
.and_return("client")
allow(Webpacker).to receive_message_chain("config.send").with(:data)
.and_return(source_path: "client/app")
expect(ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?).to eq(false)
end

expect(ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?).to eq(false)
end
it "returns false if source_path is defined in the config/webpacker.yml and node_modules defined" do
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
.and_return("client")
allow(Webpacker).to receive_message_chain("config.send").with(:data)
.and_return(source_path: "client/app")

it "returns true if node_modules is not blank and the source_path is not defined in config/webpacker.yml" do
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
.and_return("node_modules")
allow(Webpacker).to receive_message_chain("config.send").with(:data)
.and_return({})
expect(ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?).to eq(false)
end

it "returns true if node_modules is not blank and the source_path is not defined in config/webpacker.yml" do
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
.and_return("node_modules")
allow(Webpacker).to receive_message_chain("config.send").with(:data)
.and_return({})

expect(ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?).to eq(true)
expect(ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?).to eq(true)
end
end
end

Expand Down

0 comments on commit 6fad1af

Please sign in to comment.