Skip to content

Commit

Permalink
chore(jest-config): 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 820347e commit b848788
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 70 deletions.
2 changes: 1 addition & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -51,6 +50,7 @@
"jest-validate": "workspace:*",
"micromatch": "^4.0.7",
"parse-json": "^5.2.0",
"picocolors": "^1.0.1",
"pretty-format": "workspace:*",
"slash": "^3.0.0",
"strip-json-comments": "^3.1.1"
Expand Down
42 changes: 21 additions & 21 deletions packages/jest-config/src/Deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import chalk = require('chalk');
import * as pico from 'picocolors';
import type {DeprecatedOptions} from 'jest-validate';

function formatDeprecation(message: string): string {
const lines = [
message.replaceAll(/\*(.+?)\*/g, (_, s) => chalk.bold(`"${s}"`)),
message.replaceAll(/\*(.+?)\*/g, (_, s) => pico.bold(`"${s}"`)),
'',
'Please update your configuration.',
];
Expand All @@ -19,68 +19,68 @@ function formatDeprecation(message: string): string {

const deprecatedOptions: DeprecatedOptions = {
browser: () =>
` Option ${chalk.bold(
` Option ${pico.bold(
'"browser"',
)} has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as shown in the documentation: https://jestjs.io/docs/configuration#resolver-string`,

collectCoverageOnlyFrom: (_options: {
collectCoverageOnlyFrom?: Record<string, boolean>;
}) => ` Option ${chalk.bold(
}) => ` Option ${pico.bold(
'"collectCoverageOnlyFrom"',
)} was replaced by ${chalk.bold('"collectCoverageFrom"')}.
)} was replaced by ${pico.bold('"collectCoverageFrom"')}.
Please update your configuration.`,

extraGlobals: (_options: {extraGlobals?: string}) => ` Option ${chalk.bold(
extraGlobals: (_options: {extraGlobals?: string}) => ` Option ${pico.bold(
'"extraGlobals"',
)} was replaced by ${chalk.bold('"sandboxInjectedGlobals"')}.
)} was replaced by ${pico.bold('"sandboxInjectedGlobals"')}.
Please update your configuration.`,

init: () =>
` Option ${chalk.bold(
` Option ${pico.bold(
'"init"',
)} has been deprecated. Please use "create-jest" package as shown in the documentation: https://jestjs.io/docs/getting-started#generate-a-basic-configuration-file`,

moduleLoader: (_options: {moduleLoader?: string}) => ` Option ${chalk.bold(
moduleLoader: (_options: {moduleLoader?: string}) => ` Option ${pico.bold(
'"moduleLoader"',
)} was replaced by ${chalk.bold('"runtime"')}.
)} was replaced by ${pico.bold('"runtime"')}.
Please update your configuration.`,

preprocessorIgnorePatterns: (_options: {
preprocessorIgnorePatterns?: Array<string>;
}) => ` Option ${chalk.bold(
}) => ` Option ${pico.bold(
'"preprocessorIgnorePatterns"',
)} was replaced by ${chalk.bold(
)} was replaced by ${pico.bold(
'"transformIgnorePatterns"',
)}, which support multiple preprocessors.
Please update your configuration.`,

scriptPreprocessor: (_options: {
scriptPreprocessor?: string;
}) => ` Option ${chalk.bold(
}) => ` Option ${pico.bold(
'"scriptPreprocessor"',
)} was replaced by ${chalk.bold(
)} was replaced by ${pico.bold(
'"transform"',
)}, which support multiple preprocessors.
Please update your configuration.`,

setupTestFrameworkScriptFile: (_options: {
setupTestFrameworkScriptFile?: string;
}) => ` Option ${chalk.bold(
}) => ` Option ${pico.bold(
'"setupTestFrameworkScriptFile"',
)} was replaced by configuration ${chalk.bold(
)} was replaced by configuration ${pico.bold(
'"setupFilesAfterEnv"',
)}, which supports multiple paths.
Please update your configuration.`,

testPathDirs: (_options: {
testPathDirs?: Array<string>;
}) => ` Option ${chalk.bold('"testPathDirs"')} was replaced by ${chalk.bold(
}) => ` Option ${pico.bold('"testPathDirs"')} was replaced by ${pico.bold(
'"roots"',
)}.
Expand All @@ -92,17 +92,17 @@ const deprecatedOptions: DeprecatedOptions = {
'Option *testPathPattern* was replaced by *testPathPatterns*.',
),

testURL: (_options: {testURL?: string}) => ` Option ${chalk.bold(
testURL: (_options: {testURL?: string}) => ` Option ${pico.bold(
'"testURL"',
)} was replaced by passing the URL via ${chalk.bold(
)} was replaced by passing the URL via ${pico.bold(
'"testEnvironmentOptions.url"',
)}.
Please update your configuration.`,

timers: (_options: {timers?: string}) => ` Option ${chalk.bold(
timers: (_options: {timers?: string}) => ` Option ${pico.bold(
'"timers"',
)} was replaced by ${chalk.bold('"fakeTimers"')}.
)} was replaced by ${pico.bold('"fakeTimers"')}.
Please update your configuration.`,
};
Expand Down
16 changes: 9 additions & 7 deletions packages/jest-config/src/ReporterValidationErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import chalk = require('chalk');
import * as pico from 'picocolors';
import type {Config} from '@jest/types';
import {getType} from 'jest-get-type';
import {ValidationError} from 'jest-validate';
Expand All @@ -28,9 +28,9 @@ export function createReporterError(
): ValidationError {
const errorMessage =
` Reporter at index ${reporterIndex} must be of type:\n` +
` ${chalk.bold.green(validReporterTypes.join(' or '))}\n` +
` ${pico.bold(pico.green(validReporterTypes.join(' or ')))}\n` +
' but instead received:\n' +
` ${chalk.bold.red(getType(reporterValue))}`;
` ${pico.bold(pico.red(getType(reporterValue)))}`;

return new ValidationError(ERROR, errorMessage, DOCUMENTATION_NOTE);
}
Expand All @@ -47,12 +47,14 @@ export function createArrayReporterError(
` Unexpected value for ${valueName} ` +
`at index ${valueIndex} of reporter at index ${reporterIndex}\n` +
' Expected:\n' +
` ${chalk.bold.red(expectedType)}\n` +
` ${pico.bold(pico.red(expectedType))}\n` +
' Got:\n' +
` ${chalk.bold.green(getType(value))}\n` +
` ${pico.bold(pico.green(getType(value)))}\n` +
' Reporter configuration:\n' +
` ${chalk.bold.green(
JSON.stringify(arrayReporter, null, 2).split('\n').join('\n '),
` ${pico.bold(
pico.green(
JSON.stringify(arrayReporter, null, 2).split('\n').join('\n '),
),
)}`;

return new ValidationError(ERROR, errorMessage, DOCUMENTATION_NOTE);
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-config/src/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/

import {createHash} from 'crypto';
import type {ForegroundColor} from 'chalk';

type Color = typeof ForegroundColor;
type Color = 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';

const colors: Array<Color> = [
'red',
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-config/src/index.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 * as fs from 'graceful-fs';
import * as pico from 'picocolors';
import type {Config} from '@jest/types';
import {tryRealpath} from 'jest-util';
import * as constants from './constants';
Expand Down Expand Up @@ -228,16 +228,16 @@ const ensureNoDuplicateConfigs = (
const {configPath} = config;

if (configPathMap.has(configPath)) {
const message = `Whoops! Two projects resolved to the same config path: ${chalk.bold(
const message = `Whoops! Two projects resolved to the same config path: ${pico.bold(
String(configPath),
)}:
Project 1: ${chalk.bold(projects[parsedConfigs.indexOf(config)])}
Project 2: ${chalk.bold(
Project 1: ${pico.bold(projects[parsedConfigs.indexOf(config)])}
Project 2: ${pico.bold(
projects[parsedConfigs.indexOf(configPathMap.get(configPath))],
)}
This usually means that your ${chalk.bold(
This usually means that your ${pico.bold(
'"projects"',
)} config includes a directory that doesn't have any configuration recognizable by Jest. Please fix it.
`;
Expand Down
Loading

0 comments on commit b848788

Please sign in to comment.