44 */
55
66import { describe , it , expect , beforeAll , afterAll , beforeEach , afterEach , vi } from 'vitest' ;
7- import { execSync , exec } from 'child_process' ;
7+ import { execFileSync , execSync , spawnSync } from 'child_process' ;
88import { existsSync , mkdtempSync , writeFileSync , readFileSync , unlinkSync , rmSync } from 'fs' ;
99import { join } from 'path' ;
1010import { tmpdir , homedir } from 'os' ;
@@ -14,19 +14,29 @@ const TEST_MNEMONIC = 'abandon abandon abandon abandon abandon abandon abandon a
1414
1515// Check if gpg is available
1616let hasGpg = false ;
17+ let hasNodeSpawn = false ;
1718try {
1819 execSync ( 'gpg --version' , { stdio : 'pipe' } ) ;
1920 hasGpg = true ;
2021} catch {
2122 hasGpg = false ;
2223}
2324
25+ try {
26+ execFileSync ( process . execPath , [ '-e' , 'process.exit(0)' ] , { stdio : 'pipe' } ) ;
27+ hasNodeSpawn = true ;
28+ } catch {
29+ hasNodeSpawn = false ;
30+ }
31+
2432/**
2533 * Run CLI command and return output
2634 */
2735function runCLI ( args , options = { } ) {
2836 const { cwd, input, env : extraEnv } = options ;
29- const cmd = `node ${ CLI_PATH } ${ args } 2>&1` ;
37+ const cliArgs = Array . isArray ( args )
38+ ? args
39+ : Array . from ( args . matchAll ( / " ( [ ^ " ] * ) " | ' ( [ ^ ' ] * ) ' | [ ^ \s ] + / g) , ( match ) => match [ 1 ] ?? match [ 2 ] ?? match [ 0 ] ) ;
3040 const opts = {
3141 encoding : 'utf-8' ,
3242 stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
@@ -41,18 +51,14 @@ function runCLI(args, options = {}) {
4151 ...( input ? { input } : { } ) ,
4252 } ;
4353
44- try {
45- const output = execSync ( cmd , opts ) ;
46- return { output, status : 0 } ;
47- } catch ( err ) {
48- return {
49- output : ( err . stdout || '' ) + ( err . stderr || '' ) ,
50- status : err . status || 1 ,
51- } ;
52- }
54+ const result = spawnSync ( process . execPath , [ CLI_PATH , ...cliArgs ] , opts ) ;
55+ return {
56+ output : `${ result . stdout || '' } ${ result . stderr || '' } ` ,
57+ status : result . status ?? 1 ,
58+ } ;
5359}
5460
55- describe ( 'CLI Wallet Commands' , ( ) => {
61+ describe . skipIf ( ! hasNodeSpawn ) ( 'CLI Wallet Commands' , ( ) => {
5662 let tmpDir ;
5763 let testHome ;
5864 let configPath ;
0 commit comments