-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathdebugTelemetryReporter.test.ts
39 lines (31 loc) · 1.59 KB
/
debugTelemetryReporter.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { createFakeVSCode } from "./helpers/helpers";
// Allow us to mock the console object for testing
// eslint-disable no-console
jest.mock("vscode", () => createFakeVSCode(), { virtual: true });
jest.mock("@vscode/extension-telemetry");
describe("debugTelemetryReporter", () => {
it("gets created successfully", async () => {
const dtr = await import("../src/debugTelemetryReporter");
const reporter = new dtr.DebugTelemetryReporter();
expect(reporter).toBeDefined();
});
it("sendTelemetryEvent writes to the console", async () => {
const dtr = await import("../src/debugTelemetryReporter");
const reporter = new dtr.DebugTelemetryReporter();
global.console.log = jest.fn();
const expectedName = "event";
const expectedProps = { prop1: "hello" };
const expectedMeasures = { measure1: 100 };
reporter.sendTelemetryEvent(expectedName, expectedProps, expectedMeasures);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining(expectedName));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining(JSON.stringify(expectedProps)));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining(JSON.stringify(expectedProps)));
});
it("dispose completes", async () => {
const dtr = await import("../src/debugTelemetryReporter");
const reporter = new dtr.DebugTelemetryReporter();
await reporter.dispose();
});
});