@@ -33,6 +33,39 @@ function getNodeVersionInfo() {
3333 . map ( ( x ) => parseInt ( x ) ) ;
3434}
3535
36+ function runCommand ( command , args , options ) {
37+ const result = childProcess . spawnSync ( command , args , options ) ;
38+ if (
39+ result . error ||
40+ ( typeof result . status === 'number' && result . status !== 0 )
41+ ) {
42+ const parts = [
43+ `Failed to run: ${ command } ${ Array . isArray ( args ) ? args . join ( ' ' ) : '' } ` ,
44+ ] ;
45+ if (
46+ result . error &&
47+ result . error . code === 'ETIMEDOUT' &&
48+ options &&
49+ options . timeout
50+ ) {
51+ parts . push ( `Command timed out after ${ options . timeout } ms` ) ;
52+ } else if ( result . error ) {
53+ parts . push ( `Error: ${ result . error . message } ` ) ;
54+ }
55+ if ( typeof result . status === 'number' && result . status !== 0 ) {
56+ parts . push ( `Exit status: ${ result . status } ` ) ;
57+ }
58+ if ( result . stdout ) {
59+ parts . push ( `stdout:\n${ result . stdout . toString ( ) } ` ) ;
60+ }
61+ if ( result . stderr ) {
62+ parts . push ( `stderr:\n${ result . stderr . toString ( ) } ` ) ;
63+ }
64+ throw new Error ( parts . join ( '\n' ) ) ;
65+ }
66+ return result ;
67+ }
68+
3669describe ( 'rclnodejs generate-messages binary-script tests' , function ( ) {
3770 let cwd ;
3871 let tmpPkg ;
@@ -62,7 +95,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
6295 cwd : this . tmpPkg ,
6396 timeout : 60 * 1000 ,
6497 } ) ;
65- childProcess . spawnSync ( 'npm' , [ 'pack' , this . cwd ] , {
98+ runCommand ( 'npm' , [ 'pack' , this . cwd ] , {
6699 // stdio: 'inherit',
67100 shell : true ,
68101 cwd : this . tmpPkg ,
@@ -82,7 +115,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
82115 return ;
83116 }
84117 let tgzPath = path . join ( this . tmpPkg , tgz ) ;
85- childProcess . spawnSync ( 'npm' , [ 'install' , tgzPath ] , {
118+ runCommand ( 'npm' , [ 'install' , tgzPath ] , {
86119 // stdio: 'inherit',
87120 shell : true ,
88121 cwd : this . tmpPkg ,
@@ -117,7 +150,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
117150
118151 it ( 'test generate-ros-messages script operation' , function ( done ) {
119152 let script = createScriptFolderPath ( this . tmpPkg ) ;
120- childProcess . spawnSync ( script , args , {
153+ runCommand ( script , args , {
121154 // stdio: 'inherit',
122155 shell : true ,
123156 timeout : 120 * 1000 ,
@@ -136,7 +169,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
136169 } ) ;
137170
138171 it ( 'test npx generate-ros-messages script operation' , function ( done ) {
139- childProcess . spawnSync ( 'npx' , [ SCRIPT_NAME , ...args ] , {
172+ runCommand ( 'npx' , [ SCRIPT_NAME , ...args ] , {
140173 // stdio: 'inherit',
141174 shell : true ,
142175 cwd : this . tmpPkg ,
0 commit comments