Skip to content

Commit 0511891

Browse files
committed
chore(jest-core): replace chalk with picocolors
1 parent 0b2a7fc commit 0511891

15 files changed

+84
-86
lines changed

packages/jest-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@jest/types": "workspace:*",
2323
"@types/node": "*",
2424
"ansi-escapes": "^4.2.1",
25-
"chalk": "^4.0.0",
2625
"ci-info": "^4.0.0",
2726
"exit": "^0.1.2",
2827
"graceful-fs": "^4.2.9",
@@ -40,6 +39,7 @@
4039
"jest-validate": "workspace:*",
4140
"jest-watcher": "workspace:*",
4241
"micromatch": "^4.0.7",
42+
"picocolors": "^1.0.1",
4343
"pretty-format": "workspace:*",
4444
"slash": "^3.0.0",
4545
"strip-ansi": "^6.0.0"

packages/jest-core/src/FailedTestsInteractiveMode.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

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

1818
function describeKey(key: string, description: string) {
19-
return `${chalk.dim(`${ARROW}Press`)} ${key} ${chalk.dim(description)}`;
19+
return `${pico.dim(`${ARROW}Press`)} ${key} ${pico.dim(description)}`;
2020
}
2121

22-
const TestProgressLabel = chalk.bold('Interactive Test Progress');
22+
const TestProgressLabel = pico.bold('Interactive Test Progress');
2323

2424
export default class FailedTestsInteractiveMode {
2525
private _isActive = false;
@@ -105,7 +105,7 @@ export default class FailedTestsInteractiveMode {
105105
this._pipe.write(CLEAR);
106106

107107
const messages: Array<string> = [
108-
chalk.bold('Watch Usage'),
108+
pico.bold('Watch Usage'),
109109
describeKey('Enter', 'to return to watch mode.'),
110110
];
111111

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

120120
if (this._skippedNum > 0) {
121-
const skippedText = chalk.bold.yellow(
122-
`${pluralize('test', this._skippedNum)} skipped`,
121+
const skippedText = pico.bold(
122+
pico.yellow(`${pluralize('test', this._skippedNum)} skipped`),
123123
);
124124

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

148148
if (this._skippedNum > 0) {
149-
const skippedText = chalk.bold.yellow(
150-
`${pluralize('test', this._skippedNum)} skipped`,
149+
const skippedText = pico.bold(
150+
pico.yellow(`${pluralize('test', this._skippedNum)} skipped`),
151151
);
152152

153153
stats = `${stats}, ${skippedText}`;
@@ -157,7 +157,7 @@ export default class FailedTestsInteractiveMode {
157157
TestProgressLabel,
158158
`${ARROW}${stats}`,
159159
'\n',
160-
chalk.bold('Watch Usage'),
160+
pico.bold('Watch Usage'),
161161
describeKey('s', 'to skip the current test.'),
162162
describeKey('q', 'to quit Interactive Mode.'),
163163
describeKey('Enter', 'to return to watch mode.'),

packages/jest-core/src/SnapshotInteractiveMode.ts

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

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

51-
let stats = chalk.bold.dim(
52-
`${pluralize('snapshot', numRemaining)} remaining`,
51+
let stats = pico.bold(
52+
pico.dim(`${pluralize('snapshot', numRemaining)} remaining`),
5353
);
5454
if (numPass) {
55-
stats += `, ${chalk.bold.green(
56-
`${pluralize('snapshot', numPass)} updated`,
55+
stats += `, ${pico.bold(
56+
pico.green(`${pluralize('snapshot', numPass)} updated`),
5757
)}`;
5858
}
5959
if (this._skippedNum) {
60-
stats += `, ${chalk.bold.yellow(
61-
`${pluralize('snapshot', this._skippedNum)} skipped`,
60+
stats += `, ${pico.bold(
61+
pico.yellow(`${pluralize('snapshot', this._skippedNum)} skipped`),
6262
)}`;
6363
}
6464
const messages = [
65-
`\n${chalk.bold('Interactive Snapshot Progress')}`,
65+
`\n${pico.bold('Interactive Snapshot Progress')}`,
6666
ARROW + stats,
67-
`\n${chalk.bold('Watch Usage')}`,
67+
`\n${pico.bold('Watch Usage')}`,
6868

69-
`${chalk.dim(`${ARROW}Press `)}u${chalk.dim(
69+
`${pico.dim(`${ARROW}Press `)}u${pico.dim(
7070
' to update failing snapshots for this test.',
7171
)}`,
7272

73-
`${chalk.dim(`${ARROW}Press `)}s${chalk.dim(
74-
' to skip the current test.',
75-
)}`,
73+
`${pico.dim(`${ARROW}Press `)}s${pico.dim(' to skip the current test.')}`,
7674

77-
`${chalk.dim(`${ARROW}Press `)}q${chalk.dim(
75+
`${pico.dim(`${ARROW}Press `)}q${pico.dim(
7876
' to quit Interactive Snapshot Mode.',
7977
)}`,
8078

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

93-
let stats = chalk.bold.dim(
94-
`${pluralize('snapshot', this._countPaths)} reviewed`,
91+
let stats = pico.bold(
92+
pico.dim(`${pluralize('snapshot', this._countPaths)} reviewed`),
9593
);
9694
if (numPass) {
97-
stats += `, ${chalk.bold.green(
98-
`${pluralize('snapshot', numPass)} updated`,
95+
stats += `, ${pico.bold(
96+
pico.green(`${pluralize('snapshot', numPass)} updated`),
9997
)}`;
10098
}
10199
if (this._skippedNum) {
102-
stats += `, ${chalk.bold.yellow(
103-
`${pluralize('snapshot', this._skippedNum)} skipped`,
100+
stats += `, ${pico.bold(
101+
pico.yellow(`${pluralize('snapshot', this._skippedNum)} skipped`),
104102
)}`;
105103
}
106104
const messages = [
107-
`\n${chalk.bold('Interactive Snapshot Result')}`,
105+
`\n${pico.bold('Interactive Snapshot Result')}`,
108106
ARROW + stats,
109-
`\n${chalk.bold('Watch Usage')}`,
107+
`\n${pico.bold('Watch Usage')}`,
110108

111-
`${chalk.dim(`${ARROW}Press `)}r${chalk.dim(
109+
`${pico.dim(`${ARROW}Press `)}r${pico.dim(
112110
' to restart Interactive Snapshot Mode.',
113111
)}`,
114112

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

127-
let stats = chalk.bold.dim(
128-
`${pluralize('snapshot', this._countPaths)} reviewed`,
125+
let stats = pico.bold(
126+
pico.dim(`${pluralize('snapshot', this._countPaths)} reviewed`),
129127
);
130128
if (numPass) {
131-
stats += `, ${chalk.bold.green(
132-
`${pluralize('snapshot', numPass)} updated`,
129+
stats += `, ${pico.bold(
130+
pico.green(`${pluralize('snapshot', numPass)} updated`),
133131
)}`;
134132
}
135133
const messages = [
136-
`\n${chalk.bold('Interactive Snapshot Result')}`,
134+
`\n${pico.bold('Interactive Snapshot Result')}`,
137135
ARROW + stats,
138-
`\n${chalk.bold('Watch Usage')}`,
136+
`\n${pico.bold('Watch Usage')}`,
139137

140-
`${chalk.dim(`${ARROW}Press `)}Enter${chalk.dim(
138+
`${pico.dim(`${ARROW}Press `)}Enter${pico.dim(
141139
' to return to watch mode.',
142140
)}`,
143141
];

packages/jest-core/src/cli/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import {performance} from 'perf_hooks';
99
import type {WriteStream} from 'tty';
10-
import chalk = require('chalk');
1110
import exit = require('exit');
1211
import * as fs from 'graceful-fs';
12+
import * as pico from 'picocolors';
1313
import {CustomConsole} from '@jest/console';
1414
import type {AggregatedResult, TestContext} from '@jest/test-result';
1515
import type {Config} from '@jest/types';
@@ -129,7 +129,7 @@ export async function runCLI(
129129
const openHandlesString = pluralize('open handle', formatted.length, 's');
130130

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

packages/jest-core/src/getChangedFilesPromise.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import chalk = require('chalk');
8+
import * as pico from 'picocolors';
99
import type {Config} from '@jest/types';
1010
import {
1111
type ChangedFilesPromise,
@@ -31,7 +31,7 @@ export default function getChangedFilesPromise(
3131
.filter(line => !line.includes('Command failed:'))
3232
.join('\n');
3333

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

3636
process.exit(1);
3737
});

packages/jest-core/src/getNoTestFound.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import chalk = require('chalk');
8+
import * as pico from 'picocolors';
99
import type {Config} from '@jest/types';
1010
import {pluralize} from 'jest-util';
1111
import type {TestRunData} from './types';
@@ -26,15 +26,15 @@ export default function getNoTestFound(
2626
.map(p => `"${p}"`)
2727
.join(', ')}`;
2828
} else {
29-
dataMessage = `Pattern: ${chalk.yellow(
29+
dataMessage = `Pattern: ${pico.yellow(
3030
globalConfig.testPathPatterns.toPretty(),
3131
)} - 0 matches`;
3232
}
3333

3434
if (willExitWith0) {
3535
return (
36-
`${chalk.bold('No tests found, exiting with code 0')}\n` +
37-
`In ${chalk.bold(globalConfig.rootDir)}` +
36+
`${pico.bold('No tests found, exiting with code 0')}\n` +
37+
`In ${pico.bold(globalConfig.rootDir)}` +
3838
'\n' +
3939
` ${pluralize('file', testFiles, 's')} checked across ${pluralize(
4040
'project',
@@ -46,10 +46,10 @@ export default function getNoTestFound(
4646
}
4747

4848
return (
49-
`${chalk.bold('No tests found, exiting with code 1')}\n` +
49+
`${pico.bold('No tests found, exiting with code 1')}\n` +
5050
'Run with `--passWithNoTests` to exit with code 0' +
5151
'\n' +
52-
`In ${chalk.bold(globalConfig.rootDir)}` +
52+
`In ${pico.bold(globalConfig.rootDir)}` +
5353
'\n' +
5454
` ${pluralize('file', testFiles, 's')} checked across ${pluralize(
5555
'project',

packages/jest-core/src/getNoTestFoundFailed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import chalk = require('chalk');
8+
import * as pico from 'picocolors';
99
import type {Config} from '@jest/types';
1010
import {isInteractive} from 'jest-util';
1111

1212
export default function getNoTestFoundFailed(
1313
globalConfig: Config.GlobalConfig,
1414
): string {
15-
let msg = chalk.bold('No failed test found.');
15+
let msg = pico.bold('No failed test found.');
1616
if (isInteractive) {
17-
msg += chalk.dim(
17+
msg += pico.dim(
1818
`\n${
1919
globalConfig.watch
2020
? 'Press `f` to quit "only failed tests" mode.'

packages/jest-core/src/getNoTestFoundPassWithNoTests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import chalk = require('chalk');
8+
import * as pico from 'picocolors';
99

1010
export default function getNoTestFoundPassWithNoTests(): string {
11-
return chalk.bold('No tests found, exiting with code 0');
11+
return pico.bold('No tests found, exiting with code 0');
1212
}

packages/jest-core/src/getNoTestFoundRelatedToChangedFiles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import chalk = require('chalk');
8+
import * as pico from 'picocolors';
99
import type {Config} from '@jest/types';
1010
import {isInteractive} from 'jest-util';
1111

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

2020
if (isInteractive) {
21-
msg += chalk.dim(
21+
msg += pico.dim(
2222
`\n${
2323
globalConfig.watch
2424
? 'Press `a` to run all tests, or run Jest with `--watchAll`.'

packages/jest-core/src/getNoTestFoundVerbose.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import chalk = require('chalk');
8+
import * as pico from 'picocolors';
99
import type {Config} from '@jest/types';
1010
import {pluralize} from 'jest-util';
1111
import type {Stats, TestRunData} from './types';
@@ -29,15 +29,15 @@ export default function getNoTestFoundVerbose(
2929
? value.join(', ')
3030
: String(value);
3131
const matches = pluralize('match', stats[key] || 0, 'es');
32-
return ` ${key}: ${chalk.yellow(valueAsString)} - ${matches}`;
32+
return ` ${key}: ${pico.yellow(valueAsString)} - ${matches}`;
3333
}
3434
return null;
3535
})
3636
.filter(Boolean)
3737
.join('\n');
3838

3939
return testRun.matches.total
40-
? `In ${chalk.bold(config.rootDir)}\n` +
40+
? `In ${pico.bold(config.rootDir)}\n` +
4141
` ${pluralize(
4242
'file',
4343
testRun.matches.total || 0,
@@ -56,19 +56,19 @@ export default function getNoTestFoundVerbose(
5656
.map(p => `"${p}"`)
5757
.join(', ')}`;
5858
} else {
59-
dataMessage = `Pattern: ${chalk.yellow(
59+
dataMessage = `Pattern: ${pico.yellow(
6060
globalConfig.testPathPatterns.toPretty(),
6161
)} - 0 matches`;
6262
}
6363

6464
if (willExitWith0) {
65-
return `${chalk.bold(
65+
return `${pico.bold(
6666
'No tests found, exiting with code 0',
6767
)}\n${individualResults.join('\n')}\n${dataMessage}`;
6868
}
6969

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

0 commit comments

Comments
 (0)