From 70aef655d7d0d2a83f18423496b6ebca45e195b1 Mon Sep 17 00:00:00 2001 From: Maksim Ryzhikov Date: Sat, 22 Feb 2014 17:16:35 +0400 Subject: [PATCH] fix: grep for grunt-karma --- .gitignore | 1 + src/adapter.js | 25 ++++++++++++++++++++----- test/adapter.spec.js | 12 ++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1d40ef2..83c5e44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ lib/adapter.js node_modules +.idea diff --git a/src/adapter.js b/src/adapter.js index 8055b31..9e39b92 100644 --- a/src/adapter.js +++ b/src/adapter.js @@ -80,12 +80,27 @@ var createMochaReporterConstructor = function(tc) { var createMochaStartFn = function(mocha) { return function(config) { - if (config && config.args) { - config.args.join(' ').replace(/--grep[\s|=]+(\S+)?\s*/, function(match, grep) { - mocha.grep(grep); - return match; - }); + var clientArguments; + config = config || {}; + clientArguments = config.args; + + if (clientArguments) { + if (Object.prototype.toString.call(clientArguments) === '[object Array]') { + clientArguments.join(' ').replace(/--grep[\s|=]+(\S+)?\s*/, function(match, grep) { + mocha.grep(grep); + return match; + }); + } + + /** + * TODO(maksimrv): remove when karma-grunt plugin will pass + * clientArguments how Array + */ + if (clientArguments.grep) { + mocha.grep(clientArguments.grep); + } } + mocha.run(); }; }; diff --git a/test/adapter.spec.js b/test/adapter.spec.js index bd5ea99..67125c4 100644 --- a/test/adapter.spec.js +++ b/test/adapter.spec.js @@ -194,6 +194,18 @@ describe('adapter mocha', function() { expect(this.mockMocha.grep).toHaveBeenCalledWith('test'); }); + it('should pass grep argument to mocha if config.args contains property grep', function(){ + spyOn(this.mockMocha, 'grep'); + + createMochaStartFn(this.mockMocha)({ + args: { + grep: 'test' + } + }); + + expect(this.mockMocha.grep).toHaveBeenCalledWith('test'); + }); + it('should not require client arguments', function() { var that = this;