From c4cab1b8ba06a4dbb3e2f5cfba647b731805df42 Mon Sep 17 00:00:00 2001 From: biodiscus Date: Tue, 30 Jan 2024 23:51:20 +0100 Subject: [PATCH] feat: add `bgGrey` and `bgGray` aliases for `bgBlackBright` --- CHANGELOG.md | 7 +++ README.md | 90 ++++++++++++++++------------ bench/index.js | 1 + package.json | 4 +- pkg/package.json | 2 +- src/ansi-codes.js | 73 +++++++--------------- src/color-support.js | 52 ++++++++++++++++ src/index.d.ts | 7 ++- src/index.js | 140 +++++++++++++++++++------------------------ src/index.mjs | 4 +- src/utils.js | 34 ----------- test/flags.test.js | 24 +++----- test/index.test.js | 123 ++++++++++++++++--------------------- test/package.test.js | 6 +- test/unit.test.js | 99 ++++++++++-------------------- 15 files changed, 298 insertions(+), 368 deletions(-) create mode 100644 src/color-support.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f2e75a4..146e518 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change log +## 2.1.0 (2024-01-30) + +- feat: add `bgGrey` and `bgGray` aliases for `bgBlackBright` +- refactor: optimize source code +- test: refactor tests +- docs: update readme + ## 2.0.3 (2023-12-14) - fix(index.d.ts): use function overload to make the tagged template have the correct type, #16 diff --git a/README.md b/README.md index 3ec0a15..ba2ad25 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ANSI Styling -
The Node.js library for formatting text in terminal with ANSI colors & styles
+
The Node.js library for formatting Terminal and Console output with ANSI colors & styles
--- @@ -15,9 +15,8 @@ [![codecov](https://codecov.io/gh/webdiscus/ansis/branch/master/graph/badge.svg?token=H7SFJONX1X)](https://codecov.io/gh/webdiscus/ansis) [![node](https://img.shields.io/npm/dm/ansis)](https://www.npmjs.com/package/ansis) -Ansis is the tiny and faster compatible alternative to [Chalk][chalk] with even more useful features. -Colorize your output in a terminal with clean syntax, -e.g., ``` green`Hello World!` ``` ``` red`Error!` ``` ``` black.bgYellow`Warning!` ```. +**Ansis** is a **smaller** and **faster** alternative to [Chalk][chalk] with additional useful features and **clean syntax**.\ +For example: ``` green`Succeful!` ``` ``` red`Error!` ``` ``` black.bgYellow`Warning!` ``` ``` hex('#E0115F').bold`Ruby` ```. **Why yet one lib?**\ See [comparison](https://github.com/webdiscus/ansis#compare) @@ -34,25 +33,32 @@ and [benchmarks](https://github.com/webdiscus/ansis#benchmark) of most popular N ## 💡 Highlights -- supports both **ESM** and **CommonJS** -- supports **Deno**, **Next.JS** runtime -- up to **x3 faster** than **chalk**, [see benchmarks](#benchmark) -- only **3 KB** dist code -- [standard API](#base-colors) like **chalk** -- default import `import ansis from 'ansis'`, usage `ansis.red('error')` -- [named import](#named-import) `import { red } from 'ansis'`, usage ``` red('error') ``` -- [chained syntax](#chained-syntax) `red.bold.underline('text')` -- [nested **template strings**](#nested-syntax) ``` red`R ${green`G`} R` ``` +- Supports both **ESM** and **CommonJS** +- Supports **TypeScript** +- Supports **Deno**, **Next.JS** runtimes +- [Standard API](#base-colors) compatible with **Chalk**, switch from **Chalk** to **Ansis** without changing your code + ```diff + - import chalk from 'chalk'; + + import chalk, { red } from 'ansis'; + + chalk.red.bold('Error!'); // <- the original Chalk code works fine + red.bold`Error!`; // <- the same result with Ansis + ``` +- Default import `import ansis from 'ansis'` or `const ansis = require('ansis')` +- [Named import](#named-import) `import { red } from 'ansis'` or `const { red } = require('ansis')` +- [Chained syntax](#chained-syntax) `red.bold.underline('text')` +- [Nested **template strings**](#nested-syntax) ``` red`R ${green`G`} R` ``` - [ANSI 256 colors](#256-colors) and [Truecolor](#truecolor) (**RGB**, **HEX**) ``` rgb(224, 17, 95)`Ruby` ```, ``` hex('#96C')`Amethyst` ``` -- [extending of base colors](#extend-colors) with named **truecolors** +- [Extending of base colors](#extend-colors) with named **truecolors** - [ANSI codes](#escape-codes) as `open` and `close` property for each style ``` `Hello ${red.open}World${red.close}!` ``` -- [strip ANSI codes](#strip) method `ansis.strip()` -- [correct style break](#new-line) at the `end of line` when used `\n` in string -- supports the [environment variables](#cli-vars) `NO_COLOR` `FORCE_COLOR` and flags `--no-color` `--color` -- **auto detects** color support -- **TypeScript** friendly -- zero dependencies +- [Strip ANSI codes](#strip) method `ansis.strip()` +- [Correct style break](#new-line) at the `end of line` when used `\n` in string +- Supports the [environment variables](#cli-vars) `NO_COLOR` `FORCE_COLOR` and flags `--no-color` `--color` +- **Auto detects** color support +- Up to **x3 faster** than **Chalk**, [see benchmarks](#benchmark) and only **3 KB** dist code +- Doesn't extend `String.prototype` +- Zero dependencies ## ❓Question / Feature Request / Bug @@ -76,12 +82,18 @@ You can import default module or named colors with ESM or CommonJS syntax. import ansis from 'ansis'; // ESM named import import { red, green, blue } from 'ansis'; +``` + +or +```js // CommonJS default import const ansis = require('ansis'); // CommonJS named import const { red, green, blue } = require('ansis'); +``` +```js console.log(ansis.green('Success!')); console.log(green('Success!')); @@ -250,25 +262,25 @@ Output:\ Colors and styles have standard names used by many popular libraries, such as [chalk][chalk], [colorette][colorette], [kleur][kleur]. -| Foreground colors | Background colors | Styles | -|:----------------------|:------------------|--------------------------------------------| -| `black` | `bgBlack` | `dim` (alias`faint`) | -| `red` | `bgRed` | **`bold`** | -| `green` | `bgGreen` | _`italic`_ | -| `yellow` | `bgYellow` | `underline` | -| `blue` | `bgBlue` | `strikethrough` (alias `strike`) | -| `magenta` | `bgMagenta` | `doubleUnderline` (_not widely supported_) | -| `cyan` | `bgCyan` | `overline` (_not widely supported_) | -| `white` | `bgWhite` | `frame` (_not widely supported_) | -| `gray` (alias `grey`) | `bgGray` | `encircle` (_not widely supported_) | -| `blackBright` | `bgBlackBright` | `inverse` | -| `redBright` | `bgRedBright` | `visible` | -| `greenBright` | `bgGreenBright` | `hidden` | -| `yellowBright` | `bgYellowBright` | `reset` | -| `blueBright` | `bgBlueBright` | | -| `magentaBright` | `bgMagentaBright` | | -| `cyanBright` | `bgCyanBright` | | -| `whiteBright` | `bgWhiteBright` | | +| Foreground colors | Background colors | Styles | +|:----------------------|:--------------------------|--------------------------------------------| +| `black` | `bgBlack` | `dim` (alias`faint`) | +| `red` | `bgRed` | **`bold`** | +| `green` | `bgGreen` | _`italic`_ | +| `yellow` | `bgYellow` | `underline` | +| `blue` | `bgBlue` | `strikethrough` (alias `strike`) | +| `magenta` | `bgMagenta` | `doubleUnderline` (_not widely supported_) | +| `cyan` | `bgCyan` | `overline` (_not widely supported_) | +| `white` | `bgWhite` | `frame` (_not widely supported_) | +| `gray` (alias `grey`) | `bgGray` (alias `bgGrey`) | `encircle` (_not widely supported_) | +| `blackBright` | `bgBlackBright` | `inverse` | +| `redBright` | `bgRedBright` | `visible` | +| `greenBright` | `bgGreenBright` | `hidden` | +| `yellowBright` | `bgYellowBright` | `reset` | +| `blueBright` | `bgBlueBright` | | +| `magentaBright` | `bgMagentaBright` | | +| `cyanBright` | `bgCyanBright` | | +| `whiteBright` | `bgWhiteBright` | | diff --git a/bench/index.js b/bench/index.js index 9f31503..af868b7 100644 --- a/bench/index.js +++ b/bench/index.js @@ -39,6 +39,7 @@ import kleur from 'kleur'; import * as kleurColors from 'kleur/colors'; import picocolors from 'picocolors'; import { Ansis, green, red, yellow, hex } from 'ansis'; +//import { Ansis, green, red, yellow, hex } from '../_ignored/index-2.0.3.min.js'; const log = console.log; diff --git a/package.json b/package.json index 9287ce9..4cacade 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ansis", - "version": "2.0.3", - "description": "Colorize text in terminal or console output with ANSI colors & styles", + "version": "2.1.0", + "description": "Node.js library to colorize text in terminal or console output with ANSI colors & styles", "keywords": [ "ansi", "colour", diff --git a/pkg/package.json b/pkg/package.json index dd13a8a..17ecdc6 100644 --- a/pkg/package.json +++ b/pkg/package.json @@ -1,6 +1,6 @@ { "name": "ansis", - "version": "2.0.3", + "version": "2.1.0", "description": "Colorize text in terminal or console output with ANSI colors & styles", "keywords": [ "ansi", diff --git a/src/ansi-codes.js b/src/ansi-codes.js index 5cfacac..b75d8b6 100644 --- a/src/ansi-codes.js +++ b/src/ansi-codes.js @@ -1,55 +1,5 @@ -/** - * @param {Object?} mockThis The mock object of globalThis, used by unit test only. - * @returns {boolean} - */ -export const isSupported = (mockThis) => { - /** - * Detect whether flags exist with `-` or `--` prefix in command-line arguments. - * - * @param {RegExp} regex The RegEx to match all possible flags. - * @return {boolean} - */ - const oneOfFlags = (regex) => !!argv.find((value) => regex.test(value)); - - const _this = mockThis || globalThis; - const isDeno = _this.Deno != null; - const proc = _this.process || _this.Deno || {}; - - // Node -> `argv`, Deno -> `args` - const argv = proc.argv || proc.args || []; - - let env = {}; - - try { - // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js - env = isDeno ? proc.env.toObject() : proc.env || {}; - } catch (e) { - // Deno: if interactive permission is not granted, do nothing, no colors - } - - const FORCE_COLOR = 'FORCE_COLOR'; - const hasForceColor = FORCE_COLOR in env; - const forceColorValue = env[FORCE_COLOR]; - const forceColor = forceColorValue === 'true' || parseInt(forceColorValue, 10) > 0; - - const isForceDisabled = 'NO_COLOR' in env - || (hasForceColor && !forceColor) - || oneOfFlags(/^-{1,2}(no-color|color=false|color=never)$/); - - const isForceEnabled = (hasForceColor && forceColor) || oneOfFlags(/^-{1,2}(color|color=true|color=always)$/); - - const isWin = (isDeno ? _this.Deno.build.os : proc.platform) === 'win32'; - const isTTY = isDeno ? _this.Deno.isatty(1) : proc.stdout && 'isTTY' in proc.stdout; - - // when Next.JS runtime is `edge`, process.stdout is undefined, but colors output is supported - // runtime values supported colors: `nodejs`, `edge`, `experimental-edge` - const isNextJS = (env.NEXT_RUNTIME || '').indexOf('edge') > -1; - - const isTerm = (isTTY || isNextJS) && - /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM); - - return !isForceDisabled && (isForceEnabled || isTerm || isWin || 'CI' in env); -}; +import { clamp, hexToRgb } from './utils.js'; +import { isSupported } from './color-support.js'; const noColor = { open: '', close: '' }; const esc = isSupported() ? (open, close) => ({ open: `\x1b[${open}m`, close: `\x1b[${close}m` }) : () => noColor; @@ -108,6 +58,8 @@ export const baseStyles = { bgMagenta: esc(45, 49), bgCyan: esc(46, 49), bgWhite: esc(47, 49), + bgGrey: esc(100, 49), // UK spelling alias for bgBlackBright + bgGray: esc(100, 49), // US spelling alias for bgBlackBright bgBlackBright: esc(100, 49), bgRedBright: esc(101, 49), bgGreenBright: esc(102, 49), @@ -117,3 +69,20 @@ export const baseStyles = { bgCyanBright: esc(106, 49), bgWhiteBright: esc(107, 49), }; + +export const styleMethods = { + fg: (code) => fnAnsi256(clamp(code, 0, 255)), + bg: (code) => fnBgAnsi256(clamp(code, 0, 255)), + hex: (hex) => fnRgb(...hexToRgb(hex)), + bgHex: (hex) => fnBgRgb(...hexToRgb(hex)), + rgb: (r, g, b) => fnRgb( + clamp(r, 0, 255), + clamp(g, 0, 255), + clamp(b, 0, 255), + ), + bgRgb: (r, g, b) => fnBgRgb( + clamp(r, 0, 255), + clamp(g, 0, 255), + clamp(b, 0, 255), + ), +}; diff --git a/src/color-support.js b/src/color-support.js new file mode 100644 index 0000000..be48b0f --- /dev/null +++ b/src/color-support.js @@ -0,0 +1,52 @@ +/** + * @param {Object?} mockThis The mock object of globalThis, used by unit test only. + * @returns {boolean} + */ +export const isSupported = (mockThis) => { + /** + * Detect whether flags exist with `-` or `--` prefix in command-line arguments. + * + * @param {RegExp} regex The RegEx to match all possible flags. + * @return {boolean} + */ + const oneOfFlags = (regex) => !!argv.find((value) => regex.test(value)); + + const _this = mockThis || globalThis; + const isDeno = _this.Deno != null; + const proc = _this.process || _this.Deno || {}; + + // Node -> `argv`, Deno -> `args` + const argv = proc.argv || proc.args || []; + + let env = {}; + + try { + // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js + env = isDeno ? proc.env.toObject() : proc.env || {}; + } catch (e) { + // Deno: if interactive permission is not granted, do nothing, no colors + } + + const FORCE_COLOR = 'FORCE_COLOR'; + const hasForceColor = FORCE_COLOR in env; + const forceColorValue = env[FORCE_COLOR]; + const forceColor = forceColorValue === 'true' || parseInt(forceColorValue, 10) > 0; + + const isForceDisabled = 'NO_COLOR' in env + || (hasForceColor && !forceColor) + || oneOfFlags(/^-{1,2}(no-color|color=false|color=never)$/); + + const isForceEnabled = (hasForceColor && forceColor) || oneOfFlags(/^-{1,2}(color|color=true|color=always)$/); + + const isWin = (isDeno ? _this.Deno.build.os : proc.platform) === 'win32'; + const isTTY = isDeno ? _this.Deno.isatty(1) : proc.stdout && 'isTTY' in proc.stdout; + + // when Next.JS runtime is `edge`, process.stdout is undefined, but colors output is supported + // runtime values supported colors: `nodejs`, `edge`, `experimental-edge` + const isNextJS = (env.NEXT_RUNTIME || '').indexOf('edge') > -1; + + const isTerm = (isTTY || isNextJS) && + /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM); + + return !isForceDisabled && (isForceEnabled || isTerm || isWin || 'CI' in env); +}; diff --git a/src/index.d.ts b/src/index.d.ts index 4b4d892..970ba2f 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -7,6 +7,7 @@ interface Ansis { * @param {string | TemplateStringsArray} string */ (string: string): string; + (string: TemplateStringsArray, ...parameters: string[]): string; /** @@ -174,8 +175,8 @@ interface Ansis { readonly magenta: this; readonly cyan: this; readonly white: this; - readonly gray: this; readonly grey: this; + readonly gray: this; readonly blackBright: this; readonly redBright: this; readonly greenBright: this; @@ -192,6 +193,7 @@ interface Ansis { readonly bgMagenta: this; readonly bgCyan: this; readonly bgWhite: this; + readonly bgGrey: this; readonly bgGray: this; readonly bgBlackBright: this; readonly bgRedBright: this; @@ -239,8 +241,8 @@ type AnsiColors = ( | 'magenta' | 'cyan' | 'white' - | 'gray' | 'grey' + | 'gray' | 'blackBright' | 'redBright' | 'greenBright' @@ -257,6 +259,7 @@ type AnsiColors = ( | 'bgMagenta' | 'bgCyan' | 'bgWhite' + | 'bgGrey' | 'bgGray' | 'bgBlackBright' | 'bgRedBright' diff --git a/src/index.js b/src/index.js index 893811a..a1146c4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ -import { hexToRgb, clamp, strReplaceAll } from './utils.js'; -import { baseStyles, fnAnsi256, fnBgAnsi256, fnRgb, fnBgRgb } from './ansi-codes.js'; +import { hexToRgb, strReplaceAll } from './utils.js'; +import { baseStyles, styleMethods, fnRgb } from './ansi-codes.js'; /** * @typedef {Object} AnsisProps @@ -10,12 +10,68 @@ import { baseStyles, fnAnsi256, fnBgAnsi256, fnRgb, fnBgRgb } from './ansi-codes * @property {null | AnsisProps} props */ +const styles = {}; + const { defineProperty, defineProperties, setPrototypeOf } = Object; const stripANSIRegEx = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; - const regexLF = /(\r*\n)/g; +/** + * Wrap the string with styling and reset codes. + * + * @param {string | Array} strings A string or template literals. + * @param {Array} values The values of the template literals. + * @param {AnsisProps} props + * @returns {string} + */ +const wrap = (strings, values, props) => { + if (!strings) return ''; + + const { openStack, closeStack } = props; + let string = strings.raw != null ? String.raw(strings, ...values) : strings; + + if (~string.indexOf('\x1b')) { + while (props != null) { + string = strReplaceAll(string, props.close, props.open); + props = props.props; + } + + } + + if (~string.indexOf('\n')) { + string = string.replace(regexLF, closeStack + '$1' + openStack); + } + + return openStack + string + closeStack; +}; + +/** + * @param {Object} self + * @param {AnsisProps} self.props + * @param {Object} codes + * @param {string} codes.open + * @param {string} codes.close + * @returns {Ansis} + */ +const createStyle = ({ props }, { open, close }) => { + const style = (strings, ...values) => wrap(strings, values, style.props); + let openStack = open; + let closeStack = close; + + if (props != null) { + openStack = props.openStack + open; + closeStack = close + props.closeStack; + } + + setPrototypeOf(style, stylePrototype); + style.props = { open, close, openStack, closeStack, props: props }; + style.open = openStack; + style.close = closeStack; + + return style; +}; + const Ansis = function() { const self = (str) => str; @@ -53,7 +109,7 @@ const Ansis = function() { }; } - stylePrototype = defineProperties(() => {}, styles); + stylePrototype = defineProperties({}, styles); setPrototypeOf(self, stylePrototype); }; @@ -63,80 +119,6 @@ const Ansis = function() { return self; }; -/** - * @param {Object} self - * @param {AnsisProps} self.props - * @param {Object} codes - * @param {string} codes.open - * @param {string} codes.close - * @returns {Ansis} - */ -const createStyle = ({ props }, { open, close }) => { - const style = (strings, ...values) => wrap(strings, values, style.props); - let openStack = open; - let closeStack = close; - - if (props !== undefined) { - openStack = props.openStack + open; - closeStack = close + props.closeStack; - } - - setPrototypeOf(style, stylePrototype); - style.props = { open, close, openStack, closeStack, props: props }; - style.open = openStack; - style.close = closeStack; - - return style; -}; - -/** - * Wrap the string with styling and reset codes. - * - * @param {string | Array} strings A string or template literals. - * @param {Array} values The values of the template literals. - * @param {AnsisProps} props - * @returns {string} - */ -const wrap = (strings, values, props) => { - if (!strings) return ''; - - const { openStack, closeStack } = props; - let string = strings.raw != null ? String.raw(strings, ...values) : strings; - - if (~string.indexOf('\x1b')) { - while (props !== undefined) { - string = strReplaceAll(string, props.close, props.open); - props = props.props; - } - } - - if (~string.indexOf('\n')) { - string = string.replace(regexLF, closeStack + '$1' + openStack); - } - - return openStack + string + closeStack; -}; - -const styleMethods = { - fg: (code) => fnAnsi256(clamp(code, 0, 255)), - bg: (code) => fnBgAnsi256(clamp(code, 0, 255)), - hex: (hex) => fnRgb(...hexToRgb(hex)), - bgHex: (hex) => fnBgRgb(...hexToRgb(hex)), - rgb: (r, g, b) => fnRgb( - clamp(r, 0, 255), - clamp(g, 0, 255), - clamp(b, 0, 255), - ), - bgRgb: (r, g, b) => fnBgRgb( - clamp(r, 0, 255), - clamp(g, 0, 255), - clamp(b, 0, 255), - ), -}; - -const styles = {}; -let stylePrototype; - // extend styles with methods: rgb(), hex(), etc. for (let name in styleMethods) { styles[name] = { @@ -151,6 +133,8 @@ for (let name in styleMethods) { styles.ansi256 = styles.ansi = styles.fg; styles.bgAnsi256 = styles.bgAnsi = styles.bg; +// note: place it here to allow the compiler to group all constants +let stylePrototype; const ansis = new Ansis(); // for distribution code, the export will be replaced (via @rollup/plugin-replace) with the following export: diff --git a/src/index.mjs b/src/index.mjs index e5cb236..a14792a 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -43,8 +43,8 @@ export const { magenta, cyan, white, - gray, grey, + gray, blackBright, redBright, greenBright, @@ -63,6 +63,8 @@ export const { bgMagenta, bgCyan, bgWhite, + bgGrey, + bgGray, bgBlackBright, bgRedBright, bgGreenBright, diff --git a/src/utils.js b/src/utils.js index ae292ad..1437d71 100644 --- a/src/utils.js +++ b/src/utils.js @@ -66,37 +66,3 @@ export const strReplaceAll = (str, searchValue, replaceValue) => { return result + str.slice(lastPos); }; - -/** - * The style must be break at the end of the line and continued on a new line. - * TODO: compare with str.replace(/(\r*\n)/g, props.closeStack + '$1' + props.openStack); - * - check compatibility in windows - * - check performance - * - delete this function if replace() is faster - * - * @param {string} str The string containing linebreaks. - * @param {string} open The code of styling. - * @param {string} close The reset of styling. - * @param {number} pos The position of the first linebreak. - * @returns {string} - */ -// export const breakStyle = (str, open, close, pos) => { -// let result = '', -// lastPos = 0; -// -// while (pos > -1) { -// let len = pos, -// LF = '\n'; -// // fix for windows -// if (str[pos - 1] === '\r') { -// LF = '\r\n'; -// len--; -// } -// -// result += str.substr(lastPos, len - lastPos) + close + LF + open; -// lastPos = pos + 1; -// pos = str.indexOf('\n', lastPos); -// } -// -// return result + str.slice(lastPos); -// }; diff --git a/test/flags.test.js b/test/flags.test.js index 368d011..8b8ec3e 100644 --- a/test/flags.test.js +++ b/test/flags.test.js @@ -10,79 +10,71 @@ const TEST_PATH = path.resolve('./test/'); // - test NO_COLOR=1 describe('enable colors', () => { - test(`--color`, (done) => { + test(`--color`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); const received = execScriptSync(filename, ['--color']); const expected = '\x1b[31mred\x1b[39m|\x1b[38;2;80;80;80mrgb\x1b[39m|\x1b[48;2;80;80;80mbgRgb\x1b[49m|\x1b[38;2;255;255;255mhex\x1b[39m|\x1b[48;2;255;255;255mbgHex\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`--color=true`, (done) => { + test(`--color=true`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); const received = execScriptSync(filename, ['--color=true']); const expected = '\x1b[31mred\x1b[39m|\x1b[38;2;80;80;80mrgb\x1b[39m|\x1b[48;2;80;80;80mbgRgb\x1b[49m|\x1b[38;2;255;255;255mhex\x1b[39m|\x1b[48;2;255;255;255mbgHex\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`--color=always`, (done) => { + test(`--color=always`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); const received = execScriptSync(filename, ['--color=always']); const expected = '\x1b[31mred\x1b[39m|\x1b[38;2;80;80;80mrgb\x1b[39m|\x1b[48;2;80;80;80mbgRgb\x1b[49m|\x1b[38;2;255;255;255mhex\x1b[39m|\x1b[48;2;255;255;255mbgHex\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`FORCE_COLOR=true`, (done) => { + test(`FORCE_COLOR=true`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); const received = execScriptSync(filename, [], ['FORCE_COLOR=true']); const expected = '\x1b[31mred\x1b[39m|\x1b[38;2;80;80;80mrgb\x1b[39m|\x1b[48;2;80;80;80mbgRgb\x1b[49m|\x1b[38;2;255;255;255mhex\x1b[39m|\x1b[48;2;255;255;255mbgHex\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`FORCE_COLOR=1`, (done) => { + test(`FORCE_COLOR=1`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); const received = execScriptSync(filename, [], ['FORCE_COLOR=1']); const expected = '\x1b[31mred\x1b[39m|\x1b[38;2;80;80;80mrgb\x1b[39m|\x1b[48;2;80;80;80mbgRgb\x1b[49m|\x1b[38;2;255;255;255mhex\x1b[39m|\x1b[48;2;255;255;255mbgHex\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); describe('disable colors', () => { - test(`--no-color`, (done) => { + test(`--no-color`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); // flags has priority over env variable const received = execScriptSync(filename, ['--no-color'], ['FORCE_COLOR=1']); const expected = 'red|rgb|bgRgb|hex|bgHex'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`--color=false`, (done) => { + test(`--color=false`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); // flags has priority over env variable const received = execScriptSync(filename, ['--color=false'], ['FORCE_COLOR=1']); const expected = 'red|rgb|bgRgb|hex|bgHex'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`--color=never`, (done) => { + test(`--color=never`, () => { const filename = path.join(TEST_PATH, './cli/output.js'); // flags has priority over env variable const received = execScriptSync(filename, ['--color=never'], ['FORCE_COLOR=1']); const expected = 'red|rgb|bgRgb|hex|bgHex'; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 15f9e67..e078df9 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -2,98 +2,86 @@ import { esc } from './utils/helpers.js'; import ansis, { Ansis, red, yellow, green } from '../src/index.mjs'; describe('style tests', () => { - test(`ansis.visible('foo')`, (done) => { + test(`ansis.visible('foo')`, () => { const received = ansis.visible('foo'); const expected = 'foo'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`visible with template literal`, (done) => { + test(`visible with template literal`, () => { const received = ansis.visible`foo ${green`bar`}`; const expected = 'foo \x1b[32mbar\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.green('')`, (done) => { + test(`ansis.green('')`, () => { const received = ansis.green(''); const expected = ''; expect(esc(received)).toEqual(esc(expected)); - done(); + }); - test(`ansis.green('foo', 'bar')`, (done) => { + test(`ansis.green('foo', 'bar')`, () => { const received = ansis.green(['foo', 'bar'].join(' ')); const expected = '\x1b[32mfoo bar\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.bgMagenta('foo')`, (done) => { + test(`ansis.bgMagenta('foo')`, () => { const received = ansis.bgMagenta('foo'); const expected = '\x1b[45mfoo\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.green.bold.underline.italic()`, (done) => { + test(`ansis.green.bold.underline.italic()`, () => { const received = ansis.green.bold.underline.italic('foo'); const expected = '\x1b[32m\x1b[1m\x1b[4m\x1b[3mfoo\x1b[23m\x1b[24m\x1b[22m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.cyan(ansis.bold(ansis.underline(ansis.italic('foo'))))`, (done) => { + test(`ansis.cyan(ansis.bold(ansis.underline(ansis.italic('foo'))))`, () => { const received = ansis.cyan(ansis.bold(ansis.underline(ansis.italic('foo')))); const expected = '\x1b[36m\x1b[1m\x1b[4m\x1b[3mfoo\x1b[23m\x1b[24m\x1b[22m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.rgb(80, 100, 150)`, (done) => { + test(`ansis.rgb(80, 100, 150)`, () => { const received = ansis.rgb(80, 100, 150)('foo'); const expected = '\x1b[38;2;80;100;150mfoo\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.bgRgb(80, 100, 150)`, (done) => { + test(`ansis.bgRgb(80, 100, 150)`, () => { const received = ansis.bgRgb(80, 100, 150)('foo'); const expected = '\x1b[48;2;80;100;150mfoo\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.hex('#ABC')`, (done) => { + test(`ansis.hex('#ABC')`, () => { const received = ansis.hex('#ABC')('foo'); const expected = '\x1b[38;2;170;187;204mfoo\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.bgHex('#ABC123')`, (done) => { + test(`ansis.bgHex('#ABC123')`, () => { const received = ansis.bgHex('#ABC123')('foo'); const expected = '\x1b[48;2;171;193;35mfoo\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.ansi256(97)`, (done) => { + test(`ansis.ansi256(97)`, () => { const received = ansis.ansi256(97)('foo'); const expected = '\x1b[38;5;97mfoo\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.bgAnsi256(97)`, (done) => { + test(`ansis.bgAnsi256(97)`, () => { const received = ansis.bgAnsi256(97)('foo'); const expected = '\x1b[48;5;97mfoo\x1b[49m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansis.green('\nHello\nNew line\nNext new line.\n')`, (done) => { + test(`ansis.green('\nHello\nNew line\nNext new line.\n')`, () => { const received = ansis.green('\nHello\nNew line\nNext new line.\n'); const expected = `\x1b[32m\x1b[39m \x1b[32mHello\x1b[39m @@ -101,157 +89,147 @@ describe('style tests', () => { \x1b[32mNext new line.\x1b[39m \x1b[32m\x1b[39m`; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); describe('functional tests', () => { - test(`ansis('OK')`, (done) => { + test(`ansis('OK')`, () => { const received = ansis('OK'); const expected = 'OK'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`nested styles`, (done) => { + test(`nested styles`, () => { const received = ansis.red('foo' + ansis.underline.bgBlue('bar') + '!'); const expected = '\x1b[31mfoo\x1b[4m\x1b[44mbar\x1b[49m\x1b[24m!\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`nested prop.parent`, (done) => { + test(`nested prop.parent`, () => { const rgb = ansis.rgb(100, 80, 155); const received = ansis.green.bold.underline(`foo ${ansis.red.italic('bar')} foo`); const expected = '\x1b[32m\x1b[1m\x1b[4mfoo \x1b[31m\x1b[3mbar\x1b[23m\x1b[32m foo\x1b[24m\x1b[22m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`nested multi styles`, (done) => { + test(`nested multi styles`, () => { const rgb = ansis.rgb(100, 80, 155); const received = ansis.red( `begin ${rgb.bold('RGB')} ${ansis.yellow('yellow')} red ${ansis.italic.cyan('italic cyan')} red ${ansis.red( - 'red', - )} red ${ansis.underline.green.italic( - `underline italic green ${ansis.rgb(80, 120, 200)('underline italic blue')} underline italic green`, - )} red ${ansis.cyan('cyan')} red ${ansis.bold.yellow('bold yellow')} red ${ansis.green('green')} end`, - ); + 'red')} red ${ansis.underline.green.italic(`underline italic green ${ansis.rgb(80, 120, 200)( + 'underline italic blue')} underline italic green`)} red ${ansis.cyan('cyan')} red ${ansis.bold.yellow( + 'bold yellow')} red ${ansis.green('green')} end`); - const expected = - '\x1b[31mbegin \x1b[38;2;100;80;155m\x1b[1mRGB\x1b[22m\x1b[31m \x1b[33myellow\x1b[31m red \x1b[3m\x1b[36mitalic cyan\x1b[31m\x1b[23m red \x1b[31mred\x1b[31m red \x1b[4m\x1b[32m\x1b[3munderline italic green \x1b[38;2;80;120;200munderline italic blue\x1b[32m underline italic green\x1b[23m\x1b[31m\x1b[24m red \x1b[36mcyan\x1b[31m red \x1b[1m\x1b[33mbold yellow\x1b[31m\x1b[22m red \x1b[32mgreen\x1b[31m end\x1b[39m'; + const expected = '\x1b[31mbegin \x1b[38;2;100;80;155m\x1b[1mRGB\x1b[22m\x1b[31m \x1b[33myellow\x1b[31m red \x1b[3m\x1b[36mitalic cyan\x1b[31m\x1b[23m red \x1b[31mred\x1b[31m red \x1b[4m\x1b[32m\x1b[3munderline italic green \x1b[38;2;80;120;200munderline italic blue\x1b[32m underline italic green\x1b[23m\x1b[31m\x1b[24m red \x1b[36mcyan\x1b[31m red \x1b[1m\x1b[33mbold yellow\x1b[31m\x1b[22m red \x1b[32mgreen\x1b[31m end\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`strip()`, (done) => { + test(`strip()`, () => { const received = ansis.strip('\x1b[36m\x1b[1m\x1b[4m\x1b[3mfoo\x1b[23m\x1b[24m\x1b[22m\x1b[39m'); const expected = 'foo'; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); describe('alias tests', () => { - test(`faint == dim`, (done) => { + test(`faint == dim`, () => { const received = ansis.faint('foo'); const expected = ansis.dim('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`strike == strikethrough`, (done) => { + test(`strike == strikethrough`, () => { const received = ansis.strike('foo'); const expected = ansis.strikethrough('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`gray == blackBright`, (done) => { + test(`gray == blackBright`, () => { const received = ansis.gray('foo'); const expected = ansis.blackBright('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`grey == gray`, (done) => { + test(`grey == gray`, () => { const received = ansis.grey('foo'); const expected = ansis.gray('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`grey.gray('foo')`, (done) => { + test(`bgGrey == bgGray`, () => { + const received = ansis.bgGrey('foo'); + const expected = ansis.bgGray('foo'); + expect(esc(received)).toEqual(esc(expected)); + }); + + test(`grey.gray('foo')`, () => { const received = ansis.grey.gray('foo'); const expected = '\x1b[90m\x1b[90mfoo\x1b[39m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansi == ansi256`, (done) => { + test(`grey.bgGray('foo')`, () => { + const received = ansis.grey.bgGray('foo'); + const expected = '\x1b[90m\x1b[100mfoo\x1b[49m\x1b[39m'; + expect(esc(received)).toEqual(esc(expected)); + }); + + test(`ansi == ansi256`, () => { const received = ansis.ansi(96)('foo'); const expected = ansis.ansi256(96)('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`fg == ansi256`, (done) => { + test(`fg == ansi256`, () => { const received = ansis.fg(96)('foo'); const expected = ansis.ansi256(96)('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`bgAnsi == bgAnsi256`, (done) => { + test(`bgAnsi == bgAnsi256`, () => { const received = ansis.bgAnsi(96)('foo'); const expected = ansis.bgAnsi256(96)('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`bg == bgAnsi256`, (done) => { + test(`bg == bgAnsi256`, () => { const received = ansis.bg(96)('foo'); const expected = ansis.bgAnsi256(96)('foo'); expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ansi256(96).ansi(96).fg(96)('foo')`, (done) => { + test(`ansi256(96).ansi(96).fg(96)('foo')`, () => { const received = ansis.ansi256(96).ansi(96).fg(96)('foo'); const expected = '\x1b[38;5;96m\x1b[38;5;96m\x1b[38;5;96mfoo\x1b[39m\x1b[39m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); describe('template literals tests', () => { - test('ansis.red`red color`', (done) => { + test('ansis.red`red color`', () => { const received = ansis.red`red color`; const expected = '\x1b[31mred color\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test('red`red ${yellow`yellow ${green`green`} yellow`} red`', (done) => { + test('red`red ${yellow`yellow ${green`green`} yellow`} red`', () => { const received = red`red ${yellow`yellow ${green`green`} yellow`} red`; const expected = '\x1b[31mred \x1b[33myellow \x1b[32mgreen\x1b[33m yellow\x1b[31m red\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); describe('extend base colors tests', () => { - test('imported ansis`', (done) => { + test('imported ansis`', () => { ansis.extend({ orange: '#FFAB40' }); const received = ansis.orange.bold('text'); const expected = '\x1b[38;2;255;171;64m\x1b[1mtext\x1b[22m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test('new ansis`', (done) => { + test('new ansis`', () => { const ansis = new Ansis(); ansis.extend({ orange: '#FFAB40' }); @@ -259,6 +237,5 @@ describe('extend base colors tests', () => { const received = ansis.bold.orange('text'); const expected = '\x1b[1m\x1b[38;2;255;171;64mtext\x1b[39m\x1b[22m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); \ No newline at end of file diff --git a/test/package.test.js b/test/package.test.js index 83d6e4a..98dd666 100644 --- a/test/package.test.js +++ b/test/package.test.js @@ -4,7 +4,7 @@ import { esc, execScriptSync } from './utils/helpers.js'; const TEST_PATH = path.resolve('./test/'); describe('Usage `ansis` npm package', () => { - test(`CommonJS mode`, (done) => { + test(`CommonJS mode`, () => { const filename = path.join(TEST_PATH, './package/cjs/test.cjs'); const received = execScriptSync(filename, ['--color']); const expected = @@ -26,10 +26,9 @@ describe('Usage `ansis` npm package', () => { '\x1b[36m\x1b[1mcyan bold\x1b[22m\x1b[39m\n' + '\x1b[34m\x1b[3mblue italic\x1b[23m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); - test(`ESM mode`, (done) => { + test(`ESM mode`, () => { const filename = path.join(TEST_PATH, './package/esm/test.mjs'); const received = execScriptSync(filename, ['--color']); const expected = @@ -51,6 +50,5 @@ describe('Usage `ansis` npm package', () => { '\x1b[36m\x1b[1mcyan bold\x1b[22m\x1b[39m\n' + '\x1b[34m\x1b[3mblue italic\x1b[23m\x1b[39m'; expect(esc(received)).toEqual(esc(expected)); - done(); }); }); \ No newline at end of file diff --git a/test/unit.test.js b/test/unit.test.js index f6a6d7d..bca4141 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -1,60 +1,53 @@ import { hexToRgb, clamp } from '../src/utils.js'; -import { isSupported } from '../src/ansi-codes.js'; +import { isSupported } from '../src/color-support.js'; describe('utils tests', () => { - test(`hexToRgb('FFAA99')`, (done) => { + test(`hexToRgb('FFAA99')`, () => { const received = hexToRgb('FFAA99'); const expected = [255, 170, 153]; expect(received).toEqual(expected); - done(); }); - test(`hexToRgb('#FFAA99')`, (done) => { + test(`hexToRgb('#FFAA99')`, () => { const received = hexToRgb('#FFAA99'); const expected = [255, 170, 153]; expect(received).toEqual(expected); - done(); }); - test(`hexToRgb('#FA9')`, (done) => { + test(`hexToRgb('#FA9')`, () => { const received = hexToRgb('#FA9'); const expected = [255, 170, 153]; expect(received).toEqual(expected); - done(); }); - test(`hexToRgb('#FF99')`, (done) => { + test(`hexToRgb('#FF99')`, () => { const received = hexToRgb('#FF99'); const expected = [0, 0, 0]; expect(received).toEqual(expected); - done(); }); - test(`hexToRgb('something')`, (done) => { + test(`hexToRgb('something')`, () => { const received = hexToRgb('something'); const expected = [0, 0, 0]; expect(received).toEqual(expected); - done(); }); - test(`clamp(3, 0, 2)`, (done) => { + test(`clamp(3, 0, 2)`, () => { const received = clamp(3, 0, 2); const expected = 2; expect(received).toEqual(expected); - done(); }); - test(`clamp(0, 1, 2)`, (done) => { + test(`clamp(0, 1, 2)`, () => { const received = clamp(0, 1, 2); const expected = 1; expect(received).toEqual(expected); - done(); }); }); // Node.JS describe('Node.JS isSupported', () => { - test(`process undefined`, (done) => { + test(`process undefined`, () => { // save original `process` object const processOriginal = process; process = undefined; @@ -65,24 +58,21 @@ describe('Node.JS isSupported', () => { // restore original `process` object process = processOriginal; - done(); }); - test(`processMock undefined`, (done) => { + test(`processMock undefined`, () => { const received = isSupported(undefined); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`processMock {}`, (done) => { + test(`processMock {}`, () => { const received = isSupported({}); const expected = false; expect(received).toEqual(expected); - done(); }); - test(`colors in linux terminal`, (done) => { + test(`colors in linux terminal`, () => { const received = isSupported({ process: { platform: 'linux', @@ -94,10 +84,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`colors on windows platform`, (done) => { + test(`colors on windows platform`, () => { const received = isSupported({ process: { platform: 'win32', @@ -108,10 +97,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`colors in any CI`, (done) => { + test(`colors in any CI`, () => { const received = isSupported({ process: { platform: 'linux', @@ -122,10 +110,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`no colors, unsupported terminal`, (done) => { + test(`no colors, unsupported terminal`, () => { const received = isSupported({ process: { env: { TERM: 'dumb' }, @@ -137,10 +124,9 @@ describe('Node.JS isSupported', () => { }); const expected = false; expect(received).toEqual(expected); - done(); }); - test(`no colors, simulate output in file > log.txt`, (done) => { + test(`no colors, simulate output in file > log.txt`, () => { const received = isSupported({ process: { env: { TERM: 'xterm' }, @@ -150,10 +136,9 @@ describe('Node.JS isSupported', () => { }); const expected = false; expect(received).toEqual(expected); - done(); }); - test(`enable colors via --color`, (done) => { + test(`enable colors via --color`, () => { const received = isSupported({ process: { platform: 'linux', @@ -164,10 +149,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`enable colors via -color`, (done) => { + test(`enable colors via -color`, () => { const received = isSupported({ process: { platform: 'linux', @@ -178,10 +162,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`enable colors via --color=true`, (done) => { + test(`enable colors via --color=true`, () => { const received = isSupported({ process: { platform: 'linux', @@ -194,10 +177,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`enable colors via -color=true`, (done) => { + test(`enable colors via -color=true`, () => { const received = isSupported({ process: { platform: 'linux', @@ -210,10 +192,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`disable colors via --color=false`, (done) => { + test(`disable colors via --color=false`, () => { const received = isSupported({ process: { platform: 'linux', @@ -226,10 +207,9 @@ describe('Node.JS isSupported', () => { }); const expected = false; expect(received).toEqual(expected); - done(); }); - test(`disable colors via NO_COLOR=1`, (done) => { + test(`disable colors via NO_COLOR=1`, () => { const received = isSupported({ process: { platform: 'linux', @@ -242,10 +222,9 @@ describe('Node.JS isSupported', () => { }); const expected = false; expect(received).toEqual(expected); - done(); }); - test(`disable colors via FORCE_COLOR=0`, (done) => { + test(`disable colors via FORCE_COLOR=0`, () => { const received = isSupported({ process: { platform: 'linux', @@ -258,10 +237,9 @@ describe('Node.JS isSupported', () => { }); const expected = false; expect(received).toEqual(expected); - done(); }); - test(`disable colors via FORCE_COLOR=false`, (done) => { + test(`disable colors via FORCE_COLOR=false`, () => { const received = isSupported({ process: { platform: 'linux', @@ -274,10 +252,9 @@ describe('Node.JS isSupported', () => { }); const expected = false; expect(received).toEqual(expected); - done(); }); - test(`enable colors via FORCE_COLOR=1`, (done) => { + test(`enable colors via FORCE_COLOR=1`, () => { const received = isSupported({ process: { platform: 'linux', @@ -288,10 +265,9 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`enable colors via FORCE_COLOR=true`, (done) => { + test(`enable colors via FORCE_COLOR=true`, () => { const received = isSupported({ process: { platform: 'linux', @@ -302,14 +278,12 @@ describe('Node.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - }); // Deno describe('Deno isSupported', () => { - test(`env TERM`, (done) => { + test(`env TERM`, () => { const received = isSupported({ Deno: { env: { @@ -325,10 +299,9 @@ describe('Deno isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`platform win`, (done) => { + test(`platform win`, () => { const received = isSupported({ Deno: { env: { @@ -344,10 +317,9 @@ describe('Deno isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`FORCE_COLOR`, (done) => { + test(`FORCE_COLOR`, () => { const received = isSupported({ Deno: { env: { @@ -363,10 +335,9 @@ describe('Deno isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`flag '--color'`, (done) => { + test(`flag '--color'`, () => { const received = isSupported({ Deno: { env: { @@ -382,13 +353,12 @@ describe('Deno isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); }); // Next.JS describe('Next.JS isSupported', () => { - test(`runtime experimental-edge`, (done) => { + test(`runtime experimental-edge`, () => { const received = isSupported({ process: { platform: 'linux', @@ -399,10 +369,9 @@ describe('Next.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`runtime edge`, (done) => { + test(`runtime edge`, () => { const received = isSupported({ process: { platform: 'linux', @@ -413,10 +382,9 @@ describe('Next.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); - test(`runtime nodejs`, (done) => { + test(`runtime nodejs`, () => { const received = isSupported({ process: { platform: 'linux', @@ -429,6 +397,5 @@ describe('Next.JS isSupported', () => { }); const expected = true; expect(received).toEqual(expected); - done(); }); }); \ No newline at end of file