diff --git a/lib/webpack/rails/manifest.rb b/lib/webpack/rails/manifest.rb index 7226b67..7b0625c 100644 --- a/lib/webpack/rails/manifest.rb +++ b/lib/webpack/rails/manifest.rb @@ -26,7 +26,7 @@ class EntryPointMissingError < StandardError class << self # :nodoc: def asset_paths(source) - raise WebpackError, manifest["errors"] if manifest["errors"].present? + raise WebpackError, manifest["errors"] unless manifest_bundled? paths = manifest["assetsByChunkName"][source] if paths @@ -42,6 +42,10 @@ def asset_paths(source) private + def manifest_bundled? + !manifest["errors"].any? { |error| error.include? "Module build failed" } + end + def manifest if ::Rails.configuration.webpack.dev_server.enabled # Don't cache if we're in dev server mode, manifest may change ... diff --git a/spec/manifest_spec.rb b/spec/manifest_spec.rb index aa19f2b..03b615a 100644 --- a/spec/manifest_spec.rb +++ b/spec/manifest_spec.rb @@ -5,6 +5,7 @@ let(:manifest) do <<-EOF { + "errors": [], "assetsByChunkName": { "entry1": [ "entry1.js", "entry1-a.js" ], "entry2": "entry2.js" @@ -55,17 +56,33 @@ expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to raise_error(Webpack::Rails::Manifest::ManifestLoadError) end - it "should error if webpack gives us an error in its manifest" do - error_manifest = JSON.parse(manifest).merge("errors" => ["something went wrong"]).to_json - stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) - - expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to raise_error(Webpack::Rails::Manifest::WebpackError) - end - - it "should not error if errors is present but empty" do - error_manifest = JSON.parse(manifest).merge("errors" => []).to_json - stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) - expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to_not raise_error + describe "webpack errors" do + context "when webpack has 'Module build failed' errors in its manifest" do + it "should error" do + error_manifest = JSON.parse(manifest).merge("errors" => [ + "somethingModule build failed something", + "I am an error" + ]).to_json + stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) + + expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to raise_error(Webpack::Rails::Manifest::WebpackError) + end + end + + context "when webpack does not have 'Module build failed' errors in its manifest" do + it "should not error" do + error_manifest = JSON.parse(manifest).merge("errors" => ["something went wrong"]).to_json + stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) + + expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to_not raise_error + end + end + + it "should not error if errors is present but empty" do + error_manifest = JSON.parse(manifest).merge("errors" => []).to_json + stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) + expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to_not raise_error + end end end