diff --git a/lib/adapter.js b/lib/adapter.js index 1600d8d..65a7807 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -21,6 +21,10 @@ const EVENTS = { 'pending': 'test:pending' } +const allowedKeys = Object.keys(INTERFACES).reduce((prev, curr) => { + return prev.concat(INTERFACES[curr]) +}, []) + const NOOP = function () {} const SETTLE_TIMEOUT = 5000 @@ -72,7 +76,7 @@ class MochaAdapter { async run () { let {mochaOpts} = this.config - if (typeof mochaOpts.ui !== 'string' || !INTERFACES[mochaOpts.ui]) { + if (typeof mochaOpts.ui !== 'string') { mochaOpts.ui = 'bdd' } @@ -89,9 +93,16 @@ class MochaAdapter { context, file, mocha, options: mochaOpts }) - INTERFACES[mochaOpts.ui].forEach((fnName) => { - let testCommand = INTERFACES[mochaOpts.ui][2] + let interfaceCommandsArray = INTERFACES[mochaOpts.ui] + let testCommand + if (!interfaceCommandsArray) { + interfaceCommandsArray = Object.keys(global).filter(key => allowedKeys.indexOf(key) > -1) + testCommand = interfaceCommandsArray.indexOf('it') > -1 ? 'it' : 'test' + } else { + testCommand = interfaceCommandsArray[2] + } + interfaceCommandsArray.forEach((fnName) => { runInFiberContext( [testCommand, testCommand + '.only'], this.config.beforeHook,