1+ import { spawnSync } from 'node:child_process' ;
12import { nonExistentCommand , nodeHangingCommand , nodeEvalCommandStart } from './commands.js' ;
23
34export const assertSubprocessErrorName = ( t , name ) => {
@@ -23,13 +24,24 @@ export const assertNonExistent = (t, {name, exitCode, signalName, command, messa
2324 assertDurationMs ( t , durationMs ) ;
2425} ;
2526
27+ // Support localized error messages on non-English Windows.
28+ let nonExistentCommandOutput ;
29+ const toNonExistentCommandOutput = command => {
30+ if ( typeof nonExistentCommandOutput !== 'string' ) {
31+ const { stderr} = spawnSync ( nonExistentCommand , { shell : true , encoding : 'utf8' } ) ;
32+ nonExistentCommandOutput = stderr . replace ( / \r ? \n $ / , '' ) ;
33+ }
34+
35+ return nonExistentCommandOutput . replaceAll ( nonExistentCommand , command . split ( / [ / ] / ) [ 0 ] ) ;
36+ } ;
37+
2638export const assertWindowsNonExistent = ( t , { name, exitCode, signalName, command, message, stderr, cause, durationMs} , expectedCommand = nonExistentCommand ) => {
2739 assertSubprocessErrorName ( t , name ) ;
2840 t . is ( exitCode , 1 ) ;
2941 t . is ( signalName , undefined ) ;
3042 t . is ( command , expectedCommand ) ;
3143 t . is ( message , `Command failed with exit code 1: ${ expectedCommand } ` ) ;
32- t . true ( stderr . includes ( 'not recognized as an internal or external command' ) ) ;
44+ t . is ( stderr , toNonExistentCommandOutput ( expectedCommand ) ) ;
3345 t . is ( cause , undefined ) ;
3446 assertDurationMs ( t , durationMs ) ;
3547} ;
0 commit comments