11
2+ var assert = require ( 'assert' ) ;
23var http = require ( 'http' ) ;
34var path = require ( 'path' ) ;
45var request = require ( 'supertest' ) ;
@@ -17,11 +18,11 @@ describe('serveStatic()', function(){
1718 } ) ;
1819
1920 it ( 'should require root path' , function ( ) {
20- serveStatic . bind ( ) . should . throw ( / r o o t p a t h r e q u i r e d / ) ;
21+ assert . throws ( serveStatic . bind ( ) , / r o o t p a t h r e q u i r e d / ) ;
2122 } ) ;
2223
2324 it ( 'should require root path to be string' , function ( ) {
24- serveStatic . bind ( null , 42 ) . should . throw ( / r o o t p a t h .* s t r i n g / ) ;
25+ assert . throws ( serveStatic . bind ( null , 42 ) , / r o o t p a t h .* s t r i n g / ) ;
2526 } ) ;
2627
2728 it ( 'should serve static files' , function ( done ) {
@@ -195,23 +196,17 @@ describe('serveStatic()', function(){
195196 it ( 'should not include Last-Modifed' , function ( done ) {
196197 request ( createServer ( fixtures , { 'lastModified' : false } ) )
197198 . get ( '/nums' )
198- . expect ( 200 , '123456789' , function ( err , res ) {
199- if ( err ) return done ( err )
200- res . headers . should . not . have . property ( 'last-modified' )
201- done ( )
202- } )
199+ . expect ( shouldNotHaveHeader ( 'Last-Modified' ) )
200+ . expect ( 200 , '123456789' , done )
203201 } )
204202 } )
205203
206204 describe ( 'when true' , function ( ) {
207205 it ( 'should include Last-Modifed' , function ( done ) {
208206 request ( createServer ( fixtures , { 'lastModified' : true } ) )
209207 . get ( '/nums' )
210- . expect ( 200 , '123456789' , function ( err , res ) {
211- if ( err ) return done ( err )
212- res . headers . should . have . property ( 'last-modified' )
213- done ( )
214- } )
208+ . expect ( 'Last-Modified' , / ^ \w { 3 } , \d + \w + \d + \d + : \d + : \d + \w + $ / )
209+ . expect ( 200 , '123456789' , done )
215210 } )
216211 } )
217212 } )
@@ -288,7 +283,7 @@ describe('serveStatic()', function(){
288283
289284 describe ( 'setHeaders' , function ( ) {
290285 it ( 'should reject non-functions' , function ( ) {
291- serveStatic . bind ( null , fixtures , { 'setHeaders' : 3 } ) . should . throw ( / s e t H e a d e r s .* f u n c t i o n / )
286+ assert . throws ( serveStatic . bind ( null , fixtures , { 'setHeaders' : 3 } ) , / s e t H e a d e r s .* f u n c t i o n / )
292287 } )
293288
294289 it ( 'should get called when sending file' , function ( done ) {
@@ -309,11 +304,8 @@ describe('serveStatic()', function(){
309304
310305 request ( server )
311306 . get ( '/bogus' )
312- . expect ( 404 , function ( err , res ) {
313- if ( err ) return done ( err )
314- res . headers . should . not . have . property ( 'x-custom' )
315- done ( )
316- } )
307+ . expect ( shouldNotHaveHeader ( 'x-custom' ) )
308+ . expect ( 404 , done )
317309 } )
318310
319311 it ( 'should not get called on redirect' , function ( done ) {
@@ -323,11 +315,8 @@ describe('serveStatic()', function(){
323315
324316 request ( server )
325317 . get ( '/users' )
326- . expect ( 303 , function ( err , res ) {
327- if ( err ) return done ( err )
328- res . headers . should . not . have . property ( 'x-custom' )
329- done ( )
330- } )
318+ . expect ( shouldNotHaveHeader ( 'x-custom' ) )
319+ . expect ( 303 , done )
331320 } )
332321 } )
333322
@@ -618,3 +607,9 @@ function createServer(dir, opts, fn) {
618607 } ) ;
619608 } ) ;
620609}
610+
611+ function shouldNotHaveHeader ( header ) {
612+ return function ( res ) {
613+ assert . ok ( ! ( header . toLowerCase ( ) in res . headers ) , 'should not have header ' + header )
614+ }
615+ }
0 commit comments