forked from microsoft/VoTT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelemetry.test.ts
95 lines (76 loc) · 3.05 KB
/
telemetry.test.ts
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
import { setUpAppInsights, trackError, trackReduxAction } from "./telemetry";
import { ApplicationInsights, SeverityLevel, IExceptionTelemetry } from "@microsoft/applicationinsights-web";
import { Action } from "redux";
import { ErrorCode } from "./models/applicationState";
import { isElectron } from "./common/hostProcess";
jest.mock("./common/hostProcess");
jest.mock("@microsoft/applicationinsights-web");
describe("appInsights telemetry", () => {
const isElectronMock = isElectron as jest.Mock;
afterEach(() => {
jest.clearAllMocks();
});
describe("browser mode", () => {
beforeEach(() => {
isElectronMock.mockImplementation(() => false);
});
it("setUpAppInsights load an appInsights object", () => {
const spy = jest.spyOn(ApplicationInsights.prototype, "loadAppInsights");
setUpAppInsights();
expect(spy).toHaveBeenCalled();
});
it("trackReduxAction call trackEvent", () => {
const spy = jest.spyOn(ApplicationInsights.prototype, "trackEvent");
setUpAppInsights();
const action: Action = {type: "test"};
trackReduxAction(action);
expect(spy).toBeCalledWith({
name: "test",
});
});
it("trackError call trackException", () => {
const spy = jest.spyOn(ApplicationInsights.prototype, "trackException");
setUpAppInsights();
const appError = {
errorCode: ErrorCode.Unknown,
message: "test message",
};
trackError(appError);
const expectedExceptionTelemetry: IExceptionTelemetry = {
error: new Error(ErrorCode.Unknown),
properties: {
message: appError.message,
},
severityLevel: SeverityLevel.Error,
};
expect(spy).toBeCalledWith(expectedExceptionTelemetry);
});
});
describe("electron mode", () => {
beforeEach(() => {
isElectronMock.mockImplementation(() => true);
});
it("setUpAppInsights should do nothing", () => {
const spy = jest.spyOn(ApplicationInsights.prototype, "loadAppInsights");
setUpAppInsights();
expect(spy).not.toBeCalled();
});
it("trackError does not call trackException", () => {
const spy = jest.spyOn(ApplicationInsights.prototype, "trackException");
setUpAppInsights();
const appError = {
errorCode: ErrorCode.Unknown,
message: "test message",
};
trackError(appError);
expect(spy).not.toBeCalled();
});
it("trackReduxAction does not call trackEvent", () => {
const spy = jest.spyOn(ApplicationInsights.prototype, "trackEvent");
setUpAppInsights();
const action: Action = {type: "test"};
trackReduxAction(action);
expect(spy).not.toBeCalled();
});
});
});