UNPKG

4.88 kBJavaScriptView Raw
1// Copyright (c) 2015 Uber Technologies, Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21var test = require('tape');
22
23var SentryLogger = require('./lib/sentry-logger');
24
25test('can .error("message", new Error())', function (assert) {
26 var logger = SentryLogger(function (result) {
27 assert.equal(result.message,
28 'Error: sentry-errors.js: no u');
29
30 assert.equal(result.culprit,
31 'sentry-errors at logError');
32
33 assert.deepEqual(result['sentry.interfaces.Exception'], {
34 type: 'Error',
35 value: 'sentry-errors.js: no u'
36 });
37 assert.ok(result['sentry.interfaces.Stacktrace']);
38
39 logger.destroy();
40 assert.end();
41 });
42
43 function logError() {
44 logger.error('hello world', new Error('no u'));
45 }
46
47 logError();
48});
49
50test('has originalMessage for .error(str, errObj)', function (assert) {
51 var logger = SentryLogger(function (result) {
52 assert.equal(result.extra.originalMessage,
53 'original message');
54
55 logger.destroy();
56 assert.end();
57 });
58
59 function logError() {
60 logger.error('original message',
61 new Error('some error'));
62 }
63
64 logError();
65});
66
67test('.error(str, metaObj) has a stack extra', function (assert) {
68 var logger = SentryLogger(function (result) {
69 assert.equal(result.extra.oh, 'hi');
70 assert.ok(result.extra.stack);
71
72 assert.equal(result.message,
73 'sentry-errors.js: some message');
74
75 logger.destroy();
76 assert.end();
77 });
78
79 function logError() {
80 logger.error('some message', { oh: 'hi' });
81 }
82
83 logError();
84});
85
86test('respects tags defined in logger', function (assert) {
87 var logger = SentryLogger({
88 defaultTags: {
89 regionName: 'hello'
90 }
91 }, function (result) {
92 assert.equal(result.tags.regionName, 'hello');
93
94 logger.destroy();
95 assert.end();
96 });
97
98 function logError() {
99 logger.error('some message', new Error('some error'));
100 }
101
102 logError();
103});
104
105test('can error("message", { error: Error() })', function (assert) {
106 var logger = SentryLogger(function (result) {
107 assert.equal(result.extra.other, 'key');
108 assert.equal(result.extra.originalMessage, 'some message');
109
110 assert.equal(result.message,
111 'Error: sentry-errors.js: some error');
112
113 assert.equal(result.culprit,
114 'sentry-errors at logError');
115
116 assert.deepEqual(result['sentry.interfaces.Exception'], {
117 type: 'Error',
118 value: 'sentry-errors.js: some error'
119 });
120 assert.ok(result['sentry.interfaces.Stacktrace']);
121
122 logger.destroy();
123 assert.end();
124 });
125
126 function logError() {
127 logger.error('some message', {
128 error: new Error('some error'),
129 other: 'key'
130 });
131 }
132
133 logError();
134});
135
136test('can error(msg, { someKey: Error() })', function (assert) {
137 var logger = SentryLogger(function (result) {
138 assert.equal(result.extra.other, 'key');
139 assert.equal(result.extra.originalMessage, 'some message');
140
141 assert.equal(result.message,
142 'Error: sentry-errors.js: some error');
143
144 assert.equal(result.culprit,
145 'sentry-errors at logError');
146
147 assert.deepEqual(result['sentry.interfaces.Exception'], {
148 type: 'Error',
149 value: 'sentry-errors.js: some error'
150 });
151 assert.ok(result['sentry.interfaces.Stacktrace']);
152 assert.equal(result.extra.arbitraryKey, undefined);
153
154 logger.destroy();
155 assert.end();
156 });
157
158 function logError() {
159 logger.error('some message', {
160 arbitraryKey: new Error('some error'),
161 other: 'key'
162 });
163 }
164
165 logError();
166});