UNPKG

2.12 kBJavaScriptView Raw
1'use strict'
2
3const t = require('tap')
4const test = t.test
5const Fastify = require('..')
6
7test('pretty print - static routes', t => {
8 t.plan(2)
9
10 const fastify = Fastify()
11 fastify.get('/test', () => {})
12 fastify.get('/test/hello', () => {})
13 fastify.get('/hello/world', () => {})
14
15 fastify.ready(() => {
16 const tree = fastify.printRoutes()
17
18 const expected = `└── /
19 ├── test (GET)
20 │ └── /hello (GET)
21 └── hello/world (GET)
22`
23
24 t.is(typeof tree, 'string')
25 t.equal(tree, expected)
26 })
27})
28
29test('pretty print - parametric routes', t => {
30 t.plan(2)
31
32 const fastify = Fastify()
33 fastify.get('/test', () => {})
34 fastify.get('/test/:hello', () => {})
35 fastify.get('/hello/:world', () => {})
36
37 fastify.ready(() => {
38 const tree = fastify.printRoutes()
39
40 const expected = `└── /
41 ├── test (GET)
42 │ └── /
43 │ └── :hello (GET)
44 └── hello/
45 └── :world (GET)
46`
47
48 t.is(typeof tree, 'string')
49 t.equal(tree, expected)
50 })
51})
52
53test('pretty print - mixed parametric routes', t => {
54 t.plan(2)
55
56 const fastify = Fastify()
57 fastify.get('/test', () => {})
58 fastify.get('/test/:hello', () => {})
59 fastify.post('/test/:hello', () => {})
60 fastify.get('/test/:hello/world', () => {})
61
62 fastify.ready(() => {
63 const tree = fastify.printRoutes()
64
65 const expected = `└── /
66 └── test (GET)
67 └── /
68 └── :hello (GET)
69 :hello (POST)
70 └── /world (GET)
71`
72
73 t.is(typeof tree, 'string')
74 t.equal(tree, expected)
75 })
76})
77
78test('pretty print - wildcard routes', t => {
79 t.plan(2)
80
81 const fastify = Fastify()
82 fastify.get('/test', () => {})
83 fastify.get('/test/*', () => {})
84 fastify.get('/hello/*', () => {})
85
86 fastify.ready(() => {
87 const tree = fastify.printRoutes()
88
89 const expected = `└── /
90 ├── test (GET)
91 │ └── /
92 │ └── * (GET)
93 └── hello/
94 └── * (GET)
95`
96
97 t.is(typeof tree, 'string')
98 t.equal(tree, expected)
99 })
100})