Commit 01f8cb8e authored by Paul Slaughter's avatar Paul Slaughter

Revert "Merge branch '233447-fix-sourcegraph-not-loading-from-asset-host' into 'master'"

This reverts merge request !45850
parent 5ece8a52
import { joinPaths } from '~/lib/utils/url_utility';
function loadScript(path) {
const script = document.createElement('script');
script.type = 'application/javascript';
......@@ -19,11 +17,10 @@ export default function initSourcegraph() {
return;
}
const base = gon.asset_host || gon.gitlab_url;
const assetsUrl = joinPaths(base, '/assets/webpack/sourcegraph/');
const scriptPath = joinPaths(assetsUrl, 'scripts/integration.bundle.js');
const assetsUrl = new URL('/assets/webpack/sourcegraph/', window.location.href);
const scriptPath = new URL('scripts/integration.bundle.js', assetsUrl).href;
window.SOURCEGRAPH_ASSETS_URL = assetsUrl;
window.SOURCEGRAPH_ASSETS_URL = assetsUrl.href;
window.SOURCEGRAPH_URL = url;
window.SOURCEGRAPH_INTEGRATION = 'gitlab-integration';
......
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',
});
});
});
});
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