1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var test = require('tape');
|
22 |
|
23 | var SentryLogger = require('./lib/sentry-logger');
|
24 |
|
25 | test('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 |
|
50 | test('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 |
|
67 | test('.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 |
|
86 | test('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 |
|
105 | test('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 |
|
136 | test('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 | });
|