]> git.ardis.lu - envpass/commitdiff
Add test for decrypt passthrough to exec
authorArdis Lu <ardisglu@gmail.com>
Sun, 26 Jul 2026 05:01:07 +0000 (22:01 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 26 Jul 2026 05:01:07 +0000 (22:01 -0700)
Directly importing the method prevents mocking. It is required to import the default module object to mock the method.

src/command.js
test/index.test.js

index b4d497398f447edcf39deab8c5d2354aafc4a93c..7b4a3f767f74eb4d04dab1427eb799f3dfede6d2 100644 (file)
@@ -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
index 40459de1ad13da12d89248a973b66accd8a39fe5..0b8e2c81110d6540b042ad201334c81c6635ec73 100644 (file)
@@ -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);
+  });
 });
This page took 0.035239 seconds and 4 git commands to generate.