Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
Only error if manifest error was a module build failure
Browse files Browse the repository at this point in the history
This allows webpack-rails to be used with non-breaking errors (such as linting).
  • Loading branch information
Juan-Carlos Medina and Naomi Jacobs committed Sep 21, 2016
1 parent dfc0592 commit 49e345e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
6 changes: 5 additions & 1 deletion lib/webpack/rails/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ...
Expand Down
39 changes: 28 additions & 11 deletions spec/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let(:manifest) do
<<-EOF
{
"errors": [],
"assetsByChunkName": {
"entry1": [ "entry1.js", "entry1-a.js" ],
"entry2": "entry2.js"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 49e345e

Please sign in to comment.