Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: allow only by object (#407)
Browse files Browse the repository at this point in the history
The only option will now accept an object for onlying a specific test.

Previously you could only do this to only run a specific test:

```js
{
  only: ['should test a thing']
}
```

Now you can do this:

```js
{
  only: [{
    name: 'should test a thing',
    reason: 'because development' // optional!
  }]
}
```

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
Alan Shaw authored Dec 14, 2018
1 parent 570aaf0 commit 1766ef4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions js/src/utils/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ function getIt (config) {
}

if (Array.isArray(config.only)) {
if (config.only.includes(name)) return it.only(name, impl) // eslint-disable-line
const only = config.only
.map((o) => isObject(o) ? o : { name: o })
.find((o) => o.name === name)

if (only) {
if (only.reason) name = `${name} (${only.reason})`
return it.only(name, impl) // eslint-disable-line no-only-tests/no-only-tests
}
}

it(name, impl)
}

_it.skip = it.skip
_it.only = it.only // eslint-disable-line
_it.only = it.only // eslint-disable-line no-only-tests/no-only-tests

return _it
}
Expand Down

0 comments on commit 1766ef4

Please sign in to comment.