forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateCheckerPlugin.test.ts
More file actions
103 lines (89 loc) · 2.64 KB
/
DuplicateCheckerPlugin.test.ts
File metadata and controls
103 lines (89 loc) · 2.64 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 { DuplicateCheckerPlugin } from "../../../src/plugins/default/DuplicateCheckerPlugin.js";
import { ExceptionlessClient } from "../../../src/ExceptionlessClient.js";
import { EventPluginContext } from "../../../src/plugins/EventPluginContext.js";
import {
InnerErrorInfo,
StackFrameInfo
} from "../../../src/models/data/ErrorInfo.js";
import { delay } from "../../helpers.js";
const Exception1StackTrace = [
{
file_name: "index.js",
line_number: 0,
column: 50,
is_signature_target: true,
name: "createException",
},
{
file_name: "index.js",
line_number: 5,
column: 25,
is_signature_target: false,
name: "throwError",
}
];
const Exception2StackTrace = [
{
file_name: "index.js",
line_number: 0,
column: 50,
is_signature_target: true,
name: "createException2",
},
{
file_name: "index.js",
line_number: 5,
column: 25,
is_signature_target: false,
name: "throwError2",
}
];
describe("DuplicateCheckerPlugin", () => {
let now: number = 0;
let client: ExceptionlessClient;
let plugin: DuplicateCheckerPlugin;
beforeEach(() => {
client = new ExceptionlessClient();
plugin = new DuplicateCheckerPlugin(() => now, 50);
});
const run = async(stackTrace?: StackFrameInfo[]): Promise<EventPluginContext> => {
// TODO: Generate unique stack traces based on test data.
const context = new EventPluginContext(client, {
type: "error",
data: {
"@error": <InnerErrorInfo>{
type: "ReferenceError",
message: "This is a test",
stack_trace: stackTrace
}
}
});
await plugin.run(context);
return context;
}
test("should ignore duplicate within window", async () => {
await run(Exception1StackTrace);
const contextOfSecondRun = await run(Exception1StackTrace);
expect(contextOfSecondRun.cancelled).toBe(true);
await delay(100);
setTimeout(() => {
expect(contextOfSecondRun.event.count).toBe(1);
}, 100);
});
test("should ignore error without stack", async () => {
await run();
const contextOfSecondRun = await run();
expect(contextOfSecondRun.cancelled).toBe(true);
});
test("shouldn't ignore different stack within window", async () => {
await run(Exception1StackTrace);
const contextOfSecondRun = await run(Exception2StackTrace);
expect(contextOfSecondRun.cancelled).not.toBe(true);
});
test("shouldn't ignore duplicate after window", async () => {
await run(Exception1StackTrace);
now = 3000;
const contextOfSecondRun = await run(Exception1StackTrace);
expect(contextOfSecondRun.cancelled).not.toBe(true);
});
});