test(@embark/commmunication): add test for artifact generation

This also makes `fakeEmbark` configurable
This commit is contained in:
Pascal Precht 2019-10-02 12:06:46 +02:00 committed by Pascal Precht
parent 67207a239a
commit 7ea9aa417d
3 changed files with 27 additions and 7 deletions

View File

@ -10,6 +10,15 @@ describe('stack/communication', () => {
const { embark } = fakeEmbark();
beforeEach(() => {
embark.setConfig({
communicationConfig: {
connection: {
host: 'localhost',
}
},
embarkConfig: {}
});
communication = new Communication(embark);
communicationNodeLaunchFn = sinon.spy(done => {
@ -48,4 +57,13 @@ describe('stack/communication', () => {
assert(communicationNodeLaunchFn.calledOnce);
assert(doneCb.calledOnce);
});
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);
});
});

View File

@ -1,13 +1,10 @@
const sinon = require('sinon');
class Embark {
constructor(events, plugins) {
constructor(events, plugins, config) {
this.events = events;
this.plugins = plugins;
this.config = {
blockchainConfig: {}
};
this.config = config || {};
this.assert = new EmbarkAssert(this);
this.logger = {
@ -23,8 +20,13 @@ class Embark {
}
teardown() {
this.config = {};
this.plugins.teardown();
}
setConfig(config) {
this.config = config;
}
}
class EmbarkAssert {

View File

@ -2,11 +2,11 @@ const Embark = require('./embark');
const Events = require('./events');
const Plugins = require('./plugin');
const fakeEmbark = () => {
const fakeEmbark = (config) => {
const events = new Events();
const plugins = new Plugins();
const embark = new Embark(events, plugins);
const embark = new Embark(events, plugins, config);
return {
embark,
plugins