Skip to content

Commit

Permalink
chore(jest-message-util): replace chalk with picocolors
Browse files Browse the repository at this point in the history
  • Loading branch information
ishon19 committed Jul 18, 2024
1 parent 95365f5 commit e204454
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/jest-message-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 20 additions & 14 deletions packages/jest-message-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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]);
};
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e204454

Please sign in to comment.