From 2d1778f7d98a3888a4b2cf07b18ca047eb7145d4 Mon Sep 17 00:00:00 2001 From: pavelgj Date: Wed, 3 Apr 2013 13:35:02 -0700 Subject: [PATCH 1/3] feat: allow custom properties in config file. --- lib/config.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/config.js b/lib/config.js index cacecb92c..5a3a7ceb3 100644 --- a/lib/config.js +++ b/lib/config.js @@ -123,7 +123,7 @@ var normalizeConfig = function(config) { var readConfigFile = function(filepath) { - var configEnv = { + var initSandbox = { // constants LOG_DISABLE: constant.LOG_DISABLE, LOG_ERROR: constant.LOG_ERROR, @@ -137,10 +137,10 @@ var readConfigFile = function(filepath) { __filename: filepath, __dirname: path.dirname(filepath) }; - + var configEnv = vm.createContext(initSandbox); // TODO(vojta): remove - var CONST_ERR = '%s is not supported anymore.\n\tPlease use `frameworks = ["%s"];` instead.'; + var CONST_ERR = '%s is not supported anymore.\n\tPlease use `framworks = ["%s"];` instead.'; ['JASMINE', 'MOCHA', 'QUNIT'].forEach(function(framework) { [framework, framework + '_ADAPTER'].forEach(function(name) { Object.defineProperty(configEnv, name, {get: function() { @@ -169,7 +169,7 @@ var readConfigFile = function(filepath) { configSrc = coffee.compile(configSrc.toString(), {bare: true}); } - vm.runInNewContext(configSrc, configEnv); + vm.runInContext(configSrc, configEnv); } catch(e) { if (e.name === 'SyntaxError') { log.error('Syntax error in config file!\n' + e.message); @@ -181,6 +181,10 @@ var readConfigFile = function(filepath) { process.exit(1); } + + for (var i in initSandbox) { + delete configEnv[i]; + } return configEnv; }; @@ -228,11 +232,12 @@ var parseConfig = function(configFilePath, cliOptions) { }; // merge the config from config file and cliOptions (precendense) + Object.getOwnPropertyNames(configFromFile).forEach(function(key) { + config[key] = configFromFile[key]; + }); Object.getOwnPropertyNames(config).forEach(function(key) { if (cliOptions.hasOwnProperty(key)) { config[key] = cliOptions[key]; - } else if (configFromFile.hasOwnProperty(key)) { - config[key] = configFromFile[key]; } }); From b86ae0d5e1913b9cb393165c69247d02d57e1064 Mon Sep 17 00:00:00 2001 From: pavelgj Date: Wed, 3 Apr 2013 13:46:24 -0700 Subject: [PATCH 2/3] chore: merge --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index 5a3a7ceb3..b5a738587 100644 --- a/lib/config.js +++ b/lib/config.js @@ -140,7 +140,7 @@ var readConfigFile = function(filepath) { var configEnv = vm.createContext(initSandbox); // TODO(vojta): remove - var CONST_ERR = '%s is not supported anymore.\n\tPlease use `framworks = ["%s"];` instead.'; + var CONST_ERR = '%s is not supported anymore.\n\tPlease use `frameworks = ["%s"];` instead.'; ['JASMINE', 'MOCHA', 'QUNIT'].forEach(function(framework) { [framework, framework + '_ADAPTER'].forEach(function(name) { Object.defineProperty(configEnv, name, {get: function() { From de128abcb003e21093591e2b36453da93b2358f9 Mon Sep 17 00:00:00 2001 From: pavelgj Date: Wed, 3 Apr 2013 13:48:24 -0700 Subject: [PATCH 3/3] chore: added comments --- lib/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/config.js b/lib/config.js index b5a738587..708907edd 100644 --- a/lib/config.js +++ b/lib/config.js @@ -182,6 +182,7 @@ var readConfigFile = function(filepath) { process.exit(1); } + // Clean up the env before we return it. for (var i in initSandbox) { delete configEnv[i]; }