Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
fastify
GitHub Repository: fastify/point-of-view
Path: blob/main/test/import-engine.test.mjs
107 views
1
import Fastify from 'fastify'
2
import fs from 'node:fs'
3
import { test } from 'node:test'
4
5
test('using an imported engine as a promise', async t => {
6
t.plan(1)
7
const fastify = Fastify()
8
const data = { text: 'text' }
9
const ejs = import('ejs')
10
11
fastify.register(import('../index.js'), { engine: { ejs }, templates: 'templates' })
12
13
fastify.get('/', (_req, reply) => {
14
reply.view('index.ejs', data)
15
})
16
17
await fastify.listen({ port: 0 })
18
19
const result = await fetch('http://127.0.0.1:' + fastify.server.address().port)
20
21
t.assert.strictEqual((await ejs).render(fs.readFileSync('./templates/index.ejs', 'utf8'), data), await result.text())
22
fastify.close()
23
})
24
25