Commit f7b5be1a authored by Stan Hu's avatar Stan Hu

Clear memoized manifest to solve intermittent spec errors

`spec/lib/gitlab/webpack/manifest_spec.rb` appears to be failing
intermittently due to a memoized manifest that is loaded before the
tests are run. We now clear these values between each run to ensure a
clean state.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/255176
parent df7e484a
...@@ -24,6 +24,8 @@ module Gitlab ...@@ -24,6 +24,8 @@ module Gitlab
AssetMissingError = Class.new(StandardError) AssetMissingError = Class.new(StandardError)
class << self class << self
include Gitlab::Utils::StrongMemoize
def entrypoint_paths(source) def entrypoint_paths(source)
raise WebpackError, manifest["errors"] unless manifest_bundled? raise WebpackError, manifest["errors"] unless manifest_bundled?
...@@ -55,6 +57,10 @@ module Gitlab ...@@ -55,6 +57,10 @@ module Gitlab
end end
end end
def clear_manifest!
clear_memoization(:manifest)
end
private private
def manifest_bundled? def manifest_bundled?
...@@ -67,7 +73,7 @@ module Gitlab ...@@ -67,7 +73,7 @@ module Gitlab
load_manifest load_manifest
else else
# ... otherwise cache at class level, as JSON loading/parsing can be expensive # ... otherwise cache at class level, as JSON loading/parsing can be expensive
@manifest ||= load_manifest strong_memoize(:manifest) { load_manifest }
end end
end end
......
...@@ -16,6 +16,14 @@ RSpec.describe Gitlab::Webpack::Manifest do ...@@ -16,6 +16,14 @@ RSpec.describe Gitlab::Webpack::Manifest do
EOF EOF
end end
around do |example|
Gitlab::Webpack::Manifest.clear_manifest!
example.run
Gitlab::Webpack::Manifest.clear_manifest!
end
shared_examples_for "a valid manifest" do shared_examples_for "a valid manifest" do
it "returns single entry asset paths from the manifest" do it "returns single entry asset paths from the manifest" do
expect(Gitlab::Webpack::Manifest.asset_paths("entry2")).to eq(["/public_path/entry2.js"]) expect(Gitlab::Webpack::Manifest.asset_paths("entry2")).to eq(["/public_path/entry2.js"])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment