Comparing version 0.5.1 to 0.5.2
@@ -30,2 +30,3 @@ import './polyfills'; | ||
verbose: boolean; | ||
colors?: boolean; | ||
}; | ||
@@ -32,0 +33,0 @@ } |
@@ -117,6 +117,9 @@ "use strict"; | ||
return [2 /*return*/, wrap(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var trialRes; | ||
var verbose, colors, logger, trialRes; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
verbose = testArgs && testArgs.verbose ? testArgs.verbose : false; | ||
colors = testArgs && testArgs.colors ? testArgs.colors : false; | ||
logger = new utils_1.Logger(verbose, colors); | ||
config = toConfig(config, paramsOrCallback); | ||
@@ -128,3 +131,3 @@ config['async'] = false; | ||
if (!utils_1.isEmptyObj(trialRes.failures)) { | ||
utils_1.checkAndPrintErrors(trialRes, testArgs); | ||
utils_1.checkAndPrintErrors(trialRes, testArgs, logger); | ||
} | ||
@@ -131,0 +134,0 @@ return [2 /*return*/, { |
@@ -21,6 +21,7 @@ "use strict"; | ||
.option("-v, --verbose", "Print out extra information for debugging.") | ||
.option("--colors", "Print test results in color") | ||
.option("-c, --local", "Execute functional test synchronously on local machine. This flag trumps load-test and async options") | ||
.parse(process.argv); | ||
start()["catch"](function (err) { | ||
console.error('\x1b[31m', err, '\x1b[0m'); | ||
console.error(err); | ||
process.exit(2); | ||
@@ -30,8 +31,8 @@ }); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var wait, bail, async, quiet, token, verbose, local, loadTest, _a, fileOrFolder, rawParams, logger, parameters, loadmill, listOfFiles, _i, listOfFiles_1, file, res, id, method; | ||
var wait, bail, async, quiet, token, verbose, colors, local, loadTest, _a, fileOrFolder, rawParams, logger, parameters, loadmill, listOfFiles, _i, listOfFiles_1, file, res, id, method; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
wait = program.wait, bail = program.bail, async = program.async, quiet = program.quiet, token = program.token, verbose = program.verbose, local = program.local, loadTest = program.loadTest, _a = program.args, fileOrFolder = _a[0], rawParams = _a.slice(1); | ||
logger = new utils_1.Logger(verbose); | ||
wait = program.wait, bail = program.bail, async = program.async, quiet = program.quiet, token = program.token, verbose = program.verbose, colors = program.colors, local = program.local, loadTest = program.loadTest, _a = program.args, fileOrFolder = _a[0], rawParams = _a.slice(1); | ||
logger = new utils_1.Logger(verbose, colors); | ||
if (!fileOrFolder) { | ||
@@ -72,3 +73,3 @@ validationFailed("No configuration file or folder were provided."); | ||
logger.verbose("Running " + file + " as functional test locally"); | ||
return [4 /*yield*/, loadmill.runFunctionalLocally(file, parameters, undefined, { verbose: verbose })]; | ||
return [4 /*yield*/, loadmill.runFunctionalLocally(file, parameters, undefined, { verbose: verbose, colors: colors })]; | ||
case 2: | ||
@@ -123,3 +124,3 @@ res = _b.sent(); | ||
console.log(''); | ||
console.error.apply(console, ['\x1b[31m'].concat(args, ['\x1b[0m'])); | ||
console.error.apply(console, args); | ||
program.outputHelp(); | ||
@@ -126,0 +127,0 @@ process.exit(3); |
@@ -32,11 +32,18 @@ "use strict"; | ||
}; | ||
var getObjectAsString = function (obj) { return util.inspect(obj, { showHidden: false, depth: null, colors: true, compact: false }); }; | ||
var printRequest = function (trialRes, assertionErrorsPerRequest, testArgs) { | ||
var getObjectAsString = function (obj, colors) { | ||
// trim response body to length of 255 | ||
if (obj.response && obj.response.text && obj.response.text.length > 255) { | ||
obj.response.text = obj.response.text.substring(0, 255) + ' [trimmed]'; | ||
} | ||
return util.inspect(obj, { showHidden: false, depth: null, colors: colors, compact: false }); | ||
}; | ||
var printRequest = function (trialRes, assertionErrorsPerRequest, testArgs, logger) { | ||
if (testArgs && testArgs.verbose) { | ||
console.error('\x1b[31m', 'Test failure response -', '\x1b[0m', getObjectAsString(trialRes)); | ||
logger.error('Test failure response -'); | ||
logger.log(getObjectAsString(trialRes, testArgs.colors)); | ||
} | ||
else { | ||
console.error('\x1b[31m', 'Test failed request -', '\x1b[0m'); | ||
logger.error('Test failed request -'); | ||
for (var requestIndex in assertionErrorsPerRequest) { | ||
console.error(getObjectAsString(trialRes.resolvedRequests[requestIndex])); | ||
logger.log(getObjectAsString(trialRes.resolvedRequests[requestIndex], testArgs && testArgs.colors)); | ||
} | ||
@@ -46,7 +53,6 @@ } | ||
var evaluteParameterExpresion = function (expr, postParams) { return loadmill_runner_1.resolveExpression(expr, postParams); }; | ||
exports.checkAndPrintErrors = function (trialRes, testArgs) { | ||
exports.checkAndPrintErrors = function (trialRes, testArgs, logger) { | ||
var assertionErrorsPerRequest = getAssertionErrors(trialRes); | ||
printRequest(trialRes, assertionErrorsPerRequest, testArgs); | ||
if (!exports.isEmptyObj(assertionErrorsPerRequest)) { | ||
console.error('\x1b[31m', 'Test failures -', '\x1b[0m'); | ||
logger.error('Test failed -'); | ||
for (var requestIndex in assertionErrorsPerRequest) { | ||
@@ -57,13 +63,13 @@ var request = trialRes.resolvedRequests[requestIndex]; | ||
// If there was a failure but no assertion failed this means the request itself failed | ||
console.error("Failed request \"" + description + "\" - " + request.method + " " + request.url); | ||
logger.log("Failed request \"" + description + "\" - " + request.method + " " + request.url); | ||
if (request.response) { | ||
console.error("Status: " + request.response.status + " " + request.response.statusText); | ||
logger.log("Status: " + request.response.status + " " + request.response.statusText); | ||
} | ||
var histogram = trialRes.failures[requestIndex].histogram; | ||
for (var errorKey in histogram) { | ||
console.error("Error: " + errorKey); | ||
logger.log("Error: " + errorKey); | ||
} | ||
} | ||
else { | ||
console.error("Assertion errors in request \"" + description + "\" - " + request.method + " " + request.url); | ||
logger.error("Assertion errors in request \"" + description + "\" - " + request.method + " " + request.url); | ||
} | ||
@@ -86,6 +92,9 @@ for (var _i = 0, _a = assertionErrorsPerRequest[requestIndex]; _i < _a.length; _i++) { | ||
} | ||
console.error("Paramter \"" + parameterName + "\" value is \"" + actualParameterValue + "\", expected to", assertionMismatch); | ||
logger.log("Paramter \"" + parameterName + "\" value is \"" + actualParameterValue + "\", expected to", assertionMismatch); | ||
} | ||
} | ||
} | ||
logger.log('\n'); | ||
printRequest(trialRes, assertionErrorsPerRequest, testArgs, logger); | ||
logger.log('\n'); | ||
}; | ||
@@ -110,5 +119,6 @@ exports.getJSONFilesInFolderRecursively = function (fileOrFolder, filelist) { | ||
var Logger = /** @class */ (function () { | ||
function Logger(verbose) { | ||
function Logger(verbose, colors) { | ||
var _this = this; | ||
this.verb = false; | ||
this.colors = false; | ||
this.log = function (msg) { | ||
@@ -121,3 +131,10 @@ var args = []; | ||
}; | ||
this.error = function (err) { return console.error('\x1b[31m', err, '\x1b[0m'); }; | ||
this.error = function (err) { | ||
if (_this.colors) { | ||
console.error('\x1b[31m', err, '\x1b[0m'); | ||
} | ||
else { | ||
console.error(err); | ||
} | ||
}; | ||
this.verbose = function (msg) { | ||
@@ -131,2 +148,3 @@ var args = []; | ||
this.verb = verbose; | ||
this.colors = colors; | ||
} | ||
@@ -133,0 +151,0 @@ return Logger; |
{ | ||
"name": "loadmill", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A node.js module for running load tests and functional tests on loadmill.com", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -200,2 +200,3 @@ # Loadmill | ||
- `-v, --verbose` Print out extra information for debugging (trumps `-q`). In case of an error will print the entire test's requests otherwise will print only the failed request. | ||
- `--colors` Print test results in color. | ||
- `-c, --local` Execute functional test synchronously on local machine. This flag overrides load-test and async options. |
import './polyfills' | ||
import * as fs from 'fs'; | ||
import * as superagent from 'superagent'; | ||
import {getJSONFilesInFolderRecursively, isEmptyObj, isString, checkAndPrintErrors} from './utils'; | ||
import {getJSONFilesInFolderRecursively, isEmptyObj, isString, checkAndPrintErrors, Logger} from './utils'; | ||
import {runFunctionalOnLocalhost} from 'loadmill-runner'; | ||
@@ -29,3 +29,3 @@ | ||
export type TestFailures = {[reason: string]: {[histogram: string]: Histogram}}; | ||
export type Args = {verbose: boolean}; | ||
export type Args = {verbose: boolean, colors?: boolean}; | ||
} | ||
@@ -135,2 +135,6 @@ | ||
async () => { | ||
const verbose = testArgs && testArgs.verbose ? testArgs.verbose : false; | ||
const colors = testArgs && testArgs.colors ? testArgs.colors : false; | ||
const logger = new Logger(verbose, colors); | ||
config = toConfig(config, paramsOrCallback); | ||
@@ -143,3 +147,3 @@ | ||
if (!isEmptyObj(trialRes.failures)) { | ||
checkAndPrintErrors(trialRes, testArgs); | ||
checkAndPrintErrors(trialRes, testArgs, logger); | ||
} | ||
@@ -146,0 +150,0 @@ |
@@ -21,2 +21,3 @@ import * as Loadmill from './index'; | ||
.option("-v, --verbose", "Print out extra information for debugging.") | ||
.option("--colors", "Print test results in color") | ||
.option("-c, --local", "Execute functional test synchronously on local machine. This flag trumps load-test and async options") | ||
@@ -27,3 +28,3 @@ .parse(process.argv); | ||
.catch(err => { | ||
console.error('\x1b[31m', err, '\x1b[0m'); | ||
console.error(err); | ||
process.exit(2); | ||
@@ -41,2 +42,3 @@ }); | ||
verbose, | ||
colors, | ||
local, | ||
@@ -47,3 +49,3 @@ loadTest, | ||
const logger = new Logger(verbose); | ||
const logger = new Logger(verbose, colors); | ||
@@ -89,3 +91,3 @@ if (!fileOrFolder) { | ||
logger.verbose(`Running ${file} as functional test locally`); | ||
res = await loadmill.runFunctionalLocally(file, parameters, undefined, {verbose}); | ||
res = await loadmill.runFunctionalLocally(file, parameters, undefined, {verbose, colors}); | ||
} else { | ||
@@ -122,3 +124,3 @@ if (loadTest) { | ||
console.log(''); | ||
console.error('\x1b[31m', ... args, '\x1b[0m'); | ||
console.error(... args); | ||
program.outputHelp(); | ||
@@ -125,0 +127,0 @@ process.exit(3); |
@@ -38,12 +38,19 @@ import * as fs from "fs"; | ||
const getObjectAsString = obj => util.inspect(obj, { showHidden: false, depth: null, colors: true, compact: false } as any); | ||
const getObjectAsString = (obj, colors) => { | ||
// trim response body to length of 255 | ||
if (obj.response && obj.response.text && obj.response.text.length > 255) { | ||
obj.response.text = obj.response.text.substring(0, 255) + ' [trimmed]' | ||
} | ||
return util.inspect(obj, { showHidden: false, depth: null, colors: colors, compact: false } as any); | ||
} | ||
const printRequest = (trialRes, assertionErrorsPerRequest, testArgs) => { | ||
const printRequest = (trialRes, assertionErrorsPerRequest, testArgs, logger) => { | ||
if (testArgs && testArgs.verbose) { | ||
console.error('\x1b[31m', 'Test failure response -', '\x1b[0m', getObjectAsString(trialRes)); | ||
logger.error('Test failure response -'); | ||
logger.log(getObjectAsString(trialRes, testArgs.colors)); | ||
} else { | ||
console.error('\x1b[31m', 'Test failed request -', '\x1b[0m'); | ||
logger.error('Test failed request -'); | ||
for (let requestIndex in assertionErrorsPerRequest) { | ||
console.error(getObjectAsString(trialRes.resolvedRequests[requestIndex])) ; | ||
logger.log(getObjectAsString(trialRes.resolvedRequests[requestIndex], testArgs && testArgs.colors)) ; | ||
} | ||
@@ -55,7 +62,7 @@ } | ||
export const checkAndPrintErrors = (trialRes, testArgs) => { | ||
export const checkAndPrintErrors = (trialRes, testArgs, logger) => { | ||
let assertionErrorsPerRequest = getAssertionErrors(trialRes); | ||
printRequest(trialRes, assertionErrorsPerRequest, testArgs); | ||
if (!isEmptyObj(assertionErrorsPerRequest)) { | ||
console.error('\x1b[31m', 'Test failures -', '\x1b[0m'); | ||
logger.error('Test failed -'); | ||
@@ -68,5 +75,5 @@ for (let requestIndex in assertionErrorsPerRequest) { | ||
// If there was a failure but no assertion failed this means the request itself failed | ||
console.error(`Failed request "${description}" - ${request.method} ${request.url}`); | ||
logger.log(`Failed request "${description}" - ${request.method} ${request.url}`); | ||
if (request.response) { | ||
console.error(`Status: ${request.response.status} ${request.response.statusText}`); | ||
logger.log(`Status: ${request.response.status} ${request.response.statusText}`); | ||
} | ||
@@ -76,7 +83,7 @@ | ||
for (let errorKey in histogram) { | ||
console.error(`Error: ${errorKey}`); | ||
logger.log(`Error: ${errorKey}`); | ||
} | ||
} else { | ||
console.error(`Assertion errors in request "${description}" - ${request.method} ${request.url}`); | ||
logger.error(`Assertion errors in request "${description}" - ${request.method} ${request.url}`); | ||
} | ||
@@ -100,3 +107,3 @@ | ||
console.error(`Paramter "${parameterName}" value is "${actualParameterValue}", expected to`, assertionMismatch); | ||
logger.log(`Paramter "${parameterName}" value is "${actualParameterValue}", expected to`, assertionMismatch); | ||
} | ||
@@ -106,2 +113,6 @@ } | ||
} | ||
logger.log('\n'); | ||
printRequest(trialRes, assertionErrorsPerRequest, testArgs, logger); | ||
logger.log('\n'); | ||
}; | ||
@@ -131,10 +142,18 @@ | ||
private readonly verb: boolean = false; | ||
private readonly colors: boolean = false; | ||
constructor(verbose: boolean) { | ||
constructor(verbose: boolean, colors: boolean) { | ||
this.verb = verbose; | ||
this.colors = colors; | ||
} | ||
log = (msg, ...args) => console.log(msg, ...args); | ||
error = (err) => console.error('\x1b[31m', err, '\x1b[0m'); | ||
error = (err) => { | ||
if (this.colors) { | ||
console.error('\x1b[31m', err, '\x1b[0m') | ||
} else { | ||
console.error(err) | ||
} | ||
}; | ||
verbose = (msg, ...args) => this.verb ? console.log(msg, ...args) : void (0); | ||
} |
96903
1205
202