Loading src/common/gitlab/api/action_cable.test.ts +17 −0 Original line number Diff line number Diff line import WebSocket from 'ws'; import { createCable } from '@anycable/core'; import { connectToCable } from './action_cable'; import { log } from '../../log'; const cableMock = { connect: jest.fn(), Loading @@ -10,6 +11,12 @@ jest.mock('@anycable/core', () => ({ createCable: jest.fn().mockImplementation(() => cableMock), })); jest.mock('../../log', () => ({ log: { error: jest.fn(), }, })); describe('connectToCable', () => { it('creates new anycable cable and connects', async () => { const connection = await connectToCable('https://foo.bar'); Loading Loading @@ -38,4 +45,14 @@ describe('connectToCable', () => { websocketOptions: additionalOptions, }); }); it('logs error is connection to cable fails', async () => { const err = new Error('Foo Bar'); cableMock.connect = jest.fn(() => { throw err; }); await connectToCable('http://foo.bar:3000'); expect(log.error).toHaveBeenCalledWith(err); }); }); src/common/gitlab/api/action_cable.ts +5 −0 Original line number Diff line number Diff line import WebSocket from 'isomorphic-ws'; import { createCable } from '@anycable/core'; import { log } from '../../log'; export const connectToCable = async (instanceUrl: string, websocketOptions?: object) => { const cableUrl = new URL('/-/cable', instanceUrl); Loading @@ -10,7 +11,11 @@ export const connectToCable = async (instanceUrl: string, websocketOptions?: obj websocketOptions, }); try { await cable.connect(); } catch (e) { log.error(e); } return cable; }; Loading
src/common/gitlab/api/action_cable.test.ts +17 −0 Original line number Diff line number Diff line import WebSocket from 'ws'; import { createCable } from '@anycable/core'; import { connectToCable } from './action_cable'; import { log } from '../../log'; const cableMock = { connect: jest.fn(), Loading @@ -10,6 +11,12 @@ jest.mock('@anycable/core', () => ({ createCable: jest.fn().mockImplementation(() => cableMock), })); jest.mock('../../log', () => ({ log: { error: jest.fn(), }, })); describe('connectToCable', () => { it('creates new anycable cable and connects', async () => { const connection = await connectToCable('https://foo.bar'); Loading Loading @@ -38,4 +45,14 @@ describe('connectToCable', () => { websocketOptions: additionalOptions, }); }); it('logs error is connection to cable fails', async () => { const err = new Error('Foo Bar'); cableMock.connect = jest.fn(() => { throw err; }); await connectToCable('http://foo.bar:3000'); expect(log.error).toHaveBeenCalledWith(err); }); });
src/common/gitlab/api/action_cable.ts +5 −0 Original line number Diff line number Diff line import WebSocket from 'isomorphic-ws'; import { createCable } from '@anycable/core'; import { log } from '../../log'; export const connectToCable = async (instanceUrl: string, websocketOptions?: object) => { const cableUrl = new URL('/-/cable', instanceUrl); Loading @@ -10,7 +11,11 @@ export const connectToCable = async (instanceUrl: string, websocketOptions?: obj websocketOptions, }); try { await cable.connect(); } catch (e) { log.error(e); } return cable; };