From 4ccda54a350ee2ce1e4bf1e6c2839aed84418715 Mon Sep 17 00:00:00 2001 From: Alexej Yaroshevich Date: Sat, 14 Feb 2015 23:31:29 +0400 Subject: [PATCH] runner: allow to pass grep via options or env Fixes #61 Closes gh-62 --- lib/plugin.js | 5 ++++- lib/runner.js | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index c59ab5e..0110eee 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -83,7 +83,10 @@ module.exports = function (helper) { referenceDirSuffixes: options.referenceDirSuffixes || ['tmpl-specs'], saveHtml: (typeof process.env.BEM_TMPL_SPECS_SAVE_HTML === 'undefined' ? options.saveHtml : - process.env.BEM_TMPL_SPECS_SAVE_HTML) || false + process.env.BEM_TMPL_SPECS_SAVE_HTML) || false, + grep: (typeof process.env.BEM_TMPL_SPECS_GREP === 'undefined' ? + options.grep : + process.env.BEM_TMPL_SPECS_GREP) || false }; }, diff --git a/lib/runner.js b/lib/runner.js index 261450b..27d2e49 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -10,7 +10,8 @@ exports.run = function (files, opts) { var defer = vow.defer(), mocha = new Mocha({ ui: 'bdd', - reporter: runReporters + reporter: runReporters, + grep: parseRe(opts.grep) }); mocha.files = files; @@ -96,3 +97,16 @@ function saveCoverageReport(coverage, opts) { }); return defer.promise(); } + +var regexpRe = /^\/(.+)\/(i?)$/; +function parseRe(str) { + if (typeof str !== 'string') { + return str; + } + + var m = regexpRe.exec(str); + if (!m) { + return str; + } + return new RegExp(m[1], m[2]); +}