forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionlessClient.test.ts
More file actions
103 lines (82 loc) · 3.6 KB
/
ExceptionlessClient.test.ts
File metadata and controls
103 lines (82 loc) · 3.6 KB
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
import { Configuration } from "../src/configuration/Configuration.js";
import { ExceptionlessClient } from "../src/ExceptionlessClient.js";
import { EventPluginContext } from "../src/plugins/EventPluginContext.js";
import { InMemorySubmissionAdapter } from "./submission/InMemorySubmissionAdapter.js";
describe('ExceptionlessClient', () => {
beforeEach(() => {
Configuration.defaults.updateSettingsWhenIdleInterval = -1;
Configuration.defaults.submissionAdapter = new InMemorySubmissionAdapter();
});
test('should use event reference ids', async () => {
const client = new ExceptionlessClient({
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
serverUrl: 'http://localhost:5000'
});
expect(client.config.lastReferenceIdManager.getLast()).toBeNull();
const error = createException();
await client.submitException(error);
expect(client.config.lastReferenceIdManager.getLast()).toBeNull();
const numberOfPlugins = client.config.plugins.length;
client.config.useReferenceIds();
expect(client.config.plugins.length).toBe(numberOfPlugins + 1);
const context = await client.submitException(error);
if (!context.cancelled) {
expect(client.config.lastReferenceIdManager.getLast()).not.toBeNull();
} else {
expect(client.config.lastReferenceIdManager.getLast()).toBeNull();
}
});
test('should accept null source', () => {
const client = new ExceptionlessClient({
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
serverUrl: 'http://localhost:5000'
});
const builder = client.createLog(null, 'Unit Test message', 'Trace');
expect(builder.target.source).toBeUndefined();
expect(builder.target.message).toBe('Unit Test message');
expect(builder.target.data['@level']).toBe('Trace');
});
test('should accept source and message', () => {
const client = new ExceptionlessClient({
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
serverUrl: 'http://localhost:5000'
});
const builder = client.createLog('ExceptionlessClient', 'Unit Test message');
expect(builder.target.source).toBe('ExceptionlessClient');
expect(builder.target.message).toBe('Unit Test message');
expect(builder.target.data).toBeUndefined();
});
test('should accept source and message and level', () => {
const client = new ExceptionlessClient({
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
serverUrl: 'http://localhost:5000'
});
const builder = client.createLog('source', 'Unit Test message', 'Info');
expect(builder.target.source).toBe('source');
expect(builder.target.message).toBe('Unit Test message');
expect(builder.target.data['@level']).toBe('Info');
});
test('should allow construction via apiKey and serverUrl parameters', () => {
const client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:5000');
expect(client.config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
expect(client.config.serverUrl).toBe('http://localhost:5000');
});
test('should allow construction via a configuration object', () => {
const client = new ExceptionlessClient({
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
serverUrl: 'http://localhost:5000'
});
expect(client.config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
expect(client.config.serverUrl).toBe('http://localhost:5000');
});
function createException() {
function throwError() {
throw new ReferenceError('This is a test');
}
try {
throwError();
} catch (e) {
return e;
}
}
});