11"use strict" ;
22
3+ const path = require ( 'path' ) ;
4+ const fork = require ( 'child_process' ) . fork ;
35const expect = require ( 'chai' ) . expect ;
46const FastBootAppServer = require ( '../lib/fastboot-app-server' ) ;
57const request = require ( 'request-promise' ) . defaults ( { simple : false , resolveWithFullResponse : true } ) ;
68
9+ let server ;
10+
711describe ( "FastBootAppServer" , function ( ) {
812 this . timeout ( 3000 ) ;
913
14+ afterEach ( function ( ) {
15+ if ( server ) {
16+ server . kill ( ) ;
17+ }
18+ } ) ;
19+
1020 it ( "throws if no distPath or downloader is provided" , function ( ) {
1121 expect ( ( ) => {
1222 new FastBootAppServer ( ) ;
@@ -23,16 +33,7 @@ describe("FastBootAppServer", function() {
2333 } ) ;
2434
2535 it ( "serves an HTTP 500 response if the app can't be found" , function ( ) {
26- let server = new FastBootAppServer ( {
27- workerCount : 1 ,
28- downloader : {
29- download ( ) {
30- return Promise . resolve ( ) ;
31- }
32- }
33- } ) ;
34-
35- return server . start ( )
36+ return runServer ( 'not-found-server' )
3637 . then ( ( ) => request ( 'http://localhost:3000' ) )
3738 . then ( response => {
3839 expect ( response . statusCode ) . to . equal ( 500 ) ;
@@ -41,3 +42,24 @@ describe("FastBootAppServer", function() {
4142 } ) ;
4243
4344} ) ;
45+
46+ function runServer ( name ) {
47+ return new Promise ( ( res , rej ) => {
48+ let serverPath = path . join ( __dirname , 'fixtures' , `${ name } .js` ) ;
49+ server = fork ( serverPath , {
50+ silent : true
51+ } ) ;
52+
53+ server . on ( 'error' , rej ) ;
54+
55+ server . stdout . on ( 'data' , data => {
56+ if ( data . toString ( ) . match ( / H T T P s e r v e r s t a r t e d / ) ) {
57+ res ( ) ;
58+ }
59+ } ) ;
60+
61+ server . stderr . on ( 'data' , data => {
62+ console . log ( data . toString ( ) ) ;
63+ } ) ;
64+ } ) ;
65+ }
0 commit comments