@@ -4,8 +4,10 @@ import CLI, { ansi, Extension, Terminal } from '../src/index.js';
4
4
import path from 'path' ;
5
5
import { expect } from 'chai' ;
6
6
import { fileURLToPath } from 'url' ;
7
+ import { platform } from 'os' ;
7
8
import { spawnSync } from 'child_process' ;
8
9
import { WritableStream } from 'memory-streams' ;
10
+ import { nodePath } from '../src/lib/util.js' ;
9
11
10
12
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
11
13
@@ -57,12 +59,17 @@ describe('Extension', () => {
57
59
delete env . SNOOPLOGG ;
58
60
const args = [
59
61
path . join ( __dirname , 'examples' , 'external-binary' , 'extbin.js' ) ,
62
+ // this is the command name!
60
63
'node' ,
61
64
'-e' ,
62
- '\' console.log(\'foo\');\' '
65
+ 'console.log(\'foo\');'
63
66
] ;
64
- const cmd = `${ process . execPath } ${ args . join ( ' ' ) } ` ;
65
- const { status} = spawnSync ( process . execPath , args , { env, shell : true } ) ;
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 ( '' ) ;
66
73
expect ( status ) . to . equal ( 0 ) ;
67
74
} ) ;
68
75
@@ -73,9 +80,11 @@ describe('Extension', () => {
73
80
const env = { ...process . env } ;
74
81
delete env . SNOOPLOGG ;
75
82
76
- const { status, stdout, stderr } = spawnSync ( process . execPath , [
83
+ const { status, stdout, stderr } = spawnSync ( nodePath ( ) , [
77
84
path . join ( __dirname , 'examples' , 'run-node' , 'run.js' ) , 'run' , 'console.log(\'It works\')'
78
- ] , { env } ) ;
85
+ ] , {
86
+ env
87
+ } ) ;
79
88
expect ( status ) . to . equal ( 0 ) ;
80
89
expect ( stdout . toString ( ) . trim ( ) + stderr . toString ( ) . trim ( ) ) . to . match ( / I t w o r k s / m) ;
81
90
} ) ;
@@ -86,7 +95,7 @@ describe('Extension', () => {
86
95
const cli = new CLI ( {
87
96
colors : false ,
88
97
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(" "))\''
90
99
} ,
91
100
help : true ,
92
101
name : 'test-cli' ,
@@ -166,9 +175,11 @@ describe('Extension', () => {
166
175
const env = { ...process . env } ;
167
176
delete env . SNOOPLOGG ;
168
177
169
- const { status, stdout, stderr } = spawnSync ( process . execPath , [
178
+ const { status, stdout, stderr } = spawnSync ( nodePath ( ) , [
170
179
path . join ( __dirname , 'examples' , 'external-js-file' , 'extjsfile.js' ) , 'simple' , 'foo' , 'bar'
171
- ] , { env, shell : true } ) ;
180
+ ] , {
181
+ env
182
+ } ) ;
172
183
expect ( stdout . toString ( ) . trim ( ) + stderr . toString ( ) . trim ( ) ) . to . equal ( `${ process . version } foo bar` ) ;
173
184
expect ( status ) . to . equal ( 0 ) ;
174
185
} ) ;
@@ -180,9 +191,11 @@ describe('Extension', () => {
180
191
const env = { ...process . env } ;
181
192
delete env . SNOOPLOGG ;
182
193
183
- const { status, stdout, stderr } = spawnSync ( process . execPath , [
194
+ const { status, stdout, stderr } = spawnSync ( nodePath ( ) , [
184
195
path . join ( __dirname , 'examples' , 'external-module' , 'extmod.js' ) , 'foo' , 'bar'
185
- ] , { env, shell : true } ) ;
196
+ ] , {
197
+ env
198
+ } ) ;
186
199
expect ( stdout . toString ( ) . trim ( ) + stderr . toString ( ) . trim ( ) ) . to . equal ( `${ process . version } bar` ) ;
187
200
expect ( status ) . to . equal ( 0 ) ;
188
201
} ) ;
0 commit comments