Files
pnpm/patching/config/test/index.test.ts
Johan Quan Vo 7b1c189f2e feat!: remove deprecated patch options (#10505)
* refactor: remove allowNonAppliedPatches

* refactor: remove ignorePatchFailures

* refactor: remove `strict` field in groupPatchedDependencies

* test: update test failure in package patching

* test: fix

* docs: update changesets

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
2026-01-27 17:08:45 +01:00

77 lines
2.1 KiB
TypeScript

import { type PatchFile } from '@pnpm/patching.types'
import { getPatchInfo, groupPatchedDependencies } from '../src/index.js'
const _getPatchInfo = (patchedDependencies: Record<string, PatchFile>, name: string, version: string) =>
getPatchInfo(groupPatchedDependencies(patchedDependencies), name, version)
test('getPatchInfo(undefined, ...) returns undefined', () => {
expect(getPatchInfo(undefined, 'foo', '1.0.0')).toBeUndefined()
})
test('getPatchInfo(_, name, version) if name@version exists', () => {
expect(_getPatchInfo({
'foo@1.0.0': {
path: 'patches/foo@1.0.0.patch',
hash: '00000000000000000000000000000000',
},
}, 'foo', '1.0.0')).toStrictEqual({
file: {
path: 'patches/foo@1.0.0.patch',
hash: expect.any(String),
},
key: 'foo@1.0.0',
})
})
test('getPatchInfo(_, name, version) if name exists but name@version does not exist', () => {
expect(_getPatchInfo({
foo: {
path: 'patches/foo.patch',
hash: '00000000000000000000000000000000',
},
}, 'foo', '1.0.0')).toStrictEqual({
file: {
path: 'patches/foo.patch',
hash: expect.any(String),
},
key: 'foo',
})
})
test('getPatchInfo(_, name, version) prioritizes name@version over name if both exist', () => {
expect(_getPatchInfo({
foo: {
path: 'patches/foo.patch',
hash: '00000000000000000000000000000000',
},
'foo@1.0.0': {
path: 'patches/foo@1.0.0.patch',
hash: '00000000000000000000000000000000',
},
}, 'foo', '1.0.0')).toStrictEqual({
file: {
path: 'patches/foo@1.0.0.patch',
hash: expect.any(String),
},
key: 'foo@1.0.0',
})
})
test('getPatchInfo(_, name, version) does not access wrong name', () => {
expect(_getPatchInfo({
'bar@1.0.0': {
path: 'patches/bar@1.0.0.patch',
hash: '00000000000000000000000000000000',
},
}, 'foo', '1.0.0')).toBeUndefined()
})
test('getPatchInfo(_, name, version) does not access wrong version', () => {
expect(_getPatchInfo({
'foo@2.0.0': {
path: 'patches/foo@2.0.0.patch',
hash: '00000000000000000000000000000000',
},
}, 'foo', '1.0.0')).toBeUndefined()
})