@@ -172,6 +172,26 @@ if (isWindows) {
172172 t . is ( stdout , 'Hello World' ) ;
173173 } ) ;
174174
175+ test ( 'Runs a .com executable selected by PATHEXT' , async t => {
176+ const binaryDirectory = path . join ( FIXTURES_DIRECTORY , 'node_modules' , '.bin' ) ;
177+ await mkdir ( binaryDirectory , { recursive : true } ) ;
178+ await cp ( process . execPath , path . join ( binaryDirectory , 'node-com.com' ) ) ;
179+ const options = {
180+ preferLocal : true ,
181+ localDir : FIXTURES_DIRECTORY ,
182+ extendEnv : false ,
183+ env : {
184+ Path : path . dirname ( process . execPath ) ,
185+ PathExt : '.COM' ,
186+ } ,
187+ } ;
188+ const { stdout} = await execa ( 'node-com' , [ '--version' ] , options ) ;
189+ t . is ( stdout , process . version ) ;
190+
191+ const { stdout : stdoutSync } = execaSync ( 'node-com' , [ '--version' ] , options ) ;
192+ t . is ( stdoutSync , process . version ) ;
193+ } ) ;
194+
175195 // A `.cmd` file needs `cmd.exe`, so its forward-slash path must be normalized to
176196 // backslashes, otherwise it fails with ENOENT.
177197 test ( 'Runs a .cmd file given as a relative POSIX-style subpath' , async t => {
@@ -201,6 +221,35 @@ if (isWindows) {
201221 t . is ( stdoutSync , commandArgument ) ;
202222 } ) ;
203223
224+ test ( 'Double-escapes explicit batch files excluded from PATHEXT' , async t => {
225+ const commandArgument = '"& whoami &"' ;
226+ const options = {
227+ extendEnv : false ,
228+ env : {
229+ Path : path . dirname ( process . execPath ) ,
230+ PathExt : '.EXE' ,
231+ } ,
232+ } ;
233+ const command = path . join ( FIXTURES_DIRECTORY , 'echo-shim.cmd' ) ;
234+ const { stdout} = await execa ( command , [ commandArgument ] , options ) ;
235+ t . is ( stdout , commandArgument ) ;
236+
237+ const { stdout : stdoutSync } = execaSync ( command , [ commandArgument ] , options ) ;
238+ t . is ( stdoutSync , commandArgument ) ;
239+ } ) ;
240+
241+ test ( 'Runs an explicit shebang script excluded from PATHEXT' , async t => {
242+ const command = path . join ( FIXTURES_DIRECTORY , 'echo.js' ) ;
243+ const options = {
244+ extendEnv : false ,
245+ env : {
246+ Path : path . dirname ( process . execPath ) ,
247+ PathExt : '.EXE' ,
248+ } ,
249+ } ;
250+ await testResolvesCommand ( t , command , options ) ;
251+ } ) ;
252+
204253 test . serial ( 'Double-escapes metacharacters for preferLocal cmd-shims' , async t => {
205254 await setupCmdShim ( ) ;
206255 const commandArgument = 'a&whoami' ;
0 commit comments