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

Commit

Permalink
fix: restores the ability to use grep
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimr committed Feb 18, 2014
1 parent 45553a2 commit 2787886
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ module.exports = function(config) {
};
```

If you want run only some tests matching a given pattern you can
do this in the following way

```sh
karma start &
karma run -- --grep=<pattern>
```

`--grep` argument pass directly to mocha

----

For more information on Karma see the [homepage].
Expand Down
7 changes: 5 additions & 2 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ var createMochaReporterConstructor = function(tc) {

var createMochaStartFn = function(mocha) {
return function(config) {
if(config && config.args && config.args.grep){
mocha.grep(config.args.grep);
if (config && config.args) {
config.args.join(' ').replace(/--grep[\s|=]+(\S+)?\s*/, function(match, grep) {
mocha.grep(grep);
return match;
});
}
mocha.run();
};
Expand Down
41 changes: 39 additions & 2 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('adapter mocha', function() {

expect(tc.result).toHaveBeenCalled();
});

it('should end the test only once on uncaught exceptions', function() {
spyOn(tc, 'result').andCallFake(function(result) {
expect(result.success).toBe(false);
Expand All @@ -163,6 +163,43 @@ describe('adapter mocha', function() {

expect(tc.result.calls.length).toBe(1);
});
})
});
});

describe('createMochaStartFn', function() {
beforeEach(function() {
this.mockMocha = {
grep: function(){},
run: function(){},
};
});

it('should pass grep argument to mocha', function() {
spyOn(this.mockMocha, 'grep');

createMochaStartFn(this.mockMocha)({
args: ['--grep', 'test']
});

expect(this.mockMocha.grep).toHaveBeenCalledWith('test');
});

it('should pass grep argument to mocha if we called the run with --grep=xxx', 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;

expect(function(){
createMochaStartFn(that.mockMocha)({});
}).not.toThrow();
});
});
});

0 comments on commit 2787886

Please sign in to comment.