From a004b03d0f1dd0166888776b1aa96ceb339219a1 Mon Sep 17 00:00:00 2001 From: Simon Ho Date: Thu, 18 Aug 2016 11:24:31 -0700 Subject: [PATCH] Fix pretest and init test configs Environment variables set in pretest.js and test/init.js were silently being converted to Strings. For example, when TEST_MYSQL_USER is undefined, it's value was automatically converted to the String 'undefined'. This is documented a side effect of assigning values to process.env. See https://nodejs.org/api/process.html#process_process_env for more details --- pretest.js | 22 +++++++++++++--------- test/init.js | 16 ++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pretest.js b/pretest.js index 5fb162b..cbf6947 100644 --- a/pretest.js +++ b/pretest.js @@ -1,16 +1,20 @@ 'use strict'; -// TODO: used for testing support for parallel testing on ci.strongloop.com which -// provides MYSQL_* env vars instead of TEST_MYSQL_* env vars. -process.env.TEST_MYSQL_USER = process.env.TEST_MYSQL_USER || process.env.MYSQL_USER; -process.env.TEST_MYSQL_PASSWORD = process.env.TEST_MYSQL_PASSWORD || process.env.MYSQL_PASSWORD; -process.env.TEST_MYSQL_HOST = process.env.TEST_MYSQL_HOST || process.env.MYSQL_HOST; -process.env.TEST_MYSQL_PORT = process.env.TEST_MYSQL_PORT || process.env.MYSQL_PORT; -if (!process.env.TEST_MYSQL_USER) { - console.log('not seeding DB with example db'); - return; +if (!process.env.TEST_MYSQL_USER && + !process.env.MYSQL_USER && + !process.env.CI) { + return console.log('Not seeding DB with test db'); } +process.env.TEST_MYSQL_HOST = + process.env.TEST_MYSQL_HOST || process.env.MYSQL_HOST || 'localhost'; +process.env.TEST_MYSQL_PORT = + process.env.TEST_MYSQL_PORT || process.env.MYSQL_PORT || 3306; +process.env.TEST_MYSQL_USER = + process.env.TEST_MYSQL_USER || process.env.MYSQL_USER || 'test'; +process.env.TEST_MYSQL_PASSWORD = + process.env.TEST_MYSQL_PASSWORD || process.env.MYSQL_PASSWORD || 'test'; + var fs = require('fs'); var cp = require('child_process'); diff --git a/test/init.js b/test/init.js index ce17ce0..5dad0e5 100644 --- a/test/init.js +++ b/test/init.js @@ -4,12 +4,6 @@ // License text available at https://opensource.org/licenses/MIT 'use strict'; -// TODO: used for testing support for parallel testing on ci.strongloop.com which -// provides MYSQL_* env vars instead of TEST_MYSQL_* env vars. -process.env.TEST_MYSQL_USER = process.env.TEST_MYSQL_USER || process.env.MYSQL_USER; -process.env.TEST_MYSQL_PASSWORD = process.env.TEST_MYSQL_PASSWORD || process.env.MYSQL_PASSWORD; -process.env.TEST_MYSQL_HOST = process.env.TEST_MYSQL_HOST || process.env.MYSQL_HOST; -process.env.TEST_MYSQL_PORT = process.env.TEST_MYSQL_PORT || process.env.MYSQL_PORT; module.exports = require('should'); @@ -19,11 +13,13 @@ var config = require('rc')('loopback', {test: {mysql: {}}}).test.mysql; console.log(config); global.getConfig = function(options) { var dbConf = { - host: process.env.TEST_MYSQL_HOST || config.host || 'localhost', - port: process.env.TEST_MYSQL_PORT || config.port || 3306, + host: process.env.TEST_MYSQL_HOST || process.env.MYSQL_HOST || + config.host || 'localhost', + port: process.env.TEST_MYSQL_PORT || process.env.MYSQL_PORT || + config.port || 3306, database: 'myapp_test', - username: process.env.TEST_MYSQL_USER || config.username, - password: process.env.TEST_MYSQL_PASSWORD || config.password, + username: process.env.MYSQL_USER || config.username, + password: process.env.MYSQL_PASSWORD || config.password, createDatabase: true, };