mirror of https://github.com/embarklabs/embark.git
feat(@embark/testing): add missing APIs to register console commands and API calls
This commit also introduces an IPC mock object, needed for Embark to work as a dependency within the console module
This commit is contained in:
parent
e8b5c7ab89
commit
bef582d312
|
@ -51,6 +51,7 @@
|
||||||
"async": "2.6.1",
|
"async": "2.6.1",
|
||||||
"core-js": "3.4.3",
|
"core-js": "3.4.3",
|
||||||
"refute": "1.0.2",
|
"refute": "1.0.2",
|
||||||
|
"fs-extra": "8.1.0",
|
||||||
"sinon": "7.4.2"
|
"sinon": "7.4.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
class Embark {
|
class Embark {
|
||||||
constructor(events, plugins, config) {
|
constructor(events, plugins, config) {
|
||||||
|
@ -6,6 +7,7 @@ class Embark {
|
||||||
this.plugins = plugins;
|
this.plugins = plugins;
|
||||||
this.config = config || {};
|
this.config = config || {};
|
||||||
this.assert = new EmbarkAssert(this);
|
this.assert = new EmbarkAssert(this);
|
||||||
|
this.fs = fs;
|
||||||
|
|
||||||
this.logger = {
|
this.logger = {
|
||||||
debug: sinon.fake(),
|
debug: sinon.fake(),
|
||||||
|
@ -19,6 +21,10 @@ class Embark {
|
||||||
this.plugins.registerActionForEvent(name, cb);
|
this.plugins.registerActionForEvent(name, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerConsoleCommand(options) {
|
||||||
|
this.plugins.registerConsoleCommand(options);
|
||||||
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
this.config = {};
|
this.config = {};
|
||||||
this.plugins.teardown();
|
this.plugins.teardown();
|
||||||
|
|
|
@ -7,6 +7,16 @@ const fakeEmbark = (config) => {
|
||||||
const events = new Events();
|
const events = new Events();
|
||||||
const plugins = new Plugins();
|
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);
|
const embark = new Embark(events, plugins, config);
|
||||||
return {
|
return {
|
||||||
embark,
|
embark,
|
||||||
|
|
|
@ -27,6 +27,10 @@ class Plugins {
|
||||||
this.plugin.registerActionForEvent(name, cb);
|
this.plugin.registerActionForEvent(name, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerConsoleCommand(options) {
|
||||||
|
this.plugin.registerConsoleCommand(options);
|
||||||
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
this.plugin.listeners = {};
|
this.plugin.listeners = {};
|
||||||
this.plugins.forEach(plugin => plugin.teardown());
|
this.plugins.forEach(plugin => plugin.teardown());
|
||||||
|
@ -49,6 +53,7 @@ class Plugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.listeners = {};
|
this.listeners = {};
|
||||||
this.pluginTypes = [];
|
this.pluginTypes = [];
|
||||||
|
this.console = [];
|
||||||
this.compilers = [];
|
this.compilers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +82,15 @@ class Plugin {
|
||||||
this.addPluginType('compilers');
|
this.addPluginType('compilers');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerAPICall(_method, _endpoint, _callback) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
registerConsoleCommand(options) {
|
||||||
|
this.console.push(options);
|
||||||
|
this.addPluginType('console');
|
||||||
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
this.compilers = [];
|
this.compilers = [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue