mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-24 14:58:50 -05:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { createReadPackageHook } from '../lib/createReadPackageHook'
|
|
|
|
test('createReadPackageHook() is passing directory to all hooks', async () => {
|
|
const hook1 = jest.fn((manifest) => manifest)
|
|
const hook2 = jest.fn((manifest) => manifest)
|
|
const readPackageHook = createReadPackageHook({
|
|
ignoreCompatibilityDb: true,
|
|
lockfileDir: '/foo',
|
|
readPackageHook: [hook1, hook2],
|
|
})
|
|
const manifest = {}
|
|
const dir = '/bar'
|
|
await readPackageHook!(manifest, dir)
|
|
expect(hook1).toHaveBeenCalledWith(manifest, dir)
|
|
expect(hook2).toHaveBeenCalledWith(manifest, dir)
|
|
})
|
|
|
|
test('createReadPackageHook() runs the custom hook before the version overrider', async () => {
|
|
const hook = jest.fn((manifest) => ({
|
|
...manifest,
|
|
dependencies: {
|
|
...manifest.dependencies,
|
|
react: '18',
|
|
},
|
|
}))
|
|
const readPackageHook = createReadPackageHook({
|
|
ignoreCompatibilityDb: true,
|
|
lockfileDir: '/foo',
|
|
readPackageHook: [hook],
|
|
overrides: [
|
|
{
|
|
targetPkg: {
|
|
name: 'react',
|
|
},
|
|
newPref: '16',
|
|
},
|
|
],
|
|
})
|
|
const manifest = {}
|
|
const dir = '/bar'
|
|
const updatedManifest = await readPackageHook!(manifest, dir)
|
|
expect(hook).toHaveBeenCalledWith(manifest, dir)
|
|
expect(updatedManifest).toStrictEqual({
|
|
dependencies: {
|
|
react: '16',
|
|
},
|
|
})
|
|
})
|