@@ -256,155 +256,6 @@ describe("Application", function () {
256256 } ) ;
257257 } ) ;
258258
259- describe ( "logging" , function ( ) {
260- let loggingDir , messages , writable ;
261-
262- beforeEach ( function ( ) {
263- loggingDir = path . resolve ( __dirname , "fixtures/custom-logs" ) ;
264- messages = [ ] ;
265- stream . write = message => {
266- messages . push ( JSON . parse ( message ) ) ;
267- } ;
268- } ) ;
269-
270- afterEach ( function ( ) {
271- return del ( [ `${ loggingDir } /**/*.log` , `!${ loggingDir } ` ] ) ;
272- } ) ;
273-
274- it ( "allows for a custom directory" , function ( done ) {
275- application = new Application ( {
276- controllers : {
277- dir : path . resolve ( __dirname , "fixtures" , "controllers" )
278- } ,
279- database : {
280- connection,
281- models : { dir : path . resolve ( __dirname , "fixtures/models" ) }
282- } ,
283- logging : {
284- dir : loggingDir
285- } ,
286- serializers : {
287- dir : path . resolve ( __dirname , "fixtures" , "serializers" )
288- }
289- } ) ;
290-
291- application . map ( function ( ) {
292- this . resource ( "user" ) ;
293- } ) ;
294-
295- supertest ( application . getApp ( ) )
296- . get ( "/users" )
297- . end ( function ( err , res ) {
298- if ( err ) { return done ( err ) ; }
299-
300- fs . readdir ( loggingDir , ( err2 , files ) => {
301- if ( err2 ) { return done ( err2 ) ; }
302-
303- const file = files . filter ( f => f . match ( / \. l o g / ) ) ;
304- let log ;
305-
306- expect ( file ) . to . be . ok ;
307- expect ( file ) . to . have . length . gt ( 0 ) ;
308-
309- const fileData = fs . readFileSync ( path . resolve ( loggingDir , file [ 0 ] ) ) ;
310- const lines = fileData
311- . toString ( )
312- . split ( "\n" )
313- . filter ( line => line . length ) ;
314- const line = lines [ lines . length - 1 ] ;
315-
316- try {
317- log = JSON . parse ( line ) ;
318- } catch ( err3 ) {
319- throw err3 ;
320- }
321-
322- expect ( log . res . statusCode ) . to . eql ( 200 ) ;
323-
324- done ( ) ;
325- } ) ;
326- } ) ;
327- } ) ;
328-
329- it ( "allows for custom request serializer" , function ( done ) {
330- application = new Application ( {
331- controllers : {
332- dir : path . resolve ( __dirname , "fixtures" , "controllers" )
333- } ,
334- database : {
335- connection,
336- models : { dir : path . resolve ( __dirname , "fixtures/models" ) }
337- } ,
338- logging : {
339- serializers : {
340- req ( req ) {
341- return { url : req . url } ;
342- }
343- }
344- } ,
345- serializers : {
346- dir : path . resolve ( __dirname , "fixtures" , "serializers" )
347- }
348- } ) ;
349-
350- application . logger . addStream ( {
351- type : "stream" ,
352- stream
353- } ) ;
354- application . map ( function ( ) {
355- this . resource ( "user" ) ;
356- } ) ;
357- supertest ( application . getApp ( ) )
358- . get ( "/users" )
359- . end ( function ( err , res ) {
360- if ( err ) { return done ( err ) ; }
361-
362- expect ( messages [ 0 ] . req . url ) . to . eql ( "/users" ) ;
363- expect ( messages [ 0 ] . req ) . to . not . have . any . keys ( "httpVersion" , "method" ) ;
364- done ( ) ;
365- } ) ;
366- } ) ;
367-
368- it ( "allows for custom response serializer" , function ( done ) {
369- application = new Application ( {
370- controllers : {
371- dir : path . resolve ( __dirname , "fixtures" , "controllers" )
372- } ,
373- database : {
374- connection,
375- models : { dir : path . resolve ( __dirname , "fixtures/models" ) }
376- } ,
377- logging : {
378- serializers : {
379- res ( res ) {
380- return { statusCode : res . statusCode } ;
381- }
382- }
383- } ,
384- serializers : {
385- dir : path . resolve ( __dirname , "fixtures" , "serializers" )
386- }
387- } ) ;
388-
389- application . logger . addStream ( {
390- type : "stream" ,
391- stream
392- } ) ;
393- application . map ( function ( ) {
394- this . resource ( "user" ) ;
395- } ) ;
396- supertest ( application . getApp ( ) )
397- . get ( "/users" )
398- . end ( function ( err , res ) {
399- if ( err ) { return done ( err ) ; }
400-
401- expect ( messages [ 0 ] . res . statusCode ) . to . eql ( 200 ) ;
402- expect ( messages [ 0 ] . req ) . to . not . have . any . keys ( "headers" ) ;
403- done ( ) ;
404- } ) ;
405- } ) ;
406- } ) ;
407-
408259 describe ( "serializers" , function ( ) {
409260 it ( "uses JSONSerializer by default" , function ( ) {
410261 application = new Application ( {
0 commit comments