Files
pnpm/exec/plugin-commands-script-runners/test/dlx.ts
Zoltan Kochan 3a5bfaa94f chore: update zkochan packages to latest versions (#10930)
Update all packages from zkochan/packages to their latest major versions
and exclude them from minimumReleaseAge requirement. This includes
updating catalog entries, adapting to breaking API changes (default
exports replaced with named exports, sync functions renamed with Sync
suffix), and updating type declarations.
2026-03-11 13:47:46 +01:00

45 lines
1.2 KiB
TypeScript

import path from 'path'
import { prepareEmpty } from '@pnpm/prepare'
import { jest } from '@jest/globals'
import { DLX_DEFAULT_OPTS as DEFAULT_OPTS } from './utils/index.js'
jest.unstable_mockModule('execa', () => ({
safeExeca: jest.fn(),
sync: jest.fn(),
}))
const { safeExeca: execa } = await import('execa')
const { dlx } = await import('@pnpm/plugin-commands-script-runners')
beforeEach(() => jest.mocked(execa).mockClear())
test('dlx should work with scoped packages', async () => {
prepareEmpty()
const userAgent = 'pnpm/0.0.0'
await dlx.handler({
...DEFAULT_OPTS,
dir: path.resolve('project'),
storeDir: path.resolve('store'),
userAgent,
}, ['@foo/touch-file-one-bin'])
expect(execa).toHaveBeenCalledWith('touch-file-one-bin', [], expect.objectContaining({
env: expect.objectContaining({
npm_config_user_agent: userAgent,
}),
}))
})
test('dlx should work with versioned packages', async () => {
prepareEmpty()
await dlx.handler({
...DEFAULT_OPTS,
dir: path.resolve('project'),
storeDir: path.resolve('store'),
}, ['@foo/touch-file-one-bin@latest'])
expect(execa).toHaveBeenCalledWith('touch-file-one-bin', [], expect.anything())
})