@@ -4,8 +4,10 @@ import CLI, { ansi, Extension, Terminal } from '../src/index.js';
44import path from 'path' ;
55import { expect } from 'chai' ;
66import { fileURLToPath } from 'url' ;
7+ import { platform } from 'os' ;
78import { spawnSync } from 'child_process' ;
89import { WritableStream } from 'memory-streams' ;
10+ import { nodePath } from '../src/lib/util.js' ;
911
1012const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
1113
@@ -55,14 +57,19 @@ describe('Extension', () => {
5557
5658 const env = { ...process . env } ;
5759 delete env . SNOOPLOGG ;
58-
59- const { status, stdout, stderr } = spawnSync ( process . execPath , [
60+ const args = [
6061 path . join ( __dirname , 'examples' , 'external-binary' , 'extbin.js' ) ,
62+ // this is the command name!
6163 'node' ,
6264 '-e' ,
6365 'console.log(\'foo\');'
64- ] , { env } ) ;
65- expect ( stdout . toString ( ) . trim ( ) + stderr . toString ( ) . trim ( ) ) . to . match ( / f o o / im) ;
66+ ] ;
67+
68+ const { status, stdout, stderr } = spawnSync ( nodePath ( ) , args , {
69+ env
70+ } ) ;
71+ expect ( stdout . toString ( ) . trim ( ) ) . to . equal ( 'foo' ) ;
72+ expect ( stderr . toString ( ) . trim ( ) ) . to . equal ( '' ) ;
6673 expect ( status ) . to . equal ( 0 ) ;
6774 } ) ;
6875
@@ -73,9 +80,11 @@ describe('Extension', () => {
7380 const env = { ...process . env } ;
7481 delete env . SNOOPLOGG ;
7582
76- const { status, stdout, stderr } = spawnSync ( process . execPath , [
83+ const { status, stdout, stderr } = spawnSync ( nodePath ( ) , [
7784 path . join ( __dirname , 'examples' , 'run-node' , 'run.js' ) , 'run' , 'console.log(\'It works\')'
78- ] , { env } ) ;
85+ ] , {
86+ env
87+ } ) ;
7988 expect ( status ) . to . equal ( 0 ) ;
8089 expect ( stdout . toString ( ) . trim ( ) + stderr . toString ( ) . trim ( ) ) . to . match ( / I t w o r k s / m) ;
8190 } ) ;
@@ -86,7 +95,7 @@ describe('Extension', () => {
8695 const cli = new CLI ( {
8796 colors : false ,
8897 extensions : {
89- echo : 'node -e \'console.log("hi " + process.argv.slice(1).join(" "))\''
98+ echo : nodePath ( ) + ' -e \'console.log("hi " + process.argv.slice(1).join(" "))\''
9099 } ,
91100 help : true ,
92101 name : 'test-cli' ,
@@ -166,9 +175,11 @@ describe('Extension', () => {
166175 const env = { ...process . env } ;
167176 delete env . SNOOPLOGG ;
168177
169- const { status, stdout, stderr } = spawnSync ( process . execPath , [
178+ const { status, stdout, stderr } = spawnSync ( nodePath ( ) , [
170179 path . join ( __dirname , 'examples' , 'external-js-file' , 'extjsfile.js' ) , 'simple' , 'foo' , 'bar'
171- ] , { env } ) ;
180+ ] , {
181+ env
182+ } ) ;
172183 expect ( stdout . toString ( ) . trim ( ) + stderr . toString ( ) . trim ( ) ) . to . equal ( `${ process . version } foo bar` ) ;
173184 expect ( status ) . to . equal ( 0 ) ;
174185 } ) ;
@@ -180,9 +191,11 @@ describe('Extension', () => {
180191 const env = { ...process . env } ;
181192 delete env . SNOOPLOGG ;
182193
183- const { status, stdout, stderr } = spawnSync ( process . execPath , [
194+ const { status, stdout, stderr } = spawnSync ( nodePath ( ) , [
184195 path . join ( __dirname , 'examples' , 'external-module' , 'extmod.js' ) , 'foo' , 'bar'
185- ] , { env } ) ;
196+ ] , {
197+ env
198+ } ) ;
186199 expect ( stdout . toString ( ) . trim ( ) + stderr . toString ( ) . trim ( ) ) . to . equal ( `${ process . version } bar` ) ;
187200 expect ( status ) . to . equal ( 0 ) ;
188201 } ) ;
0 commit comments