Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use internal trees for prettyPrint #4618

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"abstract-logging": "^2.0.1",
"avvio": "^8.2.0",
"fast-content-type-parse": "^1.0.0",
"find-my-way": "^7.3.0",
"find-my-way": "delvedor/find-my-way#use-internal-trees-for-pretty-printing",
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
"light-my-request": "^5.6.1",
"pino": "^8.5.0",
"process-warning": "^2.0.0",
Expand Down
145 changes: 83 additions & 62 deletions test/pretty-print.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ test('pretty print - static routes', t => {
fastify.ready(() => {
const tree = fastify.printRoutes()

const expected = `└── /
const expected = `\
└── /
├── test (GET)
│ └── /hello (GET)
└── hello/world (GET)
Expand All @@ -37,10 +38,13 @@ test('pretty print - parametric routes', t => {
fastify.ready(() => {
const tree = fastify.printRoutes()

const expected = `└── /
const expected = `\
└── /
├── test (GET)
│ └── /:hello (GET)
└── hello/:world (GET)
│ └── /
│ └── :hello (GET)
└── hello/
└── :world (GET)
`

t.equal(typeof tree, 'string')
Expand All @@ -60,11 +64,12 @@ test('pretty print - mixed parametric routes', t => {
fastify.ready(() => {
const tree = fastify.printRoutes()

const expected = `└── /test (GET)
└── /
└── :hello (GET)
:hello (POST)
└── /world (GET)
const expected = `\
└── /
└── test (GET)
└── /
└── :hello (GET, POST)
└── /world (GET)
`

t.equal(typeof tree, 'string')
Expand All @@ -83,10 +88,13 @@ test('pretty print - wildcard routes', t => {
fastify.ready(() => {
const tree = fastify.printRoutes()

const expected = `└── /
const expected = `\
└── /
├── test (GET)
│ └── /* (GET)
└── hello/* (GET)
│ └── /
│ └── * (GET)
└── hello/
└── * (GET)
`

t.equal(typeof tree, 'string')
Expand Down Expand Up @@ -134,17 +142,15 @@ test('pretty print - commonPrefix', t => {
const radixTree = fastify.printRoutes()
const flatTree = fastify.printRoutes({ commonPrefix: false })

const radixExpected = `└── /
├── hel
│ ├── lo (GET)
│ │ lo (HEAD)
│ └── icopter (GET)
│ icopter (HEAD)
└── hello (PUT)
const radixExpected = `\
└── /
└── hel
├── lo (GET, HEAD, PUT)
└── icopter (GET, HEAD)
`
const flatExpected = `└── / (-)
├── helicopter (GET, HEAD)
└── hello (GET, HEAD, PUT)
const flatExpected = `\
├── /hello (GET, HEAD, PUT)
└── /helicopter (GET, HEAD)
`
t.equal(typeof radixTree, 'string')
t.equal(typeof flatTree, 'string')
Expand All @@ -170,49 +176,64 @@ test('pretty print - includeMeta, includeHooks', t => {
const flatTree = fastify.printRoutes({ commonPrefix: false, includeHooks: true, includeMeta: ['errorHandler'] })
const hooksOnly = fastify.printRoutes({ commonPrefix: false, includeHooks: true })

const radixExpected = `└── /
├── hel
│ ├── lo (GET)
│ │ • (onTimeout) ["onTimeout()"]
│ │ • (onRequest) ["anonymous()"]
│ │ • (errorHandler) "defaultErrorHandler()"
│ │ lo (HEAD)
│ │ • (onTimeout) ["onTimeout()"]
│ │ • (onRequest) ["anonymous()"]
│ │ • (onSend) ["headRouteOnSendHandler()"]
│ │ • (errorHandler) "defaultErrorHandler()"
│ └── icopter (GET)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (errorHandler) "defaultErrorHandler()"
│ icopter (HEAD)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (onSend) ["headRouteOnSendHandler()"]
│ • (errorHandler) "defaultErrorHandler()"
└── hello (PUT)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
• (errorHandler) "defaultErrorHandler()"
const radixExpected = `\
└── /
└── hel
├── lo (GET, PUT)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (errorHandler) "defaultErrorHandler()"
│ lo (HEAD)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (onSend) ["headRouteOnSendHandler()"]
│ • (errorHandler) "defaultErrorHandler()"
└── icopter (GET)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
• (errorHandler) "defaultErrorHandler()"
icopter (HEAD)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
• (onSend) ["headRouteOnSendHandler()"]
• (errorHandler) "defaultErrorHandler()"
`
const flatExpected = `└── / (-)
├── helicopter (GET, HEAD)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (errorHandler) "defaultErrorHandler()"
└── hello (GET, HEAD, PUT)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
• (errorHandler) "defaultErrorHandler()"
const flatExpected = `\
├── /hello (GET, PUT)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (errorHandler) "defaultErrorHandler()"
│ /hello (HEAD)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (onSend) ["headRouteOnSendHandler()"]
│ • (errorHandler) "defaultErrorHandler()"
└── /helicopter (GET)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
• (errorHandler) "defaultErrorHandler()"
/helicopter (HEAD)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
• (onSend) ["headRouteOnSendHandler()"]
• (errorHandler) "defaultErrorHandler()"
`

const hooksOnlyExpected = `└── / (-)
├── helicopter (GET, HEAD)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
└── hello (GET, HEAD, PUT)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
const hooksOnlyExpected = `\
├── /hello (GET, PUT)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ /hello (HEAD)
│ • (onTimeout) ["onTimeout()"]
│ • (onRequest) ["anonymous()"]
│ • (onSend) ["headRouteOnSendHandler()"]
└── /helicopter (GET)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
/helicopter (HEAD)
• (onTimeout) ["onTimeout()"]
• (onRequest) ["anonymous()"]
• (onSend) ["headRouteOnSendHandler()"]
`
t.equal(typeof radixTree, 'string')
t.equal(typeof flatTree, 'string')
Expand Down