forked from swissmanu/rxjs-debugging-for-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
144 lines (128 loc) · 5.36 KB
/
index.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
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
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import 'reflect-metadata';
import { Configuration } from '../configuration';
import { IConfigurationAccessor } from '../configuration/configurationAccessor';
import Logger from '../logger';
import { IEnvironmentInfo } from '../util/environmentInfo';
import PosthogAnalyticsReporter, { IAnalyticsReporter } from './index';
import { IPosthogConfiguration } from './posthogConfiguration';
import { getPosthogMockInstance, resetPosthogMock } from './__mocks__/posthog-node';
describe('Analytics', () => {
describe('PosthogAnalyticsReporter', () => {
let configurationAccessor: IConfigurationAccessor;
const posthogConfiguration: IPosthogConfiguration = {
host: 'https://posthog',
projectApiKey: 'foobar',
};
const environmentInfo: IEnvironmentInfo = {
extensionVersion: '1.0.0',
language: 'de-CH',
machineId: 'machine',
version: '1.62.0',
};
beforeEach(() => {
configurationAccessor = {
get: jest.fn(),
hasGlobal: jest.fn(),
update: jest.fn(),
onDidChangeConfiguration: jest.fn(),
};
});
afterEach(() => {
resetPosthogMock();
});
describe('having analytics disabled,', () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
configurationAccessor.get = jest.fn(() => false as any);
new PosthogAnalyticsReporter(posthogConfiguration, environmentInfo, configurationAccessor, Logger.nullLogger());
});
test('does not create a Posthog reporter on creation', () => {
expect(configurationAccessor.get).toBeCalledWith(Configuration.EnableAnalytics, false);
expect(getPosthogMockInstance()).toBeNull();
});
});
describe('having analytics enabled,', () => {
let posthog: IAnalyticsReporter;
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
configurationAccessor.get = jest.fn(() => true as any);
posthog = new PosthogAnalyticsReporter(
posthogConfiguration,
environmentInfo,
configurationAccessor,
Logger.nullLogger()
);
});
test('creates a Posthog reporter using provided PosthogConfiguration on creation', () => {
expect(configurationAccessor.get).toBeCalledWith(Configuration.EnableAnalytics, false);
const createdInstance = getPosthogMockInstance();
expect(createdInstance).not.toBeNull();
expect(createdInstance!.projectApiKey).toEqual(posthogConfiguration.projectApiKey);
expect(createdInstance!.options).toEqual({ host: posthogConfiguration.host });
});
test('calls Posthog.identify() on creation', () => {
expect(getPosthogMockInstance()!.identify).toBeCalledWith({
distinctId: environmentInfo.machineId,
properties: {
vscodeVersion: environmentInfo.version,
vscodeLanguage: environmentInfo.language,
extensionVersion: environmentInfo.extensionVersion,
},
});
});
describe('captures "operator log point enabled" events', () => {
test('for built-in operators', () => {
posthog.captureOperatorLogPointEnabled({ operatorName: 'map' });
expect(getPosthogMockInstance()!.capture).toBeCalledWith({
distinctId: environmentInfo.machineId,
event: 'operator log point enabled',
properties: { operatorName: 'map' },
});
});
test('for custom operators without the operator name', () => {
posthog.captureOperatorLogPointEnabled({ operatorName: 'customOperator' });
expect(getPosthogMockInstance()!.capture).toBeCalledWith({
distinctId: environmentInfo.machineId,
event: 'operator log point enabled',
properties: {},
});
});
});
describe('captures "operator log point disabled" events', () => {
test('for built-in operators', () => {
posthog.captureOperatorLogPointDisabled({ operatorName: 'map' });
expect(getPosthogMockInstance()!.capture).toBeCalledWith({
distinctId: environmentInfo.machineId,
event: 'operator log point disabled',
properties: { operatorName: 'map' },
});
});
test('for custom operators without the operator name', () => {
posthog.captureOperatorLogPointDisabled({ operatorName: 'customOperator' });
expect(getPosthogMockInstance()!.capture).toBeCalledWith({
distinctId: environmentInfo.machineId,
event: 'operator log point disabled',
properties: {},
});
});
});
test('captures "debug sessions started" events', () => {
posthog.captureDebugSessionStarted({ runtime: 'nodejs' });
expect(getPosthogMockInstance()!.capture).toBeCalledWith({
distinctId: environmentInfo.machineId,
event: 'debug session started',
properties: { runtime: 'nodejs' },
});
});
test('captures "debug sessions stopped" events', () => {
posthog.captureDebugSessionStopped({});
expect(getPosthogMockInstance()!.capture).toBeCalledWith({
distinctId: environmentInfo.machineId,
event: 'debug session stopped',
properties: {},
});
});
});
});
});