@@ -13,13 +13,17 @@ describe('staticTheme', function () {
13
13
14
14
beforeEach ( function ( ) {
15
15
req = { } ;
16
- res = { } ;
16
+ res = {
17
+ setHeader : sinon . stub ( )
18
+ } ;
17
19
18
20
activeThemeStub = sinon . stub ( themeEngine , 'getActive' ) . returns ( {
19
21
path : 'my/fake/path'
20
22
} ) ;
21
23
22
- expressStaticStub = sinon . spy ( express , 'static' ) ;
24
+ expressStaticStub = sinon . stub ( express , 'static' ) . returns ( function ( _req , _res , _next ) {
25
+ _next ( ) ;
26
+ } ) ;
23
27
} ) ;
24
28
25
29
afterEach ( function ( ) {
@@ -225,4 +229,101 @@ describe('staticTheme', function () {
225
229
done ( ) ;
226
230
} ) ;
227
231
} ) ;
232
+
233
+ describe ( 'paths without file extensions' , function ( ) {
234
+ it ( 'should skip for root path /' , function ( done ) {
235
+ req . path = '/' ;
236
+
237
+ staticTheme ( ) ( req , res , function next ( ) {
238
+ activeThemeStub . called . should . be . false ( ) ;
239
+ expressStaticStub . called . should . be . false ( ) ;
240
+
241
+ done ( ) ;
242
+ } ) ;
243
+ } ) ;
244
+
245
+ it ( 'should skip for /about/' , function ( done ) {
246
+ req . path = '/about/' ;
247
+
248
+ staticTheme ( ) ( req , res , function next ( ) {
249
+ activeThemeStub . called . should . be . false ( ) ;
250
+ expressStaticStub . called . should . be . false ( ) ;
251
+
252
+ done ( ) ;
253
+ } ) ;
254
+ } ) ;
255
+
256
+ it ( 'should skip for /blog/my-post/' , function ( done ) {
257
+ req . path = '/blog/my-post/' ;
258
+
259
+ staticTheme ( ) ( req , res , function next ( ) {
260
+ activeThemeStub . called . should . be . false ( ) ;
261
+ expressStaticStub . called . should . be . false ( ) ;
262
+
263
+ done ( ) ;
264
+ } ) ;
265
+ } ) ;
266
+
267
+ it ( 'should skip for path without trailing slash /contact' , function ( done ) {
268
+ req . path = '/contact' ;
269
+
270
+ staticTheme ( ) ( req , res , function next ( ) {
271
+ activeThemeStub . called . should . be . false ( ) ;
272
+ expressStaticStub . called . should . be . false ( ) ;
273
+
274
+ done ( ) ;
275
+ } ) ;
276
+ } ) ;
277
+
278
+ it ( 'should NOT skip for file with extension without trailing slash' , function ( done ) {
279
+ req . path = '/somefile.txt' ;
280
+
281
+ staticTheme ( ) ( req , res , function next ( ) {
282
+ // Specifically gets called twice
283
+ activeThemeStub . calledTwice . should . be . true ( ) ;
284
+ expressStaticStub . called . should . be . true ( ) ;
285
+
286
+ // Check that express static gets called with the theme path + maxAge
287
+ should . exist ( expressStaticStub . firstCall . args ) ;
288
+ expressStaticStub . firstCall . args [ 0 ] . should . eql ( 'my/fake/path' ) ;
289
+ expressStaticStub . firstCall . args [ 1 ] . should . be . an . Object ( ) . with . property ( 'maxAge' ) ;
290
+
291
+ done ( ) ;
292
+ } ) ;
293
+ } ) ;
294
+
295
+ it ( 'should NOT skip for file with extension with trailing slash' , function ( done ) {
296
+ req . path = '/somefile.txt/' ;
297
+
298
+ staticTheme ( ) ( req , res , function next ( ) {
299
+ // Specifically gets called twice
300
+ activeThemeStub . calledTwice . should . be . true ( ) ;
301
+ expressStaticStub . called . should . be . true ( ) ;
302
+
303
+ // Check that express static gets called with the theme path + maxAge
304
+ should . exist ( expressStaticStub . firstCall . args ) ;
305
+ expressStaticStub . firstCall . args [ 0 ] . should . eql ( 'my/fake/path' ) ;
306
+ expressStaticStub . firstCall . args [ 1 ] . should . be . an . Object ( ) . with . property ( 'maxAge' ) ;
307
+
308
+ done ( ) ;
309
+ } ) ;
310
+ } ) ;
311
+
312
+ it ( 'should NOT skip for deeply nested file with extension' , function ( done ) {
313
+ req . path = '/deep/nested/path/file.css' ;
314
+
315
+ staticTheme ( ) ( req , res , function next ( ) {
316
+ // Specifically gets called twice
317
+ activeThemeStub . calledTwice . should . be . true ( ) ;
318
+ expressStaticStub . called . should . be . true ( ) ;
319
+
320
+ // Check that express static gets called with the theme path + maxAge
321
+ should . exist ( expressStaticStub . firstCall . args ) ;
322
+ expressStaticStub . firstCall . args [ 0 ] . should . eql ( 'my/fake/path' ) ;
323
+ expressStaticStub . firstCall . args [ 1 ] . should . be . an . Object ( ) . with . property ( 'maxAge' ) ;
324
+
325
+ done ( ) ;
326
+ } ) ;
327
+ } ) ;
328
+ } ) ;
228
329
} ) ;
0 commit comments