Merge branch 'master' of github.com:chalk/chalk into fix/nested-styling

This commit is contained in:
Ahad Birang 2019-07-12 22:26:08 +04:30
commit 93d8c7f980
25 changed files with 553 additions and 588 deletions

View file

@ -1,4 +1,4 @@
'use strict';
const chalk = require('..');
const chalk = require('../source');
console.log(chalk.hex('#ff6159')('test'));

View file

@ -1,86 +0,0 @@
// @flow
import chalk from '..';
// $ExpectError (Can't have typo in option name)
new chalk.Instance({levl: 1});
new chalk.Instance({level: 1});
// $ExpectError (Option must have proper type)
new chalk.Instance({enabled: 'true'});
new chalk.Instance({enabled: true});
// $ExpectError (Can't have typo in chalk method)
chalk.rd('foo');
chalk.red('foo');
// $ExpectError (Can't have typo in chalk method)
chalk.gren`foo`;
chalk.green`foo`;
// $ExpectError (Can't have typo in chalk method)
chalk.red.bgBlu.underline('foo');
chalk.red.bgBlue.underline('foo');
// $ExpectError (Level must be 0, 1, 2, or 3)
const badCtx = chalk.Instance({level: 4});
const ctx = chalk.Instance({level: 3});
// $ExpectError (Can't have typo in method name)
ctx.gry('foo');
ctx.grey('foo');
// $ExpectError (Can't have typo in method name)
ctx`foo`.value();
ctx`foo`.valueOf();
// $ExpectError (Can't have typo in property name)
chalk.abled = true;
chalk.enabled = true;
// $ExpectError (Can't use invalid Level for property setter)
chalk.level = 10;
chalk.level = 1;
const chalkInstance = new chalk.Instance();
// $ExpectError (Can't have typo in method name)
chalkInstance.blu('foo');
chalkInstance.blue('foo');
chalkInstance`foo`;
// $ExpectError (Can't have typo in method name)
chalk.keywrd('orange').bgBlue('foo');
chalk.keyword('orange').bgBlue('foo');
// $ExpectError (rgb should take in 3 numbers)
chalk.rgb(1, 14).bgBlue('foo');
chalk.rgb(1, 14, 9).bgBlue('foo');
// $ExpectError (hsl should take in 3 numbers)
chalk.hsl(1, 14, '9').bgBlue('foo');
chalk.hsl(1, 14, 9).bgBlue('foo');
// $ExpectError (hsv should take in 3 numbers)
chalk.hsv(1, 14).bgBlue('foo');
chalk.hsv(1, 14, 9).bgBlue('foo');
// $ExpectError (hwb should take in 3 numbers)
chalk.hwb(1, 14).bgBlue('foo');
chalk.hwb(1, 14, 9).bgBlue('foo');
// $ExpectError (Can't have typo in method name)
chalk.visibl('foo');
chalk.visible('foo');
// $ExpectError (Can't have typo in method name)
chalk.red.visibl('foo');
chalk.red.visible('foo');
chalk.visible.red('foo');
// $ExpectError (Can't write to readonly property)
chalk.black = 'foo';
chalk.black;
// $ExpectError (Can't write to readonly property)
chalk.reset = 'foo';
console.log(chalk.reset);

View file

@ -3,7 +3,7 @@ import test from 'ava';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('..');
const chalk = require('../source');
console.log('TERM:', process.env.TERM || '[none]');
console.log('platform:', process.platform || '[unknown]');
@ -82,6 +82,10 @@ test('line breaks should open and close colors', t => {
t.is(chalk.grey('hello\nworld'), '\u001B[90mhello\u001B[39m\n\u001B[90mworld\u001B[39m');
});
test('line breaks should open and close colors with CRLF', t => {
t.is(chalk.grey('hello\r\nworld'), '\u001B[90mhello\u001B[39m\r\n\u001B[90mworld\u001B[39m');
});
test('properly convert RGB to 16 colors on basic color terminals', t => {
t.is(new chalk.Instance({level: 1}).hex('#FF0000')('hello'), '\u001B[91mhello\u001B[39m');
t.is(new chalk.Instance({level: 1}).bgHex('#FF0000')('hello'), '\u001B[101mhello\u001B[49m');
@ -97,3 +101,7 @@ test('don\'t emit RGB codes if level is 0', t => {
t.is(new chalk.Instance({level: 0}).hex('#FF0000')('hello'), 'hello');
t.is(new chalk.Instance({level: 0}).bgHex('#FF0000')('hello'), 'hello');
});
test('supports blackBright color', t => {
t.is(chalk.blackBright('foo'), '\u001B[90mfoo\u001B[39m');
});

View file

@ -1,6 +1,6 @@
import test from 'ava';
const chalk = require('..');
const chalk = require('../source');
test('Chalk.constructor should throw an expected error', t => {
const expectedError = t.throws(() => {

View file

@ -3,7 +3,7 @@ import test from 'ava';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('..');
const chalk = require('../source');
test('don\'t output colors when manually disabled', t => {
chalk.enabled = false;

View file

@ -3,7 +3,7 @@ import test from 'ava';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('..');
const chalk = require('../source');
test('create an isolated context where colors can be disabled (by level)', t => {
const instance = new chalk.Instance({level: 0, enabled: true});

View file

@ -5,7 +5,7 @@ import execa from 'execa';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('..');
const chalk = require('../source');
test('don\'t output colors when manually disabled', t => {
const oldLevel = chalk.level;
@ -40,5 +40,6 @@ test('propagate enable/disable changes from child colors', t => {
});
test('disable colors if they are not supported', async t => {
t.is(await execa.stdout('node', [path.join(__dirname, '_fixture')]), 'test');
const {stdout} = await execa.node(path.join(__dirname, '_fixture'));
t.is(stdout, 'test');
});

View file

@ -8,7 +8,7 @@ require('./_supports-color')(__dirname, {
has16m: false
});
const chalk = require('..');
const chalk = require('../source');
test.failing('colors can be forced by using chalk.enabled', t => {
chalk.enabled = true;

View file

@ -4,7 +4,7 @@ import test from 'ava';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('..');
const chalk = require('../source');
test('return an empty string for an empty literal', t => {
const instance = new chalk.Instance();
@ -168,3 +168,10 @@ test('should properly handle undefined template interpolated values', t => {
t.is(instance`hello ${undefined}`, 'hello undefined');
t.is(instance`hello ${null}`, 'hello null');
});
test('should allow bracketed Unicode escapes', t => {
const instance = new chalk.Instance({level: 3});
t.is(instance`\u{AB}`, '\u{AB}');
t.is(instance`This is a {bold \u{AB681}} test`, 'This is a \u001B[1m\u{AB681}\u001B[22m test');
t.is(instance`This is a {bold \u{10FFFF}} test`, 'This is a \u001B[1m\u{10FFFF}\u001B[22m test');
});

View file

@ -3,7 +3,7 @@ import test from 'ava';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('..');
const chalk = require('../source');
test('visible: normal output when enabled', t => {
const instance = new chalk.Instance({level: 3, enabled: true});