Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace chalk with picocolors #15197

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2f362e5
chore: replace `chalk` with `picocolors`
ishon19 Jul 17, 2024
69e103d
chore(babel-jest): replace `chalk` with `picocolors`
ishon19 Jul 17, 2024
19a4639
chore(create-jest): replace `chalk` with `picocolors`
ishon19 Jul 17, 2024
90fa15c
chore(babel-jest): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
b853195
chore(jest-circus): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
820347e
chore(jest-cli): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
b848788
chore(jest-config): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
0b2a7fc
chore(jest-console): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
0511891
chore(jest-core): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
9175c29
chore(jest-diff): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
bddbdb6
chore(jest-each): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
0900fd3
chore(jest-jasmine2): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
95365f5
chore(jest-matcher-utils): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
e204454
chore(jest-message-util): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
1e7f0e8
chore(jest-repl): replace `chalk` with `picocolors`
ishon19 Jul 18, 2024
9e09d89
chore(jest-reporters): replace `chalk` with `picocolors`
ishon19 Jul 22, 2024
87fb3f3
chore(jest-reporters): remove `chalk` dependency
ishon19 Jul 22, 2024
0fd1645
chore(jest-resolve): replace `chalk` with `picocolors`
ishon19 Jul 23, 2024
ec3cb59
chore(jest-runner): replace `chalk` with `picocolors`
ishon19 Jul 23, 2024
964e3ae
chore(jest-runtime): replace `chalk` with `picocolors`
ishon19 Jul 24, 2024
d32505e
chore: replace `chalk` with `picocolors`
ishon19 Jul 24, 2024
daf6648
Merge branch 'main' of github.com:jestjs/jest into 15189-replace-chal…
ishon19 Aug 1, 2024
47542f6
feat(scripts): replace `chalk` with `picocolors`
ishon19 Aug 5, 2024
cc0f080
Merge branch 'main' of github.com:jestjs/jest into 15189-replace-chal…
ishon19 Aug 7, 2024
51baa3e
chore(tests): replace `chalk` with `picocolors`
ishon19 Aug 8, 2024
73a4051
Merge branch 'main' of github.com:jestjs/jest into 15189-replace-chal…
ishon19 Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"babel-jest": "workspace:*",
"babel-loader": "^9.0.0",
"camelcase": "^6.2.0",
"chalk": "^4.0.0",
"dedent": "^1.0.0",
"eslint": "^8.8.0",
"eslint-config-prettier": "^9.0.0",
Expand Down Expand Up @@ -66,6 +65,7 @@
"netlify-plugin-cache": "^1.0.3",
"node-notifier": "^10.0.0",
"p-limit": "^3.1.0",
"picocolors": "^1.0.1",
"pkg-dir": "^5.0.0",
"prettier": "^3.0.3",
"promise": "^8.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@types/babel__core": "^7.1.14",
"babel-plugin-istanbul": "^7.0.0",
"babel-preset-jest": "workspace:*",
"chalk": "^4.0.0",
"graceful-fs": "^4.2.9",
"picocolors": "^1.0.1",
"slash": "^3.0.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
transformSync as babelTransform,
transformAsync as babelTransformAsync,
} from '@babel/core';
import chalk = require('chalk');
import * as fs from 'graceful-fs';
import * as pico from 'picocolors';
import slash = require('slash');
import type {
TransformOptions as JestTransformOptions,
Expand All @@ -38,9 +38,9 @@ function assertLoadedBabelConfig(
): asserts babelConfig {
if (!babelConfig) {
throw new Error(
`babel-jest: Babel ignores ${chalk.bold(
`babel-jest: Babel ignores ${pico.bold(
slash(path.relative(cwd, filename)),
)} - make sure to include the file in Jest's ${chalk.bold(
)} - make sure to include the file in Jest's ${pico.bold(
'transformIgnorePatterns',
)} as well.`,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
},
"dependencies": {
"@jest/types": "workspace:*",
"chalk": "^4.0.0",
"exit": "^0.1.2",
"graceful-fs": "^4.2.9",
"jest-config": "workspace:*",
"jest-util": "workspace:*",
"picocolors": "^1.0.1",
"prompts": "^2.0.1"
},
"engines": {
Expand Down
12 changes: 6 additions & 6 deletions packages/create-jest/src/runCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import * as path from 'path';
import chalk = require('chalk');
import exit = require('exit');
import * as fs from 'graceful-fs';
import picocolors = require('picocolors');
import prompts = require('prompts');
import {constants} from 'jest-config';
import {clearLine, tryRealpath} from 'jest-util';
Expand Down Expand Up @@ -37,9 +37,9 @@ export async function runCLI(): Promise<void> {
clearLine(process.stderr);
clearLine(process.stdout);
if (error instanceof Error && Boolean(error?.stack)) {
console.error(chalk.red(error.stack));
console.error(picocolors.red(error.stack));
} else {
console.error(chalk.red(error));
console.error(picocolors.red(String(error)));
}

exit(1);
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function runCreate(rootDir = process.cwd()): Promise<void> {
// Start the init process
console.log();
console.log(
chalk.underline(
picocolors.underline(
'The following questions will help Jest to create a suitable configuration for your project\n',
),
);
Expand Down Expand Up @@ -146,7 +146,7 @@ export async function runCreate(rootDir = process.cwd()): Promise<void> {
fs.writeFileSync(projectPackageJsonPath, modifiedPackageJson);

console.log('');
console.log(`✏️ Modified ${chalk.cyan(projectPackageJsonPath)}`);
console.log(`✏️ Modified ${picocolors.cyan(projectPackageJsonPath)}`);
}

const generatedConfig = generateConfigFile(
Expand All @@ -159,6 +159,6 @@ export async function runCreate(rootDir = process.cwd()): Promise<void> {

console.log('');
console.log(
`📝 Configuration file created at ${chalk.cyan(jestConfigPath)}`,
`📝 Configuration file created at ${picocolors.cyan(jestConfigPath)}`,
);
}
1 change: 1 addition & 0 deletions packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"jest-snapshot": "workspace:*",
"jest-util": "workspace:*",
"p-limit": "^3.1.0",
"picocolors": "^1.0.1",
"pretty-format": "workspace:*",
"pure-rand": "^6.0.0",
"slash": "^3.0.0",
Expand Down
51 changes: 24 additions & 27 deletions packages/jest-circus/src/formatNodeAssertErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import {AssertionError} from 'assert';
import chalk = require('chalk');
import * as pico from 'picocolors';
import type {Circus} from '@jest/types';
import {
type DiffOptions,
Expand Down Expand Up @@ -93,10 +93,10 @@ const operatorMessage = (operator: string | undefined) => {

const assertThrowingMatcherHint = (operatorName: string) =>
operatorName
? chalk.dim('assert') +
chalk.dim(`.${operatorName}(`) +
chalk.red('function') +
chalk.dim(')')
? pico.dim('assert') +
pico.dim(`.${operatorName}(`) +
pico.red('function') +
pico.dim(')')
: '';

const assertMatcherHint = (
Expand All @@ -108,18 +108,15 @@ const assertMatcherHint = (

if (operator === '==' && expected === true) {
message =
chalk.dim('assert') +
chalk.dim('(') +
chalk.red('received') +
chalk.dim(')');
pico.dim('assert') + pico.dim('(') + pico.red('received') + pico.dim(')');
} else if (operatorName) {
message =
chalk.dim('assert') +
chalk.dim(`.${operatorName}(`) +
chalk.red('received') +
chalk.dim(', ') +
chalk.green('expected') +
chalk.dim(')');
pico.dim('assert') +
pico.dim(`.${operatorName}(`) +
pico.red('received') +
pico.dim(', ') +
pico.green('expected') +
pico.dim(')');
}

return message;
Expand All @@ -141,10 +138,10 @@ function assertionErrorMessage(
return (
// eslint-disable-next-line prefer-template
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function not to throw an error.\n') +
chalk.reset('Instead, it threw:\n') +
pico.reset('Expected the function not to throw an error.\n') +
pico.reset('Instead, it threw:\n') +
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
pico.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
Expand All @@ -153,36 +150,36 @@ function assertionErrorMessage(
if (error.generatedMessage) {
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset(error.message) +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
pico.reset(error.message) +
pico.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function to throw an error.\n') +
chalk.reset("But it didn't throw anything.") +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
pico.reset('Expected the function to throw an error.\n') +
pico.reset("But it didn't throw anything.") +
pico.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}

if (operatorName === 'fail') {
return (
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(hasCustomMessage ? `Message:\n ${message}` : '') +
pico.reset(hasCustomMessage ? `Message:\n ${message}` : '') +
trimmedStack
);
}

return (
// eslint-disable-next-line prefer-template
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(`Expected value ${operatorMessage(operator)}`) +
pico.reset(`Expected value ${operatorMessage(operator)}`) +
` ${printExpected(expected)}\n` +
chalk.reset('Received:\n') +
pico.reset('Received:\n') +
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
pico.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
(diffString ? `\n\nDifference:\n\n${diffString}` : '') +
trimmedStack
);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"@jest/core": "workspace:*",
"@jest/test-result": "workspace:*",
"@jest/types": "workspace:*",
"chalk": "^4.0.0",
"exit": "^0.1.2",
"import-local": "^3.0.2",
"jest-config": "workspace:*",
"jest-util": "workspace:*",
"jest-validate": "workspace:*",
"picocolors": "^1.0.1",
"yargs": "^17.3.1"
},
"devDependencies": {
Expand Down
20 changes: 11 additions & 9 deletions packages/jest-cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import * as path from 'path';
import chalk = require('chalk');
import exit = require('exit');
import * as pico from 'picocolors';
import yargs = require('yargs');
import {getVersion, runCLI} from '@jest/core';
import type {AggregatedResult} from '@jest/test-result';
Expand All @@ -31,9 +31,9 @@ export async function run(
clearLine(process.stderr);
clearLine(process.stdout);
if (error?.stack) {
console.error(chalk.red(error.stack));
console.error(pico.red(error.stack));
} else {
console.error(chalk.red(error));
console.error(pico.red(error));
}

exit(1);
Expand Down Expand Up @@ -117,7 +117,7 @@ const readResultsAndExit = (
if (globalConfig.forceExit) {
if (!globalConfig.detectOpenHandles) {
console.warn(
`${chalk.bold(
`${pico.bold(
'Force exiting Jest: ',
)}Have you considered using \`--detectOpenHandles\` to detect ` +
'async operations that kept running after all tests finished?',
Expand All @@ -132,12 +132,14 @@ const readResultsAndExit = (
const timeout = globalConfig.openHandlesTimeout;
setTimeout(() => {
console.warn(
chalk.yellow.bold(
`Jest did not exit ${
timeout === 1000 ? 'one second' : `${timeout / 1000} seconds`
} after the test run has completed.\n\n'`,
pico.yellow(
pico.bold(
`Jest did not exit ${
timeout === 1000 ? 'one second' : `${timeout / 1000} seconds`
} after the test run has completed.\n\n'`,
),
) +
chalk.yellow(
pico.yellow(
'This usually means that there are asynchronous operations that ' +
"weren't stopped in your tests. Consider running Jest with " +
'`--detectOpenHandles` to troubleshoot this issue.',
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@jest/test-sequencer": "workspace:*",
"@jest/types": "workspace:*",
"babel-jest": "workspace:*",
"chalk": "^4.0.0",
"ci-info": "^4.0.0",
"deepmerge": "^4.2.2",
"glob": "^10.3.10",
Expand All @@ -56,6 +55,7 @@
"jest-validate": "workspace:*",
"micromatch": "^4.0.8",
"parse-json": "^5.2.0",
"picocolors": "^1.0.1",
"pretty-format": "workspace:*",
"slash": "^3.0.0",
"strip-json-comments": "^3.1.1"
Expand Down
Loading
Loading