chalk/test/level.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-07-23 22:17:33 +02:00
import path from 'path';
import test from 'ava';
import execa from 'execa';
// Spoof supports-color
require('./_supports-color')(__dirname);
2019-07-12 13:51:07 +07:00
const chalk = require('../source');
2017-07-23 22:17:33 +02:00
test('don\'t output colors when manually disabled', t => {
2018-09-18 14:05:08 +07:00
const oldLevel = chalk.level;
chalk.level = 0;
t.is(chalk.red('foo'), 'foo');
chalk.level = oldLevel;
2017-07-23 22:17:33 +02:00
});
test('enable/disable colors based on overall chalk .level property, not individual instances', t => {
2018-09-18 14:05:08 +07:00
const oldLevel = chalk.level;
chalk.level = 1;
const {red} = chalk;
2017-07-23 22:17:33 +02:00
t.is(red.level, 1);
2018-09-18 14:05:08 +07:00
chalk.level = 0;
t.is(red.level, chalk.level);
chalk.level = oldLevel;
2017-07-23 22:17:33 +02:00
});
test('propagate enable/disable changes from child colors', t => {
2018-09-18 14:05:08 +07:00
const oldLevel = chalk.level;
chalk.level = 1;
const {red} = chalk;
2017-07-23 22:17:33 +02:00
t.is(red.level, 1);
2018-09-18 14:05:08 +07:00
t.is(chalk.level, 1);
2017-07-23 22:17:33 +02:00
red.level = 0;
t.is(red.level, 0);
2018-09-18 14:05:08 +07:00
t.is(chalk.level, 0);
chalk.level = 1;
2017-07-23 22:17:33 +02:00
t.is(red.level, 1);
2018-09-18 14:05:08 +07:00
t.is(chalk.level, 1);
chalk.level = oldLevel;
2017-07-23 22:17:33 +02:00
});
test('disable colors if they are not supported', async t => {
2019-07-12 13:59:50 +07:00
const {stdout} = await execa.node(path.join(__dirname, '_fixture'));
2019-09-22 12:07:33 +03:00
t.is(stdout, 'testout testerr');
2017-07-23 22:17:33 +02:00
});
2019-09-27 10:53:54 +07:00
test('chalk.Level enum object', t => {
const {Level} = chalk;
t.is(Level.None, 0);
t.is(Level.Basic, 1);
t.is(Level.Ansi256, 2);
t.is(Level.TrueColor, 3);
t.is(Level[Level.None], 'None');
t.is(Level[Level.Basic], 'Basic');
t.is(Level[Level.Ansi256], 'Ansi256');
t.is(Level[Level.TrueColor], 'TrueColor');
});