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,326 @@
|
|
|
1
|
+
/* globals describe */
|
|
2
|
+
/* globals it */
|
|
3
|
+
/* globals beforeEach */
|
|
4
|
+
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
import Rollbar from '../src/server/rollbar.js';
|
|
8
|
+
import {
|
|
9
|
+
TestClient,
|
|
10
|
+
ValidOpenTracingTracerStub,
|
|
11
|
+
InvalidOpenTracingTracerStub,
|
|
12
|
+
DUMMY_TRACE_ID,
|
|
13
|
+
DUMMY_SPAN_ID,
|
|
14
|
+
} from './server.rollbar.test-utils.mjs';
|
|
15
|
+
|
|
16
|
+
describe('rollbar logging and tracing', function () {
|
|
17
|
+
describe('addTracingInfo', function () {
|
|
18
|
+
describe('with valid tracer', function () {
|
|
19
|
+
let rollbar;
|
|
20
|
+
|
|
21
|
+
beforeEach(function () {
|
|
22
|
+
rollbar = new Rollbar({
|
|
23
|
+
captureUncaught: true,
|
|
24
|
+
environment: 'fake-env',
|
|
25
|
+
tracer: ValidOpenTracingTracerStub,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should add trace ID and span ID to custom field on item if no custom field set', function () {
|
|
30
|
+
const item = { uuid: 'some-uuid', custom: null };
|
|
31
|
+
rollbar.client._addTracingInfo(item);
|
|
32
|
+
expect(item.custom.opentracing_trace_id).to.equal(DUMMY_TRACE_ID);
|
|
33
|
+
expect(item.custom.opentracing_span_id).to.equal(DUMMY_SPAN_ID);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should add trace ID and span ID to custom field on item even if already has some custom fields', function () {
|
|
37
|
+
const item = { uuid: 'some-uuid', custom: { foo: 'foo' } };
|
|
38
|
+
rollbar.client._addTracingInfo(item);
|
|
39
|
+
expect(item.custom.opentracing_trace_id).to.equal(DUMMY_TRACE_ID);
|
|
40
|
+
expect(item.custom.opentracing_span_id).to.equal(DUMMY_SPAN_ID);
|
|
41
|
+
expect(item.custom.foo).to.equal('foo');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('with invalid tracer', function () {
|
|
46
|
+
it('should add trace ID and span ID to custom field on item', function () {
|
|
47
|
+
const rollbar = new Rollbar({
|
|
48
|
+
captureUncaught: true,
|
|
49
|
+
environment: 'fake-env',
|
|
50
|
+
tracer: InvalidOpenTracingTracerStub,
|
|
51
|
+
});
|
|
52
|
+
const item = { uuid: 'some-uuid', custom: {} };
|
|
53
|
+
rollbar.client._addTracingInfo(item);
|
|
54
|
+
expect(item.custom.opentracing_trace_id).to.be.undefined;
|
|
55
|
+
expect(item.custom.opentracing_span_id).to.be.undefined;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('log', function () {
|
|
61
|
+
describe('message', function () {
|
|
62
|
+
let rollbar;
|
|
63
|
+
let client;
|
|
64
|
+
|
|
65
|
+
beforeEach(function () {
|
|
66
|
+
client = new TestClient();
|
|
67
|
+
rollbar = new Rollbar({ accessToken: 'abc123' }, client);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('unordered options', function () {
|
|
71
|
+
it('should work with custom, request, callback and message', function () {
|
|
72
|
+
const custom = { a: 1, b: 2 };
|
|
73
|
+
const request = { method: 'GET' };
|
|
74
|
+
const callback = sinon.stub();
|
|
75
|
+
const message = 'hello world';
|
|
76
|
+
rollbar.log(custom, request, callback, message);
|
|
77
|
+
|
|
78
|
+
const item = rollbar.client.logCalls[0].item;
|
|
79
|
+
expect(item.custom).to.deep.equal(custom);
|
|
80
|
+
expect(item.request).to.deep.equal(request);
|
|
81
|
+
expect(item.message).to.equal(message);
|
|
82
|
+
|
|
83
|
+
item.callback();
|
|
84
|
+
expect(callback.calledOnce).to.be.true;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('old option ordering', function () {
|
|
89
|
+
it('should work with message only', function () {
|
|
90
|
+
rollbar.log('hello world');
|
|
91
|
+
expect(client.logCalls[0].item.message).to.equal('hello world');
|
|
92
|
+
expect(client.logCalls[0].func).to.equal('log');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should work with message and null or undefined', function () {
|
|
96
|
+
rollbar.log('hello world');
|
|
97
|
+
expect(client.logCalls[0].item.message).to.equal('hello world');
|
|
98
|
+
expect(client.logCalls[0].func).to.equal('log');
|
|
99
|
+
|
|
100
|
+
rollbar.log('world hello', null);
|
|
101
|
+
expect(client.logCalls[1].item.message).to.equal('world hello');
|
|
102
|
+
expect(client.logCalls[1].func).to.equal('log');
|
|
103
|
+
|
|
104
|
+
rollbar.log('olleh dlrow', undefined);
|
|
105
|
+
expect(client.logCalls[2].item.message).to.equal('olleh dlrow');
|
|
106
|
+
expect(client.logCalls[2].func).to.equal('log');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should work with message and callback', function () {
|
|
110
|
+
const callback = sinon.stub();
|
|
111
|
+
rollbar.log('hello world', callback);
|
|
112
|
+
|
|
113
|
+
const item = client.logCalls[0].item;
|
|
114
|
+
expect(item.message).to.equal('hello world');
|
|
115
|
+
|
|
116
|
+
item.callback();
|
|
117
|
+
expect(callback.calledOnce).to.be.true;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should work with message and request', function () {
|
|
121
|
+
const request = { method: 'GET' };
|
|
122
|
+
rollbar.log('hello world', request);
|
|
123
|
+
|
|
124
|
+
const item = client.logCalls[0].item;
|
|
125
|
+
expect(item.message).to.equal('hello world');
|
|
126
|
+
expect(item.request).to.deep.equal(request);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should work with message, request and callback', function () {
|
|
130
|
+
const request = { method: 'GET' };
|
|
131
|
+
const callback = sinon.stub();
|
|
132
|
+
rollbar.log('hello world', request, callback);
|
|
133
|
+
|
|
134
|
+
const item = client.logCalls[0].item;
|
|
135
|
+
expect(item.message).to.equal('hello world');
|
|
136
|
+
expect(item.request).to.deep.equal(request);
|
|
137
|
+
|
|
138
|
+
item.callback();
|
|
139
|
+
expect(callback.calledOnce).to.be.true;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should work with message, request and custom', function () {
|
|
143
|
+
const request = { method: 'GET' };
|
|
144
|
+
const custom = { a: 1, b: 2 };
|
|
145
|
+
rollbar.log('hello world', request, custom);
|
|
146
|
+
|
|
147
|
+
const item = client.logCalls[0].item;
|
|
148
|
+
expect(item.message).to.equal('hello world');
|
|
149
|
+
expect(item.request).to.deep.equal(request);
|
|
150
|
+
expect(item.custom).to.deep.equal(custom);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('should work with message, request, custom and callback', function () {
|
|
154
|
+
const request = { method: 'GET' };
|
|
155
|
+
const custom = { a: 1, b: 2 };
|
|
156
|
+
const callback = sinon.stub();
|
|
157
|
+
rollbar.log('hello world', request, custom, callback);
|
|
158
|
+
|
|
159
|
+
const item = client.logCalls[0].item;
|
|
160
|
+
expect(item.message).to.equal('hello world');
|
|
161
|
+
expect(item.request).to.deep.equal(request);
|
|
162
|
+
expect(item.custom).to.deep.equal(custom);
|
|
163
|
+
|
|
164
|
+
item.callback();
|
|
165
|
+
expect(callback.calledOnce).to.be.true;
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('info', function () {
|
|
171
|
+
let rollbar;
|
|
172
|
+
let addItemStub;
|
|
173
|
+
|
|
174
|
+
beforeEach(function () {
|
|
175
|
+
// Uses real client and stubs queue.addItem so transforms can run.
|
|
176
|
+
rollbar = new Rollbar({
|
|
177
|
+
accessToken: 'abc123',
|
|
178
|
+
captureUncaught: false,
|
|
179
|
+
});
|
|
180
|
+
addItemStub = sinon.stub(rollbar.client.notifier.queue, 'addItem');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
afterEach(function () {
|
|
184
|
+
addItemStub.restore();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should send message when called with null or undefined', function () {
|
|
188
|
+
rollbar.info();
|
|
189
|
+
expect(addItemStub.calledOnce).to.be.true;
|
|
190
|
+
expect(addItemStub.getCall(0).args[3].data.body.message.body).to.equal(
|
|
191
|
+
'Item sent with null or missing arguments.',
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
rollbar.info(null);
|
|
195
|
+
expect(addItemStub.calledTwice).to.be.true;
|
|
196
|
+
expect(addItemStub.getCall(1).args[3].data.body.message.body).to.equal(
|
|
197
|
+
'Item sent with null or missing arguments.',
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
rollbar.info(undefined);
|
|
201
|
+
expect(addItemStub.calledThrice).to.be.true;
|
|
202
|
+
expect(addItemStub.getCall(2).args[3].data.body.message.body).to.equal(
|
|
203
|
+
'Item sent with null or missing arguments.',
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('error', function () {
|
|
209
|
+
let rollbar;
|
|
210
|
+
let client;
|
|
211
|
+
|
|
212
|
+
beforeEach(function () {
|
|
213
|
+
client = new TestClient();
|
|
214
|
+
rollbar = new Rollbar({ accessToken: 'abc123' }, client);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('unordered options', function () {
|
|
218
|
+
it('should work with custom, request, callback and error', function () {
|
|
219
|
+
const custom = { a: 1, b: 2 };
|
|
220
|
+
const request = { method: 'GET' };
|
|
221
|
+
const callback = sinon.stub();
|
|
222
|
+
const error = new Error('hello world');
|
|
223
|
+
rollbar.log(custom, request, callback, error);
|
|
224
|
+
|
|
225
|
+
const item = rollbar.client.logCalls[0].item;
|
|
226
|
+
expect(item.custom).to.deep.equal(custom);
|
|
227
|
+
expect(item.request).to.deep.equal(request);
|
|
228
|
+
expect(item.err).to.equal(error);
|
|
229
|
+
|
|
230
|
+
item.callback();
|
|
231
|
+
expect(callback.calledOnce).to.be.true;
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('old option ordering', function () {
|
|
236
|
+
it('should work with error only', function () {
|
|
237
|
+
const error = new Error('hello world');
|
|
238
|
+
rollbar.log(error);
|
|
239
|
+
expect(client.logCalls[0].item.err).to.equal(error);
|
|
240
|
+
expect(client.logCalls[0].func).to.equal('log');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('should work with error and null or undefined', function () {
|
|
244
|
+
let error = new Error('hello world');
|
|
245
|
+
rollbar.log(error);
|
|
246
|
+
expect(client.logCalls[0].item.err).to.equal(error);
|
|
247
|
+
expect(client.logCalls[0].item.err.message).to.equal('hello world');
|
|
248
|
+
|
|
249
|
+
error = new Error('world hello');
|
|
250
|
+
rollbar.log(error, null);
|
|
251
|
+
expect(client.logCalls[1].item.err).to.equal(error);
|
|
252
|
+
expect(client.logCalls[1].item.err.message).to.equal('world hello');
|
|
253
|
+
|
|
254
|
+
error = new Error('olleh dlrow');
|
|
255
|
+
rollbar.log(error, undefined);
|
|
256
|
+
expect(client.logCalls[2].item.err).to.equal(error);
|
|
257
|
+
expect(client.logCalls[2].item.err.message).to.equal('olleh dlrow');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should work with error and callback', function () {
|
|
261
|
+
const error = new Error('hello world');
|
|
262
|
+
const callback = sinon.stub();
|
|
263
|
+
rollbar.log(error, callback);
|
|
264
|
+
|
|
265
|
+
const item = client.logCalls[0].item;
|
|
266
|
+
expect(item.err).to.equal(error);
|
|
267
|
+
|
|
268
|
+
item.callback();
|
|
269
|
+
expect(callback.calledOnce).to.be.true;
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('should work with message and request', function () {
|
|
273
|
+
const error = new Error('hello world');
|
|
274
|
+
const request = { method: 'GET' };
|
|
275
|
+
rollbar.log(error, request);
|
|
276
|
+
|
|
277
|
+
const item = client.logCalls[0].item;
|
|
278
|
+
expect(item.err).to.equal(error);
|
|
279
|
+
expect(item.request).to.deep.equal(request);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('should work with message, request and callback', function () {
|
|
283
|
+
const error = new Error('hello world');
|
|
284
|
+
const request = { method: 'GET' };
|
|
285
|
+
const callback = sinon.stub();
|
|
286
|
+
rollbar.log(error, request, callback);
|
|
287
|
+
|
|
288
|
+
const item = client.logCalls[0].item;
|
|
289
|
+
expect(item.err).to.equal(error);
|
|
290
|
+
expect(item.request).to.deep.equal(request);
|
|
291
|
+
|
|
292
|
+
item.callback();
|
|
293
|
+
expect(callback.calledOnce).to.be.true;
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('should work with message, request and custom', function () {
|
|
297
|
+
const error = new Error('hello world');
|
|
298
|
+
const request = { method: 'GET' };
|
|
299
|
+
const custom = { a: 1, b: 2 };
|
|
300
|
+
rollbar.log(error, request, custom);
|
|
301
|
+
|
|
302
|
+
const item = client.logCalls[0].item;
|
|
303
|
+
expect(item.err).to.equal(error);
|
|
304
|
+
expect(item.request).to.deep.equal(request);
|
|
305
|
+
expect(item.custom).to.deep.equal(custom);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('should work with message, request, custom and callback', function () {
|
|
309
|
+
const error = new Error('hello world');
|
|
310
|
+
const request = { method: 'GET' };
|
|
311
|
+
const custom = { a: 1, b: 2 };
|
|
312
|
+
const callback = sinon.stub();
|
|
313
|
+
rollbar.log(error, request, custom, callback);
|
|
314
|
+
|
|
315
|
+
const item = client.logCalls[0].item;
|
|
316
|
+
expect(item.err).to.equal(error);
|
|
317
|
+
expect(item.request).to.deep.equal(request);
|
|
318
|
+
expect(item.custom).to.deep.equal(custom);
|
|
319
|
+
|
|
320
|
+
item.callback();
|
|
321
|
+
expect(callback.calledOnce).to.be.true;
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* globals describe */
|
|
2
|
+
/* globals it */
|
|
3
|
+
|
|
4
|
+
import { expect } from 'chai';
|
|
5
|
+
import Rollbar from '../src/server/rollbar.js';
|
|
6
|
+
import { TestClient } from './server.rollbar.test-utils.mjs';
|
|
7
|
+
|
|
8
|
+
describe('rollbar miscellaneous methods', function () {
|
|
9
|
+
describe('buildJsonPayload', function () {
|
|
10
|
+
it('should pass the object through to the client', function () {
|
|
11
|
+
const client = new TestClient();
|
|
12
|
+
const rollbar = new Rollbar({ accessToken: 'abc123' }, client);
|
|
13
|
+
const obj = { hello: 'world' };
|
|
14
|
+
|
|
15
|
+
rollbar.buildJsonPayload(obj);
|
|
16
|
+
|
|
17
|
+
expect(client.logCalls.length).to.equal(1);
|
|
18
|
+
expect(client.logCalls[0].item).to.equal(obj);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('sendJsonPayload', function () {
|
|
23
|
+
it('should pass the json string through to the client', function () {
|
|
24
|
+
const client = new TestClient();
|
|
25
|
+
const rollbar = new Rollbar({ accessToken: 'abc123' }, client);
|
|
26
|
+
const json = JSON.stringify({ hello: 'world' });
|
|
27
|
+
|
|
28
|
+
rollbar.sendJsonPayload(json);
|
|
29
|
+
|
|
30
|
+
expect(client.logCalls.length).to.equal(1);
|
|
31
|
+
expect(client.logCalls[0].item).to.equal(json);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('singleton', function () {
|
|
36
|
+
it('should work like a constructor but with an init method', function () {
|
|
37
|
+
const r = Rollbar.init({ accessToken: 'abc123' });
|
|
38
|
+
|
|
39
|
+
expect(r.log).to.be.a('function');
|
|
40
|
+
expect(r.options.accessToken).to.equal('abc123');
|
|
41
|
+
expect(Rollbar.log).to.be.a('function');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common test utilities for server rollbar tests
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const DUMMY_TRACE_ID = 'some-trace-id';
|
|
6
|
+
export const DUMMY_SPAN_ID = 'some-span-id';
|
|
7
|
+
|
|
8
|
+
export const ValidOpenTracingTracerStub = {
|
|
9
|
+
scope: () => ({
|
|
10
|
+
active: () => ({
|
|
11
|
+
setTag: () => {},
|
|
12
|
+
context: () => ({
|
|
13
|
+
toTraceId: () => DUMMY_TRACE_ID,
|
|
14
|
+
toSpanId: () => DUMMY_SPAN_ID,
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const InvalidOpenTracingTracerStub = {
|
|
21
|
+
foo: () => {},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export class TestClient {
|
|
25
|
+
logCalls = [];
|
|
26
|
+
tracer = ValidOpenTracingTracerStub;
|
|
27
|
+
|
|
28
|
+
notifier = {
|
|
29
|
+
addTransform: () => this.notifier,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
queue = {
|
|
33
|
+
addPredicate: () => this.queue,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
constructor() {
|
|
37
|
+
['log', 'debug', 'info', 'warn', 'warning', 'error', 'critical'].forEach(
|
|
38
|
+
(logLevel) => {
|
|
39
|
+
this[logLevel] = (item) => {
|
|
40
|
+
this.logCalls.push({ func: logLevel, item });
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
buildJsonPayload(obj) {
|
|
47
|
+
this.logCalls.push({ item: obj });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
sendJsonPayload(json) {
|
|
51
|
+
this.logCalls.push({ item: json });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
clearLogCalls() {
|
|
55
|
+
this.logCalls = [];
|
|
56
|
+
}
|
|
57
|
+
}
|