Skip to content

Commit

Permalink
feat(@embark/testing): add missing APIs to register console commands …
Browse files Browse the repository at this point in the history
…and API calls

This commit also introduces an IPC mock object, needed for Embark to work as a dependency
within the console module
  • Loading branch information
0x-r4bbit authored and iurimatias committed Jan 23, 2020
1 parent e8b5c7a commit bef582d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/utils/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"async": "2.6.1",
"core-js": "3.4.3",
"refute": "1.0.2",
"fs-extra": "8.1.0",
"sinon": "7.4.2"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions packages/utils/testing/src/lib/embark.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const sinon = require('sinon');
import fs from 'fs-extra';

class Embark {
constructor(events, plugins, config) {
this.events = events;
this.plugins = plugins;
this.config = config || {};
this.assert = new EmbarkAssert(this);
this.fs = fs;

this.logger = {
debug: sinon.fake(),
Expand All @@ -19,6 +21,10 @@ class Embark {
this.plugins.registerActionForEvent(name, cb);
}

registerConsoleCommand(options) {
this.plugins.registerConsoleCommand(options);
}

teardown() {
this.config = {};
this.plugins.teardown();
Expand Down
10 changes: 10 additions & 0 deletions packages/utils/testing/src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ const fakeEmbark = (config) => {
const events = new Events();
const plugins = new Plugins();

const ipc = {
isServer: () => { return true; },
broadcast: () => {},
on: () => {},
isClient: () => { return false; }
};

config = config || {};
config.ipc = config.ipc || ipc;

const embark = new Embark(events, plugins, config);
return {
embark,
Expand Down
14 changes: 14 additions & 0 deletions packages/utils/testing/src/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Plugins {
this.plugin.registerActionForEvent(name, cb);
}

registerConsoleCommand(options) {
this.plugin.registerConsoleCommand(options);
}

teardown() {
this.plugin.listeners = {};
this.plugins.forEach(plugin => plugin.teardown());
Expand All @@ -49,6 +53,7 @@ class Plugin {
constructor() {
this.listeners = {};
this.pluginTypes = [];
this.console = [];
this.compilers = [];
}

Expand Down Expand Up @@ -77,6 +82,15 @@ class Plugin {
this.addPluginType('compilers');
}

registerAPICall(_method, _endpoint, _callback) {

}

registerConsoleCommand(options) {
this.console.push(options);
this.addPluginType('console');
}

teardown() {
this.compilers = [];
}
Expand Down

0 comments on commit bef582d

Please sign in to comment.