From 553cd88df1d80fd271d4fc75749d2d8434da6b5e Mon Sep 17 00:00:00 2001 From: Adam Kliment Date: Wed, 11 Jun 2014 14:46:37 +0200 Subject: [PATCH] removed lib --- .gitignore | 1 + lib/add-hooks.js | 87 -------- lib/apply-configuration.js | 74 ------- lib/blueprint-ast-to-runtime.js | 78 ------- lib/configure-reporters.js | 105 --------- lib/dredd.js | 94 -------- lib/example-to-http-payload-pair.js | 52 ----- lib/expand-uri-template-with-parameters.js | 81 ------- lib/flatten-headers.js | 14 -- lib/handle-runtime-problems.js | 29 --- lib/hooks.js | 35 --- lib/inherit-headers.js | 15 -- lib/inherit-parameters.js | 15 -- lib/logger.js | 74 ------- lib/options.js | 78 ------- lib/parse-package-json.js | 12 -- lib/prettify-response.js | 61 ------ lib/reporters/apiary-reporter.js | 219 ------------------- lib/reporters/base-reporter.js | 54 ----- lib/reporters/cli-reporter.js | 84 -------- lib/reporters/dot-reporter.js | 71 ------ lib/reporters/html-reporter.js | 117 ---------- lib/reporters/markdown-reporter.js | 103 --------- lib/reporters/nyan-reporter.js | 239 --------------------- lib/reporters/x-unit-reporter.js | 164 -------------- lib/sort-transactions.js | 28 --- lib/transaction-runner.js | 228 -------------------- 27 files changed, 1 insertion(+), 2211 deletions(-) delete mode 100644 lib/add-hooks.js delete mode 100644 lib/apply-configuration.js delete mode 100644 lib/blueprint-ast-to-runtime.js delete mode 100644 lib/configure-reporters.js delete mode 100644 lib/dredd.js delete mode 100644 lib/example-to-http-payload-pair.js delete mode 100644 lib/expand-uri-template-with-parameters.js delete mode 100644 lib/flatten-headers.js delete mode 100644 lib/handle-runtime-problems.js delete mode 100644 lib/hooks.js delete mode 100644 lib/inherit-headers.js delete mode 100644 lib/inherit-parameters.js delete mode 100644 lib/logger.js delete mode 100644 lib/options.js delete mode 100644 lib/parse-package-json.js delete mode 100644 lib/prettify-response.js delete mode 100644 lib/reporters/apiary-reporter.js delete mode 100644 lib/reporters/base-reporter.js delete mode 100644 lib/reporters/cli-reporter.js delete mode 100644 lib/reporters/dot-reporter.js delete mode 100644 lib/reporters/html-reporter.js delete mode 100644 lib/reporters/markdown-reporter.js delete mode 100644 lib/reporters/nyan-reporter.js delete mode 100644 lib/reporters/x-unit-reporter.js delete mode 100644 lib/sort-transactions.js delete mode 100644 lib/transaction-runner.js diff --git a/.gitignore b/.gitignore index fb40a3281..152360001 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +/lib .vagrant \ No newline at end of file diff --git a/lib/add-hooks.js b/lib/add-hooks.js deleted file mode 100644 index 1190c4591..000000000 --- a/lib/add-hooks.js +++ /dev/null @@ -1,87 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var addHooks, async, glob, hooks, logger, path, proxyquire, runHook, runHooksForTransaction, - _this = this; - -path = require('path'); - -require('coffee-script'); - -proxyquire = require('proxyquire').noCallThru(); - -glob = require('glob'); - -async = require('async'); - -hooks = require('./hooks'); - -logger = require('./logger'); - -addHooks = function(runner, transactions) { - var error, file, files, pattern, transaction, _i, _j, _len, _len1, _ref, _ref1, - _this = this; - for (_i = 0, _len = transactions.length; _i < _len; _i++) { - transaction = transactions[_i]; - hooks.transactions[transaction.name] = transaction; - } - pattern = runner != null ? (_ref = runner.configuration) != null ? (_ref1 = _ref.options) != null ? _ref1.hookfiles : void 0 : void 0 : void 0; - if (!pattern) { - return; - } - files = glob.sync(pattern); - logger.info('Found Hookfiles: ' + files); - try { - for (_j = 0, _len1 = files.length; _j < _len1; _j++) { - file = files[_j]; - proxyquire(path.resolve(process.cwd(), file), { - 'hooks': hooks - }); - } - } catch (_error) { - error = _error; - logger.warn('Skipping hook loading...'); - logger.error('Error reading hook files (' + files + ')'); - logger.error('This probably means one or more of your hookfiles is invalid.'); - if (error.message != null) { - logger.error('Message: ' + error.message); - } - if (error.stack != null) { - logger.error('Stack: ' + error.stack); - } - return; - } - runner.before('executeTransaction', function(transaction, callback) { - return runHooksForTransaction(hooks.beforeHooks[transaction.name], transaction, callback); - }); - return runner.after('executeTransaction', function(transaction, callback) { - return runHooksForTransaction(hooks.afterHooks[transaction.name], transaction, callback); - }); -}; - -runHooksForTransaction = function(hooksForTransaction, transaction, callback) { - var runHookWithTransaction; - if (hooksForTransaction != null) { - logger.debug('Running hooks...'); - runHookWithTransaction = function(hook, callback) { - return runHook(hook, transaction, callback); - }; - return async.eachSeries(hooksForTransaction, runHookWithTransaction, function() { - return callback(); - }); - } else { - return callback(); - } -}; - -runHook = function(hook, transaction, callback) { - var _this = this; - if (hook.length === 1) { - hook(transaction); - return callback(); - } else if (hook.length === 2) { - return hook(transaction, function() { - return callback(); - }); - } -}; - -module.exports = addHooks; diff --git a/lib/apply-configuration.js b/lib/apply-configuration.js deleted file mode 100644 index 04bdf9114..000000000 --- a/lib/apply-configuration.js +++ /dev/null @@ -1,74 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var EventEmitter, applyConfiguration, logger, - __hasProp = {}.hasOwnProperty; - -EventEmitter = require('events').EventEmitter; - -logger = require('./logger'); - -applyConfiguration = function(config) { - var authHeader, coerceToArray, configuration, key, method, value, _i, _len, _ref; - coerceToArray = function(value) { - if (typeof value === 'string') { - return value = [value]; - } else if (value == null) { - return value = []; - } else if (value instanceof Array) { - return value; - } else { - return value; - } - }; - configuration = { - blueprintPath: null, - server: null, - emitter: new EventEmitter, - options: { - 'dry-run': false, - silent: false, - reporter: null, - output: null, - debug: false, - header: null, - user: null, - 'inline-errors': false, - details: false, - method: [], - color: true, - level: 'info', - timestamp: false, - sorted: false, - names: false, - hookfiles: null - } - }; - for (key in config) { - if (!__hasProp.call(config, key)) continue; - value = config[key]; - configuration[key] = value; - } - configuration.options.reporter = coerceToArray(configuration.options.reporter); - configuration.options.output = coerceToArray(configuration.options.output); - configuration.options.header = coerceToArray(configuration.options.header); - configuration.options.method = coerceToArray(configuration.options.method); - _ref = configuration.options.method; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - method = _ref[_i]; - method.toUpperCase(); - } - if (configuration.options.user != null) { - authHeader = 'Authorization:Basic ' + new Buffer(configuration.options.user).toString('base64'); - configuration.options.header.push(authHeader); - } - logger.transports.console.colorize = configuration.options.color; - logger.transports.console.silent = configuration.options.silent; - logger.transports.console.level = configuration.options.level; - logger.transports.console.timestamp = configuration.options.timestamp; - logger.sys.transports.systemConsole.colorize = configuration.options.color; - logger.sys.transports.systemConsole.silent = configuration.options.silent; - logger.sys.transports.systemConsole.level = configuration.options.level; - logger.sys.transports.systemConsole.timestamp = configuration.options.timestamp; - return configuration; -}; - -module.exports = applyConfiguration; diff --git a/lib/blueprint-ast-to-runtime.js b/lib/blueprint-ast-to-runtime.js deleted file mode 100644 index 380cece3d..000000000 --- a/lib/blueprint-ast-to-runtime.js +++ /dev/null @@ -1,78 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var blueprintAstToRuntime, exampleToHttpPayloadPair, expandUriTemplateWithParameters, inheritHeaders, inheritParameters; - -inheritHeaders = require('./inherit-headers'); - -inheritParameters = require('./inherit-parameters'); - -expandUriTemplateWithParameters = require('./expand-uri-template-with-parameters'); - -exampleToHttpPayloadPair = require('./example-to-http-payload-pair'); - -blueprintAstToRuntime = function(blueprintAst) { - var action, example, message, origin, resource, resourceGroup, result, runtime, transaction, uriResult, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _len6, _m, _n, _o, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6; - runtime = { - transactions: [], - errors: [], - warnings: [] - }; - origin = {}; - _ref = blueprintAst['resourceGroups']; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - resourceGroup = _ref[_i]; - origin['resourceGroupName'] = resourceGroup['name']; - _ref1 = resourceGroup['resources']; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - resource = _ref1[_j]; - origin['resourceName'] = resource['name']; - _ref2 = resource['actions']; - for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { - action = _ref2[_k]; - origin['actionName'] = action['name']; - action['headers'] = inheritHeaders(action['headers'], resource['headers']); - action['parameters'] = inheritParameters(action['parameters'], resource['parameters']); - uriResult = expandUriTemplateWithParameters(resource['uriTemplate'], action['parameters']); - _ref3 = uriResult['warnings']; - for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { - message = _ref3[_l]; - runtime['warnings'].push({ - origin: JSON.parse(JSON.stringify(origin)), - message: message - }); - } - _ref4 = uriResult['errors']; - for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) { - message = _ref4[_m]; - runtime['errors'].push({ - origin: JSON.parse(JSON.stringify(origin)), - message: message - }); - } - if (uriResult['uri'] !== null) { - _ref5 = action['examples']; - for (_n = 0, _len5 = _ref5.length; _n < _len5; _n++) { - example = _ref5[_n]; - origin['exampleName'] = example['name']; - result = exampleToHttpPayloadPair(example, action['headers']); - _ref6 = result['warnings']; - for (_o = 0, _len6 = _ref6.length; _o < _len6; _o++) { - message = _ref6[_o]; - runtime['warnings'].push({ - origin: JSON.parse(JSON.stringify(origin)), - message: message - }); - } - transaction = result['pair']; - transaction['origin'] = JSON.parse(JSON.stringify(origin)); - transaction['request']['uri'] = uriResult['uri']; - transaction['request']['method'] = action['method']; - runtime['transactions'].push(transaction); - } - } - } - } - } - return runtime; -}; - -module.exports = blueprintAstToRuntime; diff --git a/lib/configure-reporters.js b/lib/configure-reporters.js deleted file mode 100644 index e1a530fc9..000000000 --- a/lib/configure-reporters.js +++ /dev/null @@ -1,105 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var ApiaryReporter, BaseReporter, CliReporter, DotReporter, HtmlReporter, MarkdownReporter, NyanCatReporter, XUnitReporter, cliReporters, configureReporters, fileReporters, intersection, logger, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - -BaseReporter = require('./reporters/base-reporter'); - -XUnitReporter = require('./reporters/x-unit-reporter'); - -CliReporter = require('./reporters/cli-reporter'); - -DotReporter = require('./reporters/dot-reporter'); - -NyanCatReporter = require('./reporters/nyan-reporter'); - -HtmlReporter = require('./reporters/html-reporter'); - -MarkdownReporter = require('./reporters/markdown-reporter'); - -ApiaryReporter = require('./reporters/apiary-reporter'); - -logger = require('./logger'); - -fileReporters = ['junit', 'html', 'markdown', 'apiary']; - -cliReporters = ['dot', 'nyan']; - -intersection = function(a, b) { - var value, _i, _len, _ref, _results; - if (a.length > b.length) { - _ref = [b, a], a = _ref[0], b = _ref[1]; - } - _results = []; - for (_i = 0, _len = a.length; _i < _len; _i++) { - value = a[_i]; - if (__indexOf.call(b, value) >= 0) { - _results.push(value); - } - } - return _results; -}; - -configureReporters = function(config, stats, tests) { - var addCli, addReporter, baseReporter, i, outputs, path, reporter, reporters, usedFileReporters, usedFileReportersLength, _i, _len, _results; - baseReporter = new BaseReporter(config.emitter, stats, tests); - reporters = config.options.reporter; - outputs = config.options.output; - addCli = function(reporters) { - var cliReporter, usedCliReporters; - if (reporters.length > 0) { - usedCliReporters = intersection(reporters, cliReporters); - if (usedCliReporters.length === 0) { - return cliReporter = new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details); - } else { - return addReporter(usedCliReporters[0], config.emitter, stats, tests); - } - } else { - return cliReporter = new CliReporter(config.emitter, stats, tests, config.options['inline-errors'], config.options.details); - } - }; - addReporter = function(reporter, emitter, stats, tests, path) { - var apiaryReporter, dotReporter, htmlReporter, mdReporter, nyanCatReporter, xUnitReporter; - switch (reporter) { - case 'junit': - return xUnitReporter = new XUnitReporter(emitter, stats, tests, path, config.options.details); - case 'dot': - return dotReporter = new DotReporter(emitter, stats, tests); - case 'nyan': - return nyanCatReporter = new NyanCatReporter(emitter, stats, tests); - case 'html': - return htmlReporter = new HtmlReporter(emitter, stats, tests, path, config.options.details); - case 'markdown': - return mdReporter = new MarkdownReporter(emitter, stats, tests, path, config.options.details); - case 'apiary': - return apiaryReporter = new ApiaryReporter(emitter, stats, tests); - default: - return logger.warn('Invalid reporter #{reporter} selected, ignoring.'); - } - }; - if (!config.options.silent) { - addCli(reporters); - } - usedFileReporters = intersection(reporters, fileReporters); - stats.fileBasedReporters = usedFileReporters.length; - if (usedFileReporters.length > 0) { - usedFileReportersLength = usedFileReporters.length; - if (reporters.indexOf('apiary') !== -1) { - usedFileReportersLength = usedFileReportersLength - 1; - if (process.env['DREDD_REST_TOKEN'] === void 0 || process.env['DREDD_REST_SUITE'] === void 0) { - logger.warn("Apiary reporter environment variable DREDD_REST_TOKEN or DREDD_REST_SUITE not defined."); - } - } - if (usedFileReportersLength > outputs.length) { - logger.warn("There are more reporters requiring output paths than there are output paths provided, using default paths for additional file-based reporters."); - } - _results = []; - for (i = _i = 0, _len = usedFileReporters.length; _i < _len; i = ++_i) { - reporter = usedFileReporters[i]; - path = outputs[i] ? outputs[i] : null; - _results.push(addReporter(reporter, config.emitter, stats, tests, path)); - } - return _results; - } -}; - -module.exports = configureReporters; diff --git a/lib/dredd.js b/lib/dredd.js deleted file mode 100644 index b6176edf4..000000000 --- a/lib/dredd.js +++ /dev/null @@ -1,94 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var Dredd, Runner, applyConfiguration, blueprintAstToRuntime, configureReporters, fs, handleRuntimeProblems, logger, options, protagonist, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - -fs = require('fs'); - -protagonist = require('protagonist'); - -logger = require('./logger'); - -options = require('./options'); - -Runner = require('./transaction-runner'); - -applyConfiguration = require('./apply-configuration'); - -handleRuntimeProblems = require('./handle-runtime-problems'); - -blueprintAstToRuntime = require('./blueprint-ast-to-runtime'); - -configureReporters = require('./configure-reporters'); - -Dredd = (function() { - function Dredd(config) { - this.transactionsComplete = __bind(this.transactionsComplete, this); - this.tests = []; - this.stats = { - tests: 0, - failures: 0, - errors: 0, - passes: 0, - skipped: 0, - start: 0, - end: 0, - duration: 0 - }; - this.configuration = applyConfiguration(config, this.stats); - configureReporters(this.configuration, this.stats, this.tests); - this.runner = new Runner(this.configuration); - } - - Dredd.prototype.run = function(callback) { - var blueprintParsingComplete, config, stats, - _this = this; - config = this.configuration; - stats = this.stats; - fs.readFile(config.blueprintPath, 'utf8', function(parseError, data) { - var reporterCount; - if (parseError) { - return callback(parseError, stats); - } - reporterCount = config.emitter.listeners('start').length; - return config.emitter.emit('start', data, function() { - reporterCount--; - if (reporterCount === 0) { - return protagonist.parse(data, blueprintParsingComplete); - } - }); - }); - return blueprintParsingComplete = function(protagonistError, result) { - var runtime, runtimeError; - if (protagonistError) { - return callback(protagonistError, config.reporter); - } - runtime = blueprintAstToRuntime(result['ast']); - runtimeError = handleRuntimeProblems(runtime); - if (runtimeError) { - return callback(runtimeError, stats); - } - return _this.runner.run(runtime['transactions'], function() { - return _this.transactionsComplete(callback); - }); - }; - }; - - Dredd.prototype.transactionsComplete = function(callback) { - var reporterCount, stats; - stats = this.stats; - reporterCount = this.configuration.emitter.listeners('end').length; - return this.configuration.emitter.emit('end', function() { - reporterCount--; - if (reporterCount === 0) { - return callback(null, stats); - } - }); - }; - - return Dredd; - -})(); - -module.exports = Dredd; - -module.exports.options = options; diff --git a/lib/example-to-http-payload-pair.js b/lib/example-to-http-payload-pair.js deleted file mode 100644 index 083b0d57a..000000000 --- a/lib/example-to-http-payload-pair.js +++ /dev/null @@ -1,52 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var exampleToHttpPayloadPair, inheritHeaders; - -inheritHeaders = require('./inherit-headers'); - -exampleToHttpPayloadPair = function(example, inheritingHeaders) { - var request, response, result, selectedRequest, selectedResponse, text; - if (inheritingHeaders == null) { - inheritingHeaders = {}; - } - result = { - warnings: [], - errors: [], - pair: {} - }; - request = {}; - response = {}; - if (example['requests'].length > 1) { - text = "Multiple requests, using first."; - result['warnings'].push(text); - } - if (example['responses'].length > 1) { - text = "Multiple responses, using first."; - result['warnings'].push(text); - } - if (example['responses'].length === 0) { - text = "No response available. Can't create HTTP transaction."; - result['warnings'].push(text); - } else { - selectedRequest = example['requests'][0]; - selectedResponse = example['responses'][0]; - if (example['requests'].length === 0) { - selectedRequest = { - body: "", - headers: {} - }; - } - request['body'] = selectedRequest['body']; - request['headers'] = inheritHeaders(selectedRequest['headers'], inheritingHeaders); - response['body'] = selectedResponse['body']; - response['headers'] = inheritHeaders(selectedResponse['headers'], inheritingHeaders); - response['status'] = selectedResponse['name']; - if (selectedResponse['schema'] !== "") { - response['schema'] = selectedResponse['schema']; - } - result['pair']['request'] = request; - result['pair']['response'] = response; - } - return result; -}; - -module.exports = exampleToHttpPayloadPair; diff --git a/lib/expand-uri-template-with-parameters.js b/lib/expand-uri-template-with-parameters.js deleted file mode 100644 index d654630f7..000000000 --- a/lib/expand-uri-template-with-parameters.js +++ /dev/null @@ -1,81 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var expandUriTemplateWithParameters, ut; - -ut = require('uri-template'); - -expandUriTemplateWithParameters = function(uriTemplate, parameters) { - var ambigous, e, expression, param, parameter, parsed, result, text, toExpand, uriParameter, uriParameters, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; - result = { - errors: [], - warnings: [], - uri: null - }; - try { - parsed = ut.parse(uriTemplate); - } catch (_error) { - e = _error; - text = "\n Failed to parse URI template: " + uriTemplate; - text += "\n Error: " + e; - result['errors'].push(text); - return result; - } - uriParameters = []; - _ref = parsed['expressions']; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - expression = _ref[_i]; - _ref1 = expression['params']; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - param = _ref1[_j]; - uriParameters.push(param['name']); - } - } - _ref2 = Object.keys(parameters); - for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { - parameter = _ref2[_k]; - if (uriParameters.indexOf(parameter) === -1) { - text = ("\nURI template: " + uriTemplate + "\nDoesn\'t contain expression for parameter") + " '" + parameter + "'"; - result['warnings'].push(text); - } - } - if (parsed['expressions'].length === 0) { - result['uri'] = uriTemplate; - } else { - ambigous = false; - for (_l = 0, _len3 = uriParameters.length; _l < _len3; _l++) { - uriParameter = uriParameters[_l]; - if (Object.keys(parameters).indexOf(uriParameter) === -1) { - ambigous = true; - text = ("\nAmbigous URI template: " + uriTemplate + " ") + "\nParameter not defined:" + "'" + uriParameter + "'"; - result['warnings'].push(text); - } - } - if (ambigous === false) { - toExpand = {}; - for (_m = 0, _len4 = uriParameters.length; _m < _len4; _m++) { - uriParameter = uriParameters[_m]; - param = parameters[uriParameter]; - if (param['required'] === true) { - if (param['example'] === void 0) { - ambigous = true; - text = ("\nAmbigous URI template: " + uriTemplate + " ") + "\nNo example value for parameter:" + "'" + uriParameter + "'"; - result['warnings'].push(text); - } else { - toExpand[uriParameter] = param['example']; - } - } else { - if (param['example'] !== void 0) { - toExpand[uriParameter] = param['example']; - } else if (param['default'] !== void 0) { - toExpand[uriParameter] = param['default']; - } - } - } - } - if (ambigous === false) { - result['uri'] = parsed.expand(toExpand); - } - } - return result; -}; - -module.exports = expandUriTemplateWithParameters; diff --git a/lib/flatten-headers.js b/lib/flatten-headers.js deleted file mode 100644 index 5ca5599cc..000000000 --- a/lib/flatten-headers.js +++ /dev/null @@ -1,14 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var flattenHeaders; - -flattenHeaders = function(blueprintHeaders) { - var flatHeaders, name, values; - flatHeaders = {}; - for (name in blueprintHeaders) { - values = blueprintHeaders[name]; - flatHeaders[name] = values['value']; - } - return flatHeaders; -}; - -module.exports = flattenHeaders; diff --git a/lib/handle-runtime-problems.js b/lib/handle-runtime-problems.js deleted file mode 100644 index e73556f83..000000000 --- a/lib/handle-runtime-problems.js +++ /dev/null @@ -1,29 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var handleRuntimeProblems, logger; - -logger = require('./logger'); - -handleRuntimeProblems = function(runtime) { - var error, message, origin, warning, _i, _j, _len, _len1, _ref, _ref1; - if (runtime['warnings'].length > 0) { - _ref = runtime['warnings']; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - warning = _ref[_i]; - message = warning['message']; - origin = warning['origin']; - logger.warn("Runtime compilation warning: " + warning['message'] + "\n on " + origin['resourceGroupName'] + ' > ' + origin['resourceName'] + ' > ' + origin['actionName']); - } - } - if (runtime['errors'].length > 0) { - _ref1 = runtime['errors']; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - error = _ref1[_j]; - message = error['message']; - origin = error['origin']; - logger.error("Runtime compilation error: " + error['message'] + "\n on " + origin['resourceGroupName'] + ' > ' + origin['resourceName'] + ' > ' + origin['actionName']); - } - return new Error("Error parsing ast to blueprint."); - } -}; - -module.exports = handleRuntimeProblems; diff --git a/lib/hooks.js b/lib/hooks.js deleted file mode 100644 index c94949111..000000000 --- a/lib/hooks.js +++ /dev/null @@ -1,35 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var Hooks, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - -Hooks = (function() { - function Hooks() { - this.addHook = __bind(this.addHook, this); - this.after = __bind(this.after, this); - this.before = __bind(this.before, this); - this.beforeHooks = {}; - this.afterHooks = {}; - this.transactions = {}; - } - - Hooks.prototype.before = function(name, hook) { - return this.addHook(this.beforeHooks, name, hook); - }; - - Hooks.prototype.after = function(name, hook) { - return this.addHook(this.afterHooks, name, hook); - }; - - Hooks.prototype.addHook = function(hooks, name, hook) { - if (hooks[name]) { - return hooks[name].push(hook); - } else { - return hooks[name] = [hook]; - } - }; - - return Hooks; - -})(); - -module.exports = new Hooks(); diff --git a/lib/inherit-headers.js b/lib/inherit-headers.js deleted file mode 100644 index bc2da261c..000000000 --- a/lib/inherit-headers.js +++ /dev/null @@ -1,15 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var inheritHeaders; - -inheritHeaders = function(actualHeaders, inheritingHeaders) { - var name, params; - for (name in inheritingHeaders) { - params = inheritingHeaders[name]; - if (actualHeaders[name] === void 0) { - actualHeaders[name] = params; - } - } - return actualHeaders; -}; - -module.exports = inheritHeaders; diff --git a/lib/inherit-parameters.js b/lib/inherit-parameters.js deleted file mode 100644 index 4ad30f63f..000000000 --- a/lib/inherit-parameters.js +++ /dev/null @@ -1,15 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var inheritParameters; - -inheritParameters = function(actualParameters, inheritingParameters) { - var name, params; - for (name in inheritingParameters) { - params = inheritingParameters[name]; - if (actualParameters[name] === void 0) { - actualParameters[name] = params; - } - } - return actualParameters; -}; - -module.exports = inheritParameters; diff --git a/lib/logger.js b/lib/logger.js deleted file mode 100644 index 2a3c908ea..000000000 --- a/lib/logger.js +++ /dev/null @@ -1,74 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var config, consoleTransport, logger, sysConsoleTransport, syslogger, winston; - -winston = require('winston'); - -config = { - levels: { - silly: 0, - debug: 1, - verbose: 2, - info: 3, - test: 4, - pass: 5, - fail: 6, - complete: 7, - actual: 8, - expected: 9, - diff: 10, - request: 11, - skip: 12, - warn: 13, - error: 14 - }, - syslevels: { - silly: 0, - debug: 1, - verbose: 2, - info: 3, - warn: 4, - error: 5 - }, - colors: { - test: 'yellow', - info: 'blue', - pass: 'green', - fail: 'red', - complete: 'green', - actual: 'red', - expected: 'red', - diff: 'red', - request: 'green', - skip: 'yellow', - error: 'red', - warning: 'yellow', - silly: 'magenta', - verbose: 'cyan', - debug: 'blue' - } -}; - -consoleTransport = new winston.transports.Console({ - colorize: true -}); - -sysConsoleTransport = new winston.transports.Console({ - name: 'systemConsole', - colorize: true -}); - -logger = new winston.Logger({ - transports: [consoleTransport], - levels: config.levels, - colors: config.colors -}); - -syslogger = new winston.Logger({ - transports: [sysConsoleTransport], - levels: winston.config.npm.levels, - colors: config.colors -}); - -module.exports = logger; - -module.exports.sys = syslogger; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index df82ea59b..000000000 --- a/lib/options.js +++ /dev/null @@ -1,78 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var options; - -options = { - hookfiles: { - alias: 'f', - description: 'Specifes a pattern to match files with before/after hooks for running tests', - "default": null - }, - names: { - alias: 'n', - description: 'Only list names of requests (for use in a hookfile). No requests are made.', - "default": false - }, - reporter: { - alias: "r", - description: "Output additional report format. This option can be used multiple times to add multiple reporters. Options: junit, nyan, dot, markdown, html, apiary.\n", - "default": [] - }, - output: { - alias: "o", - description: "Specifies output file when using additional file-based reporter. This option can be used multiple times if multiple file-based reporters are used.\n", - "default": [] - }, - header: { - alias: "h", - description: "Extra header to include in every request. This option can be used multiple times to add multiple headers.\n", - "default": [] - }, - sorted: { - alias: "s", - description: "Sorts requests in a sensible way so that objects are not modified before they are created. Order: CONNECT, OPTIONS, POST, GET, HEAD, PUT, PATCH, DELETE, TRACE.\n", - "default": false - }, - user: { - alias: "u", - description: "Basic Auth credentials in the form username:password.\n", - "default": null - }, - "inline-errors": { - alias: "e", - description: "Determines whether failures and errors are displayed as they occur (true) or agregated and displayed at the end (false).\n", - "default": false - }, - details: { - alias: "d", - description: "Determines whether request/response details are included in passing tests.\n", - "default": false - }, - method: { - alias: "m", - description: "Restrict tests to a particular HTTP method (GET, PUT, POST, DELETE, PATCH). This option can be used multiple times to allow multiple methods.\n", - "default": [] - }, - color: { - alias: "c", - description: "Determines whether console output should include colors.\n", - "default": true - }, - level: { - alias: "l", - description: "The level of logging to output. Options: silly, debug, verbose, info, warn, error.\n", - "default": "info" - }, - timestamp: { - alias: "t", - description: "Determines whether console output should include timestamps.\n", - "default": false - }, - help: { - description: "Show usage information.\n" - }, - version: { - description: "Show version number.\n" - } -}; - -module.exports = options; diff --git a/lib/parse-package-json.js b/lib/parse-package-json.js deleted file mode 100644 index b4e6eb4cd..000000000 --- a/lib/parse-package-json.js +++ /dev/null @@ -1,12 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var fs, parsePackageJson; - -fs = require('fs'); - -parsePackageJson = function(path) { - var packagejson; - packagejson = JSON.parse(fs.readFileSync(path, "utf8")); - return packagejson.name + " v" + packagejson.version; -}; - -module.exports = parsePackageJson; diff --git a/lib/prettify-response.js b/lib/prettify-response.js deleted file mode 100644 index aaad24c9b..000000000 --- a/lib/prettify-response.js +++ /dev/null @@ -1,61 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var html, logger, prettifyResponse, - __hasProp = {}.hasOwnProperty; - -html = require('html'); - -logger = require('./logger'); - -prettifyResponse = function(response) { - var contentType, header, hkey, hval, key, prettifyBody, stringRepresentation, stringify, value; - stringify = function(obj) { - var e; - try { - if (typeof obj === 'string') { - obj = JSON.parse(obj); - } - obj = JSON.stringify(obj, null, 2); - } catch (_error) { - e = _error; - logger.debug("Could not stringify: " + obj); - } - return obj; - }; - prettifyBody = function(body, contentType) { - switch (contentType) { - case 'application/json': - body = stringify(body); - break; - case 'text/html': - body = html.prettyPrint(body, { - indent_size: 2 - }); - } - return body; - }; - if ((response != null ? response.headers : void 0) != null) { - contentType = (response != null ? response.headers['content-type'] : void 0) || (response != null ? response.headers['Content-Type'] : void 0); - } - stringRepresentation = ""; - for (key in response) { - if (!__hasProp.call(response, key)) continue; - value = response[key]; - if (key === 'body') { - value = '\n' + prettifyBody(value, contentType); - } else if (key === 'schema') { - value = '\n' + stringify(value); - } else if (key === 'headers') { - header = '\n'; - for (hkey in value) { - if (!__hasProp.call(value, hkey)) continue; - hval = value[hkey]; - header += " " + hkey + ": " + hval + "\n"; - } - value = header; - } - stringRepresentation += "" + key + ": " + value + "\n"; - } - return stringRepresentation; -}; - -module.exports = prettifyResponse; diff --git a/lib/reporters/apiary-reporter.js b/lib/reporters/apiary-reporter.js deleted file mode 100644 index a79c5b9f3..000000000 --- a/lib/reporters/apiary-reporter.js +++ /dev/null @@ -1,219 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var ApiaryReporter, http, https, logger, os, packageConfig, url, uuid, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - -uuid = require('node-uuid'); - -http = require('http'); - -https = require('https'); - -os = require('os'); - -url = require('url'); - -packageConfig = require('./../../package.json'); - -logger = require('./../logger'); - -String.prototype.startsWith = function(str) { - return this.slice(0, str.length) === str; -}; - -ApiaryReporter = (function() { - function ApiaryReporter(emitter, stats, tests, inlineErrors) { - this._performRequest = __bind(this._performRequest, this); - this.configureEmitter = __bind(this.configureEmitter, this); - this.type = "cli"; - this.stats = stats; - this.tests = tests; - this.uuid = null; - this.startedAt = null; - this.endedAt = null; - this.remoteId = null; - this.configureEmitter(emitter); - this.inlineErrors = inlineErrors; - this.errors = []; - this.verbose = process.env['DREDD_REST_DEBUG'] != null; - this.configuration = { - apiUrl: process.env['DREDD_REST_URL'] || "https://api.apiary.io", - apiToken: process.env['DREDD_REST_TOKEN'] || null, - apiSuite: process.env['DREDD_REST_SUITE'] || null - }; - logger.info('Using apiary reporter.'); - } - - ApiaryReporter.prototype.configureEmitter = function(emitter) { - var _this = this; - emitter.on('start', function(rawBlueprint, callback) { - var ciEnvVar, ciEnvVars, ciVar, ciVars, data, envVarName, envVarNames, path, _i, _j, _len, _len1; - _this.uuid = uuid.v4(); - _this.startedAt = Math.round(new Date().getTime() / 1000); - ciVars = [/^TRAVIS/, /^CIRCLE/, /^CI/, /^DRONE/]; - envVarNames = Object.keys(process.env); - ciEnvVars = {}; - for (_i = 0, _len = envVarNames.length; _i < _len; _i++) { - envVarName = envVarNames[_i]; - ciEnvVar = false; - for (_j = 0, _len1 = ciVars.length; _j < _len1; _j++) { - ciVar = ciVars[_j]; - if (envVarName.match(ciVar) !== null) { - ciEnvVar = true; - } - } - if (ciEnvVar === true) { - ciEnvVars[envVarName] = process.env[envVarName]; - } - } - data = { - blueprint: rawBlueprint, - agent: process.env['DREDD_AGENT'] || process.env['USER'], - agentRunUuid: _this.uuid, - hostname: process.env['DREDD_HOSTNAME'] || os.hostname(), - startedAt: _this.startedAt, - "public": true, - status: 'running', - agentEnvironment: ciEnvVars - }; - path = '/apis/' + _this.configuration['apiSuite'] + '/tests/runs'; - return _this._performRequest(path, 'POST', data, function(error, response, parsedBody) { - if (error) { - logger.error(error); - return callback(); - } else { - _this.remoteId = parsedBody['_id']; - return callback(); - } - }); - }); - emitter.on('test pass', function(test) { - var data, path; - data = _this._transformTestToReporter(test); - path = '/apis/' + _this.configuration['apiSuite'] + '/tests/steps?testRunId=' + _this.remoteId; - return _this._performRequest(path, 'POST', data, function(error, response, parsedBody) { - if (error) { - return logger.error(error); - } - }); - }); - emitter.on('test fail', function(test) { - var data, path; - data = _this._transformTestToReporter(test); - path = '/apis/' + _this.configuration['apiSuite'] + '/tests/steps?testRunId=' + _this.remoteId; - return _this._performRequest(path, 'POST', data, function(error, response, parsedBody) { - if (error) { - return logger.error(error); - } - }); - }); - return emitter.on('end', function(callback) { - var data, path; - data = { - endedAt: Math.round(new Date().getTime() / 1000), - result: _this.stats, - status: _this.stats['failures'] > 0 || _this.stats['errors'] > 0 ? 'failed' : 'passed' - }; - path = '/apis/' + _this.configuration['apiSuite'] + '/tests/run/' + _this.remoteId; - return _this._performRequest(path, 'PATCH', data, function(error, response, parsedBody) { - if (error) { - logger.error(error); - } - logger.complete('See results in Apiary at: https://app.apiary.io/' + _this.configuration.apiSuite + '/tests/run/' + _this.remoteId); - return callback(); - }); - }); - }; - - ApiaryReporter.prototype._transformTestToReporter = function(test) { - var data; - data = { - testRunId: this.remoteId, - origin: test['origin'], - duration: test['duration'], - result: test['status'], - resultData: { - request: test['request'], - realResponse: test['actual'], - expectedResponse: test['expected'], - result: test['results'] - } - }; - return data; - }; - - ApiaryReporter.prototype._performRequest = function(path, method, body, callback) { - var buffer, handleRequest, info, options, parsedUrl, req, system; - buffer = ""; - handleRequest = function(res) { - var _this = this; - res.on('data', function(chunk) { - if (this.verbose) { - console.log('REST Reporter HTTPS Response chunk: ' + chunk); - } - return buffer = buffer + chunk; - }); - res.on('error', function(error) { - if (this.verbose) { - console.log('REST Reporter HTTPS Response error.'); - } - return callback(error, req, res); - }); - return res.on('end', function() { - var info, parsedBody; - if (_this.verbose) { - console.log('Rest Reporter Response ended'); - } - parsedBody = JSON.parse(buffer); - if (_this.verbose) { - info = { - headers: res.headers, - statusCode: res.statusCode, - body: parsedBody - }; - console.log('Rest Reporter Response:', JSON.stringify(info, null, 2)); - } - return callback(void 0, res, parsedBody); - }); - }; - parsedUrl = url.parse(this.configuration['apiUrl']); - system = os.type() + ' ' + os.release() + '; ' + os.arch(); - options = { - host: parsedUrl['hostname'], - port: parsedUrl['port'], - path: path, - method: method, - headers: { - 'User-Agent': "Dredd REST Reporter/" + packageConfig['version'] + " (" + system + ")", - 'Content-Type': 'application/json' - } - }; - if (this.configuration['apiToken'] !== null) { - options.headers['Authentication'] = 'Token ' + this.configuration['apiToken']; - } - if (this.verbose) { - info = { - options: options, - body: body - }; - console.log('Rest Reporter Request:', JSON.stringify(info, null, 2)); - } - if (this.configuration.apiUrl.startsWith('https')) { - if (this.verbose) { - console.log('Starting REST Reporter HTTPS Request'); - } - req = https.request(options, handleRequest); - } else { - if (this.verbose) { - console.log('Starting REST Reporter HTTP Response'); - } - req = http.request(options, handleRequest); - } - req.write(JSON.stringify(body)); - return req.end(); - }; - - return ApiaryReporter; - -})(); - -module.exports = ApiaryReporter; diff --git a/lib/reporters/base-reporter.js b/lib/reporters/base-reporter.js deleted file mode 100644 index c6a2db6af..000000000 --- a/lib/reporters/base-reporter.js +++ /dev/null @@ -1,54 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var BaseReporter, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - -BaseReporter = (function() { - function BaseReporter(emitter, stats, tests) { - this.configureEmitter = __bind(this.configureEmitter, this); - this.type = "base"; - this.stats = stats; - this.tests = tests; - this.configureEmitter(emitter); - } - - BaseReporter.prototype.configureEmitter = function(emitter) { - var _this = this; - emitter.on('start', function(rawBlueprint, callback) { - _this.stats.start = new Date; - return callback(); - }); - emitter.on('end', function(callback) { - _this.stats.end = new Date; - _this.stats.duration = _this.stats.end - _this.stats.start; - return callback(); - }); - emitter.on('test start', function(test) { - _this.tests.push(test); - _this.stats.tests += 1; - return test['start'] = new Date; - }); - emitter.on('test pass', function(test) { - _this.stats.passes += 1; - test['end'] = new Date; - return test['duration'] = test.end - test.start; - }); - emitter.on('test skip', function(test) { - return _this.stats.skipped += 1; - }); - emitter.on('test fail', function(test) { - _this.stats.failures += 1; - test['end'] = new Date; - return test['duration'] = test.end - test.start; - }); - return emitter.on('test error', function(error, test) { - _this.stats.errors += 1; - test['end'] = new Date; - return test['duration'] = test.end - test.start; - }); - }; - - return BaseReporter; - -})(); - -module.exports = BaseReporter; diff --git a/lib/reporters/cli-reporter.js b/lib/reporters/cli-reporter.js deleted file mode 100644 index de58d701f..000000000 --- a/lib/reporters/cli-reporter.js +++ /dev/null @@ -1,84 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var CliReporter, logger, prettifyResponse, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - -logger = require('./../logger'); - -prettifyResponse = require('./../prettify-response'); - -CliReporter = (function() { - function CliReporter(emitter, stats, tests, inlineErrors, details) { - this.configureEmitter = __bind(this.configureEmitter, this); - this.type = "cli"; - this.stats = stats; - this.tests = tests; - this.configureEmitter(emitter); - this.inlineErrors = inlineErrors; - this.details = details; - this.errors = []; - } - - CliReporter.prototype.configureEmitter = function(emitter) { - var _this = this; - emitter.on('start', function(rawBlueprint, callback) { - logger.info('Beginning Dredd testing...'); - return callback(); - }); - emitter.on('end', function(callback) { - var test, _i, _len, _ref; - if (!_this.inlineErrors) { - if (_this.errors.length !== 0) { - logger.info("Displaying failed tests..."); - } - _ref = _this.errors; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - test = _ref[_i]; - logger.fail(test.title + (" duration: " + test.duration + "ms")); - logger.fail(test.message); - logger.request("\n" + prettifyResponse(test.request) + "\n"); - logger.expected("\n" + prettifyResponse(test.expected) + "\n"); - logger.actual("\n" + prettifyResponse(test.actual) + "\n\n"); - } - } - if (_this.stats.tests > 0) { - logger.complete("" + _this.stats.passes + " passing, " + _this.stats.failures + " failing, " + _this.stats.errors + " errors, " + _this.stats.skipped + " skipped"); - } - logger.complete("Tests took " + _this.stats.duration + "ms"); - return callback(); - }); - emitter.on('test pass', function(test) { - logger.pass(test.title + (" duration: " + test.duration + "ms")); - if (_this.details) { - logger.request("\n" + prettifyResponse(test.request) + "\n"); - logger.expected("\n" + prettifyResponse(test.expected) + "\n"); - return logger.actual("\n" + prettifyResponse(test.actual) + "\n\n"); - } - }); - emitter.on('test skip', function(test) { - return logger.skip(test.title); - }); - emitter.on('test fail', function(test) { - logger.fail(test.title + (" duration: " + test.duration + "ms")); - if (_this.inlineErrors) { - logger.fail(test.message); - logger.request("\n" + prettifyResponse(test.request) + "\n"); - logger.expected("\n" + prettifyResponse(test.expected) + "\n"); - return logger.actual("\n" + prettifyResponse(test.actual) + "\n\n"); - } else { - return _this.errors.push(test); - } - }); - return emitter.on('test error', function(error, test) { - if (!_this.inlineErrors) { - _this.errors.push(test); - } - logger.error(test.title + (" duration: " + test.duration + "ms")); - return logger.error(error.stack); - }); - }; - - return CliReporter; - -})(); - -module.exports = CliReporter; diff --git a/lib/reporters/dot-reporter.js b/lib/reporters/dot-reporter.js deleted file mode 100644 index 9bace6d8c..000000000 --- a/lib/reporters/dot-reporter.js +++ /dev/null @@ -1,71 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var DotReporter, logger, prettifyResponse, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - -logger = require('./../logger'); - -prettifyResponse = require('./../prettify-response'); - -DotReporter = (function() { - function DotReporter(emitter, stats, tests, details) { - this.configureEmitter = __bind(this.configureEmitter, this); - this.type = "dot"; - this.stats = stats; - this.tests = tests; - this.configureEmitter(emitter); - this.errors = []; - } - - DotReporter.prototype.configureEmitter = function(emitter) { - var _this = this; - emitter.on('start', function() { - return logger.info('Beginning Dredd testing...'); - }); - emitter.on('end', function(callback) { - var test, _i, _len, _ref; - if (_this.stats.tests > 0) { - if (_this.errors.length > 0) { - _this.write("\n"); - logger.info("Displaying failed tests..."); - _ref = _this.errors; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - test = _ref[_i]; - logger.fail(test.title + (" duration: " + test.duration + "ms")); - logger.fail(test.message); - logger.request("\n" + prettifyResponse(test.request) + "\n"); - logger.expected("\n" + prettifyResponse(test.expected) + "\n"); - logger.actual("\n" + prettifyResponse(test.actual) + "\n\n"); - } - } - _this.write("\n"); - logger.complete("" + _this.stats.passes + " passing, " + _this.stats.failures + " failing, " + _this.stats.errors + " errors, " + _this.stats.skipped + " skipped"); - logger.complete("Tests took " + _this.stats.duration + "ms"); - return callback(); - } - }); - emitter.on('test pass', function(test) { - return _this.write("."); - }); - emitter.on('test skip', function(test) { - return _this.write("-"); - }); - emitter.on('test fail', function(test) { - _this.write("F"); - return _this.errors.push(test); - }); - return emitter.on('test error', function(error, test) { - _this.write("E"); - test.message = "\nError: \n" + error + "\nStacktrace: \n" + error.stack + "\n"; - return _this.errors.push(test); - }); - }; - - DotReporter.prototype.write = function(str) { - return process.stdout.write(str); - }; - - return DotReporter; - -})(); - -module.exports = DotReporter; diff --git a/lib/reporters/html-reporter.js b/lib/reporters/html-reporter.js deleted file mode 100644 index 4ee52a728..000000000 --- a/lib/reporters/html-reporter.js +++ /dev/null @@ -1,117 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var EventEmitter, HtmlReporter, file, fs, logger, marked, prettifyResponse, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - -EventEmitter = require('events').EventEmitter; - -fs = require('fs'); - -marked = require('marked'); - -file = require('file'); - -logger = require('./../logger'); - -prettifyResponse = require('./../prettify-response'); - -marked.setOptions({ - gfm: true, - tables: true, - breaks: true, - pedantic: false, - sanitize: true, - smartLists: true, - smartypants: true -}); - -HtmlReporter = (function(_super) { - __extends(HtmlReporter, _super); - - function HtmlReporter(emitter, stats, tests, path, details) { - this.configureEmitter = __bind(this.configureEmitter, this); - this.sanitizedPath = __bind(this.sanitizedPath, this); - HtmlReporter.__super__.constructor.call(this); - this.type = "html"; - this.stats = stats; - this.tests = tests; - this.path = this.sanitizedPath(path); - this.buf = ""; - this.level = 1; - this.details = details; - this.configureEmitter(emitter); - } - - HtmlReporter.prototype.sanitizedPath = function(path) { - var filePath; - filePath = path != null ? file.path.abspath(path) : file.path.abspath("./report.html"); - if (fs.existsSync(filePath)) { - logger.info("File exists at " + filePath + ", will be overwritten..."); - } - return filePath; - }; - - HtmlReporter.prototype.configureEmitter = function(emitter) { - var title, - _this = this; - title = function(str) { - return Array(_this.level).join("#") + " " + str; - }; - emitter.on('start', function(rawBlueprint, callback) { - _this.level++; - _this.buf += title('Dredd Tests') + "\n"; - return callback(); - }); - emitter.on('end', function(callback) { - var html; - html = marked(_this.buf); - return fs.writeFile(_this.path, html, function(err) { - if (err) { - logger.error(err); - } - return callback(); - }); - }); - emitter.on('test start', function(test) { - return _this.level++; - }); - emitter.on('test pass', function(test) { - _this.buf += title("Pass: " + test.title) + "\n"; - if (_this.details) { - _this.level++; - _this.buf += title("Request") + "\n```\n" + prettifyResponse(test.request) + "\n```\n\n"; - _this.buf += title("Expected") + "\n```\n" + prettifyResponse(test.expected) + "\n```\n\n"; - _this.buf += title("Actual") + "\n```\n" + prettifyResponse(test.actual) + "\n```\n\n"; - _this.level--; - } - return _this.level--; - }); - emitter.on('test skip', function(test) { - _this.buf += title("Skip: " + test.title) + "\n"; - return _this.level--; - }); - emitter.on('test fail', function(test) { - _this.buf += title("Fail: " + test.title + "\n"); - _this.level++; - _this.buf += title("Message") + "\n```\n" + test.message + "\n```\n\n"; - _this.buf += title("Request") + "\n```\n" + prettifyResponse(test.request) + "\n```\n\n"; - _this.buf += title("Expected") + "\n```\n" + prettifyResponse(test.expected) + "\n```\n\n"; - _this.buf += title("Actual") + "\n```\n" + prettifyResponse(test.actual) + "\n```\n\n"; - _this.level--; - return _this.level--; - }); - return emitter.on('test error', function(error, test) { - _this.buf += title("Error: " + test.title + "\n"); - _this.buf += "\n```\n"; - _this.buf += "\nError: \n" + error + "\nStacktrace: \n" + error.stack + "\n"; - _this.buf += "```\n\n"; - return _this.level--; - }); - }; - - return HtmlReporter; - -})(EventEmitter); - -module.exports = HtmlReporter; diff --git a/lib/reporters/markdown-reporter.js b/lib/reporters/markdown-reporter.js deleted file mode 100644 index cf4c53d71..000000000 --- a/lib/reporters/markdown-reporter.js +++ /dev/null @@ -1,103 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var EventEmitter, MarkdownReporter, file, fs, logger, prettifyResponse, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - -EventEmitter = require('events').EventEmitter; - -fs = require('fs'); - -file = require('file'); - -logger = require('./../logger'); - -prettifyResponse = require('./../prettify-response'); - -MarkdownReporter = (function(_super) { - __extends(MarkdownReporter, _super); - - function MarkdownReporter(emitter, stats, tests, path, details) { - this.configureEmitter = __bind(this.configureEmitter, this); - this.sanitizedPath = __bind(this.sanitizedPath, this); - MarkdownReporter.__super__.constructor.call(this); - this.type = "markdown"; - this.stats = stats; - this.tests = tests; - this.path = this.sanitizedPath(path); - this.buf = ""; - this.level = 1; - this.details = details; - this.configureEmitter(emitter); - } - - MarkdownReporter.prototype.sanitizedPath = function(path) { - var filePath; - filePath = path != null ? file.path.abspath(path) : file.path.abspath("./report.md"); - if (fs.existsSync(filePath)) { - logger.info("File exists at " + filePath + ", will be overwritten..."); - } - return filePath; - }; - - MarkdownReporter.prototype.configureEmitter = function(emitter) { - var title, - _this = this; - title = function(str) { - return Array(_this.level).join("#") + " " + str; - }; - emitter.on('start', function(rawBlueprint, callback) { - _this.level++; - _this.buf += title('Dredd Tests') + "\n"; - return callback(); - }); - emitter.on('end', function(callback) { - return fs.writeFile(_this.path, _this.buf, function(err) { - if (err) { - logger.error(err); - } - return callback(); - }); - }); - emitter.on('test start', function(test) { - return _this.level++; - }); - emitter.on('test pass', function(test) { - _this.buf += title("Pass: " + test.title) + "\n"; - if (_this.details) { - _this.level++; - _this.buf += title("Request") + "\n```\n" + prettifyResponse(test.request) + "\n```\n\n"; - _this.buf += title("Expected") + "\n```\n" + prettifyResponse(test.expected) + "\n```\n\n"; - _this.buf += title("Actual") + "\n```\n" + prettifyResponse(test.actual) + "\n```\n\n"; - _this.level--; - } - return _this.level--; - }); - emitter.on('test skip', function(test) { - _this.buf += title("Skip: " + test.title) + "\n"; - return _this.level--; - }); - emitter.on('test fail', function(test) { - _this.buf += title("Fail: " + test.title + "\n"); - _this.level++; - _this.buf += title("Message") + "\n```\n" + test.message + "\n```\n\n"; - _this.buf += title("Request") + "\n```\n" + prettifyResponse(test.request) + "\n```\n\n"; - _this.buf += title("Expected") + "\n```\n" + prettifyResponse(test.expected) + "\n```\n\n"; - _this.buf += title("Actual") + "\n```\n" + prettifyResponse(test.actual) + "\n```\n\n"; - _this.level--; - return _this.level--; - }); - return emitter.on('test error', function(error, test) { - _this.buf += title("Error: " + test.title + "\n"); - _this.buf += "\n```\n"; - _this.buf += "\nError: \n" + error + "\nStacktrace: \n" + error.stack + "\n"; - _this.buf += "```\n\n"; - return _this.level--; - }); - }; - - return MarkdownReporter; - -})(EventEmitter); - -module.exports = MarkdownReporter; diff --git a/lib/reporters/nyan-reporter.js b/lib/reporters/nyan-reporter.js deleted file mode 100644 index 28694500d..000000000 --- a/lib/reporters/nyan-reporter.js +++ /dev/null @@ -1,239 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var NyanCatReporter, logger, prettifyResponse, tty, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - -tty = require('tty'); - -logger = require('./../logger'); - -prettifyResponse = require('./../prettify-response'); - -NyanCatReporter = (function() { - function NyanCatReporter(emitter, stats, tests) { - this.rainbowify = __bind(this.rainbowify, this); - this.generateColors = __bind(this.generateColors, this); - this.cursorHide = __bind(this.cursorHide, this); - this.cursorShow = __bind(this.cursorShow, this); - this.cursorDown = __bind(this.cursorDown, this); - this.cursorUp = __bind(this.cursorUp, this); - this.face = __bind(this.face, this); - this.drawNyanCat = __bind(this.drawNyanCat, this); - this.drawRainbow = __bind(this.drawRainbow, this); - this.appendRainbow = __bind(this.appendRainbow, this); - this.drawScoreboard = __bind(this.drawScoreboard, this); - this.draw = __bind(this.draw, this); - this.configureEmitter = __bind(this.configureEmitter, this); - var width, windowWidth; - this.type = "nyan"; - this.stats = stats; - this.tests = tests; - this.isatty = tty.isatty(1 && tty.isatty(2)); - windowWidth = (this.isatty ? (process.stdout.getWindowSize ? process.stdout.getWindowSize(1)[0] : tty.getWindowSize()[1]) : 75); - width = windowWidth * .75 | 0; - this.rainbowColors = this.generateColors(); - this.colorIndex = 0; - this.numberOfLines = 4; - this.trajectories = [[], [], [], []]; - this.nyanCatWidth = 11; - this.trajectoryWidthMax = width - this.nyanCatWidth; - this.scoreboardWidth = 5; - this.tick = 0; - this.errors = []; - this.configureEmitter(emitter); - } - - NyanCatReporter.prototype.configureEmitter = function(emitter) { - var _this = this; - emitter.on('start', function(rawBlueprint, callback) { - _this.cursorHide(); - _this.draw(); - return callback(); - }); - emitter.on('end', function(callback) { - var i, test, _i, _len, _ref; - _this.cursorShow(); - i = 0; - while (i < _this.numberOfLines) { - _this.write("\n"); - i++; - } - if (_this.errors.length > 0) { - _this.write("\n"); - logger.info("Displaying failed tests..."); - _ref = _this.errors; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - test = _ref[_i]; - logger.fail(test.title + (" duration: " + test.duration + "ms")); - logger.fail(test.message); - logger.request("\n" + prettifyResponse(test.request) + "\n"); - logger.expected("\n" + prettifyResponse(test.expected) + "\n"); - logger.actual("\n" + prettifyResponse(test.actual) + "\n\n"); - } - } - logger.complete("" + _this.stats.passes + " passing, " + _this.stats.failures + " failing, " + _this.stats.errors + " errors, " + _this.stats.skipped + " skipped"); - logger.complete("Tests took " + _this.stats.duration + "ms"); - return callback(); - }); - emitter.on('test pass', function(test) { - return _this.draw(); - }); - emitter.on('test skip', function(test) { - return _this.draw(); - }); - emitter.on('test fail', function(test) { - _this.errors.push(test); - return _this.draw(); - }); - return emitter.on('test error', function(error, test) { - test.message = "\nError: \n" + error + "\nStacktrace: \n" + error.stack + "\n"; - _this.errors.push(test); - return _this.draw(); - }); - }; - - NyanCatReporter.prototype.draw = function() { - this.appendRainbow(); - this.drawScoreboard(); - this.drawRainbow(); - this.drawNyanCat(); - return this.tick = !this.tick; - }; - - NyanCatReporter.prototype.drawScoreboard = function() { - var colors, draw, stats, write; - write = this.write; - draw = function(color, n) { - write(" "); - write("\u001b[" + color + "m" + n + "\u001b[0m"); - return write("\n"); - }; - stats = this.stats; - colors = { - fail: 31, - skipped: 36, - pass: 32 - }; - draw(colors.pass, this.stats.passes); - draw(colors.fail, this.stats.failures); - draw(colors.fail, this.stats.errors); - draw(colors.skipped, this.stats.skipped); - this.write("\n"); - return this.cursorUp(this.numberOfLines + 1); - }; - - NyanCatReporter.prototype.appendRainbow = function() { - var index, rainbowified, segment, trajectory, _results; - segment = (this.tick ? "_" : "-"); - rainbowified = this.rainbowify(segment); - index = 0; - _results = []; - while (index < this.numberOfLines) { - trajectory = this.trajectories[index]; - if (trajectory.length >= this.trajectoryWidthMax) { - trajectory.shift(); - } - trajectory.push(rainbowified); - _results.push(index++); - } - return _results; - }; - - NyanCatReporter.prototype.drawRainbow = function() { - var scoreboardWidth, write; - scoreboardWidth = this.scoreboardWidth; - write = this.write; - this.trajectories.forEach(function(line, index) { - write("\u001b[" + scoreboardWidth + "C"); - write(line.join("")); - return write("\n"); - }); - return this.cursorUp(this.numberOfLines); - }; - - NyanCatReporter.prototype.drawNyanCat = function() { - var color, face, padding, startWidth, tail; - startWidth = this.scoreboardWidth + this.trajectories[0].length; - color = "\u001b[" + startWidth + "C"; - padding = ""; - this.write(color); - this.write("_,------,"); - this.write("\n"); - this.write(color); - padding = (this.tick ? " " : " "); - this.write("_|" + padding + "/\\_/\\ "); - this.write("\n"); - this.write(color); - padding = (this.tick ? "_" : "__"); - tail = (this.tick ? "~" : "^"); - face = void 0; - this.write(tail + "|" + padding + this.face() + " "); - this.write("\n"); - this.write(color); - padding = (this.tick ? " " : " "); - this.write(padding + "\"\" \"\" "); - this.write("\n"); - return this.cursorUp(this.numberOfLines); - }; - - NyanCatReporter.prototype.face = function() { - var stats; - stats = this.stats; - if (stats.failures) { - return "( x .x)"; - } else if (stats.skipped) { - return "( o .o)"; - } else if (stats.passes) { - return "( ^ .^)"; - } else { - return "( - .-)"; - } - }; - - NyanCatReporter.prototype.cursorUp = function(n) { - return this.write("\u001b[" + n + "A"); - }; - - NyanCatReporter.prototype.cursorDown = function(n) { - return this.write("\u001b[" + n + "B"); - }; - - NyanCatReporter.prototype.cursorShow = function() { - return this.isatty && this.write('\u001b[?25h'); - }; - - NyanCatReporter.prototype.cursorHide = function() { - return this.isatty && this.write('\u001b[?25l'); - }; - - NyanCatReporter.prototype.generateColors = function() { - var b, colors, g, i, n, pi3, r; - colors = []; - i = 0; - while (i < (6 * 7)) { - pi3 = Math.floor(Math.PI / 3); - n = i * (1.0 / 6); - r = Math.floor(3 * Math.sin(n) + 3); - g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3); - b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3); - colors.push(36 * r + 6 * g + b + 16); - i++; - } - return colors; - }; - - NyanCatReporter.prototype.rainbowify = function(str) { - var color; - color = this.rainbowColors[this.colorIndex % this.rainbowColors.length]; - this.colorIndex += 1; - return "\u001b[38;5;" + color + "m" + str + "\u001b[0m"; - }; - - NyanCatReporter.prototype.write = function(str) { - return process.stdout.write(str); - }; - - return NyanCatReporter; - -})(); - -module.exports = NyanCatReporter; diff --git a/lib/reporters/x-unit-reporter.js b/lib/reporters/x-unit-reporter.js deleted file mode 100644 index 84ce62952..000000000 --- a/lib/reporters/x-unit-reporter.js +++ /dev/null @@ -1,164 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var EventEmitter, XUnitReporter, file, fs, htmlencode, logger, prettifyResponse, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - -EventEmitter = require('events').EventEmitter; - -fs = require('fs'); - -htmlencode = require('htmlencode'); - -file = require('file'); - -logger = require('./../logger'); - -prettifyResponse = require('./../prettify-response'); - -XUnitReporter = (function(_super) { - var appendLine, cdata, toTag, updateSuiteStats; - - __extends(XUnitReporter, _super); - - function XUnitReporter(emitter, stats, tests, path, details) { - this.configureEmitter = __bind(this.configureEmitter, this); - this.sanitizedPath = __bind(this.sanitizedPath, this); - XUnitReporter.__super__.constructor.call(this); - this.type = "xUnit"; - this.stats = stats; - this.tests = tests; - this.path = this.sanitizedPath(path); - this.details = details; - this.configureEmitter(emitter); - } - - XUnitReporter.prototype.sanitizedPath = function(path) { - var filePath; - filePath = path != null ? file.path.abspath(path) : file.path.abspath("./report.xml"); - if (fs.existsSync(filePath)) { - logger.info("File exists at " + filePath + ", will be overwritten..."); - } - return filePath; - }; - - XUnitReporter.prototype.configureEmitter = function(emitter) { - var _this = this; - emitter.on('start', function(rawBlueprint, callback) { - appendLine(_this.path, toTag('testsuite', { - name: 'Dredd Tests', - tests: _this.stats.tests, - failures: _this.stats.failures, - errors: _this.stats.errors, - skip: _this.stats.skipped, - timestamp: (new Date).toUTCString(), - time: _this.stats.duration / 1000 - }, false)); - return callback(); - }); - emitter.on('end', function(callback) { - return updateSuiteStats(_this.path, _this.stats, callback); - }); - emitter.on('test pass', function(test) { - var attrs, deets; - attrs = { - name: htmlencode.htmlEncode(test.title), - time: test.duration / 1000 - }; - if (_this.details) { - deets = "\nRequest: \n" + prettifyResponse(test.request) + "\nExpected: \n" + prettifyResponse(test.expected) + "\nActual:\n" + prettifyResponse(test.actual); - return appendLine(_this.path, toTag('testcase', attrs, false, toTag('system-out', null, false, cdata(deets)))); - } else { - return appendLine(_this.path, toTag('testcase', attrs, true)); - } - }); - emitter.on('test skip', function(test) { - var attrs; - attrs = { - name: htmlencode.htmlEncode(test.title), - time: test.duration / 1000 - }; - return appendLine(_this.path, toTag('testcase', attrs, false, toTag('skipped', null, true))); - }); - emitter.on('test fail', function(test) { - var attrs, diff; - attrs = { - name: htmlencode.htmlEncode(test.title), - time: test.duration / 1000 - }; - diff = "Message: \n" + test.message + "\nRequest: \n" + prettifyResponse(test.request) + "\nExpected: \n" + prettifyResponse(test.expected) + "\nActual:\n" + prettifyResponse(test.actual); - return appendLine(_this.path, toTag('testcase', attrs, false, toTag('failure', null, false, cdata(diff)))); - }); - return emitter.on('test error', function(error, test) { - var attrs, errorMessage; - attrs = { - name: htmlencode.htmlEncode(test.title), - time: test.duration / 1000 - }; - errorMessage = "\nError: \n" + error + "\nStacktrace: \n" + error.stack; - return appendLine(_this.path, toTag('testcase', attrs, false, toTag('failure', null, false, cdata(errorMessage)))); - }); - }; - - updateSuiteStats = function(path, stats, callback) { - return fs.readFile(path, function(err, data) { - var newStats, position, restOfFile, xmlHeader; - if (!err) { - data = data.toString(); - position = data.toString().indexOf('\n'); - if (position !== -1) { - restOfFile = data.substr(position + 1); - newStats = toTag('testsuite', { - name: 'Dredd Tests', - tests: stats.tests, - failures: stats.failures, - errors: stats.errors, - skip: stats.skipped, - timestamp: (new Date).toUTCString(), - time: stats.duration / 1000 - }, false); - xmlHeader = ''; - return fs.writeFile(path, xmlHeader + '\n' + newStats + '\n' + restOfFile + '', function(err) { - if (err) { - logger.error(err); - } - return callback(); - }); - } else { - return callback(); - } - } else { - logger.error(err); - return callback(); - } - }); - }; - - cdata = function(str) { - return ''; - }; - - appendLine = function(path, line) { - return fs.appendFileSync(path, line + "\n"); - }; - - toTag = function(name, attrs, close, content) { - var end, key, pairs, tag; - end = (close ? "/>" : ">"); - pairs = []; - tag = void 0; - for (key in attrs) { - pairs.push(key + "=\"" + attrs[key] + "\""); - } - tag = "<" + name + (pairs.length ? " " + pairs.join(" ") : "") + end; - if (content) { - tag += content + " methodIndexB): - return 1; - case methodIndexA !== methodIndexB: - return a['_index'] - b['_index']; - } - }); - arr.map(function(a) { - return delete a['_index']; - }); - return arr; -}; - -module.exports = sortTransactions; diff --git a/lib/transaction-runner.js b/lib/transaction-runner.js deleted file mode 100644 index 5f6fbd3ba..000000000 --- a/lib/transaction-runner.js +++ /dev/null @@ -1,228 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -var TransactionRunner, addHooks, advisable, async, flattenHeaders, gavel, html, http, https, logger, os, packageConfig, path, sortTransactions, url, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - -http = require('http'); - -https = require('https'); - -html = require('html'); - -url = require('url'); - -path = require('path'); - -os = require('os'); - -gavel = require('gavel'); - -advisable = require('advisable'); - -async = require('async'); - -flattenHeaders = require('./flatten-headers'); - -addHooks = require('./add-hooks'); - -sortTransactions = require('./sort-transactions'); - -packageConfig = require('./../package.json'); - -logger = require('./logger'); - -String.prototype.startsWith = function(str) { - return this.slice(0, str.length) === str; -}; - -TransactionRunner = (function() { - function TransactionRunner(configuration) { - this.configuration = configuration; - this.executeTransaction = __bind(this.executeTransaction, this); - this.configureTransaction = __bind(this.configureTransaction, this); - advisable.async.call(TransactionRunner.prototype); - addHooks(this, {}); - } - - TransactionRunner.prototype.run = function(transactions, callback) { - transactions = this.configuration.options['sorted'] ? sortTransactions(transactions) : transactions; - async.mapSeries(transactions, this.configureTransaction, function(err, results) { - return transactions = results; - }); - addHooks({}, transactions); - return async.eachSeries(transactions, this.executeTransaction, function() { - return callback(); - }); - }; - - TransactionRunner.prototype.configureTransaction = function(transaction, callback) { - var caseInsensitiveMap, configuration, configuredTransaction, expected, flatHeaders, fullPath, header, id, key, name, origin, parsedUrl, request, response, splitHeader, system, value, _i, _len, _ref; - configuration = this.configuration; - origin = transaction['origin']; - request = transaction['request']; - response = transaction['response']; - parsedUrl = url.parse(configuration['server']); - if (parsedUrl['path'] === "/") { - fullPath = request['uri']; - } else { - fullPath = '/' + [parsedUrl['path'].replace(/^\/|\/$/g, ""), request['uri'].replace(/^\/|\/$/g, "")].join("/"); - } - flatHeaders = flattenHeaders(request['headers']); - if (!flatHeaders['User-Agent']) { - system = os.type() + ' ' + os.release() + '; ' + os.arch(); - flatHeaders['User-Agent'] = "Dredd/" + packageConfig['version'] + " (" + system + ")"; - } - caseInsensitiveMap = {}; - for (key in flatHeaders) { - value = flatHeaders[key]; - caseInsensitiveMap[key.toLowerCase()] = key; - } - if (!caseInsensitiveMap['content-length'] && request['body'] !== '') { - flatHeaders['Content-Length'] = request['body'].length; - } - if (configuration.options.header.length > 0) { - _ref = configuration.options.header; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - header = _ref[_i]; - splitHeader = header.split(':'); - flatHeaders[splitHeader[0]] = splitHeader[1]; - } - } - request['headers'] = flatHeaders; - name = ''; - if (origin['resourceGroupName']) { - name += origin['resourceGroupName']; - } - if (origin['resourceName']) { - name += ' > ' + origin['resourceName']; - } - if (origin['actionName']) { - name += ' > ' + origin['actionName']; - } - if (origin['exampleName']) { - name += ' > ' + origin['exampleName']; - } - id = request['method'] + ' ' + request['uri']; - expected = { - headers: flattenHeaders(response['headers']), - body: response['body'], - statusCode: response['status'] - }; - if (response['schema']) { - expected['bodySchema'] = response['schema']; - } - configuredTransaction = { - name: name, - id: id, - host: parsedUrl['hostname'], - port: parsedUrl['port'], - request: request, - expected: expected, - origin: origin, - fullPath: fullPath, - protocol: parsedUrl.protocol - }; - return callback(null, configuredTransaction); - }; - - TransactionRunner.prototype.executeTransaction = function(transaction, callback) { - var buffer, configuration, handleRequest, req, requestOptions, test, transport, _ref; - configuration = this.configuration; - requestOptions = { - host: transaction.host, - port: transaction.port, - path: transaction.fullPath, - method: transaction.request['method'], - headers: transaction.request.headers - }; - test = { - status: '', - title: transaction.id, - message: transaction.name, - origin: transaction.origin - }; - if (configuration.options.names) { - logger.info(transaction.name); - return callback(); - } - configuration.emitter.emit('test start', test); - if (configuration.options['dry-run']) { - logger.info("Dry run, skipping API Tests..."); - return callback(); - } else if (configuration.options.method.length > 0 && !(_ref = transaction.request.method, __indexOf.call(configuration.options.method, _ref) >= 0)) { - configuration.emitter.emit('test skip', test); - return callback(); - } else { - buffer = ""; - handleRequest = function(res) { - res.on('data', function(chunk) { - return buffer = buffer + chunk; - }); - req.on('error', function(error) { - if (error) { - return configuration.emitter.emit('test error', error, test); - } - }); - return res.on('end', function() { - var real; - real = { - statusCode: res.statusCode, - headers: res.headers, - body: buffer - }; - transaction['real'] = real; - return gavel.isValid(real, transaction.expected, 'response', function(error, isValid) { - if (error) { - configuration.emitter.emit('test error', error, test); - } - if (isValid) { - test.status = "pass"; - test.actual = real; - test.expected = transaction.expected; - test.request = transaction.request; - configuration.emitter.emit('test pass', test); - return callback(); - } else { - return gavel.validate(real, transaction.expected, 'response', function(error, result) { - var data, entity, entityResult, message, _i, _len, _ref1; - if (error) { - configuration.emitter.emit('test error', error, test); - } - message = ''; - for (entity in result) { - data = result[entity]; - _ref1 = data['results']; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - entityResult = _ref1[_i]; - message += entity + ": " + entityResult['message'] + "\n"; - } - } - test.status = "fail"; - test.title = transaction.id; - test.message = message; - test.actual = real; - test.expected = transaction.expected; - test.request = transaction.request; - test.start = test.start; - test.results = result; - configuration.emitter.emit('test fail', test); - return callback(); - }); - } - }); - }); - }; - transport = transaction.protocol === 'https:' ? https : http; - req = transport.request(requestOptions, handleRequest); - if (transaction.request['body'] !== '') { - req.write(transaction.request['body']); - } - return req.end(); - } - }; - - return TransactionRunner; - -})(); - -module.exports = TransactionRunner;