-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathExceptionlessClient-spec.ts
96 lines (77 loc) · 3.37 KB
/
ExceptionlessClient-spec.ts
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
import { ExceptionlessClient } from './ExceptionlessClient';
import { EventPluginContext } from './plugins/EventPluginContext';
import { expect } from 'chai';
import * as sinon from 'sinon';
describe('ExceptionlessClient', () => {
let xhr: any;
beforeEach(() => {
xhr = sinon.useFakeXMLHttpRequest();
});
afterEach(() => {
xhr.restore();
});
it('should use event reference ids', (done) => {
let error = createException();
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
expect(client.config.lastReferenceIdManager.getLast()).to.be.null;
client.submitException(error, (context: EventPluginContext) => {
expect(client.config.lastReferenceIdManager.getLast()).to.be.null;
});
let numberOfPlugins = client.config.plugins.length;
client.config.useReferenceIds();
expect(client.config.plugins.length).to.equal(numberOfPlugins + 1);
client.submitException(error, (context: EventPluginContext) => {
if (!context.cancelled) {
expect(client.config.lastReferenceIdManager.getLast()).not.to.be.null;
} else {
expect(client.config.lastReferenceIdManager.getLast()).to.be.null;
}
done();
done = () => { };
});
});
it('should accept null source', () => {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
let builder = client.createLog(null, 'Unit Test message', 'Trace');
expect(builder.target.source).to.be.undefined;
expect(builder.target.message).to.equal('Unit Test message');
expect(builder.target.data['@level']).to.equal('Trace');
});
it('should accept source and message', () => {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
let builder = client.createLog('ExceptionlessClient', 'Unit Test message');
expect(builder.target.source).to.equal('ExceptionlessClient');
expect(builder.target.message).to.equal('Unit Test message');
expect(builder.target.data).to.be.undefined;
});
it('should accept source and message', () => {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
let builder = client.createLog('Unit Test message');
expect(builder.target.source).to.be.undefined;
expect(builder.target.message).to.equal('Unit Test message');
expect(builder.target.data).to.be.undefined;
});
it('should allow construction via apiKey and serverUrl parameters', () => {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
expect(client.config.apiKey).to.equal('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
expect(client.config.serverUrl).to.equal('http://localhost:50000');
});
it('should allow construction via a configuration object', () => {
let client = new ExceptionlessClient({
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
serverUrl: 'http://localhost:50000'
});
expect(client.config.apiKey).to.equal('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
expect(client.config.serverUrl).to.equal('http://localhost:50000');
});
function createException() {
function throwError() {
throw new ReferenceError('This is a test');
}
try {
throwError();
} catch (e) {
return e;
}
}
});