Files
pnpm/pnpm11/exec/lifecycle/test/argQuoting.ts
T
Zoltan Kochan 9a0918ceb3 test(executor): cover the emulator quoting branch off Windows (#14623)
The rule that the shell emulator takes POSIX quoting on every platform was
only observable on Windows. Both stacks gated it behind a platform check
that is constant for a given run, so a Linux or macOS job could not tell
`windows && !shell_emulator` from `windows` alone.

Take the platform as a value in `parsed_by_windows_shell` and give
`build_command` the shell family it should quote for. Both quoting branches
and the emulator rule are now asserted on any host, which also retires the
`build_command` case that was ignored on Windows and leaves the JSON branch
covered for the first time off Windows.

Mock `is-windows` in a lifecycle test so the same rule is exercised through
`runLifecycleHook` on any host. Each assertion was confirmed to fail when
its half of the rule is removed.

Related to pnpm/pnpm#14548
2026-09-06 20:30:39 +02:00

41 lines
1.2 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
import { expect, jest, test } from '@jest/globals'
import { fixtures } from '@pnpm/test-fixtures'
jest.unstable_mockModule('is-windows', () => ({ default: () => true }))
const { runLifecycleHook } = await import('../lib/index.js')
const f = fixtures(path.join(import.meta.dirname, 'fixtures'))
const rootModulesDir = path.join(import.meta.dirname, '..', 'node_modules')
// `is-windows` is mocked because the branch under test is otherwise
// reachable only from a Windows host.
test('runLifecycleHook() quotes arguments for the emulator rather than for cmd on Windows', async () => {
const pkgRoot = f.prepare('escape-args')
const { default: pkg } = await import(path.join(pkgRoot, 'package.json'))
const args = [
'C:\\Program Files\\tool\\',
'',
'a"b',
"it's",
'$PNPM_QUOTING_TEST',
'line\nbreak',
]
await runLifecycleHook('echo', pkg, {
args,
depPath: '/escape-args/1.0.0',
extraEnv: { PNPM_QUOTING_TEST: 'expanded' },
pkgRoot,
rootModulesDir,
shellEmulator: true,
unsafePerm: true,
})
const recorded = JSON.parse(await fs.promises.readFile(path.join(pkgRoot, 'output.json'), 'utf8'))
expect(recorded).toStrictEqual(args)
})