UNPKG

833 BJavaScriptView Raw
1'use strict'
2
3const t = require('tap')
4const test = t.test
5const Fastify = require('../..')
6const h2url = require('h2url')
7const msg = { hello: 'world' }
8
9var fastify
10try {
11 fastify = Fastify({
12 http2: true
13 })
14 t.pass('http2 successfully loaded')
15} catch (e) {
16 t.fail('http2 loading failed', e)
17}
18
19fastify.get('/', function (req, reply) {
20 reply.code(200).send(msg)
21})
22
23fastify.listen(0, err => {
24 t.error(err)
25 fastify.server.unref()
26
27 test('http UNKNOWN_METHOD request', async (t) => {
28 t.plan(2)
29
30 const url = `http://localhost:${fastify.server.address().port}`
31 const res = await h2url.concat({ url, method: 'UNKNOWN_METHOD' })
32
33 t.strictEqual(res.headers[':status'], 404)
34 t.deepEqual(JSON.parse(res.body), {
35 statusCode: 404,
36 error: 'Not Found',
37 message: 'Not Found'
38 })
39 })
40})