rollbar 2.26.4 → 3.0.0-alpha.2
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.
- package/.claude/settings.local.json +3 -0
- package/.cursor/rules/guidelines.mdc +154 -0
- package/.github/workflows/ci.yml +4 -6
- package/CLAUDE.local.md +297 -0
- package/CLAUDE.md +201 -0
- package/CLAUDE.testrunner.md +470 -0
- package/Gruntfile.js +59 -16
- package/Makefile +3 -3
- package/SECURITY.md +5 -0
- package/babel.config.json +9 -0
- package/codex.md +148 -0
- package/dist/plugins/jquery.min.js +1 -1
- package/dist/rollbar.js +19332 -6596
- package/dist/rollbar.js.map +1 -1
- package/dist/rollbar.min.js +2 -1
- package/dist/rollbar.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.min.js.map +1 -1
- package/dist/rollbar.named-amd.js +19332 -6596
- package/dist/rollbar.named-amd.js.map +1 -1
- package/dist/rollbar.named-amd.min.js +2 -1
- package/dist/rollbar.named-amd.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.named-amd.min.js.map +1 -1
- package/dist/rollbar.noconflict.umd.js +19319 -6581
- package/dist/rollbar.noconflict.umd.js.map +1 -1
- package/dist/rollbar.noconflict.umd.min.js +2 -1
- package/dist/rollbar.noconflict.umd.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.noconflict.umd.min.js.map +1 -1
- package/dist/rollbar.snippet.js +1 -1
- package/dist/rollbar.umd.js +19333 -6597
- package/dist/rollbar.umd.js.map +1 -1
- package/dist/rollbar.umd.min.js +2 -1
- package/dist/rollbar.umd.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.umd.min.js.map +1 -1
- package/eslint.config.mjs +33 -0
- package/karma.conf.js +5 -14
- package/package.json +19 -20
- package/src/api.js +57 -4
- package/src/apiUtility.js +2 -3
- package/src/browser/core.js +37 -9
- package/src/browser/replay/defaults.js +70 -0
- package/src/browser/replay/recorder.js +194 -0
- package/src/browser/replay/replayMap.js +195 -0
- package/src/browser/rollbar.js +11 -7
- package/src/browser/telemetry.js +3 -3
- package/src/browser/transport/fetch.js +17 -4
- package/src/browser/transport/xhr.js +17 -1
- package/src/browser/transport.js +11 -8
- package/src/defaults.js +1 -1
- package/src/queue.js +65 -4
- package/src/react-native/rollbar.js +1 -1
- package/src/rollbar.js +52 -10
- package/src/server/rollbar.js +3 -2
- package/src/telemetry.js +76 -11
- package/src/tracing/context.js +24 -0
- package/src/tracing/contextManager.js +37 -0
- package/src/tracing/defaults.js +7 -0
- package/src/tracing/exporter.js +188 -0
- package/src/tracing/hrtime.js +98 -0
- package/src/tracing/id.js +24 -0
- package/src/tracing/session.js +55 -0
- package/src/tracing/span.js +92 -0
- package/src/tracing/spanProcessor.js +15 -0
- package/src/tracing/tracer.js +46 -0
- package/src/tracing/tracing.js +89 -0
- package/src/utility.js +34 -0
- package/test/api.test.js +57 -12
- package/test/apiUtility.test.js +5 -6
- package/test/browser.core.test.js +1 -10
- package/test/browser.domUtility.test.js +1 -1
- package/test/browser.predicates.test.js +1 -1
- package/test/browser.replay.recorder.test.js +430 -0
- package/test/browser.rollbar.test.js +58 -12
- package/test/browser.telemetry.test.js +1 -1
- package/test/browser.transforms.test.js +20 -13
- package/test/browser.transport.test.js +5 -4
- package/test/browser.url.test.js +1 -1
- package/test/fixtures/replay/index.js +20 -0
- package/test/fixtures/replay/payloads.fixtures.js +229 -0
- package/test/fixtures/replay/rrwebEvents.fixtures.js +251 -0
- package/test/fixtures/replay/rrwebSyntheticEvents.fixtures.js +328 -0
- package/test/notifier.test.js +1 -1
- package/test/predicates.test.js +1 -1
- package/test/queue.test.js +1 -1
- package/test/rateLimiter.test.js +1 -1
- package/test/react-native.rollbar.test.js +1 -1
- package/test/react-native.transforms.test.js +2 -2
- package/test/react-native.transport.test.js +3 -3
- package/test/replay/index.js +2 -0
- package/test/replay/integration/api.spans.test.js +136 -0
- package/test/replay/integration/e2e.test.js +228 -0
- package/test/replay/integration/index.js +9 -0
- package/test/replay/integration/queue.replayMap.test.js +332 -0
- package/test/replay/integration/replayMap.test.js +163 -0
- package/test/replay/integration/sessionRecording.test.js +390 -0
- package/test/replay/unit/api.postSpans.test.js +150 -0
- package/test/replay/unit/index.js +7 -0
- package/test/replay/unit/queue.replayMap.test.js +225 -0
- package/test/replay/unit/replayMap.test.js +348 -0
- package/test/replay/util/index.js +5 -0
- package/test/replay/util/mockRecordFn.js +80 -0
- package/test/server.lambda.mocha.test.mjs +172 -0
- package/test/server.locals.constructor.mocha.test.mjs +80 -0
- package/test/server.locals.error-handling.mocha.test.mjs +387 -0
- package/test/server.locals.merge.mocha.test.mjs +267 -0
- package/test/server.locals.test-utils.mjs +114 -0
- package/test/server.parser.mocha.test.mjs +87 -0
- package/test/server.predicates.mocha.test.mjs +63 -0
- package/test/server.rollbar.constructor.mocha.test.mjs +199 -0
- package/test/server.rollbar.handlers.mocha.test.mjs +253 -0
- package/test/server.rollbar.logging.mocha.test.mjs +326 -0
- package/test/server.rollbar.misc.mocha.test.mjs +44 -0
- package/test/server.rollbar.test-utils.mjs +57 -0
- package/test/server.telemetry.mocha.test.mjs +377 -0
- package/test/server.transforms.data.mocha.test.mjs +163 -0
- package/test/server.transforms.error.mocha.test.mjs +199 -0
- package/test/server.transforms.request.mocha.test.mjs +208 -0
- package/test/server.transforms.scrub.mocha.test.mjs +140 -0
- package/test/server.transforms.sourcemaps.mocha.test.mjs +122 -0
- package/test/server.transforms.test-utils.mjs +62 -0
- package/test/server.transport.mocha.test.mjs +269 -0
- package/test/telemetry.test.js +132 -1
- package/test/tracing/contextManager.test.js +28 -0
- package/test/tracing/exporter.toPayload.test.js +400 -0
- package/test/tracing/id.test.js +24 -0
- package/test/tracing/span.test.js +183 -0
- package/test/tracing/spanProcessor.test.js +73 -0
- package/test/tracing/tracing.test.js +105 -0
- package/test/transforms.test.js +2 -2
- package/test/truncation.test.js +2 -2
- package/test/utility.test.js +44 -6
- package/webpack.config.js +6 -44
- package/.eslintignore +0 -7
- package/test/server.lambda.test.js +0 -194
- package/test/server.locals.test.js +0 -1068
- package/test/server.parser.test.js +0 -78
- package/test/server.predicates.test.js +0 -91
- package/test/server.rollbar.test.js +0 -728
- package/test/server.telemetry.test.js +0 -443
- package/test/server.transforms.test.js +0 -1193
- package/test/server.transport.test.js +0 -269
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/* globals describe */
|
|
2
|
+
/* globals it */
|
|
3
|
+
|
|
4
|
+
import { expect } from 'chai';
|
|
5
|
+
import Rollbar from '../src/server/rollbar.js';
|
|
6
|
+
import {
|
|
7
|
+
ValidOpenTracingTracerStub,
|
|
8
|
+
InvalidOpenTracingTracerStub,
|
|
9
|
+
} from './server.rollbar.test-utils.mjs';
|
|
10
|
+
|
|
11
|
+
describe('rollbar constructor and configuration', function () {
|
|
12
|
+
describe('constructor', function () {
|
|
13
|
+
describe('with accessToken', function () {
|
|
14
|
+
it('should have log method', function () {
|
|
15
|
+
const r = new Rollbar('abc123');
|
|
16
|
+
expect(r.log).to.be.a('function');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should have error method', function () {
|
|
20
|
+
const r = new Rollbar('abc123');
|
|
21
|
+
expect(r.error).to.be.a('function');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should have buildJsonPayload method', function () {
|
|
25
|
+
const r = new Rollbar('abc123');
|
|
26
|
+
expect(r.buildJsonPayload).to.be.a('function');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should have sendJsonPayload method', function () {
|
|
30
|
+
const r = new Rollbar('abc123');
|
|
31
|
+
expect(r.sendJsonPayload).to.be.a('function');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should have accessToken in options', function () {
|
|
35
|
+
const r = new Rollbar('abc123');
|
|
36
|
+
expect(r.options.accessToken).to.equal('abc123');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('with options', function () {
|
|
41
|
+
it('should have log method', function () {
|
|
42
|
+
const r = new Rollbar({ accessToken: 'abc123' });
|
|
43
|
+
expect(r.log).to.be.a('function');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should have error method', function () {
|
|
47
|
+
const r = new Rollbar({ accessToken: 'abc123' });
|
|
48
|
+
expect(r.error).to.be.a('function');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should have accessToken in options', function () {
|
|
52
|
+
const r = new Rollbar({ accessToken: 'abc123' });
|
|
53
|
+
expect(r.options.accessToken).to.equal('abc123');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should set environment based on default', function () {
|
|
57
|
+
const r = new Rollbar({ accessToken: 'abc123' });
|
|
58
|
+
expect(r.options.environment).to.be.a('string');
|
|
59
|
+
expect(r.options.environment).to.not.be.empty;
|
|
60
|
+
expect(r.options.environment).to.equal(
|
|
61
|
+
Rollbar.defaultOptions.environment,
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('with more options', function () {
|
|
67
|
+
it('should have log method', function () {
|
|
68
|
+
const r = new Rollbar({
|
|
69
|
+
accessToken: 'abc123',
|
|
70
|
+
environment: 'fake-env',
|
|
71
|
+
});
|
|
72
|
+
expect(r.log).to.be.a('function');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should have error method', function () {
|
|
76
|
+
const r = new Rollbar({
|
|
77
|
+
accessToken: 'abc123',
|
|
78
|
+
environment: 'fake-env',
|
|
79
|
+
});
|
|
80
|
+
expect(r.error).to.be.a('function');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should have accessToken in options', function () {
|
|
84
|
+
const r = new Rollbar({
|
|
85
|
+
accessToken: 'abc123',
|
|
86
|
+
environment: 'fake-env',
|
|
87
|
+
});
|
|
88
|
+
expect(r.options.accessToken).to.equal('abc123');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should set environment based on options', function () {
|
|
92
|
+
const r = new Rollbar({
|
|
93
|
+
accessToken: 'abc123',
|
|
94
|
+
environment: 'fake-env',
|
|
95
|
+
});
|
|
96
|
+
expect(r.options.environment).to.equal('fake-env');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should set configured options', function () {
|
|
100
|
+
const r = new Rollbar({
|
|
101
|
+
accessToken: 'abc123',
|
|
102
|
+
environment: 'fake-env',
|
|
103
|
+
});
|
|
104
|
+
expect(r.options._configuredOptions.environment).to.equal('fake-env');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('with deprecated options', function () {
|
|
109
|
+
it('should replace options', function () {
|
|
110
|
+
const r = new Rollbar({
|
|
111
|
+
hostWhiteList: ['foo'],
|
|
112
|
+
hostBlackList: ['bar'],
|
|
113
|
+
});
|
|
114
|
+
expect(r.options.hostWhiteList).to.be.undefined;
|
|
115
|
+
expect(r.options.hostBlackList).to.be.undefined;
|
|
116
|
+
expect(r.options.hostSafeList).to.deep.equal(['foo']);
|
|
117
|
+
expect(r.options.hostBlockList).to.deep.equal(['bar']);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('with valid tracer', function () {
|
|
122
|
+
it('should configure tracer', function () {
|
|
123
|
+
const r = new Rollbar({
|
|
124
|
+
captureUncaught: true,
|
|
125
|
+
environment: 'fake-env',
|
|
126
|
+
tracer: ValidOpenTracingTracerStub,
|
|
127
|
+
});
|
|
128
|
+
expect(r.client.tracer).to.be.an('object');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('with invalid tracer', function () {
|
|
133
|
+
it('should configure tracer', function () {
|
|
134
|
+
const r = new Rollbar({
|
|
135
|
+
captureUncaught: true,
|
|
136
|
+
environment: 'fake-env',
|
|
137
|
+
tracer: InvalidOpenTracingTracerStub,
|
|
138
|
+
});
|
|
139
|
+
expect(r.client.tracer).to.be.null;
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('configure', function () {
|
|
145
|
+
describe('with updated options', function () {
|
|
146
|
+
it('should set configured options', function () {
|
|
147
|
+
const rollbar = new Rollbar({
|
|
148
|
+
captureUncaught: true,
|
|
149
|
+
environment: 'fake-env',
|
|
150
|
+
});
|
|
151
|
+
rollbar.configure({ captureUncaught: false, environment: 'new-env' });
|
|
152
|
+
|
|
153
|
+
expect(rollbar.options._configuredOptions.environment).to.equal(
|
|
154
|
+
'new-env',
|
|
155
|
+
);
|
|
156
|
+
expect(rollbar.options._configuredOptions.captureUncaught).to.be.false;
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('with deprecated options', function () {
|
|
161
|
+
it('should replace options', function () {
|
|
162
|
+
const rollbar = new Rollbar({ captureUncaught: true });
|
|
163
|
+
rollbar.configure({
|
|
164
|
+
hostWhiteList: ['foo'],
|
|
165
|
+
hostBlackList: ['bar'],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(rollbar.options.hostWhiteList).to.be.undefined;
|
|
169
|
+
expect(rollbar.options.hostBlackList).to.be.undefined;
|
|
170
|
+
expect(rollbar.options.hostSafeList).to.deep.equal(['foo']);
|
|
171
|
+
expect(rollbar.options.hostBlockList).to.deep.equal(['bar']);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('with valid tracer', function () {
|
|
176
|
+
it('should configure tracer', function () {
|
|
177
|
+
const rollbar = new Rollbar({
|
|
178
|
+
captureUncaught: true,
|
|
179
|
+
environment: 'fake-env',
|
|
180
|
+
});
|
|
181
|
+
rollbar.configure({ tracer: ValidOpenTracingTracerStub });
|
|
182
|
+
|
|
183
|
+
expect(rollbar.client.tracer).to.equal(ValidOpenTracingTracerStub);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('with invalid tracer', function () {
|
|
188
|
+
it('should configure tracer', function () {
|
|
189
|
+
const rollbar = new Rollbar({
|
|
190
|
+
captureUncaught: true,
|
|
191
|
+
environment: 'fake-env',
|
|
192
|
+
});
|
|
193
|
+
rollbar.configure({ tracer: InvalidOpenTracingTracerStub });
|
|
194
|
+
|
|
195
|
+
expect(rollbar.client.tracer).to.be.null;
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/* globals describe */
|
|
2
|
+
/* globals it */
|
|
3
|
+
/* globals beforeEach */
|
|
4
|
+
/* globals afterEach */
|
|
5
|
+
|
|
6
|
+
import { expect } from 'chai';
|
|
7
|
+
import sinon from 'sinon';
|
|
8
|
+
import Rollbar from '../src/server/rollbar.js';
|
|
9
|
+
|
|
10
|
+
async function wait(ms) {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
setTimeout(resolve, ms);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function nodeReject() {
|
|
17
|
+
Promise.reject(new Error('node reject'));
|
|
18
|
+
await wait(500);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function nodeThrow() {
|
|
22
|
+
setTimeout(function () {
|
|
23
|
+
throw new Error('node error');
|
|
24
|
+
}, 10);
|
|
25
|
+
await wait(500);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('rollbar exception handlers', function () {
|
|
29
|
+
before(function () {
|
|
30
|
+
// Increase max listeners to avoid warnings during tests
|
|
31
|
+
// Multiple Rollbar instances are created and each adds handlers
|
|
32
|
+
process.setMaxListeners(20);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
after(function () {
|
|
36
|
+
process.setMaxListeners(10);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('captureUncaught', function () {
|
|
40
|
+
let mochaHandlers;
|
|
41
|
+
|
|
42
|
+
beforeEach(function () {
|
|
43
|
+
// Remove Mocha's uncaught exception handlers to prevent interference
|
|
44
|
+
mochaHandlers = process.listeners('uncaughtException');
|
|
45
|
+
mochaHandlers.forEach((handler) => {
|
|
46
|
+
process.removeListener('uncaughtException', handler);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(function () {
|
|
51
|
+
// Restore Mocha's handlers
|
|
52
|
+
mochaHandlers.forEach((handler) => {
|
|
53
|
+
process.on('uncaughtException', handler);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('enabled in constructor', function () {
|
|
58
|
+
let rollbar;
|
|
59
|
+
let logStub;
|
|
60
|
+
|
|
61
|
+
beforeEach(async function () {
|
|
62
|
+
rollbar = new Rollbar({
|
|
63
|
+
accessToken: 'abc123',
|
|
64
|
+
captureUncaught: true,
|
|
65
|
+
});
|
|
66
|
+
logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
67
|
+
|
|
68
|
+
await nodeThrow();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(function () {
|
|
72
|
+
logStub.restore();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should have locals disabled', function () {
|
|
76
|
+
expect(rollbar.client.notifier.locals).to.be.undefined;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should log', function () {
|
|
80
|
+
expect(logStub.called).to.be.true;
|
|
81
|
+
expect(logStub.getCall(0).args[0].err.message).to.equal('node error');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('disabled in configure after being enabled', function () {
|
|
86
|
+
it('should not log when disabled', async function () {
|
|
87
|
+
const rollbar = new Rollbar({
|
|
88
|
+
accessToken: 'abc123',
|
|
89
|
+
captureUncaught: true,
|
|
90
|
+
});
|
|
91
|
+
const logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
92
|
+
|
|
93
|
+
await nodeThrow();
|
|
94
|
+
expect(logStub.called).to.be.true;
|
|
95
|
+
logStub.reset();
|
|
96
|
+
|
|
97
|
+
rollbar.configure({ captureUncaught: false });
|
|
98
|
+
await nodeThrow();
|
|
99
|
+
expect(logStub.called).to.be.false;
|
|
100
|
+
|
|
101
|
+
logStub.restore();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('disabled in constructor', function () {
|
|
106
|
+
it('should not log', async function () {
|
|
107
|
+
const rollbar = new Rollbar({
|
|
108
|
+
accessToken: 'abc123',
|
|
109
|
+
captureUncaught: false,
|
|
110
|
+
});
|
|
111
|
+
const logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
112
|
+
|
|
113
|
+
// Install a temporary handler to prevent test crash
|
|
114
|
+
const tempHandler = () => {};
|
|
115
|
+
process.on('uncaughtException', tempHandler);
|
|
116
|
+
|
|
117
|
+
await nodeThrow();
|
|
118
|
+
expect(logStub.called).to.be.false;
|
|
119
|
+
|
|
120
|
+
process.removeListener('uncaughtException', tempHandler);
|
|
121
|
+
logStub.restore();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('enabled in configure after being disabled', function () {
|
|
126
|
+
it('should log when enabled', async function () {
|
|
127
|
+
const rollbar = new Rollbar({
|
|
128
|
+
accessToken: 'abc123',
|
|
129
|
+
captureUncaught: false,
|
|
130
|
+
});
|
|
131
|
+
const logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
132
|
+
|
|
133
|
+
// Install a temporary handler to prevent test crash when disabled
|
|
134
|
+
const tempHandler = () => {};
|
|
135
|
+
process.on('uncaughtException', tempHandler);
|
|
136
|
+
|
|
137
|
+
await nodeThrow();
|
|
138
|
+
expect(logStub.called).to.be.false;
|
|
139
|
+
|
|
140
|
+
process.removeListener('uncaughtException', tempHandler);
|
|
141
|
+
|
|
142
|
+
rollbar.configure({ captureUncaught: true });
|
|
143
|
+
await nodeThrow();
|
|
144
|
+
expect(logStub.called).to.be.true;
|
|
145
|
+
expect(logStub.getCall(0).args[0].err.message).to.equal('node error');
|
|
146
|
+
|
|
147
|
+
logStub.restore();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('captureUnhandledRejections', function () {
|
|
153
|
+
let mochaHandlers;
|
|
154
|
+
|
|
155
|
+
beforeEach(function () {
|
|
156
|
+
// Remove Mocha's unhandled rejection handlers to prevent interference
|
|
157
|
+
mochaHandlers = process.listeners('unhandledRejection');
|
|
158
|
+
mochaHandlers.forEach((handler) => {
|
|
159
|
+
process.removeListener('unhandledRejection', handler);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
afterEach(function () {
|
|
164
|
+
// Restore Mocha's handlers
|
|
165
|
+
mochaHandlers.forEach((handler) => {
|
|
166
|
+
process.on('unhandledRejection', handler);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('enabled in constructor', function () {
|
|
171
|
+
it('should log', async function () {
|
|
172
|
+
const rollbar = new Rollbar({
|
|
173
|
+
accessToken: 'abc123',
|
|
174
|
+
captureUnhandledRejections: true,
|
|
175
|
+
});
|
|
176
|
+
const logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
177
|
+
|
|
178
|
+
await nodeReject();
|
|
179
|
+
|
|
180
|
+
expect(logStub.called).to.be.true;
|
|
181
|
+
expect(logStub.getCall(0).args[0].err.message).to.equal('node reject');
|
|
182
|
+
|
|
183
|
+
logStub.restore();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('disabled in configure after being enabled', function () {
|
|
188
|
+
it('should not log when disabled', async function () {
|
|
189
|
+
const rollbar = new Rollbar({
|
|
190
|
+
accessToken: 'abc123',
|
|
191
|
+
captureUnhandledRejections: true,
|
|
192
|
+
});
|
|
193
|
+
const logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
194
|
+
|
|
195
|
+
await nodeReject();
|
|
196
|
+
expect(logStub.called).to.be.true;
|
|
197
|
+
logStub.reset();
|
|
198
|
+
|
|
199
|
+
rollbar.configure({ captureUnhandledRejections: false });
|
|
200
|
+
await nodeReject();
|
|
201
|
+
expect(logStub.called).to.be.false;
|
|
202
|
+
|
|
203
|
+
logStub.restore();
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('disabled in constructor', function () {
|
|
208
|
+
it('should not log', async function () {
|
|
209
|
+
const rollbar = new Rollbar({
|
|
210
|
+
accessToken: 'abc123',
|
|
211
|
+
captureUnhandledRejections: false,
|
|
212
|
+
});
|
|
213
|
+
const logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
214
|
+
|
|
215
|
+
// Install a temporary handler to prevent test crash
|
|
216
|
+
const tempHandler = () => {};
|
|
217
|
+
process.on('unhandledRejection', tempHandler);
|
|
218
|
+
|
|
219
|
+
await nodeReject();
|
|
220
|
+
expect(logStub.called).to.be.false;
|
|
221
|
+
|
|
222
|
+
process.removeListener('unhandledRejection', tempHandler);
|
|
223
|
+
logStub.restore();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('enabled in configure after being disabled', function () {
|
|
228
|
+
it('should log when enabled', async function () {
|
|
229
|
+
const rollbar = new Rollbar({
|
|
230
|
+
accessToken: 'abc123',
|
|
231
|
+
captureUnhandledRejections: false,
|
|
232
|
+
});
|
|
233
|
+
const logStub = sinon.stub(rollbar.client.notifier, 'log');
|
|
234
|
+
|
|
235
|
+
// Install a temporary handler to prevent test crash when disabled
|
|
236
|
+
const tempHandler = () => {};
|
|
237
|
+
process.on('unhandledRejection', tempHandler);
|
|
238
|
+
|
|
239
|
+
await nodeReject();
|
|
240
|
+
expect(logStub.called).to.be.false;
|
|
241
|
+
|
|
242
|
+
process.removeListener('unhandledRejection', tempHandler);
|
|
243
|
+
|
|
244
|
+
rollbar.configure({ captureUnhandledRejections: true });
|
|
245
|
+
await nodeReject();
|
|
246
|
+
expect(logStub.called).to.be.true;
|
|
247
|
+
expect(logStub.getCall(0).args[0].err.message).to.equal('node reject');
|
|
248
|
+
|
|
249
|
+
logStub.restore();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|