From 1766ef4300455fffbb815ad1dcb1b717ccc21e80 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 14 Dec 2018 18:14:52 +0000 Subject: [PATCH] fix: allow only by object (#407) 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 --- js/src/utils/mocha.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/js/src/utils/mocha.js b/js/src/utils/mocha.js index c21ae873..d9fe0fb6 100644 --- a/js/src/utils/mocha.js +++ b/js/src/utils/mocha.js @@ -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 }