Skip to content

Commit d16c932

Browse files
committed
update webpacker path helper; fix some tests
1 parent 1d18a8e commit d16c932

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

lib/react/server_rendering/webpacker_manifest_container.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ module ServerRendering
77
# Get a compiled file from Webpacker
88
class WebpackerManifestContainer
99
def find_asset(logical_path)
10-
asset_path = Webpacker::Manifest.lookup(logical_path) # raises if not found
10+
# raises if not found
11+
asset_path = Webpacker::Manifest.lookup(logical_path).to_s
1112
if asset_path.start_with?("http")
1213
# this includes `webpack-dev-server/client/index.js` code which causes ExecJS to 💥
1314
dev_server_asset = open(asset_path).read
1415
dev_server_asset.sub!(CLIENT_REQUIRE, '//\0')
1516
dev_server_asset
1617
else
17-
full_path = File.join(
18-
# TODO: using `.parent` here won't work for nonstandard configurations
19-
Webpacker::Configuration.output_path.parent,
20-
asset_path
21-
)
18+
full_path = Webpacker::Manifest.lookup_path(logical_path).to_s
2219
File.read(full_path)
2320
end
2421
end

test/generators/install_generator_webpacker_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class InstallGeneratorWebpackerTest < Rails::Generators::TestCase
1010
EXPECTED_SETUP = %|// Support component names relative to this directory:
1111
var componentRequireContext = require.context("components", true)
1212
var ReactRailsUJS = require("react_ujs")
13-
ReactRailsUJS.loadContext(componentRequireContext)
13+
ReactRailsUJS.useContext(componentRequireContext)
1414
|
1515

1616
DEFAULT_SERVER_RENDERING_PACK_PATH = "app/javascript/packs/server_rendering.js"
@@ -34,7 +34,7 @@ def copy_directory(dir)
3434
assert_file DEFAULT_SERVER_RENDERING_PACK_PATH do |contents|
3535
assert_includes contents, "var componentRequireContext = require.context(\"components\", true)\n"
3636
assert_includes contents, "var ReactRailsUJS = require(\"react_ujs\")\n"
37-
assert_includes contents, "ReactRailsUJS.loadContext(componentRequireContext)\n"
37+
assert_includes contents, "ReactRailsUJS.useContext(componentRequireContext)\n"
3838
end
3939
end
4040

test/react/server_rendering/bundle_renderer_test.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ class BundleRendererTest < ActiveSupport::TestCase
6868
@renderer.render("NonExistentComponent", {}, nil)
6969
end
7070

71-
if WebpackerHelpers.available?
72-
assert_includes err.message, "Cannot find module './NonExistentComponent'"
73-
else
74-
assert_match(/ReferenceError/, err.to_s)
75-
assert_match(/NonExistentComponent/, err.to_s, "it names the component")
76-
end
71+
assert_match(/ReferenceError/, err.to_s)
72+
assert_match(/NonExistentComponent/, err.to_s, "it names the component")
7773

7874
assert_match(/\n/, err.to_s, "it includes the multi-line backtrace")
7975
end

0 commit comments

Comments
 (0)