@microsoft/applicationinsights-angularplugin-js 15.1.1 → 15.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/IErrorService.mjs +2 -0
- package/esm2020/lib/applicationinsights-angularplugin-error.service.mjs +52 -0
- package/esm2020/lib/applicationinsights-angularplugin-js.component.mjs +152 -0
- package/esm2020/lib/applicationinsights-angularplugin-js.module.mjs +23 -0
- package/esm2020/microsoft-applicationinsights-angularplugin-js.mjs +5 -0
- package/esm2020/public-api.mjs +8 -0
- package/fesm2015/microsoft-applicationinsights-angularplugin-js.mjs +231 -0
- package/fesm2015/microsoft-applicationinsights-angularplugin-js.mjs.map +1 -0
- package/fesm2020/microsoft-applicationinsights-angularplugin-js.mjs +230 -0
- package/fesm2020/microsoft-applicationinsights-angularplugin-js.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/{src/lib/IErrorService.ts → lib/IErrorService.d.ts} +0 -1
- package/lib/applicationinsights-angularplugin-error.service.d.ts +16 -0
- package/lib/applicationinsights-angularplugin-js.component.d.ts +20 -0
- package/lib/applicationinsights-angularplugin-js.module.d.ts +7 -0
- package/package.json +47 -30
- package/{src/public-api.ts → public-api.d.ts} +0 -4
- package/.eslintrc.json +0 -74
- package/NOTICE +0 -17
- package/PRIVACY +0 -3
- package/SECURITY.md +0 -41
- package/SUPPORT.md +0 -14
- package/karma.conf.js +0 -43
- package/ng-package.json +0 -15
- package/src/lib/applicationininsights-angularplugin-multiple-instace.spec.ts +0 -245
- package/src/lib/applicationinsights-angularplugin-error.service.spec.ts +0 -113
- package/src/lib/applicationinsights-angularplugin-error.service.ts +0 -57
- package/src/lib/applicationinsights-angularplugin-js.component.spec.ts +0 -158
- package/src/lib/applicationinsights-angularplugin-js.component.ts +0 -203
- package/src/lib/applicationinsights-angularplugin-js.module.ts +0 -14
- package/src/test.ts +0 -13
- package/tsconfig.lib.json +0 -30
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { AppInsightsCore, IConfiguration, ITelemetryItem, IPlugin, IAppInsightsCore } from "@microsoft/applicationinsights-core-js";
|
|
2
|
-
import { IConfig} from "@microsoft/applicationinsights-common";
|
|
3
|
-
import { AngularPlugin } from "./applicationinsights-angularplugin-js.component";
|
|
4
|
-
import { ComponentFixture, TestBed, fakeAsync, tick } from "@angular/core/testing";
|
|
5
|
-
import { Router } from "@angular/router";
|
|
6
|
-
import { ApplicationinsightsAngularpluginErrorService } from "./applicationinsights-angularplugin-error.service";
|
|
7
|
-
import { AnalyticsPlugin } from "@microsoft/applicationinsights-analytics-js";
|
|
8
|
-
import { RouterTestingModule } from "@angular/router/testing";
|
|
9
|
-
import { Component, Injector } from "@angular/core";
|
|
10
|
-
|
|
11
|
-
@Component({
|
|
12
|
-
template: "<p>Fake Home Component</p>"
|
|
13
|
-
})
|
|
14
|
-
class FakeHomeComponent {}
|
|
15
|
-
class FakeAboutComponent {}
|
|
16
|
-
describe("ReactAI", () => {
|
|
17
|
-
let fixture: ComponentFixture<AngularPlugin>;
|
|
18
|
-
let angularPlugin: AngularPlugin;
|
|
19
|
-
let analyticsPlugin: AnalyticsPlugin;
|
|
20
|
-
let core: AppInsightsCore;
|
|
21
|
-
let channel: ChannelPlugin;
|
|
22
|
-
let router: Router;
|
|
23
|
-
|
|
24
|
-
let angularPlugin2: AngularPlugin;
|
|
25
|
-
let analyticsPlugin2: AnalyticsPlugin;
|
|
26
|
-
let core2: AppInsightsCore;
|
|
27
|
-
|
|
28
|
-
let angularPlugin3: AngularPlugin;
|
|
29
|
-
let analyticsPlugin3: AnalyticsPlugin;
|
|
30
|
-
let core3: AppInsightsCore;
|
|
31
|
-
|
|
32
|
-
let angularPlugin4: AngularPlugin;
|
|
33
|
-
let analyticsPlugin4: AnalyticsPlugin;
|
|
34
|
-
let core4: AppInsightsCore;
|
|
35
|
-
|
|
36
|
-
const arg1: Injector = Injector.create({
|
|
37
|
-
providers: [
|
|
38
|
-
{ provide: ApplicationinsightsAngularpluginErrorService, useClass: ApplicationinsightsAngularpluginErrorService }
|
|
39
|
-
]
|
|
40
|
-
});
|
|
41
|
-
const arg2: Injector = Injector.create({
|
|
42
|
-
providers: [
|
|
43
|
-
{ provide: ApplicationinsightsAngularpluginErrorService, useClass: ApplicationinsightsAngularpluginErrorService }
|
|
44
|
-
]
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
const spy = jasmine.createSpyObj("AnalyticsPlugin", ["trackPageView"]);
|
|
49
|
-
TestBed.configureTestingModule({
|
|
50
|
-
declarations: [AngularPlugin],
|
|
51
|
-
imports: [
|
|
52
|
-
RouterTestingModule.withRoutes([
|
|
53
|
-
{ path: "home", component: FakeHomeComponent },
|
|
54
|
-
{ path: "about", component: FakeAboutComponent },
|
|
55
|
-
{ path: "test", component: FakeHomeComponent }
|
|
56
|
-
])
|
|
57
|
-
],
|
|
58
|
-
providers: [
|
|
59
|
-
{ provide: AnalyticsPlugin, useValue: spy }
|
|
60
|
-
]
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
TestBed.overrideProvider(AngularPlugin, { useValue: new AngularPlugin(arg1) });
|
|
64
|
-
fixture = TestBed.createComponent(AngularPlugin);
|
|
65
|
-
angularPlugin = fixture.componentInstance;
|
|
66
|
-
|
|
67
|
-
// TestBed.overrideProvider(AngularPlugin, { useValue: new AngularPlugin() });
|
|
68
|
-
// fixture2 = TestBed.createComponent(AngularPlugin);
|
|
69
|
-
// angularPlugin2 = fixture2.componentInstance;
|
|
70
|
-
|
|
71
|
-
angularPlugin2 = new AngularPlugin(arg2);
|
|
72
|
-
angularPlugin3 = new AngularPlugin();
|
|
73
|
-
angularPlugin4 = new AngularPlugin();
|
|
74
|
-
|
|
75
|
-
// this is for analyticsPluginSpy
|
|
76
|
-
TestBed.inject(ApplicationinsightsAngularpluginErrorService);
|
|
77
|
-
router = TestBed.inject(Router);
|
|
78
|
-
|
|
79
|
-
// Get the spy on trackPageView from the spy object
|
|
80
|
-
TestBed.inject(AnalyticsPlugin) as jasmine.SpyObj<AnalyticsPlugin>;
|
|
81
|
-
fixture.detectChanges();
|
|
82
|
-
|
|
83
|
-
// Setup
|
|
84
|
-
analyticsPlugin = new AnalyticsPlugin();
|
|
85
|
-
analyticsPlugin2 = new AnalyticsPlugin();
|
|
86
|
-
analyticsPlugin3 = new AnalyticsPlugin();
|
|
87
|
-
analyticsPlugin4 = new AnalyticsPlugin();
|
|
88
|
-
|
|
89
|
-
core = new AppInsightsCore();
|
|
90
|
-
core2 = new AppInsightsCore();
|
|
91
|
-
core3 = new AppInsightsCore();
|
|
92
|
-
core4 = new AppInsightsCore();
|
|
93
|
-
|
|
94
|
-
channel = new ChannelPlugin();
|
|
95
|
-
|
|
96
|
-
core.initialize({
|
|
97
|
-
instrumentationKey: "",
|
|
98
|
-
extensionConfig: {
|
|
99
|
-
[angularPlugin.identifier]: {useInjector: true }
|
|
100
|
-
}
|
|
101
|
-
} as IConfig & IConfiguration, [angularPlugin, analyticsPlugin, channel]);
|
|
102
|
-
|
|
103
|
-
core2.initialize({
|
|
104
|
-
instrumentationKey: "",
|
|
105
|
-
extensionConfig: {
|
|
106
|
-
[angularPlugin.identifier]: {useInjector: true }
|
|
107
|
-
}
|
|
108
|
-
} as IConfig & IConfiguration, [angularPlugin2, analyticsPlugin2, channel]);
|
|
109
|
-
|
|
110
|
-
core3.initialize({
|
|
111
|
-
instrumentationKey: "",
|
|
112
|
-
extensionConfig: {
|
|
113
|
-
[angularPlugin.identifier]: {useInjector: true }
|
|
114
|
-
}
|
|
115
|
-
} as IConfig & IConfiguration, [angularPlugin3, analyticsPlugin3, channel]);
|
|
116
|
-
|
|
117
|
-
core4.initialize({
|
|
118
|
-
instrumentationKey: "",
|
|
119
|
-
extensionConfig: {
|
|
120
|
-
[angularPlugin.identifier]: {useInjector: false }
|
|
121
|
-
}
|
|
122
|
-
} as IConfig & IConfiguration, [angularPlugin4, analyticsPlugin4, channel]);
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
afterEach(() => {
|
|
127
|
-
// Unload and remove any previous resources
|
|
128
|
-
core.unload(false);
|
|
129
|
-
|
|
130
|
-
// clean up
|
|
131
|
-
analyticsPlugin = undefined;
|
|
132
|
-
analyticsPlugin2 = undefined;
|
|
133
|
-
analyticsPlugin3 = undefined;
|
|
134
|
-
analyticsPlugin4 = undefined;
|
|
135
|
-
|
|
136
|
-
core = undefined;
|
|
137
|
-
channel = undefined;
|
|
138
|
-
ApplicationinsightsAngularpluginErrorService.instance = null; // reset the singleton instance to null for re-assignment
|
|
139
|
-
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("Multiple: router could be added and removed", fakeAsync(()=> {
|
|
143
|
-
console.log("multiple -- ");
|
|
144
|
-
expect(angularPlugin["_getDbgPlgTargets"]().router).toEqual(undefined);
|
|
145
|
-
expect(angularPlugin2["_getDbgPlgTargets"]().router).toEqual(undefined);
|
|
146
|
-
|
|
147
|
-
core.config.extensionConfig[angularPlugin.identifier].router = router;
|
|
148
|
-
tick(3000);
|
|
149
|
-
expect(angularPlugin["_getDbgPlgTargets"]().router).toEqual(router);
|
|
150
|
-
|
|
151
|
-
// add error handler in angularPlugin1 should not affect angularPlugin2
|
|
152
|
-
let customErrorHandler = new CustomErrorHandler();
|
|
153
|
-
angularPlugin["_getErrorService"]().addErrorHandler(customErrorHandler);
|
|
154
|
-
const spy = spyOn(customErrorHandler, "handleError");
|
|
155
|
-
angularPlugin["_getErrorService"]().handleError();
|
|
156
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
157
|
-
|
|
158
|
-
angularPlugin2["_getErrorService"]().handleError();
|
|
159
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
160
|
-
|
|
161
|
-
angularPlugin3["_getErrorService"]().handleError();
|
|
162
|
-
angularPlugin4["_getErrorService"]().handleError();
|
|
163
|
-
expect(spy).toHaveBeenCalledTimes(3);
|
|
164
|
-
|
|
165
|
-
// on contrast, adding error handler to angularPlugin3 will affect angularPlugin4
|
|
166
|
-
// as they share the same ApplicationinsightsAngularpluginErrorService
|
|
167
|
-
// it will also affect angularPlugin1 as 3 is sharing from 1 error service instance
|
|
168
|
-
let customErrorHandler2 = new CustomErrorHandler2();
|
|
169
|
-
angularPlugin3["_getErrorService"]().addErrorHandler(customErrorHandler2);
|
|
170
|
-
const spy2 = spyOn(customErrorHandler2, "handleError");
|
|
171
|
-
angularPlugin3["_getErrorService"]().handleError();
|
|
172
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
173
|
-
|
|
174
|
-
angularPlugin["_getErrorService"]().handleError();
|
|
175
|
-
expect(spy2).toHaveBeenCalledTimes(2);
|
|
176
|
-
|
|
177
|
-
angularPlugin2["_getErrorService"]().handleError();
|
|
178
|
-
expect(spy2).toHaveBeenCalledTimes(2);
|
|
179
|
-
|
|
180
|
-
angularPlugin4["_getErrorService"]().handleError();
|
|
181
|
-
expect(spy2).toHaveBeenCalledTimes(3);
|
|
182
|
-
}));
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
-
class CustomErrorHandler {
|
|
187
|
-
constructor() {
|
|
188
|
-
}
|
|
189
|
-
handleError() {
|
|
190
|
-
return "Custom error handler";
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
class CustomErrorHandler2 {
|
|
194
|
-
constructor() {
|
|
195
|
-
}
|
|
196
|
-
handleError() {
|
|
197
|
-
return "Custom error handler";
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
class ChannelPlugin implements IPlugin {
|
|
201
|
-
public isFlushInvoked = false;
|
|
202
|
-
public isTearDownInvoked = false;
|
|
203
|
-
public isResumeInvoked = false;
|
|
204
|
-
public isPauseInvoked = false;
|
|
205
|
-
|
|
206
|
-
public identifier = "Sender";
|
|
207
|
-
|
|
208
|
-
public priority: number = 1001;
|
|
209
|
-
|
|
210
|
-
constructor() {
|
|
211
|
-
this.processTelemetry = this._processTelemetry.bind(this);
|
|
212
|
-
}
|
|
213
|
-
public pause(): void {
|
|
214
|
-
this.isPauseInvoked = true;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
public resume(): void {
|
|
218
|
-
this.isResumeInvoked = true;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public teardown(): void {
|
|
222
|
-
this.isTearDownInvoked = true;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
flush(async?: boolean, callBack?: () => void): void {
|
|
226
|
-
this.isFlushInvoked = true;
|
|
227
|
-
if (callBack) {
|
|
228
|
-
callBack();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
public processTelemetry(env: ITelemetryItem) { }
|
|
233
|
-
|
|
234
|
-
setNextPlugin(next: any) {
|
|
235
|
-
// no next setup
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
public initialize = (config: IConfiguration, core: IAppInsightsCore, plugin: IPlugin[]) => {
|
|
239
|
-
// Mocked - Do Nothing
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
private _processTelemetry(env: ITelemetryItem) {
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
|
2
|
-
import { AppInsightsCore, IConfiguration, ITelemetryItem, IPlugin } from "@microsoft/applicationinsights-core-js";
|
|
3
|
-
import { AnalyticsPlugin } from "@microsoft/applicationinsights-analytics-js";
|
|
4
|
-
import { IConfig } from "@microsoft/applicationinsights-common";
|
|
5
|
-
import { ApplicationinsightsAngularpluginErrorService } from "./applicationinsights-angularplugin-error.service";
|
|
6
|
-
import { AngularPlugin } from "../lib/applicationinsights-angularplugin-js.component";
|
|
7
|
-
|
|
8
|
-
describe("ApplicationinsightsAngularpluginErrorService", () => {
|
|
9
|
-
let service: ApplicationinsightsAngularpluginErrorService;
|
|
10
|
-
let fixture: ComponentFixture<AngularPlugin>;
|
|
11
|
-
let component: AngularPlugin;
|
|
12
|
-
let appInsights: AnalyticsPlugin;
|
|
13
|
-
let core: AppInsightsCore;
|
|
14
|
-
let channel: ChannelPlugin;
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
TestBed.configureTestingModule({
|
|
18
|
-
declarations: [AngularPlugin]
|
|
19
|
-
});
|
|
20
|
-
service = TestBed.inject(ApplicationinsightsAngularpluginErrorService);
|
|
21
|
-
fixture = TestBed.createComponent(AngularPlugin);
|
|
22
|
-
component = fixture.componentInstance;
|
|
23
|
-
fixture.detectChanges();
|
|
24
|
-
|
|
25
|
-
// Setup
|
|
26
|
-
appInsights = new AnalyticsPlugin();
|
|
27
|
-
core = new AppInsightsCore();
|
|
28
|
-
channel = new ChannelPlugin();
|
|
29
|
-
|
|
30
|
-
// Act
|
|
31
|
-
core.initialize({
|
|
32
|
-
instrumentationKey: "",
|
|
33
|
-
enableAutoRouteTracking: true,
|
|
34
|
-
extensions: [component]
|
|
35
|
-
} as IConfig & IConfiguration, [appInsights, channel]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
afterEach(() => {
|
|
39
|
-
// Unload and remove any previous resources
|
|
40
|
-
core.unload(false);
|
|
41
|
-
|
|
42
|
-
// clean up
|
|
43
|
-
appInsights = undefined;
|
|
44
|
-
core = undefined;
|
|
45
|
-
channel = undefined;
|
|
46
|
-
ApplicationinsightsAngularpluginErrorService.instance = null; // reset the singleton instance to null for re-assignment
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should be created", () => {
|
|
51
|
-
expect(service).toBeTruthy();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should assign analytics plugin to service plugin property", () => {
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
56
|
-
expect(service["analyticsPlugin"]).toBeTruthy();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// this is not testing if handleError is called - Angular does that already
|
|
60
|
-
it("should capture uncaught exception and send exception telemetry", () => {
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
62
|
-
const spy = spyOn(service["analyticsPlugin"], "trackException");
|
|
63
|
-
const error: Error = new Error("ERROR");
|
|
64
|
-
service.handleError(error);
|
|
65
|
-
expect(spy).toHaveBeenCalledWith({ exception: error });
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
class ChannelPlugin implements IPlugin {
|
|
70
|
-
|
|
71
|
-
public isFlushInvoked = false;
|
|
72
|
-
public isTearDownInvoked = false;
|
|
73
|
-
public isResumeInvoked = false;
|
|
74
|
-
public isPauseInvoked = false;
|
|
75
|
-
|
|
76
|
-
public processTelemetry;
|
|
77
|
-
|
|
78
|
-
public identifier = "Sender";
|
|
79
|
-
|
|
80
|
-
public priority = 1001;
|
|
81
|
-
|
|
82
|
-
constructor() {
|
|
83
|
-
this.processTelemetry = this._processTelemetry.bind(this);
|
|
84
|
-
}
|
|
85
|
-
public pause(): void {
|
|
86
|
-
this.isPauseInvoked = true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public resume(): void {
|
|
90
|
-
this.isResumeInvoked = true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public teardown(): void {
|
|
94
|
-
this.isTearDownInvoked = true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
flush(async?: boolean, callBack?: () => void): void {
|
|
98
|
-
this.isFlushInvoked = true;
|
|
99
|
-
if (callBack) {
|
|
100
|
-
callBack();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setNextPlugin(next: any): void {
|
|
105
|
-
// no next setup
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public initialize = (config: IConfiguration) => {
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
private _processTelemetry(env: ITelemetryItem): void {
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Injectable } from "@angular/core";
|
|
2
|
-
import { IAppInsights } from "@microsoft/applicationinsights-common";
|
|
3
|
-
import { arrForEach, isFunction } from "@microsoft/applicationinsights-core-js";
|
|
4
|
-
import { IErrorService } from "./IErrorService";
|
|
5
|
-
|
|
6
|
-
@Injectable({
|
|
7
|
-
providedIn: "root"
|
|
8
|
-
})
|
|
9
|
-
export class ApplicationinsightsAngularpluginErrorService implements IErrorService {
|
|
10
|
-
public static instance: ApplicationinsightsAngularpluginErrorService = null;
|
|
11
|
-
private analyticsPlugin: IAppInsights;
|
|
12
|
-
private errorServices: IErrorService[] = [];
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
if (ApplicationinsightsAngularpluginErrorService.instance === null) {
|
|
16
|
-
ApplicationinsightsAngularpluginErrorService.instance = this;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public set plugin(analyticsPlugin: IAppInsights) {
|
|
21
|
-
this.analyticsPlugin = analyticsPlugin;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public clearErrorHandlers() {
|
|
25
|
-
this.errorServices = [];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public addErrorHandler(errorService: IErrorService): void {
|
|
29
|
-
if (errorService && isFunction(errorService.handleError)) {
|
|
30
|
-
this.errorServices.push(errorService);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public removeErrorHandler(errorService: IErrorService): void {
|
|
35
|
-
if (errorService && isFunction(errorService.handleError)) {
|
|
36
|
-
const idx = this.errorServices.indexOf(errorService);
|
|
37
|
-
if (idx !== -1) {
|
|
38
|
-
this.errorServices.splice(idx, 1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
handleError(error: any): void {
|
|
44
|
-
if (this.analyticsPlugin) {
|
|
45
|
-
this.analyticsPlugin.trackException({ exception: error });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (this.errorServices && this.errorServices.length > 0) {
|
|
49
|
-
arrForEach(this.errorServices, errorService => {
|
|
50
|
-
if (isFunction(errorService.handleError)) {
|
|
51
|
-
errorService.handleError(error);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { AppInsightsCore, IConfiguration, ITelemetryItem, IPlugin, IAppInsightsCore } from "@microsoft/applicationinsights-core-js";
|
|
2
|
-
import { IConfig, IPageViewTelemetry } from "@microsoft/applicationinsights-common";
|
|
3
|
-
import { AngularPlugin } from "./applicationinsights-angularplugin-js.component";
|
|
4
|
-
import { ComponentFixture, TestBed, fakeAsync, tick } from "@angular/core/testing";
|
|
5
|
-
import { Router } from "@angular/router";
|
|
6
|
-
import { ApplicationinsightsAngularpluginErrorService } from "./applicationinsights-angularplugin-error.service";
|
|
7
|
-
import { AnalyticsPlugin } from "@microsoft/applicationinsights-analytics-js";
|
|
8
|
-
import { RouterTestingModule } from "@angular/router/testing";
|
|
9
|
-
import { Component } from "@angular/core";
|
|
10
|
-
|
|
11
|
-
@Component({
|
|
12
|
-
template: "<p>Fake Home Component</p>"
|
|
13
|
-
})
|
|
14
|
-
class FakeHomeComponent {}
|
|
15
|
-
class FakeAboutComponent {}
|
|
16
|
-
describe("ReactAI", () => {
|
|
17
|
-
|
|
18
|
-
let fixture: ComponentFixture<AngularPlugin>;
|
|
19
|
-
let angularPlugin: AngularPlugin;
|
|
20
|
-
let analyticsPlugin: AnalyticsPlugin;
|
|
21
|
-
let core: AppInsightsCore;
|
|
22
|
-
let channel: ChannelPlugin;
|
|
23
|
-
let router: Router;
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
const spy = jasmine.createSpyObj("AnalyticsPlugin", ["trackPageView"]);
|
|
27
|
-
TestBed.configureTestingModule({
|
|
28
|
-
declarations: [AngularPlugin],
|
|
29
|
-
imports: [
|
|
30
|
-
RouterTestingModule.withRoutes([
|
|
31
|
-
{ path: "home", component: FakeHomeComponent },
|
|
32
|
-
{ path: "about", component: FakeAboutComponent },
|
|
33
|
-
{ path: "test", component: FakeHomeComponent }
|
|
34
|
-
])
|
|
35
|
-
],
|
|
36
|
-
providers: [
|
|
37
|
-
{ provide: AnalyticsPlugin, useValue: spy }
|
|
38
|
-
]
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
TestBed.inject(ApplicationinsightsAngularpluginErrorService);
|
|
42
|
-
fixture = TestBed.createComponent(AngularPlugin);
|
|
43
|
-
angularPlugin = fixture.componentInstance;
|
|
44
|
-
router = TestBed.inject(Router);
|
|
45
|
-
|
|
46
|
-
// Get the spy on trackPageView from the spy object
|
|
47
|
-
// analyticsPluginSpy
|
|
48
|
-
TestBed.inject(AnalyticsPlugin) as jasmine.SpyObj<AnalyticsPlugin>;
|
|
49
|
-
fixture.detectChanges();
|
|
50
|
-
|
|
51
|
-
// Setup
|
|
52
|
-
analyticsPlugin = new AnalyticsPlugin();
|
|
53
|
-
core = new AppInsightsCore();
|
|
54
|
-
channel = new ChannelPlugin();
|
|
55
|
-
|
|
56
|
-
core.initialize({
|
|
57
|
-
instrumentationKey: "",
|
|
58
|
-
extensionConfig: {
|
|
59
|
-
[angularPlugin.identifier]: { }
|
|
60
|
-
}
|
|
61
|
-
} as IConfig & IConfiguration, [angularPlugin, analyticsPlugin, channel]);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
afterEach(() => {
|
|
67
|
-
// Unload and remove any previous resources
|
|
68
|
-
core.unload(false);
|
|
69
|
-
|
|
70
|
-
// clean up
|
|
71
|
-
analyticsPlugin = undefined;
|
|
72
|
-
core = undefined;
|
|
73
|
-
channel = undefined;
|
|
74
|
-
ApplicationinsightsAngularpluginErrorService.instance = null; // reset the singleton instance to null for re-assignment
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("Dynamic Config Test: router could be added and removed", fakeAsync(()=> {
|
|
79
|
-
expect(angularPlugin["_getDbgPlgTargets"]().router).toEqual(undefined);
|
|
80
|
-
core.config.extensionConfig[angularPlugin.identifier].router = router;
|
|
81
|
-
tick(3000);
|
|
82
|
-
expect(angularPlugin["_getDbgPlgTargets"]().router).toEqual(router);
|
|
83
|
-
}));
|
|
84
|
-
|
|
85
|
-
it("Dynamic Config Test: trackPageView is updated when router changed", fakeAsync(()=> {
|
|
86
|
-
spyOn(angularPlugin, "trackPageView");
|
|
87
|
-
core.config.extensionConfig[angularPlugin.identifier].router = router;
|
|
88
|
-
tick(3000);
|
|
89
|
-
expect(angularPlugin["_getDbgPlgTargets"]().router).toEqual(router);
|
|
90
|
-
|
|
91
|
-
expect(angularPlugin.trackPageView).toHaveBeenCalledTimes(1);
|
|
92
|
-
let args = (angularPlugin.trackPageView as jasmine.Spy).calls.mostRecent().args;
|
|
93
|
-
let pageViewEvents: IPageViewTelemetry = args[0];
|
|
94
|
-
expect(pageViewEvents.uri).toEqual(router.url);
|
|
95
|
-
router.navigate(["about"]).then(() => {
|
|
96
|
-
expect(angularPlugin.trackPageView).toHaveBeenCalledTimes(1);
|
|
97
|
-
router.navigate(["test"]).then(() => {
|
|
98
|
-
expect(angularPlugin.trackPageView).toHaveBeenCalledTimes(2);
|
|
99
|
-
let funcArgs = (angularPlugin.trackPageView as jasmine.Spy).calls.mostRecent().args;
|
|
100
|
-
pageViewEvents = funcArgs[0];
|
|
101
|
-
expect(pageViewEvents.uri).toEqual("/test");
|
|
102
|
-
router.navigateByUrl("about").then(() => {
|
|
103
|
-
funcArgs = (angularPlugin.trackPageView as jasmine.Spy).calls.mostRecent().args;
|
|
104
|
-
pageViewEvents = funcArgs[0];
|
|
105
|
-
expect(pageViewEvents.uri).toEqual("/about");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
}));
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
class ChannelPlugin implements IPlugin {
|
|
114
|
-
public isFlushInvoked = false;
|
|
115
|
-
public isTearDownInvoked = false;
|
|
116
|
-
public isResumeInvoked = false;
|
|
117
|
-
public isPauseInvoked = false;
|
|
118
|
-
|
|
119
|
-
public identifier = "Sender";
|
|
120
|
-
|
|
121
|
-
public priority: number = 1001;
|
|
122
|
-
|
|
123
|
-
constructor() {
|
|
124
|
-
this.processTelemetry = this._processTelemetry.bind(this);
|
|
125
|
-
}
|
|
126
|
-
public pause(): void {
|
|
127
|
-
this.isPauseInvoked = true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public resume(): void {
|
|
131
|
-
this.isResumeInvoked = true;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public teardown(): void {
|
|
135
|
-
this.isTearDownInvoked = true;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
flush(async?: boolean, callBack?: () => void): void {
|
|
139
|
-
this.isFlushInvoked = true;
|
|
140
|
-
if (callBack) {
|
|
141
|
-
callBack();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public processTelemetry(env: ITelemetryItem) { }
|
|
146
|
-
|
|
147
|
-
setNextPlugin(next: any) {
|
|
148
|
-
// no next setup
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public initialize = (config: IConfiguration, core: IAppInsightsCore, plugin: IPlugin[]) => {
|
|
152
|
-
// Mocked - Do Nothing
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
private _processTelemetry(env: ITelemetryItem) {
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
}
|