forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateCheckerPlugin-spec.ts
More file actions
90 lines (73 loc) · 2.42 KB
/
DuplicateCheckerPlugin-spec.ts
File metadata and controls
90 lines (73 loc) · 2.42 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
import { expect } from 'chai';
import { beforeEach, describe, it } from 'mocha';
import { ExceptionlessClient } from '../../ExceptionlessClient';
import { DefaultErrorParser } from "../../services/DefaultErrorParser";
import { EventPluginContext } from '../EventPluginContext';
import { DuplicateCheckerPlugin } from './DuplicateCheckerPlugin';
describe('DuplicateCheckerPlugin', () => {
let now: number = 0;
let client: ExceptionlessClient;
let plugin: DuplicateCheckerPlugin;
beforeEach(() => {
client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:5000');
plugin = new DuplicateCheckerPlugin(() => now, 50);
});
function run(exception: Error) {
const errorParser = client.config.errorParser || new DefaultErrorParser();
const context = new EventPluginContext(client, { type: 'error', data: {} });
context.event.data['@error'] = errorParser.parse(context, exception);
plugin.run(context);
return context;
}
it('should ignore duplicate within window', (done) => {
const exception = createException();
run(exception);
const contextOfSecondRun = run(exception);
expect(contextOfSecondRun.cancelled).to.be.true;
setTimeout(() => {
expect(contextOfSecondRun.event.count).to.equal(1);
done();
}, 100);
});
it('should ignore error without stack', () => {
const exception = new ReferenceError('This is a test');
delete exception.stack;
run(exception);
const contextOfSecondRun = run(exception);
expect(contextOfSecondRun.cancelled).to.be.true;
});
it('shouldn\'t ignore different stack within window', () => {
const exception1 = createException();
run(exception1);
const exception2 = createException2();
const contextOfSecondRun = run(exception2);
expect(contextOfSecondRun.cancelled).not.to.be.true;
});
it('shouldn\'t ignore duplicate after window', () => {
const exception = createException();
run(exception);
now = 3000;
const contextOfSecondRun = run(exception);
expect(contextOfSecondRun.cancelled).not.to.be.true;
});
});
function createException() {
function throwError() {
throw new ReferenceError('This is a test');
}
try {
throwError();
} catch (e) {
return e;
}
}
function createException2() {
function throwError2() {
throw new ReferenceError('This is a test');
}
try {
throwError2();
} catch (e) {
return e;
}
}