forked from chalk/chalk
/
level.js
57 lines (50 loc) 路 1.41 KB
/
level.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import path from 'path';
import test from 'ava';
import execa from 'execa';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('../source');
test('don\'t output colors when manually disabled', t => {
const oldLevel = chalk.level;
chalk.level = 0;
t.is(chalk.red('foo'), 'foo');
chalk.level = oldLevel;
});
test('enable/disable colors based on overall chalk .level property, not individual instances', t => {
const oldLevel = chalk.level;
chalk.level = 1;
const {red} = chalk;
t.is(red.level, 1);
chalk.level = 0;
t.is(red.level, chalk.level);
chalk.level = oldLevel;
});
test('propagate enable/disable changes from child colors', t => {
const oldLevel = chalk.level;
chalk.level = 1;
const {red} = chalk;
t.is(red.level, 1);
t.is(chalk.level, 1);
red.level = 0;
t.is(red.level, 0);
t.is(chalk.level, 0);
chalk.level = 1;
t.is(red.level, 1);
t.is(chalk.level, 1);
chalk.level = oldLevel;
});
test('disable colors if they are not supported', async t => {
const {stdout} = await execa.node(path.join(__dirname, '_fixture'));
t.is(stdout, 'testout testerr');
});
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');
});