Commit e3072811 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'ce-5276-3-update-ide-diff-and-mirror-modules' into 'master'

[CE for Part 3] Update IDE file mirror service (ce utils)

See merge request gitlab-org/gitlab-ce!29360
parents 3017d2a5 90882908
import { join as joinPaths } from 'path';
// Returns an array containing the value(s) of the
// of the key passed as an argument
export function getParameterValues(sParam) {
......@@ -157,4 +159,12 @@ export function isSafeURL(url) {
}
}
export { join as joinPaths } from 'path';
export function getWebSocketProtocol() {
return window.location.protocol.replace('http', 'ws');
}
export function getWebSocketUrl(path) {
return `${getWebSocketProtocol()}//${joinPaths(window.location.host, path)}`;
}
export { joinPaths };
import * as urlUtils from '~/lib/utils/url_utility';
const setWindowLocation = value => {
Object.defineProperty(window, 'location', {
writable: true,
value,
});
};
describe('URL utility', () => {
describe('webIDEUrl', () => {
afterEach(() => {
......@@ -110,12 +117,9 @@ describe('URL utility', () => {
describe('getBaseURL', () => {
beforeEach(() => {
global.window = Object.create(window);
Object.defineProperty(window, 'location', {
value: {
host: 'gitlab.com',
setWindowLocation({
protocol: 'https:',
},
host: 'gitlab.com',
});
});
......@@ -191,4 +195,32 @@ describe('URL utility', () => {
});
});
});
describe('getWebSocketProtocol', () => {
it.each`
protocol | expectation
${'http:'} | ${'ws:'}
${'https:'} | ${'wss:'}
`('returns "$expectation" with "$protocol" protocol', ({ protocol, expectation }) => {
setWindowLocation({
protocol,
host: 'example.com',
});
expect(urlUtils.getWebSocketProtocol()).toEqual(expectation);
});
});
describe('getWebSocketUrl', () => {
it('joins location host to path', () => {
setWindowLocation({
protocol: 'http:',
host: 'example.com',
});
const path = '/lorem/ipsum?a=bc';
expect(urlUtils.getWebSocketUrl(path)).toEqual('ws://example.com/lorem/ipsum?a=bc');
});
});
});
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