Skip to content

Commit

Permalink
fix(adapter): allow grep option to work regardless of position
Browse files Browse the repository at this point in the history
Fix issue where the regular expression would only match if the grep
option was the final argument

Closes #102
  • Loading branch information
Arthur Thornton committed Feb 1, 2016
1 parent c365021 commit e8f2c6e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,27 @@ function KarmaReporter(tc, jasmineEnv) {
* @return {string} The value of grep option by default empty string
*/
var getGrepOption = function(clientArguments) {
var clientArgString = clientArguments || '';
var grepRegex = /^--grep=(.*)$/;

if (Object.prototype.toString.call(clientArguments) === '[object Array]') {
clientArgString = clientArguments.join('=');
}
var indexOfGrep = clientArguments.indexOf('--grep');

if(indexOfGrep !== -1) {
return clientArguments[indexOfGrep + 1];
}

var match = /--grep=(.*)/.exec(clientArgString);
return match ? match[1] : '';
return clientArguments
.filter(function(arg) {
return grepRegex.test(arg);
})
.map(function(arg) {
return arg.replace(grepRegex, '$1');
})[0] || '';
} else if (typeof clientArguments === 'string') {
var match = /--grep=([^=]+)/.exec(clientArguments);

return match ? match[1] : '';
}
};

/**
Expand Down
4 changes: 4 additions & 0 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ describe('jasmine adapter', function(){
it('should get grep option from args if args is string', function() {
expect(getGrepOption('--grep=test')).toEqual('test');
});

it('should get grep option from args if second arg', function() {
expect(getGrepOption(['--arg1', 'value1', '--grep', 'grepValue'])).toEqual('grepValue');
});
});


Expand Down

0 comments on commit e8f2c6e

Please # to comment.