rollbar 2.26.2 → 2.26.4
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/.github/workflows/ci.yml +32 -10
- package/.lgtm.yml +7 -7
- package/.prettierignore +18 -0
- package/.vscode/settings.json +39 -0
- package/CHANGELOG.md +121 -35
- package/Gruntfile.js +51 -71
- package/README.md +2 -4
- package/bower.json +1 -3
- package/defaults.js +17 -5
- package/dist/plugins/jquery.min.js +1 -1
- package/dist/rollbar.js +5699 -5052
- package/dist/rollbar.js.map +1 -1
- package/dist/rollbar.min.js +1 -1
- package/dist/rollbar.min.js.map +1 -1
- package/dist/rollbar.named-amd.js +5704 -5062
- package/dist/rollbar.named-amd.js.map +1 -1
- package/dist/rollbar.named-amd.min.js +1 -1
- package/dist/rollbar.named-amd.min.js.map +1 -1
- package/dist/rollbar.noconflict.umd.js +5693 -5052
- package/dist/rollbar.noconflict.umd.js.map +1 -1
- package/dist/rollbar.noconflict.umd.min.js +1 -1
- package/dist/rollbar.noconflict.umd.min.js.map +1 -1
- package/dist/rollbar.snippet.js +1 -1
- package/dist/rollbar.umd.js +5704 -5063
- package/dist/rollbar.umd.js.map +1 -1
- package/dist/rollbar.umd.min.js +1 -1
- package/dist/rollbar.umd.min.js.map +1 -1
- package/docs/extension-exceptions.md +35 -30
- package/docs/migration_v0_to_v1.md +41 -38
- package/index.d.ts +270 -231
- package/karma.conf.js +16 -34
- package/package.json +21 -17
- package/prettier.config.js +7 -0
- package/src/api.js +21 -10
- package/src/apiUtility.js +12 -8
- package/src/browser/core.js +103 -65
- package/src/browser/defaults/scrubFields.js +3 -3
- package/src/browser/detection.js +7 -8
- package/src/browser/domUtility.js +18 -8
- package/src/browser/globalSetup.js +12 -6
- package/src/browser/logger.js +1 -1
- package/src/browser/plugins/jquery.js +35 -35
- package/src/browser/predicates.js +1 -1
- package/src/browser/rollbar.js +1 -1
- package/src/browser/rollbarWrapper.js +8 -5
- package/src/browser/shim.js +43 -19
- package/src/browser/snippet_callback.js +6 -4
- package/src/browser/telemetry.js +573 -354
- package/src/browser/transforms.js +46 -27
- package/src/browser/transport/fetch.js +16 -14
- package/src/browser/transport/xhr.js +29 -13
- package/src/browser/transport.js +82 -25
- package/src/browser/url.js +16 -8
- package/src/browser/wrapGlobals.js +27 -8
- package/src/defaults.js +3 -3
- package/src/errorParser.js +14 -11
- package/src/merge.js +32 -23
- package/src/notifier.js +16 -13
- package/src/predicates.js +43 -23
- package/src/queue.js +71 -39
- package/src/rateLimiter.js +59 -18
- package/src/react-native/logger.js +1 -1
- package/src/react-native/rollbar.js +59 -55
- package/src/react-native/transforms.js +13 -9
- package/src/react-native/transport.js +44 -34
- package/src/rollbar.js +22 -13
- package/src/scrub.js +0 -1
- package/src/server/locals.js +69 -39
- package/src/server/logger.js +4 -4
- package/src/server/parser.js +72 -47
- package/src/server/rollbar.js +133 -55
- package/src/server/sourceMap/stackTrace.js +33 -18
- package/src/server/telemetry/urlHelpers.js +9 -11
- package/src/server/telemetry.js +68 -45
- package/src/server/transforms.js +37 -21
- package/src/server/transport.js +62 -32
- package/src/telemetry.js +92 -28
- package/src/transforms.js +33 -21
- package/src/truncation.js +8 -5
- package/src/utility/headers.js +43 -43
- package/src/utility/replace.js +9 -0
- package/src/utility/traverse.js +1 -1
- package/src/utility.js +89 -52
- package/test/api.test.js +31 -29
- package/test/apiUtility.test.js +43 -44
- package/test/browser.core.test.js +141 -131
- package/test/browser.domUtility.test.js +52 -35
- package/test/browser.predicates.test.js +13 -13
- package/test/browser.rollbar.test.js +597 -503
- package/test/browser.telemetry.test.js +76 -0
- package/test/browser.transforms.test.js +146 -128
- package/test/browser.transport.test.js +54 -46
- package/test/browser.url.test.js +12 -11
- package/test/fixtures/locals.fixtures.js +245 -126
- package/test/notifier.test.js +90 -78
- package/test/predicates.test.js +260 -214
- package/test/queue.test.js +230 -214
- package/test/rateLimiter.test.js +50 -42
- package/test/react-native.rollbar.test.js +149 -115
- package/test/react-native.transforms.test.js +21 -23
- package/test/react-native.transport.test.js +23 -11
- package/test/server.lambda.test.js +70 -53
- package/test/server.locals.test.js +437 -210
- package/test/server.parser.test.js +32 -26
- package/test/server.predicates.test.js +45 -43
- package/test/server.rollbar.test.js +311 -259
- package/test/server.telemetry.test.js +208 -83
- package/test/server.transforms.test.js +455 -361
- package/test/server.transport.test.js +144 -76
- package/test/telemetry.test.js +46 -37
- package/test/transforms.test.js +68 -66
- package/test/truncation.test.js +55 -53
- package/test/utility.test.js +266 -222
- package/webpack.config.js +46 -43
- package/.gitmodules +0 -3
- package/browserstack.browsers.js +0 -153
- package/browserstack.browsers.json +0 -4384
package/src/utility.js
CHANGED
|
@@ -8,14 +8,15 @@ function setupJSON(polyfillJSON) {
|
|
|
8
8
|
|
|
9
9
|
if (isDefined(JSON)) {
|
|
10
10
|
// If polyfill is provided, prefer it over existing non-native shims.
|
|
11
|
-
if(polyfillJSON) {
|
|
11
|
+
if (polyfillJSON) {
|
|
12
12
|
if (isNativeFunction(JSON.stringify)) {
|
|
13
13
|
RollbarJSON.stringify = JSON.stringify;
|
|
14
14
|
}
|
|
15
15
|
if (isNativeFunction(JSON.parse)) {
|
|
16
16
|
RollbarJSON.parse = JSON.parse;
|
|
17
17
|
}
|
|
18
|
-
} else {
|
|
18
|
+
} else {
|
|
19
|
+
// else accept any interface that is present.
|
|
19
20
|
if (isFunction(JSON.stringify)) {
|
|
20
21
|
RollbarJSON.stringify = JSON.stringify;
|
|
21
22
|
}
|
|
@@ -65,7 +66,10 @@ function typeName(x) {
|
|
|
65
66
|
if (x instanceof Error) {
|
|
66
67
|
return 'error';
|
|
67
68
|
}
|
|
68
|
-
return
|
|
69
|
+
return {}.toString
|
|
70
|
+
.call(x)
|
|
71
|
+
.match(/\s([a-zA-Z]+)/)[1]
|
|
72
|
+
.toLowerCase();
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/* isFunction - a convenience function for checking if a value is a function
|
|
@@ -84,7 +88,8 @@ function isFunction(f) {
|
|
|
84
88
|
*/
|
|
85
89
|
function isNativeFunction(f) {
|
|
86
90
|
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
87
|
-
var funcMatchString = Function.prototype.toString
|
|
91
|
+
var funcMatchString = Function.prototype.toString
|
|
92
|
+
.call(Object.prototype.hasOwnProperty)
|
|
88
93
|
.replace(reRegExpChar, '\\$&')
|
|
89
94
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?');
|
|
90
95
|
var reIsNative = RegExp('^' + funcMatchString + '$');
|
|
@@ -95,7 +100,7 @@ function isNativeFunction(f) {
|
|
|
95
100
|
*
|
|
96
101
|
* @param value - any value
|
|
97
102
|
* @returns true is value is an object function is an object)
|
|
98
|
-
*/
|
|
103
|
+
*/
|
|
99
104
|
function isObject(value) {
|
|
100
105
|
var type = typeof value;
|
|
101
106
|
return value != null && (type == 'object' || type == 'function');
|
|
@@ -105,9 +110,9 @@ function isObject(value) {
|
|
|
105
110
|
*
|
|
106
111
|
* @param value - any value
|
|
107
112
|
* @returns true if value is a string
|
|
108
|
-
*/
|
|
113
|
+
*/
|
|
109
114
|
function isString(value) {
|
|
110
|
-
return typeof value === 'string' || value instanceof String
|
|
115
|
+
return typeof value === 'string' || value instanceof String;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
/**
|
|
@@ -116,7 +121,7 @@ function isString(value) {
|
|
|
116
121
|
* @param {*} n - any value
|
|
117
122
|
* @returns true if value is a finite number
|
|
118
123
|
*/
|
|
119
|
-
|
|
124
|
+
function isFiniteNumber(n) {
|
|
120
125
|
return Number.isFinite(n);
|
|
121
126
|
}
|
|
122
127
|
|
|
@@ -139,7 +144,7 @@ function isDefined(u) {
|
|
|
139
144
|
*/
|
|
140
145
|
function isIterable(i) {
|
|
141
146
|
var type = typeName(i);
|
|
142
|
-
return
|
|
147
|
+
return type === 'object' || type === 'array';
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
/*
|
|
@@ -169,11 +174,14 @@ function redact() {
|
|
|
169
174
|
// from http://stackoverflow.com/a/8809472/1138191
|
|
170
175
|
function uuid4() {
|
|
171
176
|
var d = now();
|
|
172
|
-
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
|
|
178
|
+
/[xy]/g,
|
|
179
|
+
function (c) {
|
|
180
|
+
var r = (d + Math.random() * 16) % 16 | 0;
|
|
181
|
+
d = Math.floor(d / 16);
|
|
182
|
+
return (c === 'x' ? r : (r & 0x7) | 0x8).toString(16);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
177
185
|
return uuid;
|
|
178
186
|
}
|
|
179
187
|
|
|
@@ -182,7 +190,7 @@ var LEVELS = {
|
|
|
182
190
|
info: 1,
|
|
183
191
|
warning: 2,
|
|
184
192
|
error: 3,
|
|
185
|
-
critical: 4
|
|
193
|
+
critical: 4,
|
|
186
194
|
};
|
|
187
195
|
|
|
188
196
|
function sanitizeUrl(url) {
|
|
@@ -216,16 +224,18 @@ var parseUriOptions = {
|
|
|
216
224
|
'directory',
|
|
217
225
|
'file',
|
|
218
226
|
'query',
|
|
219
|
-
'anchor'
|
|
227
|
+
'anchor',
|
|
220
228
|
],
|
|
221
229
|
q: {
|
|
222
230
|
name: 'queryKey',
|
|
223
|
-
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
|
|
231
|
+
parser: /(?:^|&)([^&=]*)=?([^&]*)/g,
|
|
224
232
|
},
|
|
225
233
|
parser: {
|
|
226
|
-
strict:
|
|
227
|
-
|
|
228
|
-
|
|
234
|
+
strict:
|
|
235
|
+
/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
236
|
+
loose:
|
|
237
|
+
/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
238
|
+
},
|
|
229
239
|
};
|
|
230
240
|
|
|
231
241
|
function parseUri(str) {
|
|
@@ -270,11 +280,11 @@ function addParamsAndAccessTokenToPath(accessToken, options, params) {
|
|
|
270
280
|
var p;
|
|
271
281
|
if (qs !== -1 && (h === -1 || h > qs)) {
|
|
272
282
|
p = options.path;
|
|
273
|
-
options.path = p.substring(0,qs) + query + '&' + p.substring(qs+1);
|
|
283
|
+
options.path = p.substring(0, qs) + query + '&' + p.substring(qs + 1);
|
|
274
284
|
} else {
|
|
275
285
|
if (h !== -1) {
|
|
276
286
|
p = options.path;
|
|
277
|
-
options.path = p.substring(0,h) + query + p.substring(h);
|
|
287
|
+
options.path = p.substring(0, h) + query + p.substring(h);
|
|
278
288
|
} else {
|
|
279
289
|
options.path = options.path + query;
|
|
280
290
|
}
|
|
@@ -320,7 +330,7 @@ function stringify(obj, backup) {
|
|
|
320
330
|
error = jsonError;
|
|
321
331
|
}
|
|
322
332
|
}
|
|
323
|
-
return {error: error, value: value};
|
|
333
|
+
return { error: error, value: value };
|
|
324
334
|
}
|
|
325
335
|
|
|
326
336
|
function maxByteSize(string) {
|
|
@@ -338,11 +348,14 @@ function maxByteSize(string) {
|
|
|
338
348
|
|
|
339
349
|
for (var i = 0; i < length; i++) {
|
|
340
350
|
var code = string.charCodeAt(i);
|
|
341
|
-
if (code < 128) {
|
|
351
|
+
if (code < 128) {
|
|
352
|
+
// up to 7 bits
|
|
342
353
|
count = count + 1;
|
|
343
|
-
} else if (code < 2048) {
|
|
354
|
+
} else if (code < 2048) {
|
|
355
|
+
// up to 11 bits
|
|
344
356
|
count = count + 2;
|
|
345
|
-
} else if (code < 65536) {
|
|
357
|
+
} else if (code < 65536) {
|
|
358
|
+
// up to 16 bits
|
|
346
359
|
count = count + 3;
|
|
347
360
|
}
|
|
348
361
|
}
|
|
@@ -357,7 +370,7 @@ function jsonParse(s) {
|
|
|
357
370
|
} catch (e) {
|
|
358
371
|
error = e;
|
|
359
372
|
}
|
|
360
|
-
return {error: error, value: value};
|
|
373
|
+
return { error: error, value: value };
|
|
361
374
|
}
|
|
362
375
|
|
|
363
376
|
function makeUnhandledStackInfo(
|
|
@@ -368,28 +381,36 @@ function makeUnhandledStackInfo(
|
|
|
368
381
|
error,
|
|
369
382
|
mode,
|
|
370
383
|
backupMessage,
|
|
371
|
-
errorParser
|
|
384
|
+
errorParser,
|
|
372
385
|
) {
|
|
373
386
|
var location = {
|
|
374
387
|
url: url || '',
|
|
375
388
|
line: lineno,
|
|
376
|
-
column: colno
|
|
389
|
+
column: colno,
|
|
377
390
|
};
|
|
378
391
|
location.func = errorParser.guessFunctionName(location.url, location.line);
|
|
379
392
|
location.context = errorParser.gatherContext(location.url, location.line);
|
|
380
|
-
var href =
|
|
381
|
-
|
|
393
|
+
var href =
|
|
394
|
+
typeof document !== 'undefined' &&
|
|
395
|
+
document &&
|
|
396
|
+
document.location &&
|
|
397
|
+
document.location.href;
|
|
398
|
+
var useragent =
|
|
399
|
+
typeof window !== 'undefined' &&
|
|
400
|
+
window &&
|
|
401
|
+
window.navigator &&
|
|
402
|
+
window.navigator.userAgent;
|
|
382
403
|
return {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
404
|
+
mode: mode,
|
|
405
|
+
message: error ? String(error) : message || backupMessage,
|
|
406
|
+
url: href,
|
|
407
|
+
stack: [location],
|
|
408
|
+
useragent: useragent,
|
|
388
409
|
};
|
|
389
410
|
}
|
|
390
411
|
|
|
391
412
|
function wrapCallback(logger, f) {
|
|
392
|
-
return function(err, resp) {
|
|
413
|
+
return function (err, resp) {
|
|
393
414
|
try {
|
|
394
415
|
f(err, resp);
|
|
395
416
|
} catch (e) {
|
|
@@ -402,7 +423,10 @@ function nonCircularClone(obj) {
|
|
|
402
423
|
var seen = [obj];
|
|
403
424
|
|
|
404
425
|
function clone(obj, seen) {
|
|
405
|
-
var value,
|
|
426
|
+
var value,
|
|
427
|
+
name,
|
|
428
|
+
newSeen,
|
|
429
|
+
result = {};
|
|
406
430
|
|
|
407
431
|
try {
|
|
408
432
|
for (name in obj) {
|
|
@@ -445,7 +469,7 @@ function createItem(args, logger, notifier, requestKeys, lambdaContext) {
|
|
|
445
469
|
case 'undefined':
|
|
446
470
|
break;
|
|
447
471
|
case 'string':
|
|
448
|
-
message ? extraArgs.push(arg) : message = arg;
|
|
472
|
+
message ? extraArgs.push(arg) : (message = arg);
|
|
449
473
|
break;
|
|
450
474
|
case 'function':
|
|
451
475
|
callback = wrapCallback(logger, arg);
|
|
@@ -456,12 +480,15 @@ function createItem(args, logger, notifier, requestKeys, lambdaContext) {
|
|
|
456
480
|
case 'error':
|
|
457
481
|
case 'domexception':
|
|
458
482
|
case 'exception': // Firefox Exception type
|
|
459
|
-
err ? extraArgs.push(arg) : err = arg;
|
|
483
|
+
err ? extraArgs.push(arg) : (err = arg);
|
|
460
484
|
break;
|
|
461
485
|
case 'object':
|
|
462
486
|
case 'array':
|
|
463
|
-
if (
|
|
464
|
-
|
|
487
|
+
if (
|
|
488
|
+
arg instanceof Error ||
|
|
489
|
+
(typeof DOMException !== 'undefined' && arg instanceof DOMException)
|
|
490
|
+
) {
|
|
491
|
+
err ? extraArgs.push(arg) : (err = arg);
|
|
465
492
|
break;
|
|
466
493
|
}
|
|
467
494
|
if (requestKeys && typ === 'object' && !request) {
|
|
@@ -475,11 +502,14 @@ function createItem(args, logger, notifier, requestKeys, lambdaContext) {
|
|
|
475
502
|
break;
|
|
476
503
|
}
|
|
477
504
|
}
|
|
478
|
-
custom ? extraArgs.push(arg) : custom = arg;
|
|
505
|
+
custom ? extraArgs.push(arg) : (custom = arg);
|
|
479
506
|
break;
|
|
480
507
|
default:
|
|
481
|
-
if (
|
|
482
|
-
|
|
508
|
+
if (
|
|
509
|
+
arg instanceof Error ||
|
|
510
|
+
(typeof DOMException !== 'undefined' && arg instanceof DOMException)
|
|
511
|
+
) {
|
|
512
|
+
err ? extraArgs.push(arg) : (err = arg);
|
|
483
513
|
break;
|
|
484
514
|
}
|
|
485
515
|
extraArgs.push(arg);
|
|
@@ -502,7 +532,7 @@ function createItem(args, logger, notifier, requestKeys, lambdaContext) {
|
|
|
502
532
|
callback: callback,
|
|
503
533
|
notifier: notifier,
|
|
504
534
|
diagnostic: diagnostic,
|
|
505
|
-
uuid: uuid4()
|
|
535
|
+
uuid: uuid4(),
|
|
506
536
|
};
|
|
507
537
|
|
|
508
538
|
setCustomItemKeys(item, custom);
|
|
@@ -550,7 +580,14 @@ function addErrorContext(item, errors) {
|
|
|
550
580
|
}
|
|
551
581
|
}
|
|
552
582
|
|
|
553
|
-
var TELEMETRY_TYPES = [
|
|
583
|
+
var TELEMETRY_TYPES = [
|
|
584
|
+
'log',
|
|
585
|
+
'network',
|
|
586
|
+
'dom',
|
|
587
|
+
'navigation',
|
|
588
|
+
'error',
|
|
589
|
+
'manual',
|
|
590
|
+
];
|
|
554
591
|
var TELEMETRY_LEVELS = ['critical', 'error', 'warning', 'info', 'debug'];
|
|
555
592
|
|
|
556
593
|
function arrayIncludes(arr, val) {
|
|
@@ -589,7 +626,7 @@ function createTelemetryEvent(args) {
|
|
|
589
626
|
var event = {
|
|
590
627
|
type: type || 'manual',
|
|
591
628
|
metadata: metadata || {},
|
|
592
|
-
level: level
|
|
629
|
+
level: level,
|
|
593
630
|
};
|
|
594
631
|
|
|
595
632
|
return event;
|
|
@@ -639,7 +676,7 @@ function set(obj, path, value) {
|
|
|
639
676
|
temp[keys[i]] = temp[keys[i]] || {};
|
|
640
677
|
temp = temp[keys[i]];
|
|
641
678
|
}
|
|
642
|
-
temp[keys[len-1]] = value;
|
|
679
|
+
temp[keys[len - 1]] = value;
|
|
643
680
|
obj[keys[0]] = replacement;
|
|
644
681
|
} catch (e) {
|
|
645
682
|
return;
|
|
@@ -730,12 +767,12 @@ function handleOptions(current, input, payload, logger) {
|
|
|
730
767
|
}
|
|
731
768
|
|
|
732
769
|
function updateDeprecatedOptions(options, logger) {
|
|
733
|
-
if(options.hostWhiteList && !options.hostSafeList) {
|
|
770
|
+
if (options.hostWhiteList && !options.hostSafeList) {
|
|
734
771
|
options.hostSafeList = options.hostWhiteList;
|
|
735
772
|
options.hostWhiteList = undefined;
|
|
736
773
|
logger && logger.log('hostWhiteList is deprecated. Use hostSafeList.');
|
|
737
774
|
}
|
|
738
|
-
if(options.hostBlackList && !options.hostBlockList) {
|
|
775
|
+
if (options.hostBlackList && !options.hostBlockList) {
|
|
739
776
|
options.hostBlockList = options.hostBlackList;
|
|
740
777
|
options.hostBlackList = undefined;
|
|
741
778
|
logger && logger.log('hostBlackList is deprecated. Use hostBlockList.');
|
|
@@ -775,5 +812,5 @@ module.exports = {
|
|
|
775
812
|
stringify: stringify,
|
|
776
813
|
maxByteSize: maxByteSize,
|
|
777
814
|
typeName: typeName,
|
|
778
|
-
uuid4: uuid4
|
|
815
|
+
uuid4: uuid4,
|
|
779
816
|
};
|
package/test/api.test.js
CHANGED
|
@@ -8,16 +8,16 @@ var utility = require('../src/utility');
|
|
|
8
8
|
utility.setupJSON();
|
|
9
9
|
|
|
10
10
|
function TestTransportGenerator() {
|
|
11
|
-
var TestTransport = function(callbackError, callbackResponse) {
|
|
11
|
+
var TestTransport = function (callbackError, callbackResponse) {
|
|
12
12
|
this.postArgs = [];
|
|
13
13
|
this.callbackError = callbackError;
|
|
14
14
|
this.callbackResponse = callbackResponse;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
TestTransport.prototype.post = function() {
|
|
17
|
+
TestTransport.prototype.post = function () {
|
|
18
18
|
var args = arguments;
|
|
19
19
|
this.postArgs.push(args);
|
|
20
|
-
var callback = args[args.length-1];
|
|
20
|
+
var callback = args[args.length - 1];
|
|
21
21
|
if (typeof callback === 'function') {
|
|
22
22
|
callback(this.callbackError, this.callbackResponse);
|
|
23
23
|
}
|
|
@@ -26,17 +26,17 @@ function TestTransportGenerator() {
|
|
|
26
26
|
return TestTransport;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
describe('Api()', function() {
|
|
30
|
-
it('use the defaults if no custom endpoint is given', function(done) {
|
|
29
|
+
describe('Api()', function () {
|
|
30
|
+
it('use the defaults if no custom endpoint is given', function (done) {
|
|
31
31
|
var transport = new (TestTransportGenerator())();
|
|
32
32
|
var url = {
|
|
33
|
-
parse: function(e) {
|
|
33
|
+
parse: function (e) {
|
|
34
34
|
expect(false).to.be.ok();
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
36
|
};
|
|
37
37
|
var backup = null;
|
|
38
38
|
var accessToken = 'abc123';
|
|
39
|
-
var options = {accessToken: accessToken};
|
|
39
|
+
var options = { accessToken: accessToken };
|
|
40
40
|
var api = new API(options, transport, url, backup);
|
|
41
41
|
// I know this is testing internal state but it
|
|
42
42
|
// is the most expedient way to do this
|
|
@@ -46,23 +46,23 @@ describe('Api()', function() {
|
|
|
46
46
|
expect(api.transportOptions.protocol).to.eql('https:');
|
|
47
47
|
done();
|
|
48
48
|
});
|
|
49
|
-
it('should parse the endpoint and use that if given', function(done) {
|
|
49
|
+
it('should parse the endpoint and use that if given', function (done) {
|
|
50
50
|
var transport = new (TestTransportGenerator())();
|
|
51
51
|
var endpoint = 'http://woo.foo.com/api/42';
|
|
52
52
|
var url = {
|
|
53
|
-
parse: function(e) {
|
|
53
|
+
parse: function (e) {
|
|
54
54
|
expect(e).to.eql(endpoint);
|
|
55
55
|
return {
|
|
56
56
|
hostname: 'woo.foo.com',
|
|
57
57
|
protocol: 'http:',
|
|
58
58
|
pathname: '/api/42',
|
|
59
|
-
path: '/api/42'
|
|
59
|
+
path: '/api/42',
|
|
60
60
|
};
|
|
61
|
-
}
|
|
61
|
+
},
|
|
62
62
|
};
|
|
63
63
|
var backup = null;
|
|
64
64
|
var accessToken = 'abc123';
|
|
65
|
-
var options = {accessToken: accessToken, endpoint: endpoint};
|
|
65
|
+
var options = { accessToken: accessToken, endpoint: endpoint };
|
|
66
66
|
var api = new API(options, transport, url, backup);
|
|
67
67
|
expect(api.accessToken).to.eql(accessToken);
|
|
68
68
|
expect(api.transportOptions.hostname).to.eql('woo.foo.com');
|
|
@@ -72,22 +72,22 @@ describe('Api()', function() {
|
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
describe('postItem', function() {
|
|
76
|
-
it('should call post on the transport object', function(done) {
|
|
77
|
-
var response = 'yes'
|
|
75
|
+
describe('postItem', function () {
|
|
76
|
+
it('should call post on the transport object', function (done) {
|
|
77
|
+
var response = 'yes';
|
|
78
78
|
var transport = new (TestTransportGenerator())(null, response);
|
|
79
79
|
var url = {
|
|
80
|
-
parse: function(e) {
|
|
80
|
+
parse: function (e) {
|
|
81
81
|
expect(false).to.be.ok();
|
|
82
|
-
}
|
|
82
|
+
},
|
|
83
83
|
};
|
|
84
84
|
var backup = null;
|
|
85
85
|
var accessToken = 'abc123';
|
|
86
|
-
var options = {accessToken: accessToken};
|
|
86
|
+
var options = { accessToken: accessToken };
|
|
87
87
|
var api = new API(options, transport, url, backup);
|
|
88
88
|
|
|
89
|
-
var data = {a: 1};
|
|
90
|
-
api.postItem(data, function(err, resp) {
|
|
89
|
+
var data = { a: 1 };
|
|
90
|
+
api.postItem(data, function (err, resp) {
|
|
91
91
|
expect(err).to.not.be.ok();
|
|
92
92
|
expect(resp).to.eql(response);
|
|
93
93
|
expect(transport.postArgs.length).to.eql(1);
|
|
@@ -98,21 +98,21 @@ describe('postItem', function() {
|
|
|
98
98
|
done();
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
|
-
it('should stringify context', function(done) {
|
|
102
|
-
var response = 'yes'
|
|
101
|
+
it('should stringify context', function (done) {
|
|
102
|
+
var response = 'yes';
|
|
103
103
|
var transport = new (TestTransportGenerator())(null, response);
|
|
104
104
|
var url = {
|
|
105
|
-
parse: function(e) {
|
|
105
|
+
parse: function (e) {
|
|
106
106
|
expect(false).to.be.ok();
|
|
107
|
-
}
|
|
107
|
+
},
|
|
108
108
|
};
|
|
109
109
|
var backup = null;
|
|
110
110
|
var accessToken = 'abc123';
|
|
111
|
-
var options = {accessToken: accessToken};
|
|
111
|
+
var options = { accessToken: accessToken };
|
|
112
112
|
var api = new API(options, transport, url, backup);
|
|
113
113
|
|
|
114
|
-
var data = {a: 1, context: {some: [1, 2, 'stuff']}};
|
|
115
|
-
api.postItem(data, function(err, resp) {
|
|
114
|
+
var data = { a: 1, context: { some: [1, 2, 'stuff'] } };
|
|
115
|
+
api.postItem(data, function (err, resp) {
|
|
116
116
|
expect(err).to.not.be.ok();
|
|
117
117
|
expect(resp).to.eql(response);
|
|
118
118
|
expect(transport.postArgs.length).to.eql(1);
|
|
@@ -121,7 +121,9 @@ describe('postItem', function() {
|
|
|
121
121
|
expect(transport.postArgs[0][1].method).to.eql('POST');
|
|
122
122
|
expect(transport.postArgs[0][2].access_token).to.eql(accessToken);
|
|
123
123
|
expect(transport.postArgs[0][2].data.a).to.eql(1);
|
|
124
|
-
expect(transport.postArgs[0][2].data.context).to.eql(
|
|
124
|
+
expect(transport.postArgs[0][2].data.context).to.eql(
|
|
125
|
+
'{"some":[1,2,"stuff"]}',
|
|
126
|
+
);
|
|
125
127
|
done();
|
|
126
128
|
});
|
|
127
129
|
});
|