2019-09-24 13:44:57 +00:00
|
|
|
import sinon from 'sinon';
|
|
|
|
import assert from 'assert';
|
2020-02-20 23:47:01 +00:00
|
|
|
import { fakeEmbark } from 'embark-testing';
|
2019-09-24 13:44:57 +00:00
|
|
|
import Communication from '../src/';
|
|
|
|
|
|
|
|
describe('stack/communication', () => {
|
|
|
|
|
2020-02-20 23:47:01 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-09-24 13:44:57 +00:00
|
|
|
let communication, communicationNodeLaunchFn, doneCb;
|
|
|
|
|
|
|
|
const { embark } = fakeEmbark();
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-10-02 10:06:46 +00:00
|
|
|
embark.setConfig({
|
|
|
|
communicationConfig: {
|
|
|
|
connection: {
|
2020-02-20 23:47:01 +00:00
|
|
|
host: 'localhost'
|
2019-10-02 10:06:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
embarkConfig: {}
|
|
|
|
});
|
|
|
|
|
2019-09-24 13:44:57 +00:00
|
|
|
communication = new Communication(embark);
|
|
|
|
|
|
|
|
communicationNodeLaunchFn = sinon.spy(done => {
|
|
|
|
embark.events.request('processes:register', 'communication', {
|
|
|
|
launchFn: cb => cb(),
|
2020-02-20 23:47:01 +00:00
|
|
|
stopFn: cb => cb()
|
2019-09-24 13:44:57 +00:00
|
|
|
});
|
|
|
|
|
2020-02-20 23:47:01 +00:00
|
|
|
embark.events.request('processes:launch', 'communication', _err => {
|
2019-09-24 13:44:57 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
doneCb = sinon.fake();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
embark.teardown();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it should register and start communication node', () => {
|
|
|
|
const communicationConfig = {
|
2019-10-21 17:23:43 +00:00
|
|
|
provider: 'whisper',
|
|
|
|
enabled: true
|
2019-09-24 13:44:57 +00:00
|
|
|
};
|
|
|
|
|
2020-02-20 23:47:01 +00:00
|
|
|
const processRegisterHandler = sinon.spy((_name, _fns) => {});
|
|
|
|
const processLaunchHandler = sinon.spy((_name, fn) => fn());
|
2019-09-24 13:44:57 +00:00
|
|
|
|
|
|
|
embark.events.setCommandHandler('processes:register', processRegisterHandler);
|
|
|
|
embark.events.setCommandHandler('processes:launch', processLaunchHandler);
|
|
|
|
|
|
|
|
embark.events.request('communication:node:register', 'whisper', communicationNodeLaunchFn);
|
|
|
|
embark.events.request('communication:node:start', communicationConfig, doneCb);
|
|
|
|
|
|
|
|
assert(communicationNodeLaunchFn.calledOnce);
|
|
|
|
assert(doneCb.calledOnce);
|
|
|
|
});
|
2019-10-02 10:06:46 +00:00
|
|
|
|
|
|
|
test('it should register artifact file from configuration', () => {
|
|
|
|
const pipelineRegisterHandler = sinon.spy((params, fn) => fn());
|
|
|
|
embark.events.setCommandHandler('pipeline:register', pipelineRegisterHandler);
|
|
|
|
embark.plugins.emitAndRunActionsForEvent('pipeline:generateAll:before', {}, doneCb);
|
|
|
|
|
|
|
|
assert(pipelineRegisterHandler.calledOnce);
|
|
|
|
assert(doneCb.calledOnce);
|
|
|
|
});
|
2019-09-24 13:44:57 +00:00
|
|
|
});
|