Skip to content
Merged
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
40 changes: 40 additions & 0 deletions test/helper/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* This module is maintained to promote separation between the tests and the
* implementation.
*/
'use strict';

const ansiStyles = require('ansi-styles');

function make(name) {
const style = ansiStyles[name];
return function (string) {
return style.open + string + style.close;
};
}
const bold = make('bold');
const white = make('white');
const gray = make('gray');

// The following color definitions are contextual so that they produce expected
// values which mimic the behavior of the Chalk library.
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
const openDim = isSimpleWindowsTerm ? '' : ansiStyles.dim.open;
const openBlue = isSimpleWindowsTerm ? '\u001B[94m' : ansiStyles.blue.open;
// "Use `bold` by default on Windows"
// https://github.com/chalk/chalk/issues/36
const blue = string => openBlue + string + ansiStyles.blue.close;
// "(Windows) chalk.gray.dim not visible"
// https://github.com/chalk/chalk/issues/58
const dimGray = string => gray(openDim + string + ansiStyles.dim.close);

module.exports = {
blue,
boldWhite: string => bold(white(string)),
dimGray,
gray,
green: make('green'),
magenta: make('magenta'),
red: make('red'),
yellow: make('yellow')
};
Loading