From 39e89ea4852a9de5258d14930b4e2ac06d4b91d1 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Thu, 22 Aug 2024 12:20:59 +0200 Subject: [PATCH] chore: remove handlebars (#464) Signed-off-by: Aras Abbasi --- example/server-dir-list.js | 35 ++++-------- package.json | 1 - test/dir-list.test.js | 111 ++++++++++--------------------------- 3 files changed, 42 insertions(+), 105 deletions(-) diff --git a/example/server-dir-list.js b/example/server-dir-list.js index 6dd92936..39cca982 100644 --- a/example/server-dir-list.js +++ b/example/server-dir-list.js @@ -1,32 +1,21 @@ 'use strict' const path = require('node:path') -const Handlebars = require('handlebars') const fastify = require('fastify')({ logger: { level: 'trace' } }) -// Handlebar template for listing files and directories. -const template = ` - - - dirs - - - list - - - - +const renderer = (dirs, files) => { + return ` + + + + ` -const handlebarTemplate = Handlebars.compile(template) +} fastify .register(require('..'), { @@ -41,7 +30,7 @@ fastify // A list of filenames that trigger a directory list response. names: ['index', 'index.html', 'index.htm', '/'], // You can provide your own render method as needed. - render: (dirs, files) => handlebarTemplate({ dirs, files }) + renderer } }) .listen({ port: 3000 }, err => { diff --git a/package.json b/package.json index c169c6ca..8b98a99d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "concat-stream": "^2.0.0", "eslint": "^9.9.0", "fastify": "^5.0.0-alpha.3", - "handlebars": "^4.7.8", "neostandard": "^0.11.3", "pino": "^9.1.0", "proxyquire": "^2.1.3", diff --git a/test/dir-list.test.js b/test/dir-list.test.js index 1a6449fa..74aacea3 100644 --- a/test/dir-list.test.js +++ b/test/dir-list.test.js @@ -200,51 +200,15 @@ t.test('dir list, custom options with empty array index', t => { }) t.test('dir list html format', t => { - t.plan(6) - - // render html in 2 ways: one with handlebars and one with template string - - const Handlebars = require('handlebars') - const source = ` - - - - -` - const handlebarTemplate = Handlebars.compile(source) - const templates = [ - { - render: (dirs, files) => { - return handlebarTemplate({ dirs, files }) - }, - output: ` - - - - -` - }, + t.plan(3) - { + const options = { + root: path.join(__dirname, '/static'), + prefix: '/public', + index: false, + list: { + format: 'html', + names: ['index', 'index.htm'], render: (dirs, files) => { return ` @@ -256,8 +220,24 @@ t.test('dir list html format', t => { ` - }, - output: ` + } + } + } + const routes = ['/public/index.htm', '/public/index'] + + // check all routes by names + + helper.arrange(t, options, (url) => { + for (const route of routes) { + t.test(route, t => { + t.plan(3) + simple.concat({ + method: 'GET', + url: url + route + }, (err, response, body) => { + t.error(err) + t.equal(response.statusCode, 200) + t.equal(body.toString(), ` -` - } - - ] - - for (const template of templates) { - const options = { - root: path.join(__dirname, '/static'), - prefix: '/public', - index: false, - list: { - format: 'html', - names: ['index', 'index.htm'], - render: template.render - } - } - const routes = ['/public/index.htm', '/public/index'] - - // check all routes by names - - helper.arrange(t, options, (url) => { - for (const route of routes) { - t.test(route, t => { - t.plan(3) - simple.concat({ - method: 'GET', - url: url + route - }, (err, response, body) => { - t.error(err) - t.equal(response.statusCode, 200) - t.equal(body.toString(), template.output) - }) +`) }) - } - }) - } + }) + } + }) }) t.test('dir list href nested structure', t => {