@@ -26,33 +26,27 @@ describe('FastBoot', function() {
2626 expect ( fn ) . to . throw ( / Y o u m u s t i n s t a n t i a t e F a s t B o o t w i t h a d i s t P a t h o p t i o n / ) ;
2727 } ) ;
2828
29- it ( 'can provide distPath as the first argument' , function ( ) {
29+ it ( 'can provide distPath as the first argument' , async function ( ) {
3030 let middleware = fastbootMiddleware ( fixture ( 'basic-app' ) ) ;
3131 server = new TestHTTPServer ( middleware ) ;
32+ await server . start ( ) ;
3233
33- return server
34- . start ( )
35- . then ( ( ) => server . request ( '/' ) )
36- . then ( html => {
37- expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
38- } ) ;
34+ let html = await server . request ( '/' ) ;
35+ expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
3936 } ) ;
4037
41- it ( 'can provide distPath as an option' , function ( ) {
38+ it ( 'can provide distPath as an option' , async function ( ) {
4239 let middleware = fastbootMiddleware ( {
4340 distPath : fixture ( 'basic-app' ) ,
4441 } ) ;
4542 server = new TestHTTPServer ( middleware ) ;
43+ await server . start ( ) ;
4644
47- return server
48- . start ( )
49- . then ( ( ) => server . request ( '/' ) )
50- . then ( html => {
51- expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
52- } ) ;
45+ let html = await server . request ( '/' ) ;
46+ expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
5347 } ) ;
5448
55- it ( 'can be provided with a custom FastBoot instance' , function ( ) {
49+ it ( 'can be provided with a custom FastBoot instance' , async function ( ) {
5650 let fastboot = new FastBoot ( {
5751 distPath : fixture ( 'basic-app' ) ,
5852 } ) ;
@@ -62,16 +56,13 @@ describe('FastBoot', function() {
6256 } ) ;
6357
6458 server = new TestHTTPServer ( middleware ) ;
59+ await server . start ( ) ;
6560
66- return server
67- . start ( )
68- . then ( ( ) => server . request ( '/' ) )
69- . then ( html => {
70- expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
71- } ) ;
61+ let html = await server . request ( '/' ) ;
62+ expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
7263 } ) ;
7364
74- it ( 'can reload the FastBoot instance' , function ( ) {
65+ it ( 'can reload the FastBoot instance' , async function ( ) {
7566 let fastboot = new FastBoot ( {
7667 distPath : fixture ( 'basic-app' ) ,
7768 } ) ;
@@ -81,190 +72,169 @@ describe('FastBoot', function() {
8172 } ) ;
8273
8374 server = new TestHTTPServer ( middleware ) ;
75+ await server . start ( ) ;
8476
85- return server
86- . start ( )
87- . then ( requestFirstApp )
88- . then ( hotReloadApp )
89- . then ( requestSecondApp ) ;
90-
91- function requestFirstApp ( ) {
92- return server . request ( '/' ) . then ( function ( html ) {
93- expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
94- } ) ;
95- }
77+ let html = await server . request ( '/' ) ;
78+ expect ( html ) . to . match ( / W e l c o m e t o E m b e r / ) ;
9679
97- function hotReloadApp ( ) {
98- fastboot . reload ( {
99- distPath : fixture ( 'hot-swap-app' ) ,
100- } ) ;
101- }
80+ fastboot . reload ( {
81+ distPath : fixture ( 'hot-swap-app' ) ,
82+ } ) ;
10283
103- function requestSecondApp ( ) {
104- return server . request ( '/' ) . then ( function ( html ) {
105- expect ( html ) . to . match ( / G o o d b y e f r o m E m b e r / ) ;
106- } ) ;
107- }
84+ html = await server . request ( '/' ) ;
85+ expect ( html ) . to . match ( / G o o d b y e f r o m E m b e r / ) ;
10886 } ) ;
10987
11088 /* eslint-disable mocha/no-setup-in-describe */
11189 [ true , false ] . forEach ( chunkedResponse => {
11290 describe ( `when chunked response is ${ chunkedResponse ? 'enabled' : 'disabled' } ` , function ( ) {
11391 if ( chunkedResponse ) {
114- it ( 'responds with a chunked response' , function ( ) {
92+ it ( 'responds with a chunked response' , async function ( ) {
11593 let middleware = fastbootMiddleware ( {
11694 distPath : fixture ( 'basic-app' ) ,
11795 chunkedResponse,
11896 } ) ;
11997 server = new TestHTTPServer ( middleware , { errorHandling : true } ) ;
98+ await server . start ( ) ;
12099
121- return server
122- . start ( )
123- . then ( ( ) => server . request ( '/' , { resolveWithFullResponse : true } ) )
124- . then ( ( { body, headers } ) => {
125- expect ( headers [ 'transfer-encoding' ] ) . to . eq ( 'chunked' ) ;
126- expect ( body ) . to . match ( / W e l c o m e t o E m b e r / ) ;
127- } ) ;
100+ let { body, headers } = await server . request ( '/' , { resolveWithFullResponse : true } ) ;
101+ expect ( headers [ 'transfer-encoding' ] ) . to . eq ( 'chunked' ) ;
102+ expect ( body ) . to . match ( / W e l c o m e t o E m b e r / ) ;
128103 } ) ;
129104 }
130105
131- it ( "returns 404 when navigating to a URL that doesn't exist" , function ( ) {
106+ it ( "returns 404 when navigating to a URL that doesn't exist" , async function ( ) {
132107 let middleware = fastbootMiddleware ( {
133108 distPath : fixture ( 'basic-app' ) ,
134109 chunkedResponse,
135110 } ) ;
136111 server = new TestHTTPServer ( middleware ) ;
112+ await server . start ( ) ;
137113
138- return server
139- . start ( )
140- . then ( ( ) => server . request ( '/foo-bar-baz/non-existent' ) )
141- . catch ( result => {
142- expect ( result . statusCode ) . to . equal ( 404 ) ;
143- } ) ;
114+ try {
115+ await server . request ( '/foo-bar-baz/non-existent' ) ;
116+ } catch ( error ) {
117+ expect ( error . statusCode ) . to . equal ( 404 ) ;
118+ }
144119 } ) ;
145120
146- it ( 'returns a 500 error if an error occurs' , function ( ) {
121+ it ( 'returns a 500 error if an error occurs' , async function ( ) {
147122 let middleware = fastbootMiddleware ( {
148123 distPath : fixture ( 'rejected-promise' ) ,
149124 chunkedResponse,
150125 } ) ;
151126 server = new TestHTTPServer ( middleware ) ;
127+ await server . start ( ) ;
152128
153- return server
154- . start ( )
155- . then ( ( ) => server . request ( '/' ) )
156- . catch ( err => {
157- expect ( err . message ) . to . match ( / R e j e c t e d o n p u r p o s e / ) ;
158- } ) ;
129+ try {
130+ await server . request ( '/' ) ;
131+ } catch ( error ) {
132+ expect ( error . message ) . to . match ( / R e j e c t e d o n p u r p o s e / ) ;
133+ }
159134 } ) ;
160135
161- describe ( 'when reslient mode is enabled' , function ( ) {
162- it ( 'renders no FastBoot markup' , function ( ) {
136+ describe ( 'when resilient mode is enabled' , function ( ) {
137+ it ( 'renders no FastBoot markup' , async function ( ) {
163138 let middleware = fastbootMiddleware ( {
164139 distPath : fixture ( 'rejected-promise' ) ,
165140 resilient : true ,
166141 chunkedResponse,
167142 } ) ;
168143 server = new TestHTTPServer ( middleware ) ;
144+ await server . start ( ) ;
169145
170- return server
171- . start ( )
172- . then ( ( ) => server . request ( '/' ) )
173- . then ( html => {
174- expect ( html ) . to . not . match ( / e r r o r / ) ;
175- } ) ;
146+ let html = await server . request ( '/' ) ;
147+ expect ( html ) . to . not . match ( / e r r o r / ) ;
176148 } ) ;
177149
178- it ( 'propagates to error handling middleware' , function ( ) {
150+ it ( 'propagates to error handling middleware' , async function ( ) {
179151 let middleware = fastbootMiddleware ( {
180152 distPath : fixture ( 'rejected-promise' ) ,
181153 resilient : true ,
182154 chunkedResponse,
183155 } ) ;
184156 server = new TestHTTPServer ( middleware , { errorHandling : true } ) ;
157+ await server . start ( ) ;
185158
186- return server
187- . start ( )
188- . then ( ( ) => server . request ( '/' , { resolveWithFullResponse : true } ) )
189- . then ( ( { body, statusCode, headers } ) => {
190- expect ( statusCode ) . to . equal ( 200 ) ;
191- expect ( headers [ 'x-test-error' ] ) . to . match ( / e r r o r h a n d l e r c a l l e d / ) ;
192- expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
193- } ) ;
159+ let { body, statusCode, headers } = await server . request ( '/' , {
160+ resolveWithFullResponse : true ,
161+ } ) ;
162+ expect ( statusCode ) . to . equal ( 200 ) ;
163+ expect ( headers [ 'x-test-error' ] ) . to . match ( / e r r o r h a n d l e r c a l l e d / ) ;
164+ expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
194165 } ) ;
195166
196- it ( 'is does not propagate errors when and there is no error handling middleware' , function ( ) {
167+ it ( 'is does not propagate errors when and there is no error handling middleware' , async function ( ) {
197168 let middleware = fastbootMiddleware ( {
198169 distPath : fixture ( 'rejected-promise' ) ,
199170 resilient : true ,
200171 chunkedResponse,
201172 } ) ;
202173 server = new TestHTTPServer ( middleware , { errorHandling : false } ) ;
174+ await server . start ( ) ;
203175
204- return server
205- . start ( )
206- . then ( ( ) => server . request ( '/' , { resolveWithFullResponse : true } ) )
207- . then ( ( { body, statusCode, headers } ) => {
208- expect ( statusCode ) . to . equal ( 200 ) ;
209- expect ( headers [ 'x-test-error' ] ) . to . not . match ( / e r r o r h a n d l e r c a l l e d / ) ;
210- expect ( body ) . to . not . match ( / e r r o r / ) ;
211- expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
212- } ) ;
176+ let { body, statusCode, headers } = await server . request ( '/' , {
177+ resolveWithFullResponse : true ,
178+ } ) ;
179+ expect ( statusCode ) . to . equal ( 200 ) ;
180+ expect ( headers [ 'x-test-error' ] ) . to . not . match ( / e r r o r h a n d l e r c a l l e d / ) ;
181+ expect ( body ) . to . not . match ( / e r r o r / ) ;
182+ expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
213183 } ) ;
214184
215- it ( 'allows post-fastboot middleware to recover the response when it fails' , function ( ) {
185+ it ( 'allows post-fastboot middleware to recover the response when it fails' , async function ( ) {
216186 let middleware = fastbootMiddleware ( {
217187 distPath : fixture ( 'rejected-promise' ) ,
218188 resilient : true ,
219189 chunkedResponse,
220190 } ) ;
221191 server = new TestHTTPServer ( middleware , { recoverErrors : true } ) ;
192+ await server . start ( ) ;
222193
223- return server
224- . start ( )
225- . then ( ( ) => server . request ( '/' , { resolveWithFullResponse : true } ) )
226- . then ( ( { body, statusCode, headers } ) => {
227- expect ( statusCode ) . to . equal ( 200 ) ;
228- expect ( headers [ 'x-test-recovery' ] ) . to . match ( / r e c o v e r e d r e s p o n s e / ) ;
229- expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
230- } ) ;
194+ let { body, statusCode, headers } = await server . request ( '/' , {
195+ resolveWithFullResponse : true ,
196+ } ) ;
197+ expect ( statusCode ) . to . equal ( 200 ) ;
198+ expect ( headers [ 'x-test-recovery' ] ) . to . match ( / r e c o v e r e d r e s p o n s e / ) ;
199+ expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
231200 } ) ;
232201 } ) ;
233202
234- describe ( 'when reslient mode is disabled' , function ( ) {
235- it ( 'propagates to error handling middleware' , function ( ) {
203+ describe ( 'when resilient mode is disabled' , function ( ) {
204+ it ( 'propagates to error handling middleware' , async function ( ) {
236205 let middleware = fastbootMiddleware ( {
237206 distPath : fixture ( 'rejected-promise' ) ,
238207 resilient : false ,
239208 chunkedResponse,
240209 } ) ;
241210 server = new TestHTTPServer ( middleware , { errorHandling : true } ) ;
211+ await server . start ( ) ;
242212
243- return server
244- . start ( )
245- . then ( ( ) => server . request ( '/' , { resolveWithFullResponse : true } ) )
246- . catch ( ( { statusCode, response : { headers } } ) => {
247- expect ( statusCode ) . to . equal ( 500 ) ;
248- expect ( headers [ 'x-test-error' ] ) . to . match ( / e r r o r h a n d l e r c a l l e d / ) ;
213+ try {
214+ await server . request ( '/' , {
215+ resolveWithFullResponse : true ,
249216 } ) ;
217+ } catch ( { statusCode, response : { headers } } ) {
218+ expect ( statusCode ) . to . equal ( 500 ) ;
219+ expect ( headers [ 'x-test-error' ] ) . to . match ( / e r r o r h a n d l e r c a l l e d / ) ;
220+ }
250221 } ) ;
251222
252- it ( 'allows post-fastboot middleware to recover the response when it fails' , function ( ) {
223+ it ( 'allows post-fastboot middleware to recover the response when it fails' , async function ( ) {
253224 let middleware = fastbootMiddleware ( {
254225 distPath : fixture ( 'rejected-promise' ) ,
255226 resilient : false ,
256227 chunkedResponse,
257228 } ) ;
258229 server = new TestHTTPServer ( middleware , { recoverErrors : true } ) ;
230+ await server . start ( ) ;
259231
260- return server
261- . start ( )
262- . then ( ( ) => server . request ( '/' , { resolveWithFullResponse : true } ) )
263- . then ( ( { body, statusCode, headers } ) => {
264- expect ( statusCode ) . to . equal ( 200 ) ;
265- expect ( headers [ 'x-test-recovery' ] ) . to . match ( / r e c o v e r e d r e s p o n s e / ) ;
266- expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
267- } ) ;
232+ let { body, statusCode, headers } = await server . request ( '/' , {
233+ resolveWithFullResponse : true ,
234+ } ) ;
235+ expect ( statusCode ) . to . equal ( 200 ) ;
236+ expect ( headers [ 'x-test-recovery' ] ) . to . match ( / r e c o v e r e d r e s p o n s e / ) ;
237+ expect ( body ) . to . match ( / h e l l o w o r l d / ) ;
268238 } ) ;
269239 } ) ;
270240 } ) ;
0 commit comments