diff --git a/test/before.js b/test/before.js index 66f18cc3..b9167707 100644 --- a/test/before.js +++ b/test/before.js @@ -14,8 +14,12 @@ const {assign} = Object; const pathConfig = os.homedir() + '/.cloudcmd.json'; const currentConfig = readjson.sync.try(pathConfig); -module.exports = (_config, _plugins, _fn) => { - const {config, plugins, fn} = parse(_config, _plugins, _fn); +module.exports = (options, fn = options) => { + if (fn === options) { + options = {}; + } + + const {config, plugins} = options; const app = express(); const server = http.createServer(app); @@ -46,25 +50,3 @@ function defaultConfig() { }; } -function parse(config, plugins, fn) { - if (typeof plugins === 'undefined') - return { - fn: config, - config: undefined, - plugins: undefined - } - - if (typeof fn === 'undefined') - return { - config, - fn: plugins, - plugins: undefined - } - - return { - config, - plugins, - fn - }; -} - diff --git a/test/console.js b/test/console.js index 0e7d6bc3..26a5e4e8 100644 --- a/test/console.js +++ b/test/console.js @@ -21,7 +21,7 @@ test('cloudcmd: console: enabled by default', (t) => { test('cloudcmd: console: enabled', (t) => { const config = {console: true}; - before(config, (port, after) => { + before({config}, (port, after) => { const socket = io(`http://localhost:${port}/console`) socket.once('data', (data) => { @@ -36,7 +36,7 @@ test('cloudcmd: console: enabled', (t) => { test('cloudcmd: console: disabled', (t) => { const config = {console: false}; - before(config, (port, after) => { + before({config}, (port, after) => { const socket = io(`http://localhost:${port}/console`); socket.on('error', (error) => { diff --git a/test/plugins.js b/test/plugins.js index 339c8cdf..11a999ab 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -17,10 +17,9 @@ const get = promisify((url, fn) => { }); test('cloudcmd: plugins', (t) => { - const config = {}; const plugins = []; - before(config, plugins, (port, after) => { + before({plugins}, (port, after) => { get(`http://localhost:${port}/plugins.js`) .then(warp(_pullout, 'string')) .then((content) => { @@ -35,12 +34,11 @@ test('cloudcmd: plugins', (t) => { }); test('cloudcmd: plugins', (t) => { - const config = {}; const plugins = [ __filename ]; - before(config, plugins, (port, after) => { + before({plugins}, (port, after) => { get(`http://localhost:${port}/plugins.js`) .then(warp(_pullout, 'string')) .then((content) => { @@ -56,7 +54,6 @@ test('cloudcmd: plugins', (t) => { }); test('cloudcmd: plugins: load error', (t) => { - const config = {}; const noEntry = __filename + Math.random(); const plugins = [ __filename, @@ -65,7 +62,7 @@ test('cloudcmd: plugins: load error', (t) => { const msg = `ENOENT: no such file or directory, open '${noEntry}'`; - before(config, plugins, (port, after) => { + before({plugins}, (port, after) => { get(`http://localhost:${port}/plugins.js`) .then(warp(_pullout, 'string')) .then((content) => { diff --git a/test/rest/config.js b/test/rest/config.js index 8b187f2d..4e854174 100644 --- a/test/rest/config.js +++ b/test/rest/config.js @@ -57,9 +57,11 @@ test('cloudcmd: rest: config: patch', (t) => { }); test('cloudcmd: rest: config: patch: no configDialog', (t) => { - const configDialog = false; + const config = { + configDialog: false + }; - before({configDialog}, (port, after) => { + before({config}, (port, after) => { const json = { ip: null }; @@ -78,9 +80,11 @@ test('cloudcmd: rest: config: patch: no configDialog', (t) => { }); test('cloudcmd: rest: config: patch: no configDialog: statusCode', (t) => { - const configDialog = false; + const config = { + configDialog: false + }; - before({configDialog}, (port, after) => { + before({config}, (port, after) => { const json = { ip: null }; diff --git a/test/rest/pack.js b/test/rest/pack.js index 94047b9e..971fb7e9 100644 --- a/test/rest/pack.js +++ b/test/rest/pack.js @@ -33,8 +33,9 @@ const put = promisify((options, fn) => { }); test('cloudcmd: rest: pack: tar: get', (t) => { - const options = {packer: 'tar'}; - before(options, (port, after) => { + const config = {packer: 'tar'}; + + before({config}, (port, after) => { get(`http://localhost:${port}/api/v1/pack/fixture/pack`) .then((pack) => { const extract = tar.extract(); @@ -57,8 +58,9 @@ test('cloudcmd: rest: pack: tar: get', (t) => { }); test('cloudcmd: rest: pack: tar: put: file', (t) => { - const options = {packer: 'tar'}; - before(options, (port, after) => { + const config = {packer: 'tar'}; + + before({config}, (port, after) => { const name = String(Math.random()) + '.tar.gz'; const options = getPackOptions(port, name); @@ -110,8 +112,9 @@ test('cloudcmd: rest: pack: tar: put: response', (t) => { }); test('cloudcmd: rest: pack: tar: put: error', (t) => { - const options = {packer: 'tar'}; - before(options, (port, after) => { + const config = {packer: 'tar'}; + + before({config}, (port, after) => { const options = getPackOptions(port, 'name', [ 'not found' ]); @@ -131,8 +134,8 @@ test('cloudcmd: rest: pack: tar: put: error', (t) => { }); test('cloudcmd: rest: pack: zip: get', (t) => { - const options = {packer: 'zip'}; - before(options, (port, after) => { + const config = {packer: 'zip'}; + before({config}, (port, after) => { get(`http://localhost:${port}/api/v1/pack/fixture/pack`) .then(_pullout) .then((pack) => { @@ -147,8 +150,9 @@ test('cloudcmd: rest: pack: zip: get', (t) => { }); test('cloudcmd: rest: pack: zip: put: file', (t) => { - const options = {packer: 'zip'}; - before(options, (port, after) => { + const config = {packer: 'zip'}; + + before({config}, (port, after) => { const name = String(Math.random()) + '.zip'; const options = getPackOptions(port, name); @@ -170,8 +174,9 @@ test('cloudcmd: rest: pack: zip: put: file', (t) => { }); test('cloudcmd: rest: pack: zip: put: response', (t) => { - const options = {packer: 'zip'}; - before(options, (port, after) => { + const config = {packer: 'zip'}; + + before({config}, (port, after) => { const name = String(Math.random()) + '.zip'; const options = getPackOptions(port, name); @@ -192,8 +197,8 @@ test('cloudcmd: rest: pack: zip: put: response', (t) => { }); test('cloudcmd: rest: pack: zip: put: error', (t) => { - const options = {packer: 'zip'}; - before(options, (port, after) => { + const config = {packer: 'zip'}; + before({config}, (port, after) => { const options = getPackOptions(port, 'name', [ 'not found' ]);