Permalink
Browse files

Exit successful under non 2xx and 3xx status codes

  • Loading branch information...
Kikobeats committed May 3, 2018
1 parent f032e00 commit 36b6c8f831e4f53287c6293573d9e1cd56c49d87
Showing with 33 additions and 19 deletions.
  1. +1 −1 bin/cli/index.js
  2. +11 −9 bin/view/helpers.js
  3. +21 −9 bin/view/render.js
@@ -5,8 +5,8 @@
const { chain, size, concat, first, isEmpty } = require('lodash')
const normalizeUrl = require('normalize-url')
const reachableUrl = require('reachable-url')
const dnsErrors = require('dnserrors')
const { STATUS_CODES } = require('http')
const dnsErrors = require('dnserrors')
const urlint = require('urlint')
const isCI = require('is-ci')
@@ -1,28 +1,30 @@
'use strict'
const { isEqual, includes, keys, size, isNil } = require('lodash')
const { includes, chain, isEmpty, isNil } = require('lodash')
const VALID_STATUS_CODES = ['2xx', '3xx']
const setState = (state, data) => {
const { statusCodeGroup } = data
const status = state.count[statusCodeGroup]
const linkStatus = state.links[statusCodeGroup]
const linkItem = [data.statusCode, data.url, data.timestamp]
const count = { [statusCodeGroup]: isNil(status) ? 1 : status + 1 }
const links = {
[statusCodeGroup]: isNil(linkStatus)
? [linkItem]
: linkStatus.concat([linkItem])
[statusCodeGroup]: isNil(linkStatus) ? [data] : linkStatus.concat(data)
}
return { count, links }
}
const processExit = data => {
const statusCodes = keys(data)
const isOnly2xx =
includes(statusCodes, '2xx') && isEqual(size(statusCodes), 1)
process.exit(isOnly2xx ? 0 : 1)
const statusCodes = chain(data)
.keys()
.remove(statusCode => !includes(VALID_STATUS_CODES, statusCode))
.value()
process.exit(isEmpty(statusCodes) ? 0 : 1)
}
module.exports = {
@@ -1,6 +1,6 @@
'use strict'
const { toNumber, first, chain, map, reduce } = require('lodash')
const { concat, toNumber, first, chain, map, reduce } = require('lodash')
const prettyMs = require('pretty-ms')
const { EOL } = require('os')
@@ -37,14 +37,26 @@ const renderResume = ({ startTimestamp, count, links }) => {
const info = map(sortByStatusCode(count), (count, statusCode) => {
const countByStatusCode = resumeCount(count, statusCode)
const rows = map(links[statusCode], ([statusCode, url, timestamp]) => {
const colorizeStatusCode = byStatusCode(statusCode)
const colorTimestamp = getRequestColor(timestamp)
const colorizeTimestamp = colorize[colorTimestamp](
`+${prettyMs(timestamp)}`
)
return `${colorizeStatusCode} ${url} ${colorizeTimestamp}`
}).join(EOL)
const rows = map(
links[statusCode],
({
redirectStatusCode,
statusCode,
requestUrl,
timestamp,
redirectUrls
}) => {
const colorizeStatusCode = byStatusCode(
redirectStatusCode || statusCode
)
const colorTimestamp = getRequestColor(timestamp)
const colorizeTimestamp = colorize[colorTimestamp](
`+${prettyMs(timestamp)}`
)
const urls = concat(requestUrl, redirectUrls).join('')
return `${colorizeStatusCode} ${urls} ${colorizeTimestamp}`
}
).join(EOL)
return countByStatusCode + EOL + rows + EOL
}).join(EOL)

0 comments on commit 36b6c8f

Please sign in to comment.