Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove duplicate hbs tests #415

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 0 additions & 133 deletions test/test-handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,139 +475,6 @@ test('reply.view with handlebars engine and defaultContext', t => {
})
})

test('reply.view with ejs engine and includeViewExtension property as true', t => {
t.plan(6)
const fastify = Fastify()
const ejs = require('ejs')
const data = { text: 'text' }

fastify.register(require('../index'), {
engine: {
ejs
},
includeViewExtension: true
})

fastify.get('/', (req, reply) => {
reply.view('./templates/index', data)
})

fastify.listen({ port: 0 }, err => {
t.error(err)

sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.equal(response.headers['content-length'], '' + body.length)
t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(ejs.render(fs.readFileSync('./templates/index.ejs', 'utf8'), data), body.toString())
fastify.close()
})
})
})

test('reply.view with ejs engine, template folder specified, include files (ejs and html) used in template, includeViewExtension property as true', t => {
t.plan(7)
const fastify = Fastify()
const ejs = require('ejs')
const resolve = require('node:path').resolve
const templatesFolder = 'templates'
const options = {
filename: resolve(templatesFolder), // needed for include files to be resolved in include directive ...
views: [__dirname] // must be put to make tests (with include files) working ...
}
const data = { text: 'text' }

fastify.register(require('../index'), {
engine: {
ejs
},
includeViewExtension: true,
templates: templatesFolder,
options
})

fastify.get('/', (req, reply) => {
reply.type('text/html; charset=utf-8').view('index-linking-other-pages', data) // sample for specifying with type
// reply.view('index-with-includes', data)
})

fastify.listen({ port: 0 }, err => {
t.error(err)

sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(response.headers['content-length'], '' + body.length)

let content = null
ejs.renderFile(templatesFolder + '/index-linking-other-pages.ejs', data, options, function (err, str) {
content = str
t.error(err)
t.equal(content.length, body.length)
})

fastify.close()
})
})
})

test('reply.view with ejs engine, templates with folder specified, include files and attributes; home', t => {
t.plan(7)
const fastify = Fastify()
const ejs = require('ejs')
const resolve = require('node:path').resolve
const templatesFolder = 'templates'
const options = {
filename: resolve(templatesFolder),
views: [__dirname]
}
const data = { text: 'Hello from EJS Templates' }

fastify.register(require('../index'), {
engine: {
ejs
},
includeViewExtension: true,
templates: templatesFolder,
options
})

fastify.get('/', (req, reply) => {
reply.type('text/html; charset=utf-8').view('index', data)
})

fastify.listen({ port: 0 }, err => {
t.error(err)

sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(response.headers['content-length'], '' + body.length)

let content = null
ejs.renderFile(templatesFolder + '/index.ejs', data, options, function (err, str) {
content = str
t.error(err)
t.equal(content.length, body.length)
})

fastify.close()
})
})
})

test('reply.view with handlebars engine and includeViewExtension property as true', t => {
t.plan(6)
const fastify = Fastify()
Expand Down