SymphonyElectron/spec/c9PipeHandler.spec.ts
Robin Westberg 8a7d5c0fcf
SDA-3770 Add support for optional symphony-c9-shell (#1446)
* Add support for optional symphony-c9-shell
2022-07-05 09:43:35 +02:00

45 lines
1.3 KiB
TypeScript

import { connectC9Pipe } from '../src/app/c9-pipe-handler';
import { createConnection } from 'net';
jest.mock('net');
describe('C9 pipe handler', () => {
const webContentsMocked = { send: jest.fn() };
const mockConnectionEvents = new Map<String, any>();
const mockCreateConnection = (createConnection as unknown) as jest.MockInstance<
typeof createConnection
>;
beforeEach(() => {
jest.clearAllMocks().resetModules();
mockCreateConnection.mockImplementation((_path, onConnect: () => void) => {
onConnect();
return {
on: (event, callback) => {
mockConnectionEvents.set(event, callback);
},
destroy: jest.fn(),
};
});
});
describe('connect', () => {
it('success', () => {
connectC9Pipe(webContentsMocked as any, 'symphony-c9-test');
expect(webContentsMocked.send).toHaveBeenCalledWith(
'c9-pipe-event',
expect.objectContaining({ event: 'connected' }),
);
});
it('data', () => {
connectC9Pipe(webContentsMocked as any, 'symphony-c9-test');
mockConnectionEvents.get('data')('the data');
expect(webContentsMocked.send).toHaveBeenCalledWith(
'c9-pipe-event',
expect.objectContaining({ event: 'data', arg: 'the data' }),
);
});
});
});