From 4c539ab9d17e22522b6f8c5117a827a3c23e8aa7 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Thu, 6 Nov 2014 09:48:21 -0800 Subject: [PATCH] Better configuration for TDR test mode --- lib/config.js | 5 ++++- lib/connection.js | 7 +++++-- lib/device.js | 7 +++++-- spec/helper.js | 1 - 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/config.js b/lib/config.js index 88a4483..7d90281 100644 --- a/lib/config.js +++ b/lib/config.js @@ -9,5 +9,8 @@ 'use strict'; module.exports = { - logging: {} + logging: {}, + + // are we in TDR test mode? Used to stub out adaptors/drivers. + testMode: false }; diff --git a/lib/connection.js b/lib/connection.js index 6f05aa1..94291d6 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -11,10 +11,13 @@ var EventEmitter = require('events').EventEmitter; var Registry = require('./registry'), + Config = require('./config'), Logger = require('./logger'), Utils = require('./utils'); -var testMode = process.env.NODE_ENV === 'test' && !CYLON_TEST; +var testMode = function() { + return process.env.NODE_ENV === 'test' && Config.testMode; +}; // Public: Creates a new Connection // @@ -107,7 +110,7 @@ Connection.prototype.initAdaptor = function(opts) { var adaptor = module.adaptor(opts); - if (testMode) { + if (testMode()) { var testAdaptor = Registry.findByAdaptor('test').adaptor(opts); for (var prop in adaptor) { diff --git a/lib/device.js b/lib/device.js index 66af7cf..2475f99 100644 --- a/lib/device.js +++ b/lib/device.js @@ -11,10 +11,13 @@ var EventEmitter = require('events').EventEmitter; var Registry = require('./registry'), + Config = require('./config'), Logger = require('./logger'), Utils = require('./utils'); -var testMode = process.env.NODE_ENV === 'test' && !CYLON_TEST; +var testMode = function() { + return process.env.NODE_ENV === 'test' && Config.testMode; +}; // Public: Creates a new Device // @@ -120,7 +123,7 @@ Device.prototype.initDriver = function(opts) { var driver = module.driver(opts); - if (testMode) { + if (testMode()) { var testDriver = Registry.findByDriver('test').driver(opts); for (var prop in driver) { diff --git a/spec/helper.js b/spec/helper.js index 7c84ef4..8d523d1 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -1,7 +1,6 @@ 'use strict'; process.env.NODE_ENV = 'test'; -global.CYLON_TEST = true; var path = require('path');