Commit 90882908 authored by Paul Slaughter's avatar Paul Slaughter

Update IDE file mirror service (ce utils)

**Notes:**
This module is a client to the webide-file-sync service.
https://gitlab.com/gitlab-org/webide-file-sync
parent f08abfcc
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