Skip to content

Commit

Permalink
chore(jest-core): 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 0b2a7fc commit 0511891
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 86 deletions.
2 changes: 1 addition & 1 deletion packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@jest/types": "workspace:*",
"@types/node": "*",
"ansi-escapes": "^4.2.1",
"chalk": "^4.0.0",
"ci-info": "^4.0.0",
"exit": "^0.1.2",
"graceful-fs": "^4.2.9",
Expand All @@ -40,6 +39,7 @@
"jest-validate": "workspace:*",
"jest-watcher": "workspace:*",
"micromatch": "^4.0.7",
"picocolors": "^1.0.1",
"pretty-format": "workspace:*",
"slash": "^3.0.0",
"strip-ansi": "^6.0.0"
Expand Down
20 changes: 10 additions & 10 deletions packages/jest-core/src/FailedTestsInteractiveMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import ansiEscapes = require('ansi-escapes');
import chalk = require('chalk');
import * as pico from 'picocolors';
import type {AggregatedResult, AssertionLocation} from '@jest/test-result';
import {pluralize, specialChars} from 'jest-util';
import {KEYS} from 'jest-watcher';
Expand All @@ -16,10 +16,10 @@ type RunnerUpdateFunction = (failure?: AssertionLocation) => void;
const {ARROW, CLEAR} = specialChars;

function describeKey(key: string, description: string) {
return `${chalk.dim(`${ARROW}Press`)} ${key} ${chalk.dim(description)}`;
return `${pico.dim(`${ARROW}Press`)} ${key} ${pico.dim(description)}`;
}

const TestProgressLabel = chalk.bold('Interactive Test Progress');
const TestProgressLabel = pico.bold('Interactive Test Progress');

export default class FailedTestsInteractiveMode {
private _isActive = false;
Expand Down Expand Up @@ -105,7 +105,7 @@ export default class FailedTestsInteractiveMode {
this._pipe.write(CLEAR);

const messages: Array<string> = [
chalk.bold('Watch Usage'),
pico.bold('Watch Usage'),
describeKey('Enter', 'to return to watch mode.'),
];

Expand All @@ -118,8 +118,8 @@ export default class FailedTestsInteractiveMode {
let stats = `${pluralize('test', this._countPaths)} reviewed`;

if (this._skippedNum > 0) {
const skippedText = chalk.bold.yellow(
`${pluralize('test', this._skippedNum)} skipped`,
const skippedText = pico.bold(
pico.yellow(`${pluralize('test', this._skippedNum)} skipped`),
);

stats = `${stats}, ${skippedText}`;
Expand All @@ -129,7 +129,7 @@ export default class FailedTestsInteractiveMode {
TestProgressLabel,
`${ARROW}${stats}`,
'\n',
chalk.bold('Watch Usage'),
pico.bold('Watch Usage'),
describeKey('r', 'to restart Interactive Mode.'),
describeKey('q', 'to quit Interactive Mode.'),
describeKey('Enter', 'to return to watch mode.'),
Expand All @@ -146,8 +146,8 @@ export default class FailedTestsInteractiveMode {
let stats = `${pluralize('test', numRemaining)} remaining`;

if (this._skippedNum > 0) {
const skippedText = chalk.bold.yellow(
`${pluralize('test', this._skippedNum)} skipped`,
const skippedText = pico.bold(
pico.yellow(`${pluralize('test', this._skippedNum)} skipped`),
);

stats = `${stats}, ${skippedText}`;
Expand All @@ -157,7 +157,7 @@ export default class FailedTestsInteractiveMode {
TestProgressLabel,
`${ARROW}${stats}`,
'\n',
chalk.bold('Watch Usage'),
pico.bold('Watch Usage'),
describeKey('s', 'to skip the current test.'),
describeKey('q', 'to quit Interactive Mode.'),
describeKey('Enter', 'to return to watch mode.'),
Expand Down
62 changes: 30 additions & 32 deletions packages/jest-core/src/SnapshotInteractiveMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import ansiEscapes = require('ansi-escapes');
import chalk = require('chalk');
import * as pico from 'picocolors';
import type {AggregatedResult, AssertionLocation} from '@jest/test-result';
import {pluralize, specialChars} from 'jest-util';
import {KEYS} from 'jest-watcher';
Expand Down Expand Up @@ -48,37 +48,35 @@ export default class SnapshotInteractiveMode {
const numPass = this._countPaths - this._testAssertions.length;
const numRemaining = this._countPaths - numPass - this._skippedNum;

let stats = chalk.bold.dim(
`${pluralize('snapshot', numRemaining)} remaining`,
let stats = pico.bold(
pico.dim(`${pluralize('snapshot', numRemaining)} remaining`),
);
if (numPass) {
stats += `, ${chalk.bold.green(
`${pluralize('snapshot', numPass)} updated`,
stats += `, ${pico.bold(
pico.green(`${pluralize('snapshot', numPass)} updated`),
)}`;
}
if (this._skippedNum) {
stats += `, ${chalk.bold.yellow(
`${pluralize('snapshot', this._skippedNum)} skipped`,
stats += `, ${pico.bold(
pico.yellow(`${pluralize('snapshot', this._skippedNum)} skipped`),
)}`;
}
const messages = [
`\n${chalk.bold('Interactive Snapshot Progress')}`,
`\n${pico.bold('Interactive Snapshot Progress')}`,
ARROW + stats,
`\n${chalk.bold('Watch Usage')}`,
`\n${pico.bold('Watch Usage')}`,

`${chalk.dim(`${ARROW}Press `)}u${chalk.dim(
`${pico.dim(`${ARROW}Press `)}u${pico.dim(
' to update failing snapshots for this test.',
)}`,

`${chalk.dim(`${ARROW}Press `)}s${chalk.dim(
' to skip the current test.',
)}`,
`${pico.dim(`${ARROW}Press `)}s${pico.dim(' to skip the current test.')}`,

`${chalk.dim(`${ARROW}Press `)}q${chalk.dim(
`${pico.dim(`${ARROW}Press `)}q${pico.dim(
' to quit Interactive Snapshot Mode.',
)}`,

`${chalk.dim(`${ARROW}Press `)}Enter${chalk.dim(
`${pico.dim(`${ARROW}Press `)}Enter${pico.dim(
' to trigger a test run.',
)}`,
];
Expand All @@ -90,29 +88,29 @@ export default class SnapshotInteractiveMode {
this._pipe.write(CLEAR);
const numPass = this._countPaths - this._testAssertions.length;

let stats = chalk.bold.dim(
`${pluralize('snapshot', this._countPaths)} reviewed`,
let stats = pico.bold(
pico.dim(`${pluralize('snapshot', this._countPaths)} reviewed`),
);
if (numPass) {
stats += `, ${chalk.bold.green(
`${pluralize('snapshot', numPass)} updated`,
stats += `, ${pico.bold(
pico.green(`${pluralize('snapshot', numPass)} updated`),
)}`;
}
if (this._skippedNum) {
stats += `, ${chalk.bold.yellow(
`${pluralize('snapshot', this._skippedNum)} skipped`,
stats += `, ${pico.bold(
pico.yellow(`${pluralize('snapshot', this._skippedNum)} skipped`),
)}`;
}
const messages = [
`\n${chalk.bold('Interactive Snapshot Result')}`,
`\n${pico.bold('Interactive Snapshot Result')}`,
ARROW + stats,
`\n${chalk.bold('Watch Usage')}`,
`\n${pico.bold('Watch Usage')}`,

`${chalk.dim(`${ARROW}Press `)}r${chalk.dim(
`${pico.dim(`${ARROW}Press `)}r${pico.dim(
' to restart Interactive Snapshot Mode.',
)}`,

`${chalk.dim(`${ARROW}Press `)}q${chalk.dim(
`${pico.dim(`${ARROW}Press `)}q${pico.dim(
' to quit Interactive Snapshot Mode.',
)}`,
];
Expand All @@ -124,20 +122,20 @@ export default class SnapshotInteractiveMode {
this._pipe.write(CLEAR);
const numPass = this._countPaths - this._testAssertions.length;

let stats = chalk.bold.dim(
`${pluralize('snapshot', this._countPaths)} reviewed`,
let stats = pico.bold(
pico.dim(`${pluralize('snapshot', this._countPaths)} reviewed`),
);
if (numPass) {
stats += `, ${chalk.bold.green(
`${pluralize('snapshot', numPass)} updated`,
stats += `, ${pico.bold(
pico.green(`${pluralize('snapshot', numPass)} updated`),
)}`;
}
const messages = [
`\n${chalk.bold('Interactive Snapshot Result')}`,
`\n${pico.bold('Interactive Snapshot Result')}`,
ARROW + stats,
`\n${chalk.bold('Watch Usage')}`,
`\n${pico.bold('Watch Usage')}`,

`${chalk.dim(`${ARROW}Press `)}Enter${chalk.dim(
`${pico.dim(`${ARROW}Press `)}Enter${pico.dim(
' to return to watch mode.',
)}`,
];
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import {performance} from 'perf_hooks';
import type {WriteStream} from 'tty';
import chalk = require('chalk');
import exit = require('exit');
import * as fs from 'graceful-fs';
import * as pico from 'picocolors';
import {CustomConsole} from '@jest/console';
import type {AggregatedResult, TestContext} from '@jest/test-result';
import type {Config} from '@jest/types';
Expand Down Expand Up @@ -129,7 +129,7 @@ export async function runCLI(
const openHandlesString = pluralize('open handle', formatted.length, 's');

const message =
chalk.red(
pico.red(
`\nJest has detected the following ${openHandlesString} potentially keeping Jest from exiting:\n\n`,
) + formatted.join('\n\n');

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/getChangedFilesPromise.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 {
type ChangedFilesPromise,
Expand All @@ -31,7 +31,7 @@ export default function getChangedFilesPromise(
.filter(line => !line.includes('Command failed:'))
.join('\n');

console.error(chalk.red(`\n\n${message}`));
console.error(pico.red(`\n\n${message}`));

process.exit(1);
});
Expand Down
12 changes: 6 additions & 6 deletions packages/jest-core/src/getNoTestFound.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 {pluralize} from 'jest-util';
import type {TestRunData} from './types';
Expand All @@ -26,15 +26,15 @@ export default function getNoTestFound(
.map(p => `"${p}"`)
.join(', ')}`;
} else {
dataMessage = `Pattern: ${chalk.yellow(
dataMessage = `Pattern: ${pico.yellow(
globalConfig.testPathPatterns.toPretty(),
)} - 0 matches`;
}

if (willExitWith0) {
return (
`${chalk.bold('No tests found, exiting with code 0')}\n` +
`In ${chalk.bold(globalConfig.rootDir)}` +
`${pico.bold('No tests found, exiting with code 0')}\n` +
`In ${pico.bold(globalConfig.rootDir)}` +
'\n' +
` ${pluralize('file', testFiles, 's')} checked across ${pluralize(
'project',
Expand All @@ -46,10 +46,10 @@ export default function getNoTestFound(
}

return (
`${chalk.bold('No tests found, exiting with code 1')}\n` +
`${pico.bold('No tests found, exiting with code 1')}\n` +
'Run with `--passWithNoTests` to exit with code 0' +
'\n' +
`In ${chalk.bold(globalConfig.rootDir)}` +
`In ${pico.bold(globalConfig.rootDir)}` +
'\n' +
` ${pluralize('file', testFiles, 's')} checked across ${pluralize(
'project',
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-core/src/getNoTestFoundFailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* 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 {isInteractive} from 'jest-util';

export default function getNoTestFoundFailed(
globalConfig: Config.GlobalConfig,
): string {
let msg = chalk.bold('No failed test found.');
let msg = pico.bold('No failed test found.');
if (isInteractive) {
msg += chalk.dim(
msg += pico.dim(
`\n${
globalConfig.watch
? 'Press `f` to quit "only failed tests" mode.'
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/getNoTestFoundPassWithNoTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import chalk = require('chalk');
import * as pico from 'picocolors';

export default function getNoTestFoundPassWithNoTests(): string {
return chalk.bold('No tests found, exiting with code 0');
return pico.bold('No tests found, exiting with code 0');
}
6 changes: 3 additions & 3 deletions packages/jest-core/src/getNoTestFoundRelatedToChangedFiles.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 {isInteractive} from 'jest-util';

Expand All @@ -15,10 +15,10 @@ export default function getNoTestFoundRelatedToChangedFiles(
const ref = globalConfig.changedSince
? `"${globalConfig.changedSince}"`
: 'last commit';
let msg = chalk.bold(`No tests found related to files changed since ${ref}.`);
let msg = pico.bold(`No tests found related to files changed since ${ref}.`);

if (isInteractive) {
msg += chalk.dim(
msg += pico.dim(
`\n${
globalConfig.watch
? 'Press `a` to run all tests, or run Jest with `--watchAll`.'
Expand Down
12 changes: 6 additions & 6 deletions packages/jest-core/src/getNoTestFoundVerbose.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 {pluralize} from 'jest-util';
import type {Stats, TestRunData} from './types';
Expand All @@ -29,15 +29,15 @@ export default function getNoTestFoundVerbose(
? value.join(', ')
: String(value);
const matches = pluralize('match', stats[key] || 0, 'es');
return ` ${key}: ${chalk.yellow(valueAsString)} - ${matches}`;
return ` ${key}: ${pico.yellow(valueAsString)} - ${matches}`;
}
return null;
})
.filter(Boolean)
.join('\n');

return testRun.matches.total
? `In ${chalk.bold(config.rootDir)}\n` +
? `In ${pico.bold(config.rootDir)}\n` +
` ${pluralize(
'file',
testRun.matches.total || 0,
Expand All @@ -56,19 +56,19 @@ export default function getNoTestFoundVerbose(
.map(p => `"${p}"`)
.join(', ')}`;
} else {
dataMessage = `Pattern: ${chalk.yellow(
dataMessage = `Pattern: ${pico.yellow(
globalConfig.testPathPatterns.toPretty(),
)} - 0 matches`;
}

if (willExitWith0) {
return `${chalk.bold(
return `${pico.bold(
'No tests found, exiting with code 0',
)}\n${individualResults.join('\n')}\n${dataMessage}`;
}

return (
`${chalk.bold('No tests found, exiting with code 1')}\n` +
`${pico.bold('No tests found, exiting with code 1')}\n` +
'Run with `--passWithNoTests` to exit with code 0' +
`\n${individualResults.join('\n')}\n${dataMessage}`
);
Expand Down
Loading

0 comments on commit 0511891

Please sign in to comment.