fastify 3.16.0 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1685,19 +1685,3 @@ test('reply.then', t => {
1685
1685
  response.destroy(_err)
1686
1686
  })
1687
1687
  })
1688
-
1689
- test('reply.sent should read from response.writableEnded if it is defined', t => {
1690
- t.plan(1)
1691
-
1692
- const reply = new Reply({ writableEnded: true }, {}, {})
1693
-
1694
- t.equal(reply.sent, true)
1695
- })
1696
-
1697
- test('reply.sent should read from response.headersSent and response.finished if response.writableEnded is not defined', t => {
1698
- t.plan(1)
1699
-
1700
- const reply = new Reply({ headersSent: true, finished: true }, {}, {})
1701
-
1702
- t.equal(reply.sent, true)
1703
- })
@@ -121,3 +121,92 @@ test('pretty print - nested plugins', t => {
121
121
  t.match(tree, 'baz')
122
122
  })
123
123
  })
124
+
125
+ test('pretty print - commonPrefix', t => {
126
+ t.plan(4)
127
+
128
+ const fastify = Fastify()
129
+ fastify.get('/hello', () => {})
130
+ fastify.put('/hello', () => {})
131
+ fastify.get('/helicopter', () => {})
132
+
133
+ fastify.ready(() => {
134
+ const radixTree = fastify.printRoutes()
135
+ const flatTree = fastify.printRoutes({ commonPrefix: false })
136
+
137
+ const radixExpected = `└── /
138
+ ├── hel
139
+ │ ├── lo (GET)
140
+ │ └── icopter (GET)
141
+ └── hello (PUT)
142
+ `
143
+ const flatExpected = `└── / (-)
144
+ ├── helicopter (GET)
145
+ └── hello (GET, PUT)
146
+ `
147
+ t.equal(typeof radixTree, 'string')
148
+ t.equal(typeof flatTree, 'string')
149
+ t.equal(radixTree, radixExpected)
150
+ t.equal(flatTree, flatExpected)
151
+ })
152
+ })
153
+
154
+ test('pretty print - includeMeta, includeHooks', t => {
155
+ t.plan(6)
156
+
157
+ const fastify = Fastify()
158
+ const onTimeout = () => {}
159
+ fastify.get('/hello', () => {})
160
+ fastify.put('/hello', () => {})
161
+ fastify.get('/helicopter', () => {})
162
+
163
+ fastify.addHook('onRequest', () => {})
164
+ fastify.addHook('onTimeout', onTimeout)
165
+
166
+ fastify.ready(() => {
167
+ const radixTree = fastify.printRoutes({ includeHooks: true, includeMeta: ['errorHandler'] })
168
+ const flatTree = fastify.printRoutes({ commonPrefix: false, includeHooks: true, includeMeta: ['errorHandler'] })
169
+ const hooksOnly = fastify.printRoutes({ commonPrefix: false, includeHooks: true })
170
+
171
+ const radixExpected = `└── /
172
+ ├── hel
173
+ │ ├── lo (GET)
174
+ │ │ • (onTimeout) ["onTimeout()"]
175
+ │ │ • (onRequest) ["anonymous()"]
176
+ │ │ • (errorHandler) "defaultErrorHandler()"
177
+ │ └── icopter (GET)
178
+ │ • (onTimeout) ["onTimeout()"]
179
+ │ • (onRequest) ["anonymous()"]
180
+ │ • (errorHandler) "defaultErrorHandler()"
181
+ └── hello (PUT)
182
+ • (onTimeout) ["onTimeout()"]
183
+ • (onRequest) ["anonymous()"]
184
+ • (errorHandler) "defaultErrorHandler()"
185
+ `
186
+ const flatExpected = `└── / (-)
187
+ ├── helicopter (GET)
188
+ │ • (onTimeout) ["onTimeout()"]
189
+ │ • (onRequest) ["anonymous()"]
190
+ │ • (errorHandler) "defaultErrorHandler()"
191
+ └── hello (GET, PUT)
192
+ • (onTimeout) ["onTimeout()"]
193
+ • (onRequest) ["anonymous()"]
194
+ • (errorHandler) "defaultErrorHandler()"
195
+ `
196
+
197
+ const hooksOnlyExpected = `└── / (-)
198
+ ├── helicopter (GET)
199
+ │ • (onTimeout) ["onTimeout()"]
200
+ │ • (onRequest) ["anonymous()"]
201
+ └── hello (GET, PUT)
202
+ • (onTimeout) ["onTimeout()"]
203
+ • (onRequest) ["anonymous()"]
204
+ `
205
+ t.equal(typeof radixTree, 'string')
206
+ t.equal(typeof flatTree, 'string')
207
+ t.equal(typeof hooksOnlyExpected, 'string')
208
+ t.equal(radixTree, radixExpected)
209
+ t.equal(flatTree, flatExpected)
210
+ t.equal(hooksOnly, hooksOnlyExpected)
211
+ })
212
+ })
@@ -3,12 +3,15 @@ import fastify, {
3
3
  FastifyInstance,
4
4
  FastifyPlugin,
5
5
  FastifyPluginAsync,
6
- FastifyPluginCallback
6
+ FastifyPluginCallback,
7
+ LightMyRequestChain,
8
+ LightMyRequestResponse,
9
+ LightMyRequestCallback,
10
+ InjectOptions
7
11
  } from '../../fastify'
8
12
  import * as http from 'http'
9
13
  import * as https from 'https'
10
14
  import * as http2 from 'http2'
11
- import { Chain as LightMyRequestChain } from 'light-my-request'
12
15
  import { expectType, expectError, expectAssignable } from 'tsd'
13
16
  import { FastifyLoggerInstance } from '../../types/logger'
14
17
  import { Socket } from 'net'
@@ -27,6 +30,14 @@ expectType<LightMyRequestChain>(fastify({ http2: true, https: {} }).inject())
27
30
  expectError(fastify<http2.Http2Server>({ http2: false })) // http2 option must be true
28
31
  expectError(fastify<http2.Http2SecureServer>({ http2: false })) // http2 option must be true
29
32
 
33
+ // light-my-request
34
+ expectAssignable<InjectOptions>({ query: '' })
35
+ fastify({ http2: true, https: {} }).inject().then((resp) => {
36
+ expectAssignable<LightMyRequestResponse>(resp)
37
+ })
38
+ const lightMyRequestCallback: LightMyRequestCallback = (err: Error, response: LightMyRequestResponse) => {}
39
+ fastify({ http2: true, https: {} }).inject({}, lightMyRequestCallback)
40
+
30
41
  // server options
31
42
  expectAssignable<FastifyInstance<http2.Http2Server, http2.Http2ServerRequest, http2.Http2ServerResponse>>(fastify({ http2: true }))
32
43
  expectAssignable<FastifyInstance>(fastify({ ignoreTrailingSlash: true }))
@@ -632,7 +632,7 @@ test('Should trigger a warning when a versioned route is registered via version
632
632
  t.plan(4)
633
633
 
634
634
  function onWarning (code) {
635
- t.equal(code, 'FSTDEP006')
635
+ t.equal(code, 'FSTDEP008')
636
636
  }
637
637
  const warning = {
638
638
  emit: onWarning
@@ -4,7 +4,6 @@ const t = require('tap')
4
4
  const test = t.test
5
5
  const { kReplySentOverwritten } = require('../lib/symbols')
6
6
  const wrapThenable = require('../lib/wrapThenable')
7
- const Reply = require('../lib/reply')
8
7
 
9
8
  test('should resolve immediately when reply[kReplySentOverwritten] is true', t => {
10
9
  const reply = {}
@@ -16,7 +15,7 @@ test('should resolve immediately when reply[kReplySentOverwritten] is true', t =
16
15
 
17
16
  test('should reject immediately when reply[kReplySentOverwritten] is true', t => {
18
17
  t.plan(1)
19
- const reply = new Reply({}, {}, {})
18
+ const reply = { res: {} }
20
19
  reply[kReplySentOverwritten] = true
21
20
  reply.log = {
22
21
  error: ({ err }) => {