@roarr/sentry
Version:
Sentry integration that adds Roarr logs to Sentry breadcrumbs.
86 lines (85 loc) • 3.16 kB
JavaScript
;
/* eslint-disable @typescript-eslint/no-explicit-any */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = __importDefault(require("ava"));
const roarr_1 = require("roarr");
const sinon = __importStar(require("sinon"));
const createRoarrSentryIntegration_1 = require("../../../src/factories/createRoarrSentryIntegration");
(0, ava_1.default)('creates class with CaptureRoarr constructor name', (t) => {
t.is((0, createRoarrSentryIntegration_1.createRoarrSentryIntegration)({
addBreadcrumb: () => { },
}).constructor.name, 'CaptureRoarr');
});
(0, ava_1.default)('overrides ROARR.write method', (t) => {
const originalWrite = roarr_1.ROARR.write;
(0, createRoarrSentryIntegration_1.createRoarrSentryIntegration)({
addBreadcrumb: () => { },
}).setupOnce();
t.not(roarr_1.ROARR.write, originalWrite);
});
(0, ava_1.default)('passes-through calls to ROARR.write', (t) => {
const spy = sinon.stub();
roarr_1.ROARR.write = spy;
(0, createRoarrSentryIntegration_1.createRoarrSentryIntegration)({
addBreadcrumb: () => { },
}).setupOnce();
const payload = JSON.stringify({
context: {
namespace: 'bar',
},
message: 'foo',
});
roarr_1.ROARR.write(payload);
t.true(spy.called);
});
(0, ava_1.default)('adds logs to breadcrumbs', (t) => {
const addBreadcrumb = sinon.stub();
roarr_1.ROARR.write = () => { };
(0, createRoarrSentryIntegration_1.createRoarrSentryIntegration)({
addBreadcrumb,
}).setupOnce();
const payload = JSON.stringify({
context: {
namespace: 'bar',
},
message: 'foo',
});
roarr_1.ROARR.write(payload);
t.like(addBreadcrumb.firstCall.firstArg, {
category: 'bar',
data: {
context: {
namespace: 'bar',
},
},
level: 'error',
message: 'foo',
type: 'default',
});
});