Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
fix: grep for grunt-karma
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimr committed Feb 22, 2014
1 parent 7ab966b commit 70aef65
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/adapter.js
node_modules
.idea
25 changes: 20 additions & 5 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
};
Expand Down
12 changes: 12 additions & 0 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 70aef65

Please sign in to comment.