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
This commit is contained in:
commit
e307281147
|
@ -1,3 +1,5 @@
|
|||
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 };
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
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',
|
||||
protocol: 'https:',
|
||||
},
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue