@@ -54,101 +54,33 @@ describe('fastboot server task', function() {
5454 } ) ;
5555
5656 describe ( 'run' , function ( ) {
57- it ( 'calls restart on postBuild ' , function ( ) {
58- const restartStub = this . sinon . stub ( task , 'restart' ) ;
57+ it ( 'calls restart on outputReady ' , function ( ) {
58+ const restartStub = this . sinon . stub ( task , 'outputReady' , function ( ) { } ) ;
5959 task . run ( options ) ;
60- addon . emit ( 'postBuild ' ) ;
60+ addon . emit ( 'outputReady ' ) ;
6161 expect ( restartStub . called ) . to . be . ok ;
6262 } ) ;
6363 } ) ;
6464
6565 describe ( 'restart' , function ( ) {
66- let restartSpy , stopStub , clearRequireCacheStub , startStub ;
66+ let fbReloadStub , oldFb ;
6767
6868 beforeEach ( function ( ) {
69- restartSpy = this . sinon . spy ( task , 'restart' ) ;
70- stopStub = this . sinon . stub ( task , 'stop' ) . returns ( RSVP . resolve ( ) ) ;
71- clearRequireCacheStub = this . sinon . stub ( task , 'clearRequireCache' ) ;
72- startStub = this . sinon . stub ( task , 'start' ) ;
69+ oldFb = task . fastboot ;
70+ fbReloadStub = this . sinon . stub ( ) . returns ( RSVP . resolve ( ) ) ;
71+ task . fastboot = {
72+ reload : fbReloadStub
73+ } ;
7374 } ) ;
7475
75- it ( 'calls stop, clearRequireCache, and start' , function ( ) {
76- return task . restart ( options ) . then ( ( ) => {
77- expect ( restartSpy . callCount ) . to . equal ( 1 ) ;
78- expect ( stopStub . callCount ) . to . equal ( 1 ) ;
79- expect ( clearRequireCacheStub . callCount ) . to . equal ( 1 ) ;
80- expect ( startStub . callCount ) . to . equal ( 1 ) ;
81- } ) ;
76+ afterEach ( function ( ) {
77+ task . fastboot = oldFb ;
8278 } ) ;
8379
84- it ( 'can restart multiple times' , function ( ) {
85- const restartPromise = task . restart ( options ) ;
86- return restartPromise
87- . then ( ( ) => task . restart ( options ) )
88- . then ( ( ) => {
89- expect ( restartSpy . callCount ) . to . equal ( 2 ) ;
90- expect ( stopStub . callCount ) . to . equal ( 2 ) ;
91- expect ( clearRequireCacheStub . callCount ) . to . equal ( 2 ) ;
92- expect ( startStub . callCount ) . to . equal ( 2 ) ;
93- } ) ;
94- } ) ;
95-
96- // when outputReady while server is starting
97- // (e.g. app file change during server npm install)
98- // - wait on start, then reload
99- // when outputReady multiple times during startup
100- // (e.g. fast app build, slow server npm install)
101- // - call reload only once
102- it ( 'restarts again just once for all calls during startup' , function ( ) {
103- const restartPromise = task . restart ( options ) ;
104- expect ( task . restartPromise ) . to . equal ( restartPromise ) ;
105- expect ( task . restartAgain ) . to . equal ( false ) ;
106- task . restart ( options ) ;
107- task . restart ( options ) ;
108- expect ( task . restartPromise ) . to . equal ( restartPromise ) ;
109- expect ( task . restartAgain ) . to . equal ( true ) ;
110- return restartPromise
111- . then ( ( ) => {
112- expect ( task . restartPromise ) . to . not . equal ( restartPromise ) ;
113- expect ( task . restartAgain ) . to . equal ( false ) ;
114- return task . restartPromise ;
115- } )
80+ it ( 'calls fastboot.reload' , function ( ) {
81+ return task . restart ( options )
11682 . then ( ( ) => {
117- expect ( task . restartPromise ) . to . equal ( null ) ;
118- expect ( task . restartAgain ) . to . equal ( false ) ;
119- expect ( restartSpy . callCount ) . to . equal ( 4 ) ;
120- expect ( stopStub . callCount ) . to . equal ( 2 ) ;
121- expect ( clearRequireCacheStub . callCount ) . to . equal ( 2 ) ;
122- expect ( startStub . callCount ) . to . equal ( 2 ) ;
123- } ) ;
124- } ) ;
125-
126- it ( 'can restart again after immediate restart completes' , function ( ) {
127- const restartPromise = task . restart ( options ) ;
128- expect ( task . restartPromise ) . to . equal ( restartPromise ) ;
129- expect ( task . restartAgain ) . to . equal ( false ) ;
130- task . restart ( options ) ;
131- task . restart ( options ) ;
132- expect ( task . restartPromise ) . to . equal ( restartPromise ) ;
133- expect ( task . restartAgain ) . to . equal ( true ) ;
134- return restartPromise
135- . then ( ( ) => {
136- expect ( task . restartPromise ) . to . not . equal ( restartPromise ) ;
137- expect ( task . restartAgain ) . to . equal ( false ) ;
138- return task . restartPromise ;
139- } )
140- . then ( ( ) => {
141- expect ( task . restartPromise ) . to . equal ( null ) ;
142- expect ( task . restartAgain ) . to . equal ( false ) ;
143- return task . restart ( options ) ;
144- } )
145- . then ( ( ) => {
146- expect ( task . restartPromise ) . to . equal ( null ) ;
147- expect ( task . restartAgain ) . to . equal ( false ) ;
148- expect ( restartSpy . callCount ) . to . equal ( 5 ) ;
149- expect ( stopStub . callCount ) . to . equal ( 3 ) ;
150- expect ( clearRequireCacheStub . callCount ) . to . equal ( 3 ) ;
151- expect ( startStub . callCount ) . to . equal ( 3 ) ;
83+ expect ( fbReloadStub . callCount ) . to . equal ( 1 ) ;
15284 } ) ;
15385 } ) ;
15486 } ) ;
@@ -162,6 +94,7 @@ describe('fastboot server task', function() {
16294 const mockRequire = ( which ) => {
16395 if ( which === 'express' ) { return mockExpress ; }
16496 if ( which === 'fastboot-express-middleware' ) return ( ) => { } ;
97+ if ( which === 'fastboot' ) return function fakeBoot ( ) { } ;
16598 } ;
16699
167100 beforeEach ( function ( ) {
@@ -173,21 +106,6 @@ describe('fastboot server task', function() {
173106 useStub = this . sinon . stub ( mockApp , 'use' ) ;
174107 } ) ;
175108
176- it ( 'runs npm install in server root' , function ( ) {
177- return task . start ( options )
178- . then ( ( ) => {
179- expect ( execStub . calledWith ( 'npm install' , { cwd : 'dist' } ) ) . to . equal ( true ) ;
180- } ) ;
181- } ) ;
182-
183- it ( 'requires server dependencies' , function ( ) {
184- return task . start ( options )
185- . then ( ( ) => {
186- expect ( requireSpy . calledWith ( 'fastboot-express-middleware' ) ) . to . equal ( true ) ;
187- expect ( requireSpy . calledWith ( 'express' ) ) . to . equal ( true ) ;
188- } ) ;
189- } ) ;
190-
191109 it ( 'uses express.static when serve-assets=true' , function ( ) {
192110 options = new CommandOptions ( { serveAssets : true } ) ;
193111 return task . start ( options )
0 commit comments