fastify 5.11.3 → 6.0.0-alpha.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.
Files changed (54) hide show
  1. package/README.md +2 -2
  2. package/SPONSORS.md +1 -0
  3. package/build/build-validation.js +20 -34
  4. package/docs/Guides/Getting-Started.md +2 -2
  5. package/docs/Guides/Serverless.md +34 -2
  6. package/docs/Reference/Errors.md +5 -3
  7. package/docs/Reference/Hooks.md +0 -4
  8. package/docs/Reference/LTS.md +6 -5
  9. package/docs/Reference/Server.md +8 -88
  10. package/docs/Reference/TypeScript.md +3 -49
  11. package/docs/Reference/Warnings.md +4 -11
  12. package/fastify.d.ts +10 -24
  13. package/fastify.js +17 -34
  14. package/lib/config-validator.js +368 -475
  15. package/lib/errors.js +9 -3
  16. package/lib/log-controller.js +2 -4
  17. package/lib/logger-factory.js +1 -1
  18. package/lib/route.js +4 -9
  19. package/lib/server.js +2 -3
  20. package/lib/warnings.js +2 -46
  21. package/package.json +2 -3
  22. package/test/404s.test.js +0 -49
  23. package/test/allow-unsafe-regex.test.js +12 -4
  24. package/test/case-insensitive.test.js +12 -4
  25. package/test/custom-querystring-parser.test.js +0 -16
  26. package/test/hooks.test.js +6 -1
  27. package/test/http-methods/custom-http-methods.test.js +12 -17
  28. package/test/http-methods/trace.test.js +1 -1
  29. package/test/https/custom-https-server.test.js +1 -1
  30. package/test/internals/errors.test.js +15 -5
  31. package/test/internals/initial-config.test.js +56 -38
  32. package/test/internals/logger.test.js +17 -4
  33. package/test/internals/reply.test.js +1 -1
  34. package/test/internals/request.test.js +8 -24
  35. package/test/logger/logging.test.js +2 -121
  36. package/test/logger/request.test.js +1 -36
  37. package/test/plugin.4.test.js +5 -4
  38. package/test/route-prefix.test.js +46 -18
  39. package/test/route.1.test.js +2 -2
  40. package/test/router-options.test.js +25 -523
  41. package/test/set-error-handler.test.js +7 -9
  42. package/test/types/errors.tst.ts +2 -1
  43. package/test/types/fastify.tst.ts +44 -48
  44. package/test/types/instance.tst.ts +4 -5
  45. package/test/types/logger.tst.ts +3 -7
  46. package/test/use-semicolon-delimiter.test.js +0 -60
  47. package/types/context.d.ts +0 -20
  48. package/types/errors.d.ts +2 -1
  49. package/types/instance.d.ts +0 -4
  50. package/types/logger.d.ts +1 -16
  51. package/types/plugin.d.ts +0 -9
  52. package/types/request.d.ts +0 -4
  53. package/lib/promise.js +0 -23
  54. package/test/internals/promise.test.js +0 -63
@@ -1,8 +1,8 @@
1
+ import Ajv, { ErrorObject as AjvErrorObject } from 'ajv'
1
2
  import * as http from 'node:http'
2
3
  import * as http2 from 'node:http2'
3
4
  import * as https from 'node:https'
4
5
  import { Socket } from 'node:net'
5
- import Ajv, { ErrorObject as AjvErrorObject } from 'ajv'
6
6
  import { expect } from 'tstyche'
7
7
  import fastify, {
8
8
  ConnectionError,
@@ -10,7 +10,6 @@ import fastify, {
10
10
  FastifyError,
11
11
  FastifyErrorCodes,
12
12
  FastifyInstance,
13
- FastifyPlugin,
14
13
  FastifyPluginAsync,
15
14
  FastifyPluginCallback,
16
15
  InjectOptions,
@@ -127,9 +126,6 @@ expect(fastify({ pluginTimeout: 1000 })).type.toBeAssignableTo<FastifyInstance>(
127
126
  expect(fastify({ bodyLimit: 100 })).type.toBeAssignableTo<FastifyInstance>()
128
127
  expect(fastify({ handlerTimeout: 5000 })).type.toBeAssignableTo<FastifyInstance>()
129
128
  expect(fastify({ maxParamLength: 100 })).type.toBeAssignableTo<FastifyInstance>()
130
- expect(fastify({ disableRequestLogging: true })).type.toBeAssignableTo<FastifyInstance>()
131
- expect(fastify({ disableRequestLogging: (req) => req.url?.includes('/health') ?? false })).type.toBeAssignableTo<FastifyInstance>()
132
- expect(fastify({ requestIdLogLabel: 'request-id' })).type.toBeAssignableTo<FastifyInstance>()
133
129
  expect(fastify({ onProtoPoisoning: 'error' })).type.toBeAssignableTo<FastifyInstance>()
134
130
  expect(fastify({ onConstructorPoisoning: 'error' })).type.toBeAssignableTo<FastifyInstance>()
135
131
  expect(fastify({ serializerOpts: { rounding: 'ceil' } })).type.toBeAssignableTo<FastifyInstance>()
@@ -188,7 +184,7 @@ expect(fastify({ logger: customLogger })).type.toBeAssignableTo<
188
184
  FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyBaseLogger>
189
185
  >()
190
186
  expect(fastify({ serverFactory: () => http.createServer() })).type.toBeAssignableTo<FastifyInstance>()
191
- expect(fastify({ caseSensitive: true })).type.toBeAssignableTo<FastifyInstance>()
187
+ expect(fastify({ routerOptions: { caseSensitive: true } })).type.toBeAssignableTo<FastifyInstance>()
192
188
  expect(fastify({ requestIdHeader: 'request-id' })).type.toBeAssignableTo<FastifyInstance>()
193
189
  expect(fastify({ requestIdHeader: false })).type.toBeAssignableTo<FastifyInstance>()
194
190
  expect(fastify({
@@ -198,45 +194,46 @@ expect(fastify({
198
194
  }
199
195
  })).type.toBeAssignableTo<FastifyInstance>()
200
196
  expect(fastify({ trustProxy: true })).type.toBeAssignableTo<FastifyInstance>()
201
- expect(fastify({ querystringParser: () => ({ foo: 'bar' }) })).type.toBeAssignableTo<FastifyInstance>()
202
- expect(fastify({ querystringParser: () => ({ foo: { bar: 'fuzz' } }) })).type.toBeAssignableTo<FastifyInstance>()
203
- expect(fastify({ querystringParser: () => ({ foo: ['bar', 'fuzz'] }) })).type.toBeAssignableTo<FastifyInstance>()
204
- expect(fastify({ constraints: {} })).type.toBeAssignableTo<FastifyInstance>()
197
+ expect(fastify({ routerOptions: { querystringParser: () => ({ foo: 'bar' }) } })).type.toBeAssignableTo<FastifyInstance>()
198
+ expect(fastify({ routerOptions: { querystringParser: () => ({ foo: { bar: 'fuzz' } }) } })).type.toBeAssignableTo<FastifyInstance>()
199
+ expect(fastify({ routerOptions: { querystringParser: () => ({ foo: ['bar', 'fuzz'] }) } })).type.toBeAssignableTo<FastifyInstance>()
200
+ expect(fastify({ routerOptions: { constraints: {} } })).type.toBeAssignableTo<FastifyInstance>()
205
201
  expect(fastify({
206
- constraints: {
207
- version: {
208
- name: 'version',
209
- storage: () => ({
210
- get: () => () => { },
211
- set: () => { },
212
- del: () => { },
213
- empty: () => { }
214
- }),
215
- validate () { },
216
- deriveConstraint: () => 'foo'
217
- },
218
- host: {
219
- name: 'host',
220
- storage: () => ({
221
- get: () => () => { },
222
- set: () => { },
223
- del: () => { },
224
- empty: () => { }
225
- }),
226
- validate () { },
227
- deriveConstraint: () => 'foo'
228
- },
229
- withObjectValue: {
230
- name: 'withObjectValue',
231
- storage: () => ({
232
- get: () => () => { },
233
- set: () => { },
234
- del: () => { },
235
- empty: () => { }
236
- }),
237
- validate () { },
238
- deriveConstraint: () => { }
239
-
202
+ routerOptions: {
203
+ constraints: {
204
+ version: {
205
+ name: 'version',
206
+ storage: () => ({
207
+ get: () => () => { },
208
+ set: () => { },
209
+ del: () => { },
210
+ empty: () => { }
211
+ }),
212
+ validate () { },
213
+ deriveConstraint: () => 'foo'
214
+ },
215
+ host: {
216
+ name: 'host',
217
+ storage: () => ({
218
+ get: () => () => { },
219
+ set: () => { },
220
+ del: () => { },
221
+ empty: () => { }
222
+ }),
223
+ validate () { },
224
+ deriveConstraint: () => 'foo'
225
+ },
226
+ withObjectValue: {
227
+ name: 'withObjectValue',
228
+ storage: () => ({
229
+ get: () => () => { },
230
+ set: () => { },
231
+ del: () => { },
232
+ empty: () => { }
233
+ }),
234
+ validate () { },
235
+ deriveConstraint: () => { }
236
+ }
240
237
  }
241
238
  }
242
239
  })).type.toBeAssignableTo<FastifyInstance>()
@@ -322,7 +319,6 @@ fastify().then(fastifyInstance => expect(fastifyInstance).type.toBeAssignableTo<
322
319
 
323
320
  expect<FastifyPluginAsync>().type.toBeAssignableFrom(async () => { })
324
321
  expect<FastifyPluginCallback>().type.toBeAssignableFrom(() => { })
325
- expect<FastifyPlugin>().type.toBeAssignableFrom(() => { })
326
322
 
327
323
  const ajvErrorObject: AjvErrorObject = {
328
324
  keyword: '',
@@ -354,9 +350,9 @@ expect<RouteGenericInterface['Reply']>().type.toBe<unknown>()
354
350
  // ErrorCodes
355
351
  expect(fastify.errorCodes).type.toBe<FastifyErrorCodes>()
356
352
 
357
- fastify({ allowUnsafeRegex: true })
358
- fastify({ allowUnsafeRegex: false })
359
- expect(fastify).type.not.toBeCallableWith({ allowUnsafeRegex: 'invalid' })
353
+ fastify({ routerOptions: { allowUnsafeRegex: true } })
354
+ fastify({ routerOptions: { allowUnsafeRegex: false } })
355
+ expect(fastify).type.not.toBeCallableWith({ routerOptions: { allowUnsafeRegex: 'invalid' } })
360
356
 
361
357
  expect(fastify({ allowErrorHandlerOverride: true })).type.toBeAssignableTo<FastifyInstance>()
362
358
  expect(fastify({ allowErrorHandlerOverride: false })).type.toBeAssignableTo<FastifyInstance>()
@@ -314,13 +314,11 @@ type InitialConfig = Readonly<{
314
314
  https?: boolean | Readonly<{ allowHTTP1: boolean }>,
315
315
  ignoreTrailingSlash?: boolean,
316
316
  ignoreDuplicateSlashes?: boolean,
317
- disableRequestLogging?: boolean | ((req: FastifyRequest) => boolean),
318
317
  maxParamLength?: number,
319
318
  onProtoPoisoning?: 'error' | 'remove' | 'ignore',
320
319
  onConstructorPoisoning?: 'error' | 'remove' | 'ignore',
321
320
  pluginTimeout?: number,
322
321
  requestIdHeader?: string | false,
323
- requestIdLogLabel?: string,
324
322
  http2SessionTimeout?: number,
325
323
  useSemicolonDelimiter?: boolean,
326
324
  routerOptions?: FastifyRouterOptions<RawServerDefault>
@@ -328,9 +326,10 @@ type InitialConfig = Readonly<{
328
326
 
329
327
  expect(fastify().initialConfig).type.toBe<InitialConfig>()
330
328
 
331
- expect<FastifyRouterOptions<RawServerDefault>>().type.toBeAssignableTo<
332
- FindMyWayConfig<FindMyWayVersion<RawServerDefault>>
333
- >()
329
+ // TODO: we accept wider types than find-my-way and it cannot be assign to a restricted types
330
+ // expect<FastifyRouterOptions<RawServerDefault>>().type.toBeAssignableTo<
331
+ // FindMyWayConfig<FindMyWayVersion<RawServerDefault>>
332
+ // >()
334
333
 
335
334
  fastify({
336
335
  routerOptions: {
@@ -10,7 +10,6 @@ import fastify, {
10
10
  FastifyRequest,
11
11
  LogLevel
12
12
  } from '../../fastify.js'
13
- import { ResSerializerReply } from '../../types/logger.js'
14
13
 
15
14
  expect(fastify().log).type.toBe<FastifyBaseLogger>()
16
15
 
@@ -158,8 +157,7 @@ const serverWithPinoConfig = fastify({
158
157
  }
159
158
  },
160
159
  res (reply) {
161
- expect(reply).type.toBe<ResSerializerReply<Server, FastifyReply>>()
162
- expect(reply).type.toBeAssignableTo<Partial<FastifyReply> & Pick<FastifyReply, 'statusCode'>>()
160
+ expect(reply).type.toBe<Partial<FastifyReply>>()
163
161
  expect(reply).type.not.toBeAssignableTo<FastifyReply>()
164
162
  return {
165
163
  statusCode: 'statusCode'
@@ -194,8 +192,7 @@ const serverAutoInferredSerializerResponseObjectOption = fastify({
194
192
  logger: {
195
193
  serializers: {
196
194
  res (reply) {
197
- expect(reply).type.toBe<ResSerializerReply<Server, FastifyReply>>()
198
- expect(reply).type.toBeAssignableTo<Partial<FastifyReply> & Pick<FastifyReply, 'statusCode'>>()
195
+ expect(reply).type.toBe<Partial<FastifyReply>>()
199
196
  expect(reply).type.not.toBeAssignableTo<FastifyReply>()
200
197
  return {
201
198
  status: '200'
@@ -223,8 +220,7 @@ const serverAutoInferredSerializerObjectOption = fastify({
223
220
  }
224
221
  },
225
222
  res (reply) {
226
- expect(reply).type.toBe<ResSerializerReply<Server, FastifyReply>>()
227
- expect(reply).type.toBeAssignableTo<Partial<FastifyReply> & Pick<FastifyReply, 'statusCode'>>()
223
+ expect(reply).type.toBe<Partial<FastifyReply>>()
228
224
  expect(reply).type.not.toBeAssignableTo<FastifyReply>()
229
225
  return {
230
226
  statusCode: 'statusCode'
@@ -23,66 +23,6 @@ test('use semicolon delimiter default false', async (t) => {
23
23
  t.assert.deepStrictEqual(body, {})
24
24
  })
25
25
 
26
- test('use semicolon delimiter set to true', async (t) => {
27
- t.plan(3)
28
- const fastify = Fastify({
29
- useSemicolonDelimiter: true
30
- })
31
-
32
- fastify.get('/1234', (req, reply) => {
33
- reply.send(req.query)
34
- })
35
-
36
- const fastifyServer = await fastify.listen({ port: 0 })
37
- t.after(() => { fastify.close() })
38
-
39
- const result = await fetch(fastifyServer + '/1234;foo=bar')
40
- t.assert.ok(result.ok)
41
- t.assert.strictEqual(result.status, 200)
42
- t.assert.deepStrictEqual(await result.json(), {
43
- foo: 'bar'
44
- })
45
- })
46
-
47
- test('use semicolon delimiter set to false', async (t) => {
48
- t.plan(3)
49
-
50
- const fastify = Fastify({
51
- useSemicolonDelimiter: false
52
- })
53
-
54
- fastify.get('/1234;foo=bar', (req, reply) => {
55
- reply.send(req.query)
56
- })
57
-
58
- const fastifyServer = await fastify.listen({ port: 0 })
59
- t.after(() => { fastify.close() })
60
-
61
- const result = await fetch(fastifyServer + '/1234;foo=bar')
62
- t.assert.ok(result.ok)
63
- t.assert.strictEqual(result.status, 200)
64
- t.assert.deepStrictEqual(await result.json(), {})
65
- })
66
-
67
- test('use semicolon delimiter set to false return 404', async (t) => {
68
- t.plan(2)
69
-
70
- const fastify = Fastify({
71
- useSemicolonDelimiter: false
72
- })
73
-
74
- fastify.get('/1234', (req, reply) => {
75
- reply.send(req.query)
76
- })
77
-
78
- const fastifyServer = await fastify.listen({ port: 0 })
79
- t.after(() => { fastify.close() })
80
-
81
- const result = await fetch(fastifyServer + '/1234;foo=bar')
82
- t.assert.ok(!result.ok)
83
- t.assert.strictEqual(result.status, 404)
84
- })
85
-
86
26
  test('use routerOptions semicolon delimiter default false', async t => {
87
27
  t.plan(3)
88
28
 
@@ -1,22 +1,2 @@
1
- import { FastifyRouteConfig } from './route'
2
- import { ContextConfigDefault } from './utils'
3
-
4
1
  export interface FastifyContextConfig {
5
2
  }
6
-
7
- /**
8
- * Route context object. Properties defined here will be available in the route's handler
9
- */
10
- export interface FastifyRequestContext<ContextConfig = ContextConfigDefault> {
11
- /**
12
- * @deprecated Use Request#routeOptions#config or Request#routeOptions#schema instead
13
- */
14
- config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
15
- }
16
-
17
- export interface FastifyReplyContext<ContextConfig = ContextConfigDefault> {
18
- /**
19
- * @deprecated Use Reply#routeOptions#config or Reply#routeOptions#schema instead
20
- */
21
- config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
22
- }
package/types/errors.d.ts CHANGED
@@ -74,6 +74,7 @@ export type FastifyErrorCodes = Record<
74
74
  'FST_ERR_ROUTE_HANDLER_NOT_FN' |
75
75
  'FST_ERR_ROUTE_MISSING_HANDLER' |
76
76
  'FST_ERR_ROUTE_METHOD_INVALID' |
77
+ 'FST_ERR_ROUTE_METHOD_ALREADY_SUPPORTED' |
77
78
  'FST_ERR_ROUTE_METHOD_NOT_SUPPORTED' |
78
79
  'FST_ERR_ROUTE_LOG_LEVEL_INVALID' |
79
80
  'FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED' |
@@ -85,7 +86,7 @@ export type FastifyErrorCodes = Record<
85
86
  'FST_ERR_ROUTE_MISSING_CONTENT' |
86
87
  'FST_ERR_REOPENED_CLOSE_SERVER' |
87
88
  'FST_ERR_REOPENED_SERVER' |
88
- 'FST_ERR_INSTANCE_ALREADY_LISTENING' |
89
+ 'FST_ERR_INSTANCE_ALREADY_STARTED' |
89
90
  'FST_ERR_PLUGIN_VERSION_MISMATCH' |
90
91
  'FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE' |
91
92
  'FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER' |
@@ -701,15 +701,11 @@ export interface FastifyInstance<
701
701
  https?: boolean | Readonly<{ allowHTTP1: boolean }>,
702
702
  ignoreTrailingSlash?: boolean,
703
703
  ignoreDuplicateSlashes?: boolean,
704
- /** @deprecated Use the `logController` option with `disableRequestLogging` or `isLogDisabled` override instead. Will be removed in `fastify@6`. */
705
- disableRequestLogging?: boolean | ((req: FastifyRequest) => boolean),
706
704
  maxParamLength?: number,
707
705
  onProtoPoisoning?: ProtoAction,
708
706
  onConstructorPoisoning?: ConstructorAction,
709
707
  pluginTimeout?: number,
710
708
  requestIdHeader?: string | false,
711
- /** @deprecated Use the `logController` option with `requestIdLogLabel` instead. Will be removed in `fastify@6`. */
712
- requestIdLogLabel?: string,
713
709
  http2SessionTimeout?: number,
714
710
  useSemicolonDelimiter?: boolean,
715
711
  routerOptions?: FastifyRouterOptions<RawServer>
package/types/logger.d.ts CHANGED
@@ -28,25 +28,10 @@ export interface FastifyBaseLogger extends Pick<BaseLogger, 'level' | 'info' | '
28
28
  child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
29
29
  }
30
30
 
31
- // TODO delete FastifyLoggerInstance in the next major release. It seems that it is enough to have only FastifyBaseLogger.
32
- /**
33
- * @deprecated Use FastifyBaseLogger instead
34
- */
35
- export type FastifyLoggerInstance = FastifyBaseLogger
36
-
37
31
  export interface FastifyLoggerStreamDestination {
38
32
  write(msg: string): void;
39
33
  }
40
34
 
41
- // TODO: once node 18 is EOL, this type can be replaced with plain FastifyReply.
42
- /**
43
- * Specialized reply type used for the `res` log serializer, since only `statusCode` is passed in certain cases.
44
- */
45
- export type ResSerializerReply<
46
- RawServer extends RawServerBase,
47
- RawReply extends FastifyReply<RouteGenericInterface, RawServer>
48
- > = Partial<RawReply> & Pick<RawReply, 'statusCode'>
49
-
50
35
  /**
51
36
  * Fastify Custom Logger options.
52
37
  */
@@ -99,7 +84,7 @@ export interface FastifyLoggerOptions<
99
84
  stack: string;
100
85
  [key: string]: unknown;
101
86
  };
102
- res?: (res: ResSerializerReply<RawServer, RawReply>) => {
87
+ res?: (res: Partial<RawReply>) => {
103
88
  statusCode?: string | number;
104
89
  [key: string]: unknown;
105
90
  };
package/types/plugin.d.ts CHANGED
@@ -37,12 +37,3 @@ export type FastifyPluginAsync<
37
37
  TypeProvider>,
38
38
  opts: Options
39
39
  ) => Promise<void>
40
-
41
- /**
42
- * Generic plugin type.
43
- * @deprecated union type doesn't work well with type inference in TS and is therefore deprecated in favor of explicit types. Use `FastifyPluginCallback` or `FastifyPluginAsync` instead. To activate
44
- * plugins use `FastifyRegister`. https://fastify.dev/docs/latest/Reference/TypeScript/#register
45
- */
46
- export type FastifyPlugin<
47
- Options extends FastifyPluginOptions = Record<never, never>
48
- > = FastifyPluginCallback<Options> | FastifyPluginAsync<Options>
@@ -67,10 +67,6 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
67
67
  /** in order for this to be used the user should ensure they have set the attachValidation option. */
68
68
  validationError?: Error & { validation: any; validationContext: string };
69
69
 
70
- /**
71
- * @deprecated Use `raw` property
72
- */
73
- readonly req: RawRequest & RouteGeneric['Headers']; // this enables the developer to extend the existing http(s|2) headers list
74
70
  /**
75
71
  * Derived from request socket metadata or forwarding headers.
76
72
  * Treat as untrusted input and validate before security-sensitive use.
package/lib/promise.js DELETED
@@ -1,23 +0,0 @@
1
- 'use strict'
2
-
3
- const { kTestInternals } = require('./symbols')
4
-
5
- function withResolvers () {
6
- let res, rej
7
- const promise = new Promise((resolve, reject) => {
8
- res = resolve
9
- rej = reject
10
- })
11
- return { promise, resolve: res, reject: rej }
12
- }
13
-
14
- module.exports = {
15
- // TODO(20.x): remove when node@20 is not supported
16
- withResolvers: typeof Promise.withResolvers === 'function'
17
- ? Promise.withResolvers.bind(Promise) // Promise.withResolvers must bind to itself
18
- /* c8 ignore next */
19
- : withResolvers, // Tested using the kTestInternals
20
- [kTestInternals]: {
21
- withResolvers
22
- }
23
- }
@@ -1,63 +0,0 @@
1
- 'use strict'
2
-
3
- const { test } = require('node:test')
4
-
5
- const { kTestInternals } = require('../../lib/symbols')
6
- const PonyPromise = require('../../lib/promise')
7
-
8
- test('withResolvers', async (t) => {
9
- t.plan(3)
10
- await t.test('resolve', async (t) => {
11
- t.plan(1)
12
- const { promise, resolve } = PonyPromise.withResolvers()
13
- resolve(true)
14
- t.assert.ok(await promise)
15
- })
16
- await t.test('reject', async (t) => {
17
- t.plan(1)
18
- const { promise, reject } = PonyPromise.withResolvers()
19
- await t.assert.rejects(async () => {
20
- reject(Error('reject'))
21
- return promise
22
- }, {
23
- name: 'Error',
24
- message: 'reject'
25
- })
26
- })
27
- await t.test('thenable', async (t) => {
28
- t.plan(1)
29
- const { promise, resolve } = PonyPromise.withResolvers()
30
- resolve(true)
31
- promise.then((value) => {
32
- t.assert.ok(value)
33
- })
34
- })
35
- })
36
-
37
- test('withResolvers - ponyfill', async (t) => {
38
- await t.test('resolve', async (t) => {
39
- t.plan(1)
40
- const { promise, resolve } = PonyPromise[kTestInternals].withResolvers()
41
- resolve(true)
42
- t.assert.ok(await promise)
43
- })
44
- await t.test('reject', async (t) => {
45
- t.plan(1)
46
- const { promise, reject } = PonyPromise[kTestInternals].withResolvers()
47
- await t.assert.rejects(async () => {
48
- reject(Error('reject'))
49
- return promise
50
- }, {
51
- name: 'Error',
52
- message: 'reject'
53
- })
54
- })
55
- await t.test('thenable', async (t) => {
56
- t.plan(1)
57
- const { promise, resolve } = PonyPromise.withResolvers()
58
- resolve(true)
59
- promise.then((value) => {
60
- t.assert.ok(value)
61
- })
62
- })
63
- })