Skip to content

Commit

Permalink
support for config sharing via options
Browse files Browse the repository at this point in the history
  • Loading branch information
geddski committed Feb 19, 2013
1 parent a5c4a1d commit c54f600
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
9 changes: 5 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
module.exports = function(grunt) {
grunt.initConfig({
testacular: {
continuous: {
options: {
configFile: 'testacular.conf.js',
singleRun: true,
browsers: ['Chrome']
},
continuous: {
singleRun: true
},
dev: {
configFile: 'testacular.conf.js',
browsers: ['Chrome']
reporters: 'dots'
}
}
});
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ testacular: {
}
```

##Sharing Configs
If you have multiple targets, it may be helpful to share common configuration settings between them. Gruntacular supports this by using the `options` property:

```js
testacular: {
options: {
configFile: 'testacular.conf.js',
runnerPort: 9999,
browsers: ['Chrome', 'Firefox']
},
continuous: {
singleRun: true
browsers: ['PhantomJS']
},
dev: {
reporters: 'dots'
}
}
```

In this example the `continuous` and `dev` targets will both use the `configFile` and `runnerPort` specified in the `options`. But the `continuous` target will override the browser setting to use PhantomJS, and also run as a singleRun. The `dev` target will simply change the reporter to dots.

##Running tests
There are three ways to run your tests with testacular:

Expand Down
6 changes: 1 addition & 5 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
[] tests
[] support the options object to close #3
[] update docs
[] make config file optional
[] version bump
[] make config file optional
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"peerDependencies": {
"grunt": "0.4.x"
}
}
}
15 changes: 11 additions & 4 deletions tasks/gruntacular.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ var server = require('testacular').server;
module.exports = function(grunt) {
grunt.registerMultiTask('testacular', 'run testacular.', function() {
var done = this.async();
if (this.data.configFile) {
this.data.configFile = grunt.template.process(this.data.configFile);
var options = this.options();
var data = this.data;
//merge options onto data, with data taking precedence
Object.keys(this.options()).forEach(function(prop){
if (!data[prop]) data[prop] = options[prop];
});

if (data.configFile) {
data.configFile = grunt.template.process(data.configFile);
}
//support `testacular run`, useful for grunt watch
if (this.flags.run){
runner.run(this.data, finished.bind(done));
runner.run(data, finished.bind(done));
return;
}
server.start(this.data, finished.bind(done));
server.start(data, finished.bind(done));
});
};

Expand Down
2 changes: 1 addition & 1 deletion testacular.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//TODO make the configFile optional
//TODO make the configFile optional, waiting on https://github.com/testacular/testacular/issues/358
files = [
MOCHA,
MOCHA_ADAPTER,
Expand Down

0 comments on commit c54f600

Please sign in to comment.