@@ -61,46 +61,84 @@ describe("BinTestCases", function() {
6161 cwd : path . resolve ( "./" , testDirectory )
6262 } ;
6363
64+ const async = fs . existsSync ( path . join ( testDirectory , "async" ) ) ;
65+
6466 const env = {
6567 stdout : [ ] ,
6668 stderr : [ ] ,
6769 error : [ ]
6870 } ;
6971
70- describe ( testName , function ( ) {
71- before ( function ( done ) {
72- this . timeout ( 20000 ) ;
73-
74- const child = spawn ( process . execPath , [ cmd ] . concat ( args ) , opts ) ;
75-
76- child . on ( "close" , function ( code ) {
77- env . code = code ;
78- done ( ) ;
72+ if ( async ) {
73+ describe ( testName , function ( ) {
74+ it ( "should run successfully" , function ( done ) {
75+ this . timeout ( 10000 ) ;
76+ const child = spawn ( process . execPath , [ cmd ] . concat ( args ) , opts ) ;
77+
78+ child . on ( "close" , function ( code ) {
79+ env . code = code ;
80+ } ) ;
81+
82+ child . on ( "error" , function ( error ) {
83+ env . error . push ( error ) ;
84+ } ) ;
85+
86+ child . stdout . on ( "data" , ( data ) => {
87+ env . stdout . push ( data ) ;
88+ } ) ;
89+
90+ child . stderr . on ( "data" , ( data ) => {
91+ env . stderr . push ( data ) ;
92+ } ) ;
93+
94+ setTimeout ( ( ) => {
95+ if ( env . code ) {
96+ done ( env . error )
97+ }
98+
99+ const stdout = convertToArrayOfLines ( env . stdout ) ;
100+ const stderr = convertToArrayOfLines ( env . stderr ) ;
101+ testAssertions ( stdout , stderr , done ) ;
102+ child . kill ( )
103+ } , 3000 ) ; // wait a little to get an output
79104 } ) ;
80-
81- child . on ( "error" , function ( error ) {
82- env . error . push ( error ) ;
105+ } )
106+ } else {
107+ describe ( testName , function ( ) {
108+ before ( function ( done ) {
109+ this . timeout ( 20000 ) ;
110+
111+ const child = spawn ( process . execPath , [ cmd ] . concat ( args ) , opts ) ;
112+
113+ child . on ( "close" , function ( code ) {
114+ env . code = code ;
115+ done ( ) ;
116+ } ) ;
117+
118+ child . on ( "error" , function ( error ) {
119+ env . error . push ( error ) ;
120+ } ) ;
121+
122+ child . stdout . on ( "data" , ( data ) => {
123+ env . stdout . push ( data ) ;
124+ } ) ;
125+
126+ child . stderr . on ( "data" , ( data ) => {
127+ env . stderr . push ( data ) ;
128+ } ) ;
83129 } ) ;
84130
85- child . stdout . on ( "data ", ( data ) => {
86- env . stdout . push ( data ) ;
131+ it ( "should not cause any errors ", function ( ) {
132+ should ( env . error ) . be . empty ( ) ;
87133 } ) ;
88134
89- child . stderr . on ( "data" , ( data ) => {
90- env . stderr . push ( data ) ;
135+ it ( "should run successfully" , function ( ) {
136+ const stdout = convertToArrayOfLines ( env . stdout ) ;
137+ const stderr = convertToArrayOfLines ( env . stderr ) ;
138+ testAssertions ( env . code , stdout , stderr ) ;
91139 } ) ;
92140 } ) ;
93-
94- it ( "should not cause any errors" , function ( ) {
95- should ( env . error ) . be . empty ( ) ;
96- } ) ;
97-
98- it ( "should run successfully" , function ( ) {
99- const stdout = convertToArrayOfLines ( env . stdout ) ;
100- const stderr = convertToArrayOfLines ( env . stderr ) ;
101- testAssertions ( env . code , stdout , stderr ) ;
102- } ) ;
103- } ) ;
141+ }
104142 } ) ;
105143 } ) ;
106144 } ) ;
0 commit comments