Skip to content

Commit

Permalink
feat: Allow for passing of all sorts of client.args again.
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 14, 2014
1 parent b658ec9 commit f0bd531
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,14 @@ karma: {
The build would then run `grunt karma:continuous` to start PhantomJS,
run tests, and close PhantomJS.

## Using grep
When using `[karma-mocha] >= 0.1.3` you can use Mocha's `grep` feature
on the commandline like this:
## Using additional client.args
You can pass arbitrary `client.args` through the commandline like this:

```bash
$ grunt karma:dev watch --grep=mypattern
$ grunt karma:dev watch --grep=multiple,patterns,work
```


## License
MIT License

Expand Down
20 changes: 12 additions & 8 deletions tasks/grunt-karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ module.exports = function(grunt) {
if (!options.client) {
options.client = {};
}
// Allow for passing of `--grep=x` or `--grep=x,two`
var args = grunt.option('grep')
if (args) {
args = _.map(args.split(','), function (arg) {
return '--grep=' + arg;
});
}
// Allow for passing cli arguments to `client.args` using `--grep=x`
var args = parseArgs(process.argv.slice(2));
if (_.isArray(options.client.args)) {
options.client.args = options.client.args.concat(args);
} else {
Expand All @@ -50,7 +45,7 @@ module.exports = function(grunt) {
data.browsers = this.data.browsers || data.browsers;

// Merge client.args
if (_.isArray(this.data.client.args)) {
if (this.data.client && _.isArray(this.data.client.args)) {
data.client.args = this.data.client.args.concat(options.client.args);
}

Expand Down Expand Up @@ -80,3 +75,12 @@ module.exports = function(grunt) {
};

function finished(code){ return this(code === 0); }


// Parse out all cli arguments in the form of `--arg=something` or
// `-c=otherthing` and return the array.
function parseArgs(args) {
return _.filter(args, function (arg) {
return arg.match(/^--?/);
});
}

0 comments on commit f0bd531

Please sign in to comment.