From bef582d312c5c3463ab9c91fcf906bb98e22ec27 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 20 Jan 2020 16:43:19 +0100 Subject: [PATCH] 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 --- packages/utils/testing/package.json | 1 + packages/utils/testing/src/lib/embark.js | 6 ++++++ packages/utils/testing/src/lib/index.js | 10 ++++++++++ packages/utils/testing/src/lib/plugin.js | 14 ++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/packages/utils/testing/package.json b/packages/utils/testing/package.json index fb8a140c5..5cb500150 100644 --- a/packages/utils/testing/package.json +++ b/packages/utils/testing/package.json @@ -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": { diff --git a/packages/utils/testing/src/lib/embark.js b/packages/utils/testing/src/lib/embark.js index 7be257e67..7b45accb9 100644 --- a/packages/utils/testing/src/lib/embark.js +++ b/packages/utils/testing/src/lib/embark.js @@ -1,4 +1,5 @@ const sinon = require('sinon'); +import fs from 'fs-extra'; class Embark { constructor(events, plugins, config) { @@ -6,6 +7,7 @@ class Embark { this.plugins = plugins; this.config = config || {}; this.assert = new EmbarkAssert(this); + this.fs = fs; this.logger = { debug: sinon.fake(), @@ -19,6 +21,10 @@ class Embark { this.plugins.registerActionForEvent(name, cb); } + registerConsoleCommand(options) { + this.plugins.registerConsoleCommand(options); + } + teardown() { this.config = {}; this.plugins.teardown(); diff --git a/packages/utils/testing/src/lib/index.js b/packages/utils/testing/src/lib/index.js index b42d46c08..a69d42ac9 100644 --- a/packages/utils/testing/src/lib/index.js +++ b/packages/utils/testing/src/lib/index.js @@ -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, diff --git a/packages/utils/testing/src/lib/plugin.js b/packages/utils/testing/src/lib/plugin.js index e42e6034c..3fe250945 100644 --- a/packages/utils/testing/src/lib/plugin.js +++ b/packages/utils/testing/src/lib/plugin.js @@ -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()); @@ -49,6 +53,7 @@ class Plugin { constructor() { this.listeners = {}; this.pluginTypes = []; + this.console = []; this.compilers = []; } @@ -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 = []; }