-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfastify.ts
More file actions
34 lines (29 loc) · 1.28 KB
/
fastify.ts
File metadata and controls
34 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fastifyConstructor, { FastifyInstance } from 'fastify';
/**
* 単体テストに適した設定がなされたfastifyインスタンスを生成する
*
* @param opts fastifyConstructor に渡す引数
* @example
* import slack from '../lib/slackMock.js';
* import {fastifyDevConstructor} from '../lib/fastify';
* import {server} from './index';
*
* const fastify = fastifyDevConstructor();
* fastify.register(server(slack));
*/
export const fastifyDevConstructor = (opts?: Parameters<typeof fastifyConstructor>[0]): FastifyInstance => {
// TODO: support generics of fastifyConstructor
/*
* Setting the return type to ReturnType<fastifyConstructor> causes typeerror
* because type Server is not compatible with type Http2SecureServer
* Maybe because of not handling the generics of fastifyConstructor
*/
const fastify = fastifyConstructor(Object.assign({}, { logger: true }, opts));
/**
* デフォルトのエラーハンドラはエラーをログに出力して握り潰すため,
* 単体テストでexpectの失敗などによる例外をJestが検知することができない
* 発生した例外は全て再送出するように設定
*/
fastify.setErrorHandler((err) => { throw err; });
return fastify;
};