Files
pnpm/pnpm/test/exec.ts
Zoltan Kochan 19d5d714c7 test(pnpm): run e2e suite against pacquet via PNPM_E2E_BIN
The pnpm CLI e2e tests already exercise the bundled `pnpm.mjs` end-to-end,
so they can serve as a parity probe for the Rust port too. A new
`PNPM_E2E_BIN` env var swaps the spawned binary in `execPnpm`/`execPnpmSync`/
`spawnPnpm`, and a `skipIfPacquet` helper gates the per-test cases that
the port doesn't yet pass. Every failing test in the existing suite was
marked from a local sweep against `target/release/pacquet`; pacquet-CI
gets a new job that builds the binary, builds the pnpm bundle, and runs
jest with the env var set so future regressions surface in CI.

Written by an agent (Claude Code, claude-opus-4-7).
2026-05-21 19:46:53 +02:00

52 lines
1.3 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
import { expect } from '@jest/globals'
import { prepare } from '@pnpm/prepare'
import { writeYamlFileSync } from 'write-yaml-file'
import {
execPnpm,
execPnpmSync,
skipIfPacquet,
} from './utils/index.js'
skipIfPacquet("exec should respect the caller's current working directory", async () => {
prepare({
name: 'root',
version: '1.0.0',
})
const projectRoot = process.cwd()
fs.mkdirSync('some-directory', { recursive: true })
const subdirPath = path.join(projectRoot, 'some-directory')
await execPnpm(['install'])
const cmdFilePath = path.join(subdirPath, 'cwd.txt')
execPnpmSync(
['exec', 'node', '-e', `require('fs').writeFileSync(${JSON.stringify(cmdFilePath)}, process.cwd(), 'utf8')`],
{
cwd: subdirPath,
expectSuccess: true,
}
)
expect(fs.readFileSync(cmdFilePath, 'utf8')).toBe(subdirPath)
})
skipIfPacquet('silent exec does not print verifyDepsBeforeRun install output', async () => {
prepare({})
writeYamlFileSync('pnpm-workspace.yaml', {
verifyDepsBeforeRun: 'install',
})
const result = execPnpmSync(['--silent', 'exec', 'node', '-e', 'process.stdout.write("hi")'], {
expectSuccess: true,
omitEnvDefaults: ['pnpm_config_silent'],
})
expect(result.stdout.toString()).toBe('hi')
})