Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60959e0
commit de2f4cd
Showing
11 changed files
with
107 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,15 @@ | ||
import test from 'ava'; | ||
|
||
// Spoof supports-color | ||
require('./_supports-color')(__dirname); | ||
|
||
const chalk = require('..'); | ||
|
||
test('create an isolated context where colors can be disabled (by level)', t => { | ||
const instance = new chalk.constructor({level: 0, enabled: true}); | ||
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('Chalk.constructor should throw an expected error', t => { | ||
const expectedError = t.throws(() => { | ||
chalk.constructor(); | ||
}); | ||
|
||
test('create an isolated context where colors can be disabled (by enabled flag)', t => { | ||
const instance = new chalk.constructor({enabled: false}); | ||
t.is(instance.red('foo'), 'foo'); | ||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
instance.enabled = true; | ||
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.constructor({level: 10}); | ||
}, /should be an integer from 0 to 3/); | ||
t.is(expectedError.message, '`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.'); | ||
|
||
t.throws(() => { | ||
new chalk.constructor({level: -1}); | ||
}, /should be an integer from 0 to 3/); | ||
/* eslint-enable no-new */ | ||
new chalk.constructor(); // eslint-disable-line no-new | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import test from 'ava'; | ||
|
||
// Spoof supports-color | ||
require('./_supports-color')(__dirname); | ||
|
||
const chalk = require('..'); | ||
|
||
test('create an isolated context where colors can be disabled (by level)', t => { | ||
const instance = new chalk.Instance({level: 0, enabled: true}); | ||
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('create an isolated context where colors can be disabled (by enabled flag)', t => { | ||
const instance = new chalk.Instance({enabled: false}); | ||
t.is(instance.red('foo'), 'foo'); | ||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
instance.enabled = true; | ||
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}); | ||
}, /should be an integer from 0 to 3/); | ||
|
||
t.throws(() => { | ||
new chalk.Instance({level: -1}); | ||
}, /should be an integer from 0 to 3/); | ||
/* eslint-enable no-new */ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.