2019-03-12 12:53:03 +00:00
|
|
|
import test from 'ava';
|
|
|
|
|
|
|
|
|
|
// Spoof supports-color
|
|
|
|
|
require('./_supports-color')(__dirname);
|
|
|
|
|
|
2019-07-12 13:51:07 +07:00
|
|
|
const chalk = require('../source');
|
2019-03-12 12:53:03 +00:00
|
|
|
|
|
|
|
|
test('create an isolated context where colors can be disabled (by level)', t => {
|
2019-07-13 07:45:31 +02:00
|
|
|
const instance = new chalk.Instance({level: 0});
|
2019-03-12 12:53:03 +00:00
|
|
|
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('the `level` option should be a number from 0 to 3', t => {
|
|
|
|
|
/* eslint-disable no-new */
|
|
|
|
|
t.throws(() => {
|
|
|
|
|
new chalk.Instance({level: 10});
|
2020-10-04 10:56:24 +13:00
|
|
|
}, {message: /should be an integer from 0 to 3/});
|
2019-03-12 12:53:03 +00:00
|
|
|
|
|
|
|
|
t.throws(() => {
|
|
|
|
|
new chalk.Instance({level: -1});
|
2020-10-04 10:56:24 +13:00
|
|
|
}, {message: /should be an integer from 0 to 3/});
|
2019-03-12 12:53:03 +00:00
|
|
|
/* eslint-enable no-new */
|
|
|
|
|
});
|