Skip to content

Commit

Permalink
Adding support for custom interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dstgermain committed Jan 19, 2018
1 parent f529e40 commit eaa2dd8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
}

Expand All @@ -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,
Expand Down

0 comments on commit eaa2dd8

Please sign in to comment.