-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
48 lines (42 loc) · 1.15 KB
/
test.js
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
"use strict";
const fastify = require("fastify")();
const tap = require("tap");
const fastifySentry = require("./index");
// Custom error handler declaration
const errorHandler = (err, req, reply) => {
reply.status(req.body.error).send({
message: req.body.message,
e: err.message
});
};
tap.test("fastify sentry error handler exist", test => {
test.plan(4);
fastify.register(fastifySentry, {
dsn: "https://[email protected]/0000000",
environment: "test",
errorHandler: errorHandler
});
fastify.post("/", async (request, reply) => {
throw new Error("Oops");
});
fastify.ready(err => {
test.error(err);
fastify.inject(
{
method: "POST",
url: "/",
payload: { error: 503, message: "Internal Server Error" }
},
(err, { statusCode, payload }) => {
payload = JSON.parse(payload);
test.strictEqual(statusCode, 503);
test.strictEqual(payload.message, "Internal Server Error");
test.strictEqual(payload.e, "Oops");
fastify.close(() => {
test.end();
process.exit(0);
});
}
);
});
});