From 8a837458ca90a72a8047ac7a15b104b545fa7676 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 25 Jul 2026 22:01:07 -0700 Subject: [PATCH] Add test for decrypt passthrough to exec Directly importing the method prevents mocking. It is required to import the default module object to mock the method. --- src/command.js | 4 ++-- test/index.test.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/command.js b/src/command.js index b4d4973..7b4a3f7 100644 --- a/src/command.js +++ b/src/command.js @@ -1,6 +1,6 @@ import { parseEnv } from 'node:util'; import { readFile, writeFile } from 'node:fs/promises'; -import { execSync } from 'node:child_process'; +import childProcess from 'node:child_process'; /** @import { PathLike } from 'node:fs'; */ import { getPrf } from '#src/getPrf.js'; @@ -172,6 +172,6 @@ export async function decrypt(options = {}, { args = [] } = {}) { } if (args.length > 0) { logger.debug?.('Follow-on command found, executing in child process.'); - execSync(args.join(' '), { stdio: 'inherit' }); + childProcess.execSync(args.join(' '), { stdio: 'inherit' }); } } \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 40459de..0b8e2c8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,5 +1,6 @@ import { suite, test } from 'node:test'; import { deepStrictEqual } from 'node:assert'; +import childProcess from 'node:child_process'; import { encrypt, decrypt } from '#src/index.js'; import { BROWSER } from '#src/getPrf.js'; @@ -106,4 +107,11 @@ suite('e2e', () => { await fileEqual(envFile, env); deepStrictEqual(openMock.mock.calls.length, 0); }); + test('decrypt passes through excess args to execute', async (t) => { + const execMock = t.mock.method(childProcess, 'execSync', () => { }); + const envFile = await setupEnv(t, STD_ENV); + + await decrypt({ inFile: envFile }, { args: ['test', 'test', 'test'] }); + deepStrictEqual(execMock.mock.calls.length, 1); + }); }); -- 2.47.3