* Fix XO linting and update some dev dependencies Fixes #275 * Add some badges to the readme * Tiny travis.yml tweak * Require Node.js 6 * Validate the `level` option Fixes #248 * Add failing test for #234 (#235) * Add type definitions badge (#286) * Add Tidelift mention in the readme * Replace RawGit URL Fixes #305 * Fix ignore chars regex flags in rainbow example (#306) Use global matches rather than stopping after the first match. * Strict mode in Flow definition (#309) * Add security section * Add docs comments and tests for TypeScript definitions (#299) Fixes #293 * Update dependencies and meta tweaks * Type definition improvements * Enforce `chalk.constructor` to be called with `new` in TypeScript * Add extra level/enabled property info in the readme (#308) * Code style tweaks * Change tagged template literal argument type to accept `unknown` instead of just `string` (#316)
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
import test from 'ava';
|
|
|
|
// Spoof supports-color
|
|
require('./_supports-color')(__dirname);
|
|
|
|
const chalk = require('..');
|
|
|
|
test('visible: normal output when enabled', t => {
|
|
const instance = new chalk.constructor({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});
|
|
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});
|
|
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});
|
|
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;
|
|
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;
|
|
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');
|
|
});
|