Skip to content

Commit e2cabc6

Browse files
committed
Modify colors support
1 parent d35bc15 commit e2cabc6

File tree

4 files changed

+6
-35
lines changed

4 files changed

+6
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ logProcessErrors(options)
4747
- [`log` `{function}`](#custom-logging)
4848
- [`getLevel` `{function}`](#log-level)
4949
- [`getMessage` `{function}`](#log-message)
50-
- [`colors` `{boolean}`](#log-message) (default: `false`)
50+
- [`colors` `{boolean}`](#log-message) (default: `true`)
5151
- [`skipEvent` `{function}`](#skipping-events)
5252
- [`exitOn` `{string[]}`](#process-exit) (default: `['uncaughtException']`)
5353

src/colors.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
'use strict'
22

33
const chalk = require('chalk')
4-
const { stdout: { level } = {} } = require('supports-color')
54

6-
const getColors = function({ opts }) {
7-
const chalkOpts = getChalkOpts({ opts })
8-
return chalk.constructor(chalkOpts)
9-
}
10-
11-
// Can disable or force colors with `opts.colors`.
12-
// chalk will automatically disable colors if output does not support it.
13-
const getChalkOpts = function({ opts: { colors } }) {
14-
if (colors === false) {
15-
return { enabled: false }
16-
}
17-
18-
// Chalk `level` must be set otherwise `enabled` will be noop if terminal
19-
// does not support color (e.g. during a shell file redirection)
20-
// However it should only be set if it is `undefined` or `0`
21-
return { enabled: true, level: level || 2 }
5+
const getColors = function({ opts: { colors } }) {
6+
// Can disable colors with `opts.colors`.
7+
// chalk will automatically disable colors if output does not support it.
8+
return chalk.constructor({ enabled: colors })
229
}
2310

2411
module.exports = {

src/options.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const { validate } = require('jest-validate')
4-
const supportsColor = require('supports-color')
54

65
const { defaultGetLevel } = require('./level')
76
const { defaultGetMessage } = require('./message')
@@ -23,7 +22,7 @@ const DEFAULT_OPTS = {
2322
getLevel: defaultGetLevel,
2423
getMessage: defaultGetMessage,
2524
log: defaultLog,
26-
colors: Boolean(supportsColor.stdout),
25+
colors: true,
2726
exitOn: ['uncaughtException'],
2827
}
2928

test/colors.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@ repeatEvents((prefix, { eventName, emitEvent }) => {
1919
stopLogging()
2020
})
2121

22-
test(`${prefix} should allow forcing colorizing default opts.getMessage()`, async t => {
23-
const { stopLogging, log } = startLogging({
24-
log: 'spy',
25-
colors: true,
26-
eventName,
27-
})
28-
29-
await emitEvent()
30-
31-
t.true(log.calledOnce)
32-
t.true(hasAnsi(log.firstCall.args[0]))
33-
34-
stopLogging()
35-
})
36-
3722
test(`${prefix} should allow disabling colorizing default opts.getMessage()`, async t => {
3823
const { stopLogging, log } = startLogging({
3924
log: 'spy',

0 commit comments

Comments
 (0)