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
e9441729
Commit
e9441729
authored
Oct 21, 2020
by
Paul Slaughter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sourcegraph not loading from asset host
- Adds unit test
parent
a1ae6803
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
3 deletions
+70
-3
app/assets/javascripts/sourcegraph/index.js
app/assets/javascripts/sourcegraph/index.js
+6
-3
spec/frontend/sourcegraph/index_spec.js
spec/frontend/sourcegraph/index_spec.js
+64
-0
No files found.
app/assets/javascripts/sourcegraph/index.js
View file @
e9441729
import
{
joinPaths
}
from
'
~/lib/utils/url_utility
'
;
function
loadScript
(
path
)
{
const
script
=
document
.
createElement
(
'
script
'
);
script
.
type
=
'
application/javascript
'
;
...
...
@@ -17,10 +19,11 @@ export default function initSourcegraph() {
return
;
}
const
assetsUrl
=
new
URL
(
'
/assets/webpack/sourcegraph/
'
,
window
.
location
.
href
);
const
scriptPath
=
new
URL
(
'
scripts/integration.bundle.js
'
,
assetsUrl
).
href
;
const
base
=
gon
.
asset_host
||
gon
.
gitlab_url
;
const
assetsUrl
=
joinPaths
(
base
,
'
/assets/webpack/sourcegraph/
'
);
const
scriptPath
=
joinPaths
(
assetsUrl
,
'
scripts/integration.bundle.js
'
);
window
.
SOURCEGRAPH_ASSETS_URL
=
assetsUrl
.
href
;
window
.
SOURCEGRAPH_ASSETS_URL
=
assetsUrl
;
window
.
SOURCEGRAPH_URL
=
url
;
window
.
SOURCEGRAPH_INTEGRATION
=
'
gitlab-integration
'
;
...
...
spec/frontend/sourcegraph/index_spec.js
0 → 100644
View file @
e9441729
import
initSourcegraph
from
'
~/sourcegraph
'
;
const
TEST_SOURCEGRAPH_URL
=
'
https://sourcegraph.test:9000
'
;
const
TEST_GITLAB_URL
=
'
https://gitlab.example.com/test
'
;
const
TEST_ASSET_HOST
=
'
https://gitlab-assets.example.com/
'
;
describe
(
'
~/sourcegraph/index
'
,
()
=>
{
let
origGon
;
beforeEach
(()
=>
{
origGon
=
window
.
gon
;
window
.
gon
=
{
sourcegraph
:
{},
gitlab_url
:
TEST_GITLAB_URL
,
};
});
afterEach
(()
=>
{
document
.
head
.
innerHTML
=
''
;
document
.
body
.
innerHTML
=
''
;
window
.
gon
=
origGon
;
});
const
findScript
=
()
=>
document
.
querySelector
(
'
script
'
);
it
(
'
with no sourcegraph url, does nothing
'
,
()
=>
{
initSourcegraph
();
expect
(
findScript
()).
toBeNull
();
});
describe
.
each
`
assetHost | assetsUrl | scriptPath
${
null
}
|
${
`
${
TEST_GITLAB_URL
}
/assets/webpack/sourcegraph/`
}
|
${
`
${
TEST_GITLAB_URL
}
/assets/webpack/sourcegraph/scripts/integration.bundle.js`
}
${
TEST_ASSET_HOST
}
|
${
`
${
TEST_ASSET_HOST
}
assets/webpack/sourcegraph/`
}
|
${
`
${
TEST_ASSET_HOST
}
assets/webpack/sourcegraph/scripts/integration.bundle.js`
}
`
(
'
loads sourcegraph (assetHost=$assetHost)
'
,
({
assetHost
,
assetsUrl
,
scriptPath
})
=>
{
beforeEach
(()
=>
{
Object
.
assign
(
window
.
gon
,
{
sourcegraph
:
{
url
:
TEST_SOURCEGRAPH_URL
,
},
asset_host
:
assetHost
,
});
initSourcegraph
();
});
it
(
'
should add sourcegraph config constants to window
'
,
()
=>
{
expect
(
window
).
toMatchObject
({
SOURCEGRAPH_ASSETS_URL
:
assetsUrl
,
SOURCEGRAPH_URL
:
TEST_SOURCEGRAPH_URL
,
SOURCEGRAPH_INTEGRATION
:
'
gitlab-integration
'
,
});
});
it
(
'
should add script tag
'
,
()
=>
{
expect
(
findScript
()).
toMatchObject
({
src
:
scriptPath
,
defer
:
true
,
type
:
'
application/javascript
'
,
});
});
});
});
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