From 4693b6156eb358fcfa3b777745ccfdf3556a5567 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Tue, 11 Oct 2016 12:04:51 +0200 Subject: [PATCH] fix: Minor fixes in previously added extended logging --- src/add-hooks.coffee | 6 ++--- ...figuration.coffee => configuration.coffee} | 7 +++--- src/dredd-command.coffee | 2 +- src/dredd.coffee | 2 +- src/reporters/apiary-reporter.coffee | 22 +++++++++---------- ...-test.coffee => configuration-test.coffee} | 14 ++++++------ 6 files changed, 27 insertions(+), 26 deletions(-) rename src/{apply-configuration.coffee => configuration.coffee} (93%) rename test/unit/{apply-configuration-test.coffee => configuration-test.coffee} (80%) diff --git a/src/add-hooks.coffee b/src/add-hooks.coffee index ccd37c936..9c2e6bbc7 100644 --- a/src/add-hooks.coffee +++ b/src/add-hooks.coffee @@ -46,7 +46,7 @@ addHooks = (runner, transactions, callback) -> catch error logger.warn("""\ Skipping hook loading. Error reading hook file '#{filePath}'. \ - This probably means one or more of your hook files is invalid. + This probably means one or more of your hook files are invalid. Message: #{error.message} Stack: #{error.stack} """) @@ -88,10 +88,10 @@ addHooks = (runner, transactions, callback) -> loadSandboxHooksFromStrings(callback) else # not sandboxed code can't be loaded from the string - msg = """\ + msg = '''\ Not sandboxed hooks loading from strings is not implemented, \ Sandbox mode must be enabled when loading hooks from strings.\ - """ + ''' callback(new Error(msg)) else diff --git a/src/apply-configuration.coffee b/src/configuration.coffee similarity index 93% rename from src/apply-configuration.coffee rename to src/configuration.coffee index 3a2490bc6..e0a54f8cb 100644 --- a/src/apply-configuration.coffee +++ b/src/configuration.coffee @@ -16,10 +16,11 @@ coerceToArray = (value) -> applyLoggingOptions = (options) -> - # coerce color to bool - if options.color == 'false' + # Color can be either specified as "stringified bool" or bool (nothing else + # is expected valid value). Here we're coercing the value to boolean. + if options.color is 'false' options.color = false - else if options.color == 'true' + else if options.color is 'true' options.color = true logger.transports.console.colorize = options.color diff --git a/src/dredd-command.coffee b/src/dredd-command.coffee index 64ecc3906..fdca27e99 100644 --- a/src/dredd-command.coffee +++ b/src/dredd-command.coffee @@ -9,7 +9,7 @@ execSync = require('sync-exec') Dredd = require './dredd' interactiveConfig = require './interactive-config' -{applyLoggingOptions} = require './apply-configuration' +{applyLoggingOptions} = require './configuration' configUtils = require './config-utils' logger = require('./logger') diff --git a/src/dredd.coffee b/src/dredd.coffee index fd731a28b..7fcc2c168 100644 --- a/src/dredd.coffee +++ b/src/dredd.coffee @@ -7,7 +7,7 @@ url = require 'url' logger = require('./logger') options = require './options' Runner = require './transaction-runner' -{applyConfiguration} = require './apply-configuration' +{applyConfiguration} = require './configuration' handleRuntimeProblems = require './handle-runtime-problems' dreddTransactions = require 'dredd-transactions' configureReporters = require './configure-reporters' diff --git a/src/reporters/apiary-reporter.coffee b/src/reporters/apiary-reporter.coffee index 6ce827740..85f3b6ba9 100644 --- a/src/reporters/apiary-reporter.coffee +++ b/src/reporters/apiary-reporter.coffee @@ -192,20 +192,20 @@ class ApiaryReporter res.setEncoding 'utf8' res.on 'data', (chunk) -> - logger.verbose('Apiary Reporter HTTP response chunk:', chunk) + logger.verbose('Apiary reporter received HTTP response chunk:', chunk) buffer = buffer + chunk res.on 'error', (error) -> - logger.debug('Apiary Reporter HTTP response error:', error) + logger.debug('Apiary reporter got HTTP response error:', error) return callback error, req, res res.on 'end', -> - logger.verbose('Apiary reporter Response received.') + logger.verbose('Apiary reporter received response from Apiary API.') try parsedBody = JSON.parse buffer catch e - return callback new Error("Apiary reporter: Failed to parse Apiary API response body:\n#{buffer}") + return callback new Error("Apiary reporter failed to parse Apiary API response body: #{e.message}\n#{buffer}") info = {headers: res.headers, statusCode: res.statusCode, body: parsedBody} logger.verbose('Apiary reporter response:', JSON.stringify(info, null, 2)) @@ -229,7 +229,7 @@ class ApiaryReporter unless @configuration['apiToken'] == null options.headers['Authentication'] = 'Token ' + @configuration['apiToken'] - logger.verbose('Apiary reporter request:', JSON.stringify({options: options, body}, null, 2)) + logger.verbose('Apiary reporter request:', JSON.stringify({options, body}, null, 2)) handleReqError = (error) => @serverError = true @@ -238,16 +238,16 @@ class ApiaryReporter else return callback error, req, null - logger.verbose('Starting Apiary reporter HTTP request') - if @configuration.apiUrl.match(/^https/) + logger.verbose('Starting HTTP request from Apiary reporter to Apiary API') + if @configuration.apiUrl?.match(/^https/) logger.debug('Using HTTPS for Apiary reporter request') - req = https.request options, handleResponse + req = https.request(options, handleResponse) else logger.debug('Using unsecured HTTP for Apiary reporter request') - req = http.request options, handleResponse + req = http.request(options, handleResponse) - req.on 'error', handleReqError - req.write postData + req.on('error', handleReqError) + req.write(postData) req.end() diff --git a/test/unit/apply-configuration-test.coffee b/test/unit/configuration-test.coffee similarity index 80% rename from test/unit/apply-configuration-test.coffee rename to test/unit/configuration-test.coffee index 62e39a586..12ff5cfb4 100644 --- a/test/unit/apply-configuration-test.coffee +++ b/test/unit/configuration-test.coffee @@ -1,11 +1,11 @@ {assert} = require('chai') clone = require('clone') -applyConfiguration = require('../../src/apply-configuration') +configuration = require('../../src/configuration') logger = require('../../src/logger') -describe('applyLoggingOptions()', -> +describe('configuration.applyLoggingOptions()', -> loggerSettings = undefined config = undefined @@ -17,7 +17,7 @@ describe('applyLoggingOptions()', -> ) it('applies logging options', -> - config = applyConfiguration.applyLoggingOptions( + config = configuration.applyLoggingOptions( color: 'true' level: 'debug' ) @@ -31,21 +31,21 @@ describe('applyLoggingOptions()', -> describe('with color set to legacy \'true\' string value', -> it('resulting configuration should contain \'color\' set to boolean true', -> - options = applyConfiguration.applyLoggingOptions({color: 'true'}) + options = configuration.applyLoggingOptions({color: 'true'}) assert.propertyVal(options, 'color', true) ) ) describe('with color option set to legacy \'false\' string value', -> it('resulting configuration should contain \'color\' set to boolean false', -> - options = applyConfiguration.applyLoggingOptions({color: 'false'}) + options = configuration.applyLoggingOptions({color: 'false'}) assert.propertyVal(options, 'color', false) ) ) ) -describe('applyConfiguration()', -> +describe('configuration.applyConfiguration()', -> loggerSettings = undefined config = undefined @@ -57,7 +57,7 @@ describe('applyConfiguration()', -> ) it('applies logging options', -> - config = applyConfiguration.applyConfiguration( + config = configuration.applyConfiguration( options: color: 'true' level: 'debug'