Skip to content

Commit

Permalink
setup build
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianlzy committed Jan 29, 2017
1 parent 2d07593 commit 3517466
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ before_script:
- npm install
script:
- npm run test
- npm run build
after_success:
- npm run coverage
deploy:
Expand Down
15 changes: 7 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ var appendQuery = function appendQuery(qs) {
return '';
};

var constructUrl = function constructUrl(url) {
var constructUrl = exports.constructUrl = function constructUrl(url) {
var qs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return url + appendQuery(qs);
};

var mapRequestToCurl = function mapRequestToCurl(request, requestUrl) {
var mapRequestToCurl = exports.mapRequestToCurl = function mapRequestToCurl(request, requestUrl) {
var headers = reduce(request.header, function (headers, value, header) {
return headers + ('-H \'' + header + ': ' + value + '\' ');
}, ' ');
return 'curl -v -X ' + request.method + headers + requestUrl;
};

var getColorByResponseStatus = function getColorByResponseStatus(status) {
var getColorByResponseStatus = exports.getColorByResponseStatus = function getColorByResponseStatus(status) {
if (status < 300) {
return 'green';
} else if (status < 400) {
Expand All @@ -39,7 +39,7 @@ var getColorByResponseStatus = function getColorByResponseStatus(status) {
return 'red';
};

var getColorByResponseSpeed = function getColorByResponseSpeed(ms) {
var getColorByResponseTime = exports.getColorByResponseTime = function getColorByResponseTime(ms) {
if (ms < 200) {
return 'green';
} else if (ms < 1000) {
Expand All @@ -65,8 +65,9 @@ var handleResponse = function handleResponse(request, start, logger, debugLog, d
var curl = mapRequestToCurl(request, requestUrl);

debugCurl.apply(null, [chalk.gray(curl)]);
logger(curl);

debugLog.apply(null, ['%s %s %s %s %s', chalk.magenta(protocol), chalk.cyan(requestMethod), chalk[getColorByResponseStatus(responseStatus)](responseStatus), chalk.gray(requestUrl), chalk.gray('(') + chalk[getColorByResponseSpeed(elapsed)](elapseTime) + chalk.gray(')')]);
debugLog.apply(null, ['%s %s %s %s %s', chalk.magenta(protocol), chalk.cyan(requestMethod), chalk[getColorByResponseStatus(responseStatus)](responseStatus), chalk.gray(requestUrl), chalk.gray('(') + chalk[getColorByResponseTime(elapsed)](elapseTime) + chalk.gray(')')]);
logger(protocol + ' ' + requestMethod + ' ' + responseStatus + ' ' + requestUrl + ' (' + elapseTime + ')');
};
};
Expand All @@ -82,6 +83,4 @@ exports.default = function () {

request.on('response', handleResponse(request, start, logger, debugLog, debugCurl));
};
};

module.exports = exports['default'];
};

0 comments on commit 3517466

Please sign in to comment.