Remove the .enabled property in favor of .level (#356)
This commit is contained in:
parent
87156ce8e2
commit
1f77953f1a
9 changed files with 17 additions and 101 deletions
|
|
@ -1,35 +0,0 @@
|
|||
import test from 'ava';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const chalk = require('../source');
|
||||
|
||||
test('don\'t output colors when manually disabled', t => {
|
||||
chalk.enabled = false;
|
||||
t.is(chalk.red('foo'), 'foo');
|
||||
chalk.enabled = true;
|
||||
});
|
||||
|
||||
test('enable/disable colors based on overall chalk enabled property, not individual instances', t => {
|
||||
chalk.enabled = false;
|
||||
const {red} = chalk;
|
||||
t.false(red.enabled);
|
||||
chalk.enabled = true;
|
||||
t.true(red.enabled);
|
||||
chalk.enabled = true;
|
||||
});
|
||||
|
||||
test('propagate enable/disable changes from child colors', t => {
|
||||
chalk.enabled = false;
|
||||
const {red} = chalk;
|
||||
t.false(red.enabled);
|
||||
t.false(chalk.enabled);
|
||||
red.enabled = true;
|
||||
t.true(red.enabled);
|
||||
t.true(chalk.enabled);
|
||||
chalk.enabled = false;
|
||||
t.false(red.enabled);
|
||||
t.false(chalk.enabled);
|
||||
chalk.enabled = true;
|
||||
});
|
||||
|
|
@ -6,21 +6,13 @@ require('./_supports-color')(__dirname);
|
|||
const chalk = require('../source');
|
||||
|
||||
test('create an isolated context where colors can be disabled (by level)', t => {
|
||||
const instance = new chalk.Instance({level: 0, enabled: true});
|
||||
const instance = new chalk.Instance({level: 0});
|
||||
t.is(instance.red('foo'), 'foo');
|
||||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
instance.level = 2;
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('create an isolated context where colors can be disabled (by enabled flag)', t => {
|
||||
const instance = new chalk.Instance({enabled: false});
|
||||
t.is(instance.red('foo'), 'foo');
|
||||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
instance.enabled = true;
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('the `level` option should be a number from 0 to 3', t => {
|
||||
/* eslint-disable no-new */
|
||||
t.throws(() => {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ test('don\'t output colors when manually disabled', t => {
|
|||
chalk.level = oldLevel;
|
||||
});
|
||||
|
||||
test('enable/disable colors based on overall chalk enabled property, not individual instances', t => {
|
||||
test('enable/disable colors based on overall chalk .level property, not individual instances', t => {
|
||||
const oldLevel = chalk.level;
|
||||
chalk.level = 1;
|
||||
const {red} = chalk;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ require('./_supports-color')(__dirname, {
|
|||
|
||||
const chalk = require('../source');
|
||||
|
||||
test.failing('colors can be forced by using chalk.enabled', t => {
|
||||
chalk.enabled = true;
|
||||
test('colors can be forced by using chalk.level', t => {
|
||||
chalk.level = 1;
|
||||
t.is(chalk.green('hello'), '\u001B[32mhello\u001B[39m');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,40 +5,34 @@ require('./_supports-color')(__dirname);
|
|||
|
||||
const chalk = require('../source');
|
||||
|
||||
test('visible: normal output when enabled', t => {
|
||||
const instance = new chalk.Instance({level: 3, enabled: true});
|
||||
test('visible: normal output when level > 0', t => {
|
||||
const instance = new chalk.Instance({level: 3});
|
||||
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('visible: no output when disabled', t => {
|
||||
const instance = new chalk.Instance({level: 3, enabled: false});
|
||||
t.is(instance.red.visible('foo'), '');
|
||||
t.is(instance.visible.red('foo'), '');
|
||||
});
|
||||
|
||||
test('visible: no output when level is too low', t => {
|
||||
const instance = new chalk.Instance({level: 0, enabled: true});
|
||||
const instance = new chalk.Instance({level: 0});
|
||||
t.is(instance.visible.red('foo'), '');
|
||||
t.is(instance.red.visible('foo'), '');
|
||||
});
|
||||
|
||||
test('test switching back and forth between enabled and disabled', t => {
|
||||
const instance = new chalk.Instance({level: 3, enabled: true});
|
||||
test('test switching back and forth between level == 0 and level > 0', t => {
|
||||
const instance = new chalk.Instance({level: 3});
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.visible('foo'), 'foo');
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
|
||||
instance.enabled = false;
|
||||
instance.level = 0;
|
||||
t.is(instance.red('foo'), 'foo');
|
||||
t.is(instance.visible('foo'), '');
|
||||
t.is(instance.visible.red('foo'), '');
|
||||
t.is(instance.red.visible('foo'), '');
|
||||
t.is(instance.red('foo'), 'foo');
|
||||
|
||||
instance.enabled = true;
|
||||
instance.level = 3;
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue