2019-03-12 12:53:03 +00:00
|
|
|
import test from 'ava';
|
2021-04-16 15:23:29 +07:00
|
|
|
import chalk from '../source/index.js';
|
2019-03-12 12:53:03 +00:00
|
|
|
|
2021-04-16 15:23:29 +07:00
|
|
|
chalk.level = 1;
|
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 */
|
|
|
|
|
});
|