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

chore: replace chalk with picocolors #15487

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 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
91e7576
chore: bump `picocolors`
pralkarz Feb 3, 2025
9ea9a4c
chore: rename `pico` imports to `pc`
pralkarz Feb 3, 2025
b84ee34
Merge `upstream/main` into `chalk-to-picocolors`
pralkarz Feb 3, 2025
36c1c35
chore(jest-watcher): replace `chalk` with `picocolors`
pralkarz Feb 3, 2025
da20f84
chore(jest-validate): replace `chalk` with `picocolors`
pralkarz Feb 3, 2025
b137cfd
chore(jest-util): replace `chalk` with `picocolors`
pralkarz Feb 3, 2025
af46c38
chore(jest-types): replace `chalk` with `picocolors`
pralkarz Feb 3, 2025
bd355eb
chore(jest-transform): replace `chalk` with `picocolors`
pralkarz Feb 3, 2025
636346a
chore(jest-snapshot-utils): replace `chalk` with `picocolors`
pralkarz Feb 3, 2025
05e1bd7
chore(jest-snapshot-utils): remove dependency on `chalk`
pralkarz Feb 3, 2025
5a7cd65
chore(expect): remove dependency on `chalk`
pralkarz Feb 3, 2025
35a9822
chore: fix import order
pralkarz Feb 3, 2025
1e02600
chore(jest-reporters): replace `chalk` with `picocolors`
pralkarz Feb 3, 2025
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 @@ -29,7 +29,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": "^10.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.1.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.1.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 pc 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 ${pc.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 ${pc.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-x": "^0.2.2",
"graceful-fs": "^4.2.9",
"jest-config": "workspace:*",
"jest-util": "workspace:*",
"picocolors": "^1.1.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-x');
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 @@
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));

Check warning on line 40 in packages/create-jest/src/runCreate.ts

View check run for this annotation

Codecov / codecov/patch

packages/create-jest/src/runCreate.ts#L40

Added line #L40 was not covered by tests
} else {
console.error(chalk.red(error));
console.error(picocolors.red(String(error)));

Check warning on line 42 in packages/create-jest/src/runCreate.ts

View check run for this annotation

Codecov / codecov/patch

packages/create-jest/src/runCreate.ts#L42

Added line #L42 was not covered by tests
}

exit(1);
Expand Down Expand Up @@ -103,7 +103,7 @@
// 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 @@
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 @@

console.log('');
console.log(
`📝 Configuration file created at ${chalk.cyan(jestConfigPath)}`,
`📝 Configuration file created at ${picocolors.cyan(jestConfigPath)}`,
);
}
1 change: 0 additions & 1 deletion packages/expect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"devDependencies": {
"@fast-check/jest": "^2.0.0",
"@jest/test-utils": "workspace:*",
"chalk": "^4.0.0",
"immutable": "^5.0.0"
},
"engines": {
Expand Down
10 changes: 0 additions & 10 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

const chalk = require('chalk');
const Immutable = require('immutable');
const {alignedAnsiStyleSerializer} = require('@jest/test-utils');
const {stringify} = require('jest-matcher-utils');
const {expect: jestExpect} = require('../');
const chalkEnabled = chalk.enabled;

expect.addSnapshotSerializer(alignedAnsiStyleSerializer);

Expand All @@ -21,14 +19,6 @@ jestExpect.extend({
},
});

beforeAll(() => {
chalk.enabled = true;
});

afterAll(() => {
chalk.enabled = chalkEnabled;
});

it('should throw if passed two arguments', () => {
expect(() => jestExpect('foo', 'bar')).toThrow(
new Error('Expect takes at most one argument.'),
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@jest/test-result": "workspace:*",
"@jest/types": "workspace:*",
"@types/node": "*",
"chalk": "^4.0.0",
"co": "^4.6.0",
"dedent": "^1.0.0",
"is-generator-fn": "^2.0.0",
Expand All @@ -36,6 +35,7 @@
"jest-snapshot": "workspace:*",
"jest-util": "workspace:*",
"p-limit": "^3.1.0",
"picocolors": "^1.1.1",
"pretty-format": "workspace:*",
"pure-rand": "^6.0.0",
"slash": "^3.0.0",
Expand Down
52 changes: 24 additions & 28 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 pc from 'picocolors';
import type {Circus} from '@jest/types';
import {
type DiffOptions,
Expand Down Expand Up @@ -93,10 +93,10 @@

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

Check warning on line 96 in packages/jest-circus/src/formatNodeAssertErrors.ts

View check run for this annotation

Codecov / codecov/patch

packages/jest-circus/src/formatNodeAssertErrors.ts#L96

Added line #L96 was not covered by tests
pc.dim(`.${operatorName}(`) +
pc.red('function') +
pc.dim(')')
: '';

const assertMatcherHint = (
Expand All @@ -107,19 +107,15 @@
let message = '';

if (operator === '==' && expected === true) {
message =
chalk.dim('assert') +
chalk.dim('(') +
chalk.red('received') +
chalk.dim(')');
message = pc.dim('assert') + pc.dim('(') + pc.red('received') + pc.dim(')');

Check warning on line 110 in packages/jest-circus/src/formatNodeAssertErrors.ts

View check run for this annotation

Codecov / codecov/patch

packages/jest-circus/src/formatNodeAssertErrors.ts#L110

Added line #L110 was not covered by tests
} else if (operatorName) {
message =
chalk.dim('assert') +
chalk.dim(`.${operatorName}(`) +
chalk.red('received') +
chalk.dim(', ') +
chalk.green('expected') +
chalk.dim(')');
pc.dim('assert') +
pc.dim(`.${operatorName}(`) +
pc.red('received') +
pc.dim(', ') +
pc.green('expected') +
pc.dim(')');
}

return message;
Expand All @@ -141,10 +137,10 @@
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') +
pc.reset('Expected the function not to throw an error.\n') +
pc.reset('Instead, it threw:\n') +
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
pc.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
Expand All @@ -153,36 +149,36 @@
if (error.generatedMessage) {
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset(error.message) +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
pc.reset(error.message) +
pc.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}` : '') +
pc.reset('Expected the function to throw an error.\n') +
pc.reset("But it didn't throw anything.") +
pc.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}

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

return (
// eslint-disable-next-line prefer-template
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(`Expected value ${operatorMessage(operator)}`) +
pc.reset(`Expected value ${operatorMessage(operator)}`) +
` ${printExpected(expected)}\n` +
chalk.reset('Received:\n') +
pc.reset('Received:\n') +
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
pc.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-x": "^0.2.2",
"import-local": "^3.0.2",
"jest-config": "workspace:*",
"jest-util": "workspace:*",
"jest-validate": "workspace:*",
"picocolors": "^1.1.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-x');
import * as pc 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 @@
clearLine(process.stderr);
clearLine(process.stdout);
if (error?.stack) {
console.error(chalk.red(error.stack));
console.error(pc.red(error.stack));

Check warning on line 34 in packages/jest-cli/src/run.ts

View check run for this annotation

Codecov / codecov/patch

packages/jest-cli/src/run.ts#L34

Added line #L34 was not covered by tests
} else {
console.error(chalk.red(error));
console.error(pc.red(error));

Check warning on line 36 in packages/jest-cli/src/run.ts

View check run for this annotation

Codecov / codecov/patch

packages/jest-cli/src/run.ts#L36

Added line #L36 was not covered by tests
}

exit(1);
Expand Down Expand Up @@ -117,7 +117,7 @@
if (globalConfig.forceExit) {
if (!globalConfig.detectOpenHandles) {
console.warn(
`${chalk.bold(
`${pc.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 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'`,
pc.yellow(
pc.bold(
`Jest did not exit ${
timeout === 1000 ? 'one second' : `${timeout / 1000} seconds`
} after the test run has completed.\n\n'`,
),
) +
chalk.yellow(
pc.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.1.1",
"pretty-format": "workspace:*",
"slash": "^3.0.0",
"strip-json-comments": "^3.1.1"
Expand Down
Loading
Loading