cleanup(testing): migrate jest to picocolors (#29561)

migrates `@nx/jest` from `chalk` to `picocolors`

Part of https://github.com/es-tooling/ecosystem-cleanup/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 #
This commit is contained in:
Phillip Barta 2025-01-09 15:58:44 +01:00 committed by GitHub
parent f98ae78734
commit b491489cb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 32 deletions

View File

@ -4,13 +4,15 @@
"overrides": [ "overrides": [
{ {
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["**/*.ts"],
"excludedFiles": ["./src/migrations/**"],
"rules": { "rules": {
"no-restricted-imports": ["error", "@nx/workspace"] "no-restricted-imports": [
"error",
"@nx/workspace",
{
"name": "chalk",
"message": "Please use `picocolors` in place of `chalk` for rendering terminal colors"
}
]
} }
}, },
{ {

View File

@ -40,12 +40,12 @@
"@nx/devkit": "file:../devkit", "@nx/devkit": "file:../devkit",
"@nx/js": "file:../js", "@nx/js": "file:../js",
"@phenomnomnominal/tsquery": "~5.0.1", "@phenomnomnominal/tsquery": "~5.0.1",
"chalk": "^4.1.0",
"identity-obj-proxy": "3.0.0", "identity-obj-proxy": "3.0.0",
"jest-config": "^29.4.1", "jest-config": "^29.4.1",
"jest-resolve": "^29.4.1", "jest-resolve": "^29.4.1",
"jest-util": "^29.4.1", "jest-util": "^29.4.1",
"minimatch": "9.0.3", "minimatch": "9.0.3",
"picocolors": "^1.1.0",
"resolve.exports": "2.0.3", "resolve.exports": "2.0.3",
"semver": "^7.5.3", "semver": "^7.5.3",
"tslib": "^2.3.0", "tslib": "^2.3.0",

View File

@ -1,6 +1,6 @@
import { AggregatedResult } from '@jest/reporters'; import { AggregatedResult } from '@jest/reporters';
import { pluralize, formatTime } from 'jest-util'; import { pluralize, formatTime } from 'jest-util';
import * as chalk from 'chalk'; import * as pc from 'picocolors';
/** /**
* Copied from the jest repo because these utility functions are not exposed through the package * 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) => {
// If we are more than one second over the estimated time, highlight it. // If we are more than one second over the estimated time, highlight it.
const renderedTime = const renderedTime =
estimatedTime && runTime >= estimatedTime + 1 estimatedTime && runTime >= estimatedTime + 1
? chalk.bold.yellow(formatTime(runTime, 0)) ? pc.bold(pc.yellow(formatTime(runTime, 0)))
: formatTime(runTime, 0); : formatTime(runTime, 0);
let time = chalk.bold(`Time:`) + ` ${renderedTime}`; let time = pc.bold(`Time:`) + ` ${renderedTime}`;
if (runTime < estimatedTime) { if (runTime < estimatedTime) {
time += `, estimated ${formatTime(estimatedTime, 0)}`; time += `, estimated ${formatTime(estimatedTime, 0)}`;
} }
@ -68,8 +68,8 @@ const renderTime = (runTime: number, estimatedTime: number, width: number) => {
if (availableWidth >= 2) { if (availableWidth >= 2) {
time += time +=
'\n' + '\n' +
chalk.green('█').repeat(length) + pc.green('█').repeat(length) +
chalk.white('█').repeat(availableWidth - length); pc.white('█').repeat(availableWidth - length);
} }
} }
return time; return time;
@ -120,12 +120,12 @@ export const getSummary = (
const width = options?.width || 0; const width = options?.width || 0;
const suites = const suites =
chalk.bold('Test Suites: ') + pc.bold('Test Suites: ') +
(suitesFailed ? chalk.bold.red(`${suitesFailed} failed`) + ', ' : '') + (suitesFailed ? pc.bold(pc.red(`${suitesFailed} failed`)) + ', ' : '') +
(suitesPending (suitesPending
? chalk.bold.yellow(`${suitesPending} skipped`) + ', ' ? pc.bold(pc.yellow(`${suitesPending} skipped`)) + ', '
: '') + : '') +
(suitesPassed ? chalk.bold.green(`${suitesPassed} passed`) + ', ' : '') + (suitesPassed ? pc.bold(pc.green(`${suitesPassed} passed`)) + ', ' : '') +
(suitesRun !== suitesTotal (suitesRun !== suitesTotal
? suitesRun + ' of ' + suitesTotal ? suitesRun + ' of ' + suitesTotal
: suitesTotal) + : suitesTotal) +
@ -138,50 +138,50 @@ export const getSummary = (
const updatedTestsTotal = testsTotal + numTotalTests; const updatedTestsTotal = testsTotal + numTotalTests;
const tests = const tests =
chalk.bold('Tests: ') + pc.bold('Tests: ') +
(updatedTestsFailed > 0 (updatedTestsFailed > 0
? chalk.bold.red(`${updatedTestsFailed} failed`) + ', ' ? pc.bold(pc.red(`${updatedTestsFailed} failed`)) + ', '
: '') + : '') +
(updatedTestsPending > 0 (updatedTestsPending > 0
? chalk.bold.yellow(`${updatedTestsPending} skipped`) + ', ' ? pc.bold(pc.yellow(`${updatedTestsPending} skipped`)) + ', '
: '') + : '') +
(updatedTestsTodo > 0 (updatedTestsTodo > 0
? chalk.bold.magenta(`${updatedTestsTodo} todo`) + ', ' ? pc.bold(pc.magenta(`${updatedTestsTodo} todo`)) + ', '
: '') + : '') +
(updatedTestsPassed > 0 (updatedTestsPassed > 0
? chalk.bold.green(`${updatedTestsPassed} passed`) + ', ' ? pc.bold(pc.green(`${updatedTestsPassed} passed`)) + ', '
: '') + : '') +
`${updatedTestsTotal} total`; `${updatedTestsTotal} total`;
const snapshots = const snapshots =
chalk.bold('Snapshots: ') + pc.bold('Snapshots: ') +
(snapshotsFailed (snapshotsFailed
? chalk.bold.red(`${snapshotsFailed} failed`) + ', ' ? pc.bold(pc.red(`${snapshotsFailed} failed`)) + ', '
: '') + : '') +
(snapshotsOutdated && !snapshotsDidUpdate (snapshotsOutdated && !snapshotsDidUpdate
? chalk.bold.yellow(`${snapshotsOutdated} obsolete`) + ', ' ? pc.bold(pc.yellow(`${snapshotsOutdated} obsolete`)) + ', '
: '') + : '') +
(snapshotsOutdated && snapshotsDidUpdate (snapshotsOutdated && snapshotsDidUpdate
? chalk.bold.green(`${snapshotsOutdated} removed`) + ', ' ? pc.bold(pc.green(`${snapshotsOutdated} removed`)) + ', '
: '') + : '') +
(snapshotsFilesRemoved && !snapshotsDidUpdate (snapshotsFilesRemoved && !snapshotsDidUpdate
? chalk.bold.yellow( ? pc.bold(
pluralize('file', snapshotsFilesRemoved) + ' obsolete' pc.yellow(pluralize('file', snapshotsFilesRemoved) + ' obsolete')
) + ', ' ) + ', '
: '') + : '') +
(snapshotsFilesRemoved && snapshotsDidUpdate (snapshotsFilesRemoved && snapshotsDidUpdate
? chalk.bold.green( ? pc.bold(
pluralize('file', snapshotsFilesRemoved) + ' removed' pc.green(pluralize('file', snapshotsFilesRemoved) + ' removed')
) + ', ' ) + ', '
: '') + : '') +
(snapshotsUpdated (snapshotsUpdated
? chalk.bold.green(`${snapshotsUpdated} updated`) + ', ' ? pc.bold(pc.green(`${snapshotsUpdated} updated`)) + ', '
: '') + : '') +
(snapshotsAdded (snapshotsAdded
? chalk.bold.green(`${snapshotsAdded} written`) + ', ' ? pc.bold(pc.green(`${snapshotsAdded} written`)) + ', '
: '') + : '') +
(snapshotsPassed (snapshotsPassed
? chalk.bold.green(`${snapshotsPassed} passed`) + ', ' ? pc.bold(pc.green(`${snapshotsPassed} passed`)) + ', '
: '') + : '') +
`${snapshotsTotal} total`; `${snapshotsTotal} total`;