forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventPluginManager.test.ts
More file actions
145 lines (118 loc) · 4.75 KB
/
EventPluginManager.test.ts
File metadata and controls
145 lines (118 loc) · 4.75 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
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
import { Configuration } from "../../src/configuration/Configuration.js";
import { ContextData } from "../../src/plugins/ContextData.js";
import { ExceptionlessClient } from "../../src/ExceptionlessClient.js";
import { EventPluginContext } from "../../src/plugins/EventPluginContext.js";
import { EventPluginManager } from "../../src/plugins/EventPluginManager.js";
import { delay } from "../helpers.js";
beforeEach(() => {
Configuration.defaults.updateSettingsWhenIdleInterval = -1;
});
describe("EventPluginManager", () => {
test("should add items to the event.", async () => {
const client = new ExceptionlessClient();
await client.startup({
apiKey: "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
serverUrl: "http://localhost:5000"
});
const context = new EventPluginContext(client, {}, new ContextData());
expect(context.event.source).toBeUndefined();
expect(context.event.geo).toBeUndefined();
expect(client.config.plugins).not.toBeNull();
while (client.config.plugins.length > 0) {
client.config.removePlugin(client.config.plugins[0]);
}
client.config.addPlugin("1", 1, async (ctx: EventPluginContext) => {
await delay(25);
ctx.event.source = "plugin 1";
});
client.config.addPlugin("2", 2, (ctx: EventPluginContext) => {
ctx.event.geo = "43.5775,88.4472";
return Promise.resolve();
});
await EventPluginManager.run(context);
expect(context.cancelled).toBe(false);
expect(context.event.source).toBe("plugin 1");
expect(context.event.geo).toBe("43.5775,88.4472");
});
test("setting cancel should stop plugin execution.", async () => {
const client = new ExceptionlessClient();
await client.startup({
apiKey: "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
serverUrl: "http://localhost:5000"
});
const context = new EventPluginContext(client, {}, new ContextData());
expect(client.config.plugins).not.toBeNull();
while (client.config.plugins.length > 0) {
client.config.removePlugin(client.config.plugins[0]);
}
client.config.addPlugin("1", 1, (ctx: EventPluginContext) => {
ctx.cancelled = true;
return Promise.resolve();
});
client.config.addPlugin("2", 2, () => {
throw new Error("Plugin should not be called due to cancellation");
});
await EventPluginManager.run(context);
expect(context.cancelled).toBe(true);
});
test("throwing error should stop plugin execution.", async () => {
const client = new ExceptionlessClient();
await client.startup({
apiKey: "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
serverUrl: "http://localhost:5000"
});
const context = new EventPluginContext(client, {}, new ContextData());
expect(client.config.plugins).not.toBeNull();
while (client.config.plugins.length > 0) {
client.config.removePlugin(client.config.plugins[0]);
}
client.config.addPlugin("1", 1, () => {
throw new Error("Random Error");
});
client.config.addPlugin("2", 2, () => {
throw new Error("Plugin should not be called due to cancellation");
});
await EventPluginManager.run(context);
expect(context.cancelled).toBe(true);
});
test("should cancel via timeout.", async () => {
const client = new ExceptionlessClient();
await client.startup({
apiKey: "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
serverUrl: "http://localhost:5000"
});
const context = new EventPluginContext(client, {}, new ContextData());
expect(client.config.plugins).not.toBeNull();
while (client.config.plugins.length > 0) {
client.config.removePlugin(client.config.plugins[0]);
}
client.config.addPlugin("1", 1, async () => {
await delay(25);
});
client.config.addPlugin("2", 2, () => {
throw new Error("Plugin should not be called due to cancellation");
});
await EventPluginManager.run(context);
expect(context.cancelled).toBe(true);
});
test("should ensure config plugins are not wrapped.", async () => {
const client = new ExceptionlessClient();
await client.startup({
apiKey: "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
serverUrl: "http://localhost:5000"
});
const context = new EventPluginContext(client, {}, new ContextData());
expect(client.config.plugins).not.toBeNull();
while (client.config.plugins.length > 0) {
client.config.removePlugin(client.config.plugins[0]);
}
client.config.addPlugin("1", 1, (ctx: EventPluginContext) => {
return Promise.resolve();
});
expect(client.config.plugins[0].name).toBe("1");
expect(client.config.plugins.length).toBe(1);
await EventPluginManager.run(context);
expect(client.config.plugins[0].name).toBe("1");
expect(client.config.plugins.length).toBe(1);
});
});