@@ -159,7 +159,7 @@ describe('Unit: Commands > Run', function () {
159
159
const errorStub = sinon . stub ( ) ;
160
160
const exitStub = sinon . stub ( process , 'exit' ) ;
161
161
162
- instance . useDirect ( { dir : '/var/www/ghost' , process : { success : successStub , error : errorStub } } , { delayErrorChaining : false } ) ;
162
+ instance . useDirect ( { dir : '/var/www/ghost' , version : '3.0.0' , process : { success : successStub , error : errorStub } } , { delayErrorChaining : false } ) ;
163
163
164
164
expect ( spawnStub . calledOnce ) . to . be . true ;
165
165
expect ( spawnStub . calledWithExactly ( process . execPath , [ 'current/index.js' ] , {
@@ -202,6 +202,62 @@ describe('Unit: Commands > Run', function () {
202
202
} , 2000 ) ;
203
203
} ) ;
204
204
205
+ it ( 'useDirect spawns child process and handles events correctly (v4+)' , async function ( ) {
206
+ this . timeout ( 10000 ) ;
207
+
208
+ const childStub = new EventEmitter ( ) ;
209
+ childStub . stderr = getReadableStream ( ) ;
210
+
211
+ const spawnStub = sinon . stub ( ) . returns ( childStub ) ;
212
+ const RunCommand = proxyquire ( modulePath , {
213
+ child_process : { spawn : spawnStub }
214
+ } ) ;
215
+ const instance = new RunCommand ( { } , { } ) ;
216
+ const successStub = sinon . stub ( ) ;
217
+ const errorStub = sinon . stub ( ) ;
218
+
219
+ instance . useDirect ( { dir : '/var/www/ghost' , version : '4.0.0' , process : { success : successStub , error : errorStub } } , { delayErrorChaining : false } ) ;
220
+
221
+ expect ( spawnStub . calledOnce ) . to . be . true ;
222
+ expect ( spawnStub . calledWithExactly ( process . execPath , [ 'current/index.js' ] , {
223
+ cwd : '/var/www/ghost' ,
224
+ stdio : [ 0 , 1 , 'pipe' , 'ipc' ]
225
+ } ) ) . to . be . true ;
226
+ expect ( instance . child ) . to . equal ( childStub ) ;
227
+
228
+ // Check error prior to started
229
+ expect ( successStub . called ) . to . be . false ;
230
+ expect ( errorStub . called ) . to . be . false ;
231
+ childStub . emit ( 'message' , { error : { message : 'test error' } } ) ;
232
+ await new Promise ( ( resolve ) => {
233
+ setTimeout ( resolve , 2000 ) ;
234
+ } ) ;
235
+ expect ( successStub . called ) . to . be . false ;
236
+ expect ( errorStub . calledOnceWithExactly ( { message : 'test error' } ) ) ;
237
+
238
+ errorStub . reset ( ) ;
239
+
240
+ // emit started message
241
+ childStub . emit ( 'message' , { started : true } ) ;
242
+ expect ( successStub . called ) . to . be . false ;
243
+ expect ( errorStub . called ) . to . be . false ;
244
+
245
+ // check error after started
246
+ childStub . emit ( 'message' , { error : { message : 'test error' } } ) ;
247
+ await new Promise ( ( resolve ) => {
248
+ setTimeout ( resolve , 2000 ) ;
249
+ } ) ;
250
+ expect ( successStub . called ) . to . be . false ;
251
+ expect ( errorStub . calledOnceWithExactly ( { message : 'Ghost was able to start, but errored during boot with: test error' } ) ) ;
252
+
253
+ errorStub . reset ( ) ;
254
+
255
+ // finally, check ready event
256
+ childStub . emit ( 'message' , { ready : true } ) ;
257
+ expect ( successStub . calledOnce ) . to . be . true ;
258
+ expect ( errorStub . called ) . to . be . false ;
259
+ } ) ;
260
+
205
261
describe ( 'cleanup handler' , function ( ) {
206
262
const RunCommand = require ( modulePath ) ;
207
263
0 commit comments