Browse files

Implement JSON config file support

Supporting JSON is nice for people who are familiar with it. It's also nice if you want to pass in JavaScript objects as options
  • Loading branch information...
1 parent e6bc272 commit 05a0d134c32b53050878374f34d9c07d922ae722 @Raynos Raynos committed with airportyh Jul 3, 2012
View
3 examples/custom_adapter/testem.json
@@ -0,0 +1,3 @@
+{
+ "framework": "custom"
+}
View
1 examples/custom_adapter/testem.yml
@@ -1 +0,0 @@
-framework: custom
View
3 examples/mocha_simple/testem.json
@@ -0,0 +1,3 @@
+{
+ "framework": "mocha"
+}
View
1 examples/mocha_simple/testem.yml
@@ -1 +0,0 @@
-framework: mocha
View
17 lib/config.js
@@ -18,11 +18,20 @@ function Config(progOptions){
Config.prototype.read = function(callback){
var configFile = this.progOptions.file
, self = this
- fs.readFile(configFile, function(err, data){
- if (!err){
- var cfg = yaml.load(String(data))
- self.config = cfg
+ , jsonConfigFile = configFile.replace(/\.yml$/, ".json")
+
+ fs.readFile(configFile, function (err, data) {
+ if (err) {
+ return fs.readFile(jsonConfigFile, function (err, data) {
+ if (!err) {
+ var cfg = JSON.parse(data.toString())
+ self.config = cfg
+ }
+ if (callback) callback.call(self)
+ })
}
+ var cfg = yaml.load(String(data))
+ self.config = cfg
if (callback) callback.call(self)
})
}

0 comments on commit 05a0d13

Please sign in to comment.