@@ -200,51 +200,15 @@ t.test('dir list, custom options with empty array index', t => {
200200} )
201201
202202t . test ( 'dir list html format' , t => {
203- t . plan ( 6 )
204-
205- // render html in 2 ways: one with handlebars and one with template string
206-
207- const Handlebars = require ( 'handlebars' )
208- const source = `
209- <html><body>
210- <ul>
211- {{#dirs}}
212- <li><a href="{{href}}">{{name}}</a></li>
213- {{/dirs}}
214- </ul>
215- <ul>
216- {{#files}}
217- <li><a href="{{href}}" target="_blank">{{name}}</a></li>
218- {{/files}}
219- </ul>
220- </body></html>
221- `
222- const handlebarTemplate = Handlebars . compile ( source )
223- const templates = [
224- {
225- render : ( dirs , files ) => {
226- return handlebarTemplate ( { dirs, files } )
227- } ,
228- output : `
229- <html><body>
230- <ul>
231- <li><a href="/public/deep">deep</a></li>
232- <li><a href="/public/shallow">shallow</a></li>
233- </ul>
234- <ul>
235- <li><a href="/public/.example" target="_blank">.example</a></li>
236- <li><a href="/public/100%25.txt" target="_blank">100%.txt</a></li>
237- <li><a href="/public/a%20.md" target="_blank">a .md</a></li>
238- <li><a href="/public/foo.html" target="_blank">foo.html</a></li>
239- <li><a href="/public/foobar.html" target="_blank">foobar.html</a></li>
240- <li><a href="/public/index.css" target="_blank">index.css</a></li>
241- <li><a href="/public/index.html" target="_blank">index.html</a></li>
242- </ul>
243- </body></html>
244- `
245- } ,
203+ t . plan ( 3 )
246204
247- {
205+ const options = {
206+ root : path . join ( __dirname , '/static' ) ,
207+ prefix : '/public' ,
208+ index : false ,
209+ list : {
210+ format : 'html' ,
211+ names : [ 'index' , 'index.htm' ] ,
248212 render : ( dirs , files ) => {
249213 return `
250214<html><body>
@@ -256,8 +220,24 @@ t.test('dir list html format', t => {
256220</ul>
257221</body></html>
258222`
259- } ,
260- output : `
223+ }
224+ }
225+ }
226+ const routes = [ '/public/index.htm' , '/public/index' ]
227+
228+ // check all routes by names
229+
230+ helper . arrange ( t , options , ( url ) => {
231+ for ( const route of routes ) {
232+ t . test ( route , t => {
233+ t . plan ( 3 )
234+ simple . concat ( {
235+ method : 'GET' ,
236+ url : url + route
237+ } , ( err , response , body ) => {
238+ t . error ( err )
239+ t . equal ( response . statusCode , 200 )
240+ t . equal ( body . toString ( ) , `
261241<html><body>
262242<ul>
263243 <li><a href="/public/deep">deep</a></li>
@@ -273,42 +253,11 @@ t.test('dir list html format', t => {
273253 <li><a href="/public/index.html" target="_blank">index.html</a></li>
274254</ul>
275255</body></html>
276- `
277- }
278-
279- ]
280-
281- for ( const template of templates ) {
282- const options = {
283- root : path . join ( __dirname , '/static' ) ,
284- prefix : '/public' ,
285- index : false ,
286- list : {
287- format : 'html' ,
288- names : [ 'index' , 'index.htm' ] ,
289- render : template . render
290- }
291- }
292- const routes = [ '/public/index.htm' , '/public/index' ]
293-
294- // check all routes by names
295-
296- helper . arrange ( t , options , ( url ) => {
297- for ( const route of routes ) {
298- t . test ( route , t => {
299- t . plan ( 3 )
300- simple . concat ( {
301- method : 'GET' ,
302- url : url + route
303- } , ( err , response , body ) => {
304- t . error ( err )
305- t . equal ( response . statusCode , 200 )
306- t . equal ( body . toString ( ) , template . output )
307- } )
256+ ` )
308257 } )
309- }
310- } )
311- }
258+ } )
259+ }
260+ } )
312261} )
313262
314263t . test ( 'dir list href nested structure' , t => {
0 commit comments