Skip to content

Commit 3c928f3

Browse files
Phillip9587FrozenPandaz
authored andcommitted
cleanup(testing): migrate jest to picocolors (#29561)
migrates `@nx/jest` from `chalk` to `picocolors` Part of e18e/ecosystem-issues#117 <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit b491489)
1 parent 27444bd commit 3c928f3

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

packages/jest/.eslintrc.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"overrides": [
55
{
66
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7-
"rules": {}
8-
},
9-
{
10-
"files": ["**/*.ts"],
11-
"excludedFiles": ["./src/migrations/**"],
127
"rules": {
13-
"no-restricted-imports": ["error", "@nx/workspace"]
8+
"no-restricted-imports": [
9+
"error",
10+
"@nx/workspace",
11+
{
12+
"name": "chalk",
13+
"message": "Please use `picocolors` in place of `chalk` for rendering terminal colors"
14+
}
15+
]
1416
}
1517
},
1618
{

packages/jest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
"@nx/devkit": "file:../devkit",
4141
"@nx/js": "file:../js",
4242
"@phenomnomnominal/tsquery": "~5.0.1",
43-
"chalk": "^4.1.0",
4443
"identity-obj-proxy": "3.0.0",
4544
"jest-config": "^29.4.1",
4645
"jest-resolve": "^29.4.1",
4746
"jest-util": "^29.4.1",
4847
"minimatch": "9.0.3",
48+
"picocolors": "^1.1.0",
4949
"resolve.exports": "2.0.3",
5050
"semver": "^7.5.3",
5151
"tslib": "^2.3.0",

packages/jest/src/executors/jest/summary.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AggregatedResult } from '@jest/reporters';
22
import { pluralize, formatTime } from 'jest-util';
3-
import * as chalk from 'chalk';
3+
import * as pc from 'picocolors';
44

55
/**
66
* Copied from the jest repo because these utility functions are not exposed through the package
@@ -50,9 +50,9 @@ const renderTime = (runTime: number, estimatedTime: number, width: number) => {
5050
// If we are more than one second over the estimated time, highlight it.
5151
const renderedTime =
5252
estimatedTime && runTime >= estimatedTime + 1
53-
? chalk.bold.yellow(formatTime(runTime, 0))
53+
? pc.bold(pc.yellow(formatTime(runTime, 0)))
5454
: formatTime(runTime, 0);
55-
let time = chalk.bold(`Time:`) + ` ${renderedTime}`;
55+
let time = pc.bold(`Time:`) + ` ${renderedTime}`;
5656
if (runTime < estimatedTime) {
5757
time += `, estimated ${formatTime(estimatedTime, 0)}`;
5858
}
@@ -68,8 +68,8 @@ const renderTime = (runTime: number, estimatedTime: number, width: number) => {
6868
if (availableWidth >= 2) {
6969
time +=
7070
'\n' +
71-
chalk.green('█').repeat(length) +
72-
chalk.white('█').repeat(availableWidth - length);
71+
pc.green('█').repeat(length) +
72+
pc.white('█').repeat(availableWidth - length);
7373
}
7474
}
7575
return time;
@@ -120,12 +120,12 @@ export const getSummary = (
120120
const width = options?.width || 0;
121121

122122
const suites =
123-
chalk.bold('Test Suites: ') +
124-
(suitesFailed ? chalk.bold.red(`${suitesFailed} failed`) + ', ' : '') +
123+
pc.bold('Test Suites: ') +
124+
(suitesFailed ? pc.bold(pc.red(`${suitesFailed} failed`)) + ', ' : '') +
125125
(suitesPending
126-
? chalk.bold.yellow(`${suitesPending} skipped`) + ', '
126+
? pc.bold(pc.yellow(`${suitesPending} skipped`)) + ', '
127127
: '') +
128-
(suitesPassed ? chalk.bold.green(`${suitesPassed} passed`) + ', ' : '') +
128+
(suitesPassed ? pc.bold(pc.green(`${suitesPassed} passed`)) + ', ' : '') +
129129
(suitesRun !== suitesTotal
130130
? suitesRun + ' of ' + suitesTotal
131131
: suitesTotal) +
@@ -138,50 +138,50 @@ export const getSummary = (
138138
const updatedTestsTotal = testsTotal + numTotalTests;
139139

140140
const tests =
141-
chalk.bold('Tests: ') +
141+
pc.bold('Tests: ') +
142142
(updatedTestsFailed > 0
143-
? chalk.bold.red(`${updatedTestsFailed} failed`) + ', '
143+
? pc.bold(pc.red(`${updatedTestsFailed} failed`)) + ', '
144144
: '') +
145145
(updatedTestsPending > 0
146-
? chalk.bold.yellow(`${updatedTestsPending} skipped`) + ', '
146+
? pc.bold(pc.yellow(`${updatedTestsPending} skipped`)) + ', '
147147
: '') +
148148
(updatedTestsTodo > 0
149-
? chalk.bold.magenta(`${updatedTestsTodo} todo`) + ', '
149+
? pc.bold(pc.magenta(`${updatedTestsTodo} todo`)) + ', '
150150
: '') +
151151
(updatedTestsPassed > 0
152-
? chalk.bold.green(`${updatedTestsPassed} passed`) + ', '
152+
? pc.bold(pc.green(`${updatedTestsPassed} passed`)) + ', '
153153
: '') +
154154
`${updatedTestsTotal} total`;
155155

156156
const snapshots =
157-
chalk.bold('Snapshots: ') +
157+
pc.bold('Snapshots: ') +
158158
(snapshotsFailed
159-
? chalk.bold.red(`${snapshotsFailed} failed`) + ', '
159+
? pc.bold(pc.red(`${snapshotsFailed} failed`)) + ', '
160160
: '') +
161161
(snapshotsOutdated && !snapshotsDidUpdate
162-
? chalk.bold.yellow(`${snapshotsOutdated} obsolete`) + ', '
162+
? pc.bold(pc.yellow(`${snapshotsOutdated} obsolete`)) + ', '
163163
: '') +
164164
(snapshotsOutdated && snapshotsDidUpdate
165-
? chalk.bold.green(`${snapshotsOutdated} removed`) + ', '
165+
? pc.bold(pc.green(`${snapshotsOutdated} removed`)) + ', '
166166
: '') +
167167
(snapshotsFilesRemoved && !snapshotsDidUpdate
168-
? chalk.bold.yellow(
169-
pluralize('file', snapshotsFilesRemoved) + ' obsolete'
168+
? pc.bold(
169+
pc.yellow(pluralize('file', snapshotsFilesRemoved) + ' obsolete')
170170
) + ', '
171171
: '') +
172172
(snapshotsFilesRemoved && snapshotsDidUpdate
173-
? chalk.bold.green(
174-
pluralize('file', snapshotsFilesRemoved) + ' removed'
173+
? pc.bold(
174+
pc.green(pluralize('file', snapshotsFilesRemoved) + ' removed')
175175
) + ', '
176176
: '') +
177177
(snapshotsUpdated
178-
? chalk.bold.green(`${snapshotsUpdated} updated`) + ', '
178+
? pc.bold(pc.green(`${snapshotsUpdated} updated`)) + ', '
179179
: '') +
180180
(snapshotsAdded
181-
? chalk.bold.green(`${snapshotsAdded} written`) + ', '
181+
? pc.bold(pc.green(`${snapshotsAdded} written`)) + ', '
182182
: '') +
183183
(snapshotsPassed
184-
? chalk.bold.green(`${snapshotsPassed} passed`) + ', '
184+
? pc.bold(pc.green(`${snapshotsPassed} passed`)) + ', '
185185
: '') +
186186
`${snapshotsTotal} total`;
187187

0 commit comments

Comments
 (0)