Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,10 @@ function fastifyView (fastify, opts, next) {
templates: options.templates ? options.templates : lru
})

const config = Object.assign({ views: templatesDir }, options)
const config = Object.assign({
cache: prod,
views: templatesDir
}, options)

data = Object.assign({}, defaultCtx, this.locals, data)
// Append view extension (Eta will append '.eta' by default,
Expand Down
34 changes: 34 additions & 0 deletions test/test-eta.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,40 @@ test('fastify.view with eta engine and callback in production mode', t => {
})
})

test('fastify.view with eta engine in production mode should use cache', t => {
t.plan(1)

const fastify = Fastify()
const cache = {
cache: {},
get (k) {
if (typeof this.cache[k] !== 'undefined') {
t.pass()
}
return this.cache[k]
},
define (k, v) {
this.cache[k] = v
}
}

fastify.register(pointOfView, {
production: true,
engine: {
eta: eta
},
options: {
templates: cache
}
})

fastify.ready(async () => {
await fastify.view('templates/index.eta', { text: 'test' })
await fastify.view('templates/index.eta', { text: 'test' }) // This should trigger the cache
fastify.close()
})
})

test('fastify.view with eta engine and custom cache', t => {
t.plan(9)
const fastify = Fastify()
Expand Down