Skip to content

Commit 0aefeca

Browse files
committed
Fixed unit tests
1 parent fd65666 commit 0aefeca

File tree

7 files changed

+54
-50
lines changed

7 files changed

+54
-50
lines changed

packages/core/src/ExceptionlessClient.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ export class ExceptionlessClient {
217217
context.log.info(`Setting last reference id "${ev.reference_id}"`);
218218
config.services.lastReferenceIdManager.setLast(ev.reference_id);
219219
}
220+
221+
return context;
220222
}
221223

222224
/**

packages/core/src/configuration/Configuration.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ export class Configuration {
4848
public enabled: boolean = true;
4949

5050
public services: {
51-
environmentInfoCollector?: IEnvironmentInfoCollector,
52-
errorParser?: IErrorParser,
53-
lastReferenceIdManager: ILastReferenceIdManager,
54-
log: ILog,
55-
moduleCollector?: IModuleCollector,
56-
requestInfoCollector?: IRequestInfoCollector,
57-
submissionClient?: ISubmissionClient,
58-
storage: IStorageProvider,
59-
queue: IEventQueue
60-
} = {
51+
environmentInfoCollector?: IEnvironmentInfoCollector,
52+
errorParser?: IErrorParser,
53+
lastReferenceIdManager: ILastReferenceIdManager,
54+
log: ILog,
55+
moduleCollector?: IModuleCollector,
56+
requestInfoCollector?: IRequestInfoCollector,
57+
submissionClient?: ISubmissionClient,
58+
storage: IStorageProvider,
59+
queue: IEventQueue
60+
} = {
6161
lastReferenceIdManager: new DefaultLastReferenceIdManager(),
6262
log: new NullLog(),
6363
storage: new InMemoryStorageProvider(),
6464
queue: new DefaultEventQueue(this)
65-
}
65+
};
6666

6767
/**
6868
* Maximum number of events that should be sent to the server together in a batch. (Defaults to 50)
@@ -117,13 +117,13 @@ export class Configuration {
117117
*/
118118
private _dataExclusions: string[] = [];
119119

120-
private _includePrivateInformation: boolean;
121-
private _includeUserName: boolean;
122-
private _includeMachineName: boolean;
123-
private _includeIpAddress: boolean;
124-
private _includeCookies: boolean;
125-
private _includePostData: boolean;
126-
private _includeQueryString: boolean;
120+
private _includePrivateInformation: boolean = true;
121+
private _includeUserName: boolean = true;
122+
private _includeMachineName: boolean = true;
123+
private _includeIpAddress: boolean = true;
124+
private _includeCookies: boolean = true;
125+
private _includePostData: boolean = true;
126+
private _includeQueryString: boolean = true;
127127

128128
/**
129129
* A list of user agent patterns.
@@ -305,7 +305,7 @@ export class Configuration {
305305
* @param value
306306
*/
307307
public set includePrivateInformation(value: boolean) {
308-
const val = value || false;
308+
const val = value === true;
309309
this._includePrivateInformation = val;
310310
this._includeUserName = val;
311311
this._includeMachineName = val;
@@ -330,7 +330,7 @@ export class Configuration {
330330
* @param value
331331
*/
332332
public set includeUserName(value: boolean) {
333-
this._includeUserName = value || false;
333+
this._includeUserName = value === true;
334334
this.changed();
335335
}
336336

@@ -347,7 +347,7 @@ export class Configuration {
347347
* @param value
348348
*/
349349
public set includeMachineName(value: boolean) {
350-
this._includeMachineName = value || false;
350+
this._includeMachineName = value === true;
351351
this.changed();
352352
}
353353

@@ -364,7 +364,7 @@ export class Configuration {
364364
* @param value
365365
*/
366366
public set includeIpAddress(value: boolean) {
367-
this._includeIpAddress = value || false;
367+
this._includeIpAddress = value === true;
368368
this.changed();
369369
}
370370

@@ -383,7 +383,7 @@ export class Configuration {
383383
* @param value
384384
*/
385385
public set includeCookies(value: boolean) {
386-
this._includeCookies = value || false;
386+
this._includeCookies = value === true;
387387
this.changed();
388388
}
389389

@@ -402,7 +402,7 @@ export class Configuration {
402402
* @param value
403403
*/
404404
public set includePostData(value: boolean) {
405-
this._includePostData = value || false;
405+
this._includePostData = value === true;
406406
this.changed();
407407
}
408408

@@ -421,7 +421,7 @@ export class Configuration {
421421
* @param value
422422
*/
423423
public set includeQueryString(value: boolean) {
424-
this._includeQueryString = value || false;
424+
this._includeQueryString = value === true;
425425
this.changed();
426426
}
427427

packages/core/test/ExceptionlessClient.test.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@ import { KnownEventDataKeys } from "../src/models/Event.js";
44

55
describe("ExceptionlessClient", () => {
66
test("should use event reference ids", async () => {
7+
const error = createException();
8+
79
const client = new ExceptionlessClient();
810
client.config.apiKey = "UNIT_TEST_API_KEY";
9-
const { lastReferenceIdManager } = client.config.services;
1011

12+
const { lastReferenceIdManager } = client.config.services;
1113
expect(lastReferenceIdManager.getLast()).toBeNull();
1214

13-
const error = createException();
14-
await client.submitException(error);
15+
let context = await client.submitException(error);
16+
expect(context.event.reference_id).toBeUndefined();
1517
expect(lastReferenceIdManager.getLast()).toBeNull();
1618

1719
const numberOfPlugins = client.config.plugins.length;
1820
client.config.useReferenceIds();
1921
expect(client.config.plugins.length).toBe(numberOfPlugins + 1);
2022

21-
const context = await client.submitException(error);
22-
if (!context.cancelled) {
23-
expect(lastReferenceIdManager.getLast()).not.toBeNull();
24-
} else {
25-
expect(lastReferenceIdManager.getLast()).toBeNull();
26-
}
23+
context = await client.submitException(error);
24+
expect(context.event.reference_id).not.toBeUndefined();
25+
const lastReference: string = lastReferenceIdManager.getLast();
26+
expect(context.event.reference_id).toBe(lastReference);
27+
28+
context = await client.submitException(error);
29+
expect(context.event.reference_id).not.toBeUndefined();
30+
expect(context.event.reference_id).not.toBe(lastReference);
31+
expect(context.event.reference_id).toBe(lastReferenceIdManager.getLast());
2732
});
2833

2934
test("should accept null source", () => {

packages/core/test/plugins/default/ErrorPlugin.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ describe("ErrorPlugin", () => {
5050
const additionalData = getAdditionalData(event);
5151
expect(additionalData).toBeUndefined();
5252
});
53-
5453
});
5554

5655
test("should add custom properties to additional data", async () => {

packages/core/test/plugins/default/EventPluginTestFixture.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ContextData } from "../../../src/plugins/ContextData.js";
22
import { EventPluginContext } from "../../../src/plugins/EventPluginContext.js";
33
import { IErrorParser } from "../../../src/services/IErrorParser.js";
44
import { Event } from "../../../src/models/Event.js";
5+
import { ExceptionlessClient } from "../../../src/ExceptionlessClient.js";
56

6-
// TODO: This should use the real object instances and inject the error parser.
77
export function createFixture(): { contextData: ContextData, context: EventPluginContext, client: any, event: Event } {
88
const errorParser: IErrorParser = {
99
parse: (c: EventPluginContext, exception: Error) => Promise.resolve({
@@ -12,15 +12,9 @@ export function createFixture(): { contextData: ContextData, context: EventPlugi
1212
stack_trace: (exception as any).testStack || null
1313
})
1414
};
15-
const client: any = {
16-
config: {
17-
dataExclusions: [],
18-
errorParser,
19-
log: {
20-
info: () => { }
21-
}
22-
}
23-
};
15+
const client: ExceptionlessClient = new ExceptionlessClient();
16+
client.config.services.errorParser = errorParser;
17+
2418
const event: Event = {
2519
data: {}
2620
};

packages/core/test/storage/InMemoryStorage.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import { InMemoryStorage } from "../../src/storage/InMemoryStorage.js";
33
import { IStorage } from "../../src/storage/IStorage.js";
44
import { IStorageItem } from "../../src/storage/IStorageItem.js";
55

6-
describeStorage("InMemoryStorage", (maxItems = 250) => {
7-
return new InMemoryStorage(maxItems);
8-
});
6+
describeStorage(
7+
"InMemoryStorage",
8+
(maxItems = 250) => {
9+
return new InMemoryStorage(maxItems);
10+
}
11+
);
912

1013
export function describeStorage(
1114
name: string,

packages/node/test/storage/NodeFileStorage.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import {
99

1010
const directory: string = "./test-data";
1111
const nodeFileStorageFactory = (maxItems?: number): IStorage => {
12-
return new NodeFileStorage("test", directory, "ex-", maxItems);
12+
return new NodeFileStorage("test", directory, maxItems);
1313
};
1414

1515
function resetStorageDirectory() {
1616
rmSync(directory, { recursive: true, force: true });
1717
mkdirSync(directory);
1818
}
1919

20-
describeStorage("NodeFileStorage",
20+
describeStorage(
21+
"NodeFileStorage",
2122
nodeFileStorageFactory,
2223
resetStorageDirectory,
2324
resetStorageDirectory,

0 commit comments

Comments
 (0)