Skip to content

Commit

Permalink
fix decorator render methods for nunjucks and marko (#177)
Browse files Browse the repository at this point in the history
-added tests
  • Loading branch information
KidsDontPlay committed Sep 9, 2020
1 parent 45a07b6 commit c8fa75b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ function fastifyView (fastify, opts, next) {
if (options.useHtmlMinifier && (typeof options.useHtmlMinifier.minify === 'function')) {
html = options.useHtmlMinifier.minify(html, options.htmlMinifierOptions || {})
}
this.header('Content-Type', 'text/html; charset=' + charset).send(html)
this.header('Content-Type', 'text/html; charset=' + charset)
this.send(html)
})
}

Expand Down Expand Up @@ -358,7 +359,8 @@ function fastifyView (fastify, opts, next) {
if (options.useHtmlMinifier && (typeof options.useHtmlMinifier.minify === 'function')) {
html = options.useHtmlMinifier.minify(html, options.htmlMinifierOptions || {})
}
that.header('Content-Type', 'text/html; charset=' + charset).send(html)
that.header('Content-Type', 'text/html; charset=' + charset)
that.send(html)
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/test-marko.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,35 @@ test('reply.view with marko engine, with stream and html-minify-stream', t => {
})
})
})

test('fastify.view with marko engine', t => {
t.plan(6)
const fastify = Fastify()
const marko = require('marko')
const data = { text: 'text' }

fastify.register(require('../index'), {
engine: {
marko: marko
}
})

fastify.ready(err => {
t.error(err)

fastify.view('templates/index.marko', data, (err, compiled) => {
t.error(err)
t.strictEqual(marko.load('./templates/index.marko').renderToString(data), compiled)

fastify.ready(err => {
t.error(err)

fastify.view('templates/index.marko', data, (err, compiled) => {
t.error(err)
t.strictEqual(marko.load('./templates/index.marko').renderToString(data), compiled)
fastify.close()
})
})
})
})
})
32 changes: 32 additions & 0 deletions test/test-nunjucks.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,35 @@ test('reply.view with nunjucks engine using onConfigure callback', t => {
})
})
})

test('fastify.view with nunjucks engine', t => {
t.plan(6)
const fastify = Fastify()
const nunjucks = require('nunjucks')
const data = { text: 'text' }

fastify.register(require('../index'), {
engine: {
nunjucks: nunjucks
}
})

fastify.ready(err => {
t.error(err)

fastify.view('templates/index.njk', data, (err, compiled) => {
t.error(err)
t.strictEqual(nunjucks.render('./templates/index.njk', data), compiled)

fastify.ready(err => {
t.error(err)

fastify.view('templates/index.njk', data, (err, compiled) => {
t.error(err)
t.strictEqual(nunjucks.render('./templates/index.njk', data), compiled)
fastify.close()
})
})
})
})
})

0 comments on commit c8fa75b

Please sign in to comment.