Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-org code #449

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"standard"
],
"rules": {
"no-var": "off"
}
}
3 changes: 3 additions & 0 deletions .taprc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
coverage: true
coverage-map: 'coverage-map.js'

reporter: terse

files:
- 'lib/**/*.test.js'
- 'test/**/*.test.js'
9 changes: 9 additions & 0 deletions coverage-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

module.exports = testFile => {
// Ignore coverage on files that do not have a direct corollary.
if (testFile.startsWith('test/')) return false

// Indicate the matching name, sans '.test.js', should be checked for coverage.
return testFile.replace(/\.test\.js$/, '.js')
}
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const {
prettifyTime,
buildSafeSonicBoom,
filterLog,
handleCustomlevelsOpts,
handleCustomlevelNamesOpts
handleCustomLevelsOpts,
handleCustomLevelsNamesOpts
} = require('./lib/utils')

const jsonParser = input => {
Expand All @@ -40,7 +40,7 @@ const defaultOptions = {
useOnlyCustomProps: true,
levelFirst: false,
messageKey: MESSAGE_KEY,
messageFormat: false,
messageFormat: null,
timestampKey: TIMESTAMP_KEY,
translateTime: true,
useMetadata: false,
Expand All @@ -65,8 +65,8 @@ function prettyFactory (options) {
const errorLikeObjectKeys = opts.errorLikeObjectKeys
const errorProps = opts.errorProps.split(',')
const useOnlyCustomProps = typeof opts.useOnlyCustomProps === 'boolean' ? opts.useOnlyCustomProps : opts.useOnlyCustomProps === 'true'
const customLevels = handleCustomlevelsOpts(opts.customLevels)
const customLevelNames = handleCustomlevelNamesOpts(opts.customLevels)
const customLevels = handleCustomLevelsOpts(opts.customLevels)
const customLevelNames = handleCustomLevelsNamesOpts(opts.customLevels)

const customColors = opts.customColors
? opts.customColors
Expand Down
18 changes: 10 additions & 8 deletions test/lib/colors.test.js → lib/colors.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'

const { test } = require('tap')
const getColorizerPrivate = require('../../lib/colors')
const { colorizerFactory: getColorizerPublic } = require('../../index')
const getColorizer = require('./colors')

const testDefaultColorizer = getColorizer => async t => {
const colorizer = getColorizer()
Expand Down Expand Up @@ -122,9 +121,12 @@ const testCustomColoringColorizer = getColorizer => async t => {
t.equal(colorized, '\u001B[37mUSERLVL\u001B[39m')
}

test('returns default colorizer - private export', testDefaultColorizer(getColorizerPrivate))
test('returns default colorizer - public export', testDefaultColorizer(getColorizerPublic))
test('returns colorizing colorizer - private export', testColoringColorizer(getColorizerPrivate))
test('returns colorizing colorizer - public export', testColoringColorizer(getColorizerPublic))
test('returns custom colorizing colorizer - private export', testCustomColoringColorizer(getColorizerPrivate))
test('returns custom colorizing colorizer - public export', testCustomColoringColorizer(getColorizerPublic))
test('returns default colorizer - private export', testDefaultColorizer(getColorizer))
test('returns colorizing colorizer - private export', testColoringColorizer(getColorizer))
test('returns custom colorizing colorizer - private export', testCustomColoringColorizer(getColorizer))

test('custom props defaults to standard levels', async t => {
const colorizer = getColorizer(true, [], true)
const colorized = colorizer('info')
t.equal(colorized, '\u001B[37mINFO\u001B[39m')
})
9 changes: 9 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
'use strict'

/**
* A set of property names that indicate the value represents an error object.
*
* @typedef {string[]} K_ERROR_LIKE_KEYS
*/

module.exports = {
DATE_FORMAT: 'yyyy-mm-dd HH:MM:ss.l o',
DATE_FORMAT_SIMPLE: 'HH:MM:ss.l',

/**
* @type {K_ERROR_LIKE_KEYS}
*/
ERROR_LIKE_KEYS: ['err', 'error'],

MESSAGE_KEY: 'msg',
Expand Down
Loading