Files
pnpm/installing/commands/test/update/getUpdateChoices.test.ts
Zoltan Kochan 7a304b17c4 refactor: rename directories and unify command packages per domain (#10993)
- Rename `installing/core` → `installing/deps-installer` and `installing/headless` → `installing/deps-restorer` for clearer naming
- Rename all `plugin-commands-*` directories to use `-commands` suffix convention
- Merge multiple command packages per domain into a single `commands/` directory (one commands package per domain rule):
  - `building/{build-commands,policy-commands}` → `building/commands`
  - `deps/compliance/{audit-commands,licenses-commands,sbom-commands}` → `deps/compliance/commands`
  - `deps/inspection/{listing-commands,outdated-commands}` → `deps/inspection/commands`
  - `store/{store-commands,inspecting-commands}` → `store/commands`
  - `releasing/{publish-commands,deploy-commands}` → `releasing/commands`
  - `cli/{completion-commands,doctor-commands}` → `cli/commands`
  - `engine/pm/{self-updater-commands,setup-commands}` → `engine/pm/commands`
  - `engine/runtime/{runtime-commands,env-commands}` → `engine/runtime/commands`
  - `cache/cache-commands` → `cache/commands`
- Fix relative paths in merged test files (pnpmBin, __typings__ references)
- Update jest config to ignore `utils/` dirs at any nesting depth under `test/`
- Fix stale package names in changeset files
2026-03-17 17:42:20 +01:00

176 lines
5.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { stripVTControlCharacters } from 'node:util'
import chalk from 'chalk'
import { getUpdateChoices } from '../../lib/update/getUpdateChoices.js'
test('getUpdateChoices()', () => {
expect(
getUpdateChoices([
{
alias: 'foo',
belongsTo: 'dependencies' as const,
current: '1.0.0',
latestManifest: {
name: 'foo',
version: '2.0.0',
homepage: 'https://pnpm.io/',
},
packageName: 'foo',
wanted: '1.0.0',
},
{
alias: 'foo',
belongsTo: 'devDependencies' as const,
current: '1.0.0',
latestManifest: {
name: 'foo',
version: '2.0.0',
repository: {
url: 'git://github.com/pnpm/pnpm.git',
},
},
packageName: 'foo',
wanted: '1.0.0',
},
{
alias: 'qar',
belongsTo: 'devDependencies' as const,
current: '1.0.0',
latestManifest: {
name: 'qar',
version: '1.2.0',
},
packageName: 'qar',
wanted: '1.0.0',
},
{
alias: 'zoo',
belongsTo: 'devDependencies' as const,
current: '1.1.0',
latestManifest: {
name: 'zoo',
version: '1.2.0',
},
packageName: 'zoo',
wanted: '1.1.0',
},
{
alias: 'qaz',
belongsTo: 'optionalDependencies' as const,
current: '1.0.1',
latestManifest: {
name: 'qaz',
version: '1.2.0',
},
packageName: 'qaz',
wanted: '1.0.1',
},
{
alias: 'qaz',
belongsTo: 'devDependencies' as const,
current: '1.0.1',
latestManifest: {
name: 'qaz',
version: '1.2.0',
},
packageName: 'foo',
wanted: '1.0.1',
},
], false))
.toStrictEqual([
{
name: '[dependencies]',
message: 'dependencies',
choices: [
{
name: 'Package Current Target URL ',
disabled: true,
hint: '',
value: '',
},
{
message: `foo 1.0.0 ${chalk.redBright.bold('2.0.0')} https://pnpm.io/ `,
value: 'foo',
name: 'foo',
},
],
},
{
name: '[devDependencies]',
message: 'devDependencies',
choices: [
{
name: 'Package Current Target URL ',
disabled: true,
hint: '',
value: '',
},
{
message: `qar 1.0.0 1.${chalk.yellowBright.bold('2.0')} `,
name: 'qar',
value: 'qar',
},
{
message: `zoo 1.1.0 1.${chalk.yellowBright.bold('2.0')} `,
name: 'zoo',
value: 'zoo',
},
{
message: `foo 1.0.1 1.${chalk.yellowBright.bold('2.0')} `,
name: 'foo',
value: 'foo',
},
],
},
{
name: '[optionalDependencies]',
message: 'optionalDependencies',
choices: [
{
name: 'Package Current Target URL ',
disabled: true,
hint: '',
value: '',
},
{
message: `qaz 1.0.1 1.${chalk.yellowBright.bold('2.0')} `,
name: 'qaz',
value: 'qaz',
},
],
},
])
})
test('getUpdateChoices() handles long version strings without wrapping', () => {
const choices = getUpdateChoices([
{
alias: '@typescript/native-preview',
belongsTo: 'devDependencies' as const,
current: '7.0.0-dev.20251209.1',
latestManifest: {
name: '@typescript/native-preview',
version: '7.0.0-dev.20251214.1',
homepage: 'https://github.com/nicolo-ribaudo/tc39-proposal-structs',
},
packageName: '@typescript/native-preview',
wanted: '7.0.0-dev.20251209.1',
},
], false)
const dataRow = choices[0].choices[1] as { message: string; value: string; name: string }
expect(dataRow).toStrictEqual({
message: expect.stringContaining('7.0.0-dev.20251209.1'),
value: '@typescript/native-preview',
name: '@typescript/native-preview',
})
// The rendered message must be a single line (no wrapping)
expect(dataRow.message).not.toContain('\n')
// Both current and target versions must appear in the output.
// Strip ANSI codes first because colorizeSemverDiff embeds color escapes
// within the version string, which would break a plain substring match
// when chalk has colors enabled.
expect(stripVTControlCharacters(dataRow.message)).toContain('7.0.0-dev.20251214.1')
})