Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4d03c17d
Commit
4d03c17d
authored
Sep 22, 2020
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for webpack manifest helper
parent
29977d31
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
0 deletions
+104
-0
spec/lib/gitlab/webpack/manifest_spec.rb
spec/lib/gitlab/webpack/manifest_spec.rb
+104
-0
No files found.
spec/lib/gitlab/webpack/manifest_spec.rb
0 → 100644
View file @
4d03c17d
require
'spec_helper'
require
'json'
RSpec
.
describe
Gitlab
::
Webpack
::
Manifest
do
let
(
:manifest
)
do
<<-
EOF
{
"errors": [],
"assetsByChunkName": {
"entry1": [ "entry1.js", "entry1-a.js" ],
"entry2": "entry2.js"
}
}
EOF
end
shared_examples_for
"a valid manifest"
do
it
"should return single entry asset paths from the manifest"
do
expect
(
Gitlab
::
Webpack
::
Manifest
.
asset_paths
(
"entry2"
)).
to
eq
([
"/public_path/entry2.js"
])
end
it
"should return multiple entry asset paths from the manifest"
do
expect
(
Gitlab
::
Webpack
::
Manifest
.
asset_paths
(
"entry1"
)).
to
eq
([
"/public_path/entry1.js"
,
"/public_path/entry1-a.js"
])
end
it
"should error on a missing entry point"
do
expect
{
Gitlab
::
Webpack
::
Manifest
.
asset_paths
(
"herp"
)
}.
to
raise_error
(
Gitlab
::
Webpack
::
Manifest
::
AssetMissingError
)
end
end
before
do
# Test that config variables work while we're here
::
Rails
.
configuration
.
webpack
.
dev_server
.
host
=
'hostname'
::
Rails
.
configuration
.
webpack
.
dev_server
.
port
=
2000
::
Rails
.
configuration
.
webpack
.
manifest_filename
=
"my_manifest.json"
::
Rails
.
configuration
.
webpack
.
public_path
=
"public_path"
::
Rails
.
configuration
.
webpack
.
output_dir
=
"manifest_output"
end
context
"with dev server enabled"
do
before
do
::
Rails
.
configuration
.
webpack
.
dev_server
.
enabled
=
true
stub_request
(
:get
,
"http://hostname:2000/public_path/my_manifest.json"
).
to_return
(
body:
manifest
,
status:
200
)
end
describe
:asset_paths
do
it_should_behave_like
"a valid manifest"
it
"should error if we can't find the manifest"
do
::
Rails
.
configuration
.
webpack
.
manifest_filename
=
"broken.json"
stub_request
(
:get
,
"http://hostname:2000/public_path/broken.json"
).
to_raise
(
SocketError
)
expect
{
Gitlab
::
Webpack
::
Manifest
.
asset_paths
(
"entry1"
)
}.
to
raise_error
(
Gitlab
::
Webpack
::
Manifest
::
ManifestLoadError
)
end
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://hostname:2000/public_path/my_manifest.json"
).
to_return
(
body:
error_manifest
,
status:
200
)
expect
{
Gitlab
::
Webpack
::
Manifest
.
asset_paths
(
"entry1"
)
}.
to
raise_error
(
Gitlab
::
Webpack
::
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://hostname:2000/public_path/my_manifest.json"
).
to_return
(
body:
error_manifest
,
status:
200
)
expect
{
Gitlab
::
Webpack
::
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://hostname:2000/public_path/my_manifest.json"
).
to_return
(
body:
error_manifest
,
status:
200
)
expect
{
Gitlab
::
Webpack
::
Manifest
.
asset_paths
(
"entry1"
)
}.
to_not
raise_error
end
end
end
end
context
"with dev server disabled"
do
before
do
::
Rails
.
configuration
.
webpack
.
dev_server
.
enabled
=
false
allow
(
File
).
to
receive
(
:read
).
with
(
::
Rails
.
root
.
join
(
"manifest_output/my_manifest.json"
)).
and_return
(
manifest
)
end
describe
:asset_paths
do
it_should_behave_like
"a valid manifest"
it
"should error if we can't find the manifest"
do
::
Rails
.
configuration
.
webpack
.
manifest_filename
=
"broken.json"
allow
(
File
).
to
receive
(
:read
).
with
(
::
Rails
.
root
.
join
(
"manifest_output/broken.json"
)).
and_raise
(
Errno
::
ENOENT
)
expect
{
Gitlab
::
Webpack
::
Manifest
.
asset_paths
(
"entry1"
)
}.
to
raise_error
(
Gitlab
::
Webpack
::
Manifest
::
ManifestLoadError
)
end
end
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment