This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
/
raven.client.js
147 lines (131 loc) · 4.91 KB
/
raven.client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var raven = require('../')
, fs = require('fs')
, nock = require('nock');
var dsn = 'https://public:private@app.getsentry.com/269';
function wait(scope, done) {
setTimeout(function() {
scope.done(); done();
}, 10);
}
describe('raven.version', function(){
it('should be valid', function(){
raven.version.should.match(/^\d+\.\d+\.\d+(-\w+)?$/);
});
});
describe('raven.Client', function(){
var client;
before(function(){
client = new raven.Client(dsn);
});
it('should parse the DSN with options', function(){
var expected = {
protocol: 'https',
public_key: 'public',
private_key: 'private',
host: 'app.getsentry.com',
path: '',
project_id: 269
};
var client = new raven.Client(dsn, {name: 'YAY!', site:'Googlez'});
client.dsn.should.eql(expected);
client.name.should.equal('YAY!');
client.site.should.equal('Googlez');
});
it('should pull SENTRY_DSN from environment', function(){
var expected = {
protocol: 'https',
public_key: 'abc',
private_key: '123',
host: 'app.getsentry.com',
path: '',
project_id: 1
};
process.env.SENTRY_DSN='https://abc:123@app.getsentry.com/1';
var client = new raven.Client();
client.dsn.should.eql(expected);
delete process.env.SENTRY_DSN; // gotta clean up so it doesn't leak into other tests
});
it('should pull SENTRY_DSN from environment when passing options', function(){
var expected = {
protocol: 'https',
public_key: 'abc',
private_key: '123',
host: 'app.getsentry.com',
path: '',
project_id: 1
};
process.env.SENTRY_DSN='https://abc:123@app.getsentry.com/1';
var client = new raven.Client({name: 'YAY!'});
client.dsn.should.eql(expected);
client.name.should.equal('YAY!');
delete process.env.SENTRY_DSN; // gotta clean up so it doesn't leak into other tests
});
it('should pull SENTRY_NAME from environment', function(){
process.env.SENTRY_NAME='new_name';
var client = new raven.Client(dsn);
client.name.should.eql('new_name');
delete process.env.SENTRY_NAME;
});
it('should pull SENTRY_SITE from environment', function(){
process.env.SENTRY_SITE='Googlez';
var client = new raven.Client(dsn);
client.site.should.eql('Googlez');
delete process.env.SENTRY_SITE;
});
describe('#getIdent()', function(){
it('should match', function(){
var result = {
id: 'c988bf5cb7db4653825c92f6864e7206',
checksum: 'b8a6fbd29cc9113a149ad62cf7e0ddd5'
};
client.getIdent(result).should.equal('c988bf5cb7db4653825c92f6864e7206$b8a6fbd29cc9113a149ad62cf7e0ddd5');
});
});
describe('#captureMessage()', function(){
it('should send a plain text message to Sentry server', function(done){
var scope = nock('https://app.getsentry.com')
.filteringRequestBody(/.*/, '*')
.post('/api/store/', '*')
.reply(200, 'OK');
client.captureMessage('Hey!');
wait(scope, done);
});
});
describe('#captureError()', function(){
it('should send an Error to Sentry server', function(done){
var scope = nock('https://app.getsentry.com')
.filteringRequestBody(/.*/, '*')
.post('/api/store/', '*')
.reply(200, 'OK');
client.captureError(new Error('wtf?'));
wait(scope, done);
});
});
describe('#patchGlobal()', function(){
it('should add itself to the uncaughtException event list', function(){
var before = process._events.uncaughtException;
client.patchGlobal();
process._events.uncaughtException.length.should.equal(before.length+1);
process._events.uncaughtException = before; // patch it back to what it was
});
/* Why can't I do this?!?!
it('should send an uncaughtException to Sentry server', function(done){
var scope = nock('https://app.getsentry.com')
.filteringRequestBody(/.*\/, '*')
.post('/api/store/', '*')
.reply(200, 'OK');
var before = process._events.uncaughtException;
process.removeAllListeners('uncaughtException');
console.log(process._events);
client.patchGlobal();
console.log(process._events);
''(); // should be caught and sent to Sentry
before.forEach(function(cb) {
// restore old callbacks
process.on('uncaughtException', cb);
});
done();
});
*/
});
});