Skip to content

Commit e581a5f

Browse files
committed
Ensure webpacker compiled
1 parent ed89ebf commit e581a5f

File tree

7 files changed

+25
-2
lines changed

7 files changed

+25
-2
lines changed

test/react/rails/component_mount_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
when_sprockets_available do
44
class ComponentMountTest < ActionDispatch::IntegrationTest
55
setup do
6+
WebpackerHelpers.compile_if_missing
67
@helper = React::Rails::ComponentMount.new
78
end
89

test/react/rails/controller_lifecycle_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def react_component(*args)
2424

2525
class ControllerLifecycleTest < ActionDispatch::IntegrationTest
2626
def setup
27+
WebpackerHelpers.compile_if_missing
2728
@previous_helper_implementation = React::Rails::ViewHelper.helper_implementation_class
2829
React::Rails::ViewHelper.helper_implementation_class = DummyHelperImplementation
2930
end

test/react/rails/pages_controller_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
require 'test_helper'
22

33
class PagesControllerTest < ActionController::TestCase
4+
setup do
5+
WebpackerHelpers.compile_if_missing
6+
end
7+
48
test 'renders successfully' do
59
get :show, id: 1
610
assert_equal(200, response.status)

test/react/rails/react_rails_ujs_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ReactRailsUJSTest < ActionDispatch::IntegrationTest
66

77
setup do
88
Capybara.current_driver = Capybara.javascript_driver
9+
WebpackerHelpers.compile_if_missing
910
end
1011

1112
test 'ujs object present on the global React object and has our methods' do

test/react/server_rendering/webpacker_manifest_container_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ def test_it_loads_from_webpack_dev_server
3131
Webpacker::Manifest.load("./test/dummy/public/packs/manifest.json")
3232
webpack_manifest = Webpacker::Manifest.instance.data
3333
example_asset_path = webpack_manifest.values.first
34+
if example_asset_path.nil?
35+
next
36+
end
3437
assert_includes example_asset_path, "http://localhost:8080"
3538
# Make sure the dev server is up:
3639
open("http://localhost:8080/application.js")
3740
detected_dev_server = true
3841
break
3942
rescue StandardError => err
43+
puts err.message
44+
ensure
4045
sleep 0.5
46+
puts i
4147
end
4248
end
4349

test/support/webpacker_helpers.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module WebpackerHelpers
2+
PACKS_DIRECTORY = File.expand_path("../dummy/public/packs", __FILE__)
3+
24
module_function
35
def available?
46
defined?(Webpacker)
@@ -11,6 +13,7 @@ def when_webpacker_available
1113
end
1214

1315
def compile
16+
return if !available?
1417
clear_webpacker_packs
1518
Dir.chdir("./test/dummy") do
1619
capture_io do
@@ -22,8 +25,13 @@ def compile
2225
Webpacker::Manifest.load
2326
end
2427

28+
def compile_if_missing
29+
if !File.exist?(PACKS_DIRECTORY)
30+
compile
31+
end
32+
end
33+
2534
def clear_webpacker_packs
26-
packs_directory = File.expand_path("../dummy/public/packs", __FILE__)
27-
FileUtils.rm_rf(packs_directory)
35+
FileUtils.rm_rf(PACKS_DIRECTORY)
2836
end
2937
end

test/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
require(f)
2121
end
2222

23+
WebpackerHelpers.clear_webpacker_packs
24+
2325
Capybara.javascript_driver = :poltergeist
2426
Capybara.app = Rails.application
2527

0 commit comments

Comments
 (0)