Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
fastify
GitHub Repository: fastify/point-of-view
Path: blob/main/test/edge.test.js
107 views
1
'use strict'
2
3
const { test } = require('node:test')
4
const Fastify = require('fastify')
5
const { join } = require('node:path')
6
7
require('./helper').liquidHtmlMinifierTests(true)
8
require('./helper').liquidHtmlMinifierTests(false)
9
10
test('reply.view with liquid engine', async t => {
11
t.plan(4)
12
const fastify = Fastify()
13
const { Edge } = require('edge.js')
14
const data = { text: 'text' }
15
16
const engine = new Edge()
17
engine.mount(join(__dirname, '..', 'templates'))
18
19
fastify.register(require('../index'), {
20
engine: {
21
edge: engine
22
}
23
})
24
25
fastify.get('/', (_req, reply) => {
26
reply.view('index.edge', data)
27
})
28
29
await fastify.listen({ port: 0 })
30
31
const result = await fetch('http://127.0.0.1:' + fastify.server.address().port)
32
const responseContent = await result.text()
33
34
t.assert.strictEqual(result.status, 200)
35
t.assert.strictEqual(result.headers.get('content-length'), '' + responseContent.length)
36
t.assert.strictEqual(result.headers.get('content-type'), 'text/html; charset=utf-8')
37
38
const html = await engine.render('index.edge', data)
39
t.assert.strictEqual(html, responseContent)
40
41
await fastify.close()
42
})
43
44