Deprecate chalk.constructor() in favor of new chalk.Instance() (#322)

This commit is contained in:
Tom Sherman 2019-03-12 12:53:03 +00:00 committed by Sindre Sorhus
parent 60959e05cf
commit de2f4cd606
11 changed files with 110 additions and 88 deletions

View file

@ -6,25 +6,25 @@ require('./_supports-color')(__dirname);
const chalk = require('..');
test('visible: normal output when enabled', t => {
const instance = new chalk.constructor({level: 3, enabled: true});
const instance = new chalk.Instance({level: 3, enabled: true});
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.constructor({level: 3, enabled: false});
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.constructor({level: 0, enabled: true});
const instance = new chalk.Instance({level: 0, enabled: true});
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.constructor({level: 3, enabled: true});
const instance = new chalk.Instance({level: 3, enabled: true});
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');