forked from mcollina/fastify-asyncforge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test-d.ts
55 lines (49 loc) · 1.95 KB
/
index.test-d.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { expectAssignable, expectError, expectType } from "tsd";
import fastifyasyncforge, { app, logger, reply, request, start } from ".";
import fastify, {
type FastifyInstance,
type FastifyBaseLogger,
type FastifyRequest,
type FastifyReply,
type RawServerDefault,
type RouteGenericInterface,
type FastifyPluginCallback,
} from "fastify";
const fastifyInstance = fastify();
expectAssignable<FastifyInstance>(fastifyInstance.register(fastifyasyncforge));
expectAssignable<FastifyPluginCallback>(fastifyasyncforge);
expectType<void>(fastifyInstance.enterWith());
expectType<number>(fastifyInstance.runInAsyncScope(() => 42));
// app
expectAssignable<FastifyInstance>(fastifyInstance);
expectAssignable<FastifyInstance>(app());
expectAssignable<FastifyInstance>(app<FastifyInstance<RawServerDefault>>());
expectError<FastifyInstance>(app<string>());
expectError<FastifyInstance>({});
// request
expectType<FastifyRequest>(request());
expectType<FastifyRequest>(request<FastifyRequest<RouteGenericInterface>>());
expectError<FastifyRequest>(request<boolean>());
expectType<unknown>(request().body);
expectType<boolean>(request().is404);
expectError<FastifyRequest>({});
// reply
expectType<FastifyReply>(reply());
expectType<FastifyReply>(reply<FastifyReply<RawServerDefault>>());
expectType<number>(reply().statusCode);
expectType<boolean>(reply().sent);
expectError<FastifyReply>(reply<number>());
expectError<FastifyReply>({});
// logger
expectType<FastifyBaseLogger>(fastifyInstance.log);
expectType<FastifyBaseLogger>(logger());
expectType<FastifyBaseLogger>(logger<FastifyBaseLogger>());
expectType<void>(logger().debug({ msg: "hey" }));
expectType<void>(logger().info({ msg: "oh!" }));
expectType<void>(logger().warn({ msg: "let's go!!!" }));
expectError<FastifyBaseLogger>(logger<object>());
expectError<FastifyBaseLogger>({});
// start
expectType<void>(await start(fastifyInstance));
expectError<void>(await start({ invalid: "object" }));
expectError<void>(await start());