From e2044544bb872d8b2b48466c3a5cf988abb2af08 Mon Sep 17 00:00:00 2001 From: Shreyans Pathak Date: Thu, 18 Jul 2024 04:07:02 -0400 Subject: [PATCH] chore(jest-message-util): replace `chalk` with `picocolors` --- packages/jest-message-util/package.json | 2 +- packages/jest-message-util/src/index.ts | 34 +++++++++++++++---------- yarn.lock | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index 30b49650bee5..7001f8265b90 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -25,9 +25,9 @@ "@babel/code-frame": "^7.12.13", "@jest/types": "workspace:*", "@types/stack-utils": "^2.0.0", - "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "micromatch": "^4.0.7", + "picocolors": "^1.0.1", "pretty-format": "workspace:*", "slash": "^3.0.0", "stack-utils": "^2.0.3" diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index fd6efbb88e30..e410002ec831 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -9,9 +9,9 @@ import * as path from 'path'; import {fileURLToPath} from 'url'; import {types} from 'util'; import {codeFrameColumns} from '@babel/code-frame'; -import chalk = require('chalk'); import * as fs from 'graceful-fs'; import micromatch = require('micromatch'); +import * as pico from 'picocolors'; import slash = require('slash'); import StackUtils = require('stack-utils'); import type {Config, TestResult} from '@jest/types'; @@ -58,8 +58,8 @@ const TITLE_INDENT = ' '; const MESSAGE_INDENT = ' '; const STACK_INDENT = ' '; const ANCESTRY_SEPARATOR = ' \u203A '; -const TITLE_BULLET = chalk.bold('\u25CF '); -const STACK_TRACE_COLOR = chalk.dim; +const TITLE_BULLET = pico.bold('\u25CF '); +const STACK_TRACE_COLOR = pico.dim; const STACK_PATH_REGEXP = /\s*at.*\(?(:\d*:\d*|native)\)?/; const EXEC_ERROR_MESSAGE = 'Test suite failed to run'; const NOT_EMPTY_LINE_REGEXP = /^(?!$)/gm; @@ -111,10 +111,14 @@ function checkForCommonEnvironmentErrors(error: string) { function warnAboutWrongTestEnvironment(error: string, env: 'jsdom' | 'node') { return ( - chalk.bold.red( - `The error below may be caused by using the wrong test environment, see ${chalk.dim.underline( - 'https://jestjs.io/docs/configuration#testenvironment-string', - )}.\nConsider using the "${env}" test environment.\n\n`, + pico.bold( + pico.red( + `The error below may be caused by using the wrong test environment, see ${pico.dim( + pico.underline( + 'https://jestjs.io/docs/configuration#testenvironment-string', + ), + )}.\nConsider using the "${env}" test environment.\n\n`, + ), ) + error ); } @@ -305,7 +309,7 @@ export const formatPath = ( micromatch([filePath], config.testMatch).length > 0) || filePath === relativeTestPath ) { - filePath = chalk.reset.cyan(filePath); + filePath = pico.reset(pico.cyan(filePath)); } return STACK_TRACE_COLOR(match[1]) + filePath + STACK_TRACE_COLOR(match[3]); }; @@ -488,12 +492,14 @@ export const formatResultsErrors = ( content, ); - const title = `${chalk.bold.red( - TITLE_INDENT + - TITLE_BULLET + - result.ancestorTitles.join(ANCESTRY_SEPARATOR) + - (result.ancestorTitles.length > 0 ? ANCESTRY_SEPARATOR : '') + - result.title, + const title = `${pico.bold( + pico.red( + TITLE_INDENT + + TITLE_BULLET + + result.ancestorTitles.join(ANCESTRY_SEPARATOR) + + (result.ancestorTitles.length > 0 ? ANCESTRY_SEPARATOR : '') + + result.title, + ), )}\n`; return `${title}\n${formatErrorStack( diff --git a/yarn.lock b/yarn.lock index df8cca91a0dd..c3a1d4a88ca4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13299,9 +13299,9 @@ __metadata: "@types/graceful-fs": ^4.1.3 "@types/micromatch": ^4.0.7 "@types/stack-utils": ^2.0.0 - chalk: ^4.0.0 graceful-fs: ^4.2.9 micromatch: ^4.0.7 + picocolors: ^1.0.1 pretty-format: "workspace:*" slash: ^3.0.0 stack-utils: ^2.0.3