test(stderr): test if stderr work

This commit is contained in:
Pavel Lang 2018-12-27 19:05:58 +01:00
parent 85f99bb677
commit 6be301b1a4
No known key found for this signature in database
GPG key ID: 623A223A57974B55
3 changed files with 35 additions and 0 deletions

View file

@ -1,4 +1,6 @@
'use strict';
const chalk = require('..');
const cherr = require('../stderr');
console.log(chalk.hex('#ff6159')('test'));
console.error(cherr.hex('#ffe861')('test stderr'));

View file

@ -7,6 +7,12 @@ const DEFAULT = {
hasBasic: true,
has256: true,
has16m: true
},
stderr: {
level: 3,
hasBasic: true,
has256: true,
has16m: true
}
};

27
test/stderr.js Normal file
View file

@ -0,0 +1,27 @@
import path from 'path';
import test from 'ava';
import execa from 'execa';
// Spoof supports-color
require('./_supports-color')(__dirname);
const cherr = require('../stderr');
test('stderr don\'t output colors when manually disabled', t => {
cherr.enabled = false;
t.is(cherr.red('foo'), 'foo');
cherr.enabled = true;
});
test('stderr enable/disable colors based on overall chalk enabled property, not individual instances', t => {
cherr.enabled = false;
const {red} = cherr;
t.false(red.enabled);
cherr.enabled = true;
t.true(red.enabled);
cherr.enabled = true;
});
test('disable colors if they are not supported', async t => {
t.is(await execa.stderr('node', [path.join(__dirname, '_fixture')]), 'test stderr');
});