mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-23 06:02:50 -04:00
* chore: upgrade @typescript/native-preview to 7.0.0-dev.20260421.2
- Add explicit `types: ["node"]` to the shared tsconfig because tsgo
20260421 no longer auto-acquires `@types/*` from `node_modules`.
- Refactor test files to explicitly import jest globals (`describe`,
`it`, `test`, `expect`, `beforeEach`, etc.) from `@jest/globals`
instead of relying on `@types/jest` ambient declarations. Under the
new tsgo build, `import { jest } from '@jest/globals'` shadows the
ambient `jest` namespace, breaking `@types/jest`'s `declare var
describe: jest.Describe;` globals.
- Add `@jest/globals` to each package's devDependencies where tests
now import from it, and add `@types/node` to packages that need it
but were relying on hoisted resolution.
- Replace `fail()` calls with `throw new Error(...)` since `fail` is
no longer globally available.
* chore: fix remaining tsgo type-strictness errors
- Strip `as <PnpmType>` casts on objects passed to toMatchObject /
toStrictEqual / toEqual; @jest/globals rejects the typed objects
(which include AsymmetricMatchers) vs. the repo-specific type.
- Type `jest.fn<...>()` explicitly where the mock's signature matters
for toHaveBeenCalledWith.
- Replace `beforeEach(() => X)` with `beforeEach(() => { X })` so the
return value is void, as the stricter jest typing requires.
- Use `expect.objectContaining({...})` in one place where the full
expected object triggered stricter type resolution.
- Cast `prompt.mock.calls` arg through `as unknown as Record<...>[]`
for patch.test.ts's nested-array matchers.
- Fix off-by-one `<reference path>` in pnpm/test/getConfig.test.ts
that only surfaced now.
- Move `@jest/globals` from devDependencies to dependencies in the
two `__utils__` packages that import it from `src/`.
- Clean up unused imports from the @jest/globals migration.
* chore: address Copilot review on #11332
- Move misplaced `@jest/globals` imports to the top import block in
checkEngine, run.ts, and workspace/root-finder tests where the
script dropped them below executable code.
- Replace `try { await x(); throw new Error('should have thrown') } catch`
in bins/linker, lockfile/fs, and resolving/local-resolver tests with
`await expect(x()).rejects.toMatchObject({...})`. The old pattern
swallowed an unrelated `throw` if the under-test call silently
succeeded, which would fail on the catch-block assertion with a
misleading message.
177 lines
5.2 KiB
TypeScript
177 lines
5.2 KiB
TypeScript
import { stripVTControlCharacters } from 'node:util'
|
||
|
||
import { expect, test } from '@jest/globals'
|
||
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')
|
||
})
|