Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to a helper and fix tests #648

Merged
merged 2 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "webpacker_test_helper"

class ConfigurationTest < Minitest::Test
class ConfigurationTest < Webpacker::Test
def test_source_path
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
assert_equal source_path, Webpacker.config.source_path.to_s
Expand Down Expand Up @@ -39,18 +39,4 @@ def test_compile?
refute reloaded_config.compile?
end
end

private
def with_node_env(env)
original = ENV["NODE_ENV"]
ENV["NODE_ENV"] = env
yield
ensure
ENV["NODE_ENV"] = original
end

def reloaded_config
Webpacker.instance.instance_variable_set(:@config, nil)
Webpacker.config
end
end
12 changes: 9 additions & 3 deletions test/dev_server_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
require "webpacker_test_helper"

class DevServerTest < Minitest::Test
class DevServerTest < Webpacker::Test
def test_host
assert_equal "localhost", Webpacker.dev_server.host
with_node_env("development") do
reloaded_config
assert_equal Webpacker.dev_server.host, "localhost"
end
end

def test_port
assert_equal Webpacker.dev_server.port, 3035
with_node_env("development") do
reloaded_config
assert_equal Webpacker.dev_server.port, 3035
end
end
end
16 changes: 16 additions & 0 deletions test/webpacker_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,21 @@ class Application < ::Rails::Application
end
end

class Webpacker::Test < Minitest::Test
private
def reloaded_config
Webpacker.instance.instance_variable_set(:@config, nil)
Webpacker.config
end

def with_node_env(env)
original = ENV["NODE_ENV"]
ENV["NODE_ENV"] = env
yield
ensure
ENV["NODE_ENV"] = original
end
end

Rails.backtrace_cleaner.remove_silencers!
TestApp::Application.initialize!