@microsoft/applicationinsights-angularplugin-js 15.1.0 → 15.1.1

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.
Files changed (35) hide show
  1. package/.eslintrc.json +74 -0
  2. package/NOTICE +17 -0
  3. package/PRIVACY +3 -0
  4. package/SECURITY.md +41 -0
  5. package/SUPPORT.md +14 -0
  6. package/karma.conf.js +43 -0
  7. package/ng-package.json +15 -0
  8. package/package.json +30 -47
  9. package/{lib/IErrorService.d.ts → src/lib/IErrorService.ts} +1 -0
  10. package/src/lib/applicationininsights-angularplugin-multiple-instace.spec.ts +245 -0
  11. package/src/lib/applicationinsights-angularplugin-error.service.spec.ts +113 -0
  12. package/src/lib/applicationinsights-angularplugin-error.service.ts +57 -0
  13. package/src/lib/applicationinsights-angularplugin-js.component.spec.ts +158 -0
  14. package/src/lib/applicationinsights-angularplugin-js.component.ts +203 -0
  15. package/src/lib/applicationinsights-angularplugin-js.module.ts +14 -0
  16. package/{public-api.d.ts → src/public-api.ts} +4 -0
  17. package/src/test.ts +13 -0
  18. package/tsconfig.lib.json +30 -0
  19. package/tsconfig.lib.prod.json +10 -0
  20. package/tsconfig.spec.json +17 -0
  21. package/esm2020/lib/IErrorService.mjs +0 -2
  22. package/esm2020/lib/applicationinsights-angularplugin-error.service.mjs +0 -52
  23. package/esm2020/lib/applicationinsights-angularplugin-js.component.mjs +0 -152
  24. package/esm2020/lib/applicationinsights-angularplugin-js.module.mjs +0 -23
  25. package/esm2020/microsoft-applicationinsights-angularplugin-js.mjs +0 -5
  26. package/esm2020/public-api.mjs +0 -8
  27. package/fesm2015/microsoft-applicationinsights-angularplugin-js.mjs +0 -231
  28. package/fesm2015/microsoft-applicationinsights-angularplugin-js.mjs.map +0 -1
  29. package/fesm2020/microsoft-applicationinsights-angularplugin-js.mjs +0 -230
  30. package/fesm2020/microsoft-applicationinsights-angularplugin-js.mjs.map +0 -1
  31. package/index.d.ts +0 -5
  32. package/lib/applicationinsights-angularplugin-error.service.d.ts +0 -16
  33. package/lib/applicationinsights-angularplugin-js.component.d.ts +0 -20
  34. package/lib/applicationinsights-angularplugin-js.module.d.ts +0 -7
  35. package/microsoft-applicationinsights-angularplugin-js-15.1.0.tgz +0 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "extends": "../../.eslintrc.json",
3
+ "ignorePatterns": [
4
+ "!**/*"
5
+ ],
6
+ "overrides": [
7
+ {
8
+ "files": [
9
+ "*.ts"
10
+ ],
11
+ "parserOptions": {
12
+ "project": [
13
+ "projects/applicationinsights-angularplugin-js/tsconfig.lib.json",
14
+ "projects/applicationinsights-angularplugin-js/tsconfig.spec.json"
15
+ ],
16
+ "createDefaultProgram": true
17
+ },
18
+ "rules": {
19
+ "indent": ["error"], // Enabling for auto fixing
20
+ "quotes": ["warn", "double"], // Enabled for auto fixing
21
+ "curly": [ "error" ], // Enabling for auto fixing
22
+ "brace-style": [ "error" ], // Enabling for auto fixing
23
+ "prefer-const": "off",
24
+ "prefer-spread": "off",
25
+ "no-var": "off",
26
+ "no-extra-boolean-cast": "off",
27
+ "prefer-rest-params": "off",
28
+ "no-case-declarations": "off",
29
+ "no-prototype-builtins": "off",
30
+ "no-useless-escape": "off", // Suppressing Error -- need to Review Later
31
+ "no-trailing-spaces": [ "warn", { "skipBlankLines": true }],// Enabled for auto fixing
32
+ "no-const-assign": "error",
33
+ "comma-dangle": [ "error", "never" ], // Enabled for auto fixing
34
+ "security/detect-object-injection": "off", // Suppress Warning -- need to Review Later
35
+ "security/detect-non-literal-fs-filename": "off", // This was causing a bunch of false positive matches for dynamic config "watch" function
36
+ "@typescript-eslint/ban-types": "off",
37
+ "@typescript-eslint/no-unused-vars": [ "warn", { "vars": "all", "args": "none", "argsIgnorePattern": "^_", "ignoreRestSiblings": true } ],
38
+ "@typescript-eslint/triple-slash-reference": "off",
39
+ "@typescript-eslint/no-inferrable-types": "off",
40
+ "@typescript-eslint/no-this-alias": "off",
41
+ "@typescript-eslint/no-explicit-any": "off",
42
+ "@typescript-eslint/no-empty-function": "off",
43
+ "@typescript-eslint/no-empty-interface": "off",
44
+ "@typescript-eslint/explicit-module-boundary-types": "off",
45
+ "@typescript-eslint/no-extra-semi": "error", // Enabled for auto fixing
46
+ "@typescript-eslint/no-non-null-assertion": "error",
47
+ "@typescript-eslint/dot-notation": "off",
48
+ "@typescript-eslint/quotes": ["warn", "double"],
49
+ "@angular-eslint/component-selector": [
50
+ "error",
51
+ {
52
+ "type": "element",
53
+ "prefix": "lib",
54
+ "style": "kebab-case"
55
+ }
56
+ ],
57
+ "@angular-eslint/directive-selector": [
58
+ "error",
59
+ {
60
+ "type": "attribute",
61
+ "prefix": "lib",
62
+ "style": "camelCase"
63
+ }
64
+ ]
65
+ }
66
+ },
67
+ {
68
+ "files": [
69
+ "*.html"
70
+ ],
71
+ "rules": {}
72
+ }
73
+ ]
74
+ }
package/NOTICE ADDED
@@ -0,0 +1,17 @@
1
+ NOTICES AND INFORMATION
2
+ Do Not Translate or Localize
3
+
4
+ This software incorporates material from third parties. Microsoft makes certain
5
+ open source code available at https://3rdpartysource.microsoft.com, or you may
6
+ send a check or money order for US $5.00, including the product name, the open
7
+ source component name, and version number, to:
8
+
9
+ Source Code Compliance Team
10
+ Microsoft Corporation
11
+ One Microsoft Way
12
+ Redmond, WA 98052
13
+ USA
14
+
15
+ Notwithstanding any other terms, you may reverse engineer this software to the
16
+ extent required to debug changes to any libraries licensed under the GNU Lesser
17
+ General Public License.
package/PRIVACY ADDED
@@ -0,0 +1,3 @@
1
+ # Data Collection
2
+
3
+ The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
package/SECURITY.md ADDED
@@ -0,0 +1,41 @@
1
+ <!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->
2
+
3
+ ## Security
4
+
5
+ Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6
+
7
+ If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
8
+
9
+ ## Reporting Security Issues
10
+
11
+ **Please do not report security vulnerabilities through public GitHub issues.**
12
+
13
+ Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
14
+
15
+ If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
16
+
17
+ You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18
+
19
+ Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20
+
21
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22
+ * Full paths of source file(s) related to the manifestation of the issue
23
+ * The location of the affected source code (tag/branch/commit or direct URL)
24
+ * Any special configuration required to reproduce the issue
25
+ * Step-by-step instructions to reproduce the issue
26
+ * Proof-of-concept or exploit code (if possible)
27
+ * Impact of the issue, including how an attacker might exploit the issue
28
+
29
+ This information will help us triage your report more quickly.
30
+
31
+ If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
32
+
33
+ ## Preferred Languages
34
+
35
+ We prefer all communications to be in English.
36
+
37
+ ## Policy
38
+
39
+ Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
40
+
41
+ <!-- END MICROSOFT SECURITY.MD BLOCK -->
package/SUPPORT.md ADDED
@@ -0,0 +1,14 @@
1
+ # Support
2
+
3
+ ## How to file issues and get help
4
+
5
+ This project uses GitHub Issues to track bugs and feature requests. Please search the existing
6
+ issues before filing new issues to avoid duplicates. For new issues, file your bug or
7
+ feature request as a new Issue.
8
+
9
+ For help and questions about using this project, please create a Support request issue on
10
+ https://github.com/microsoft/applicationinsights-angularplugin-js/issues.
11
+
12
+ ## Microsoft Support Policy
13
+
14
+ Support for this **PROJECT or PRODUCT** is limited to the resources listed above.
package/karma.conf.js ADDED
@@ -0,0 +1,43 @@
1
+ // Karma configuration file, see link for more information
2
+ // https://karma-runner.github.io/1.0/config/configuration-file.html
3
+
4
+ module.exports = function (config) {
5
+ config.set({
6
+ basePath: '',
7
+ frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
+ plugins: [
9
+ require('karma-jasmine'),
10
+ require('karma-chrome-launcher'),
11
+ require('karma-coverage'),
12
+ require('@angular-devkit/build-angular/plugins/karma')
13
+ ],
14
+ client: {
15
+ jasmine: {
16
+ // you can add configuration options for Jasmine here
17
+ // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
18
+ // for example, you can disable the random execution with `random: false`
19
+ // or set a specific seed with `seed: 4321`
20
+ },
21
+ clearContext: false // leave Jasmine Spec Runner output visible in browser
22
+ },
23
+ jasmineHtmlReporter: {
24
+ suppressAll: true // removes the duplicated traces
25
+ },
26
+ coverageReporter: {
27
+ dir: require('path').join(__dirname, '../../coverage'),
28
+ subdir: '.',
29
+ reporters: [
30
+ { type: 'text' },
31
+ { type: 'html-spa' }
32
+ ]
33
+ },
34
+ reporters: ['progress'],
35
+ port: 9876,
36
+ colors: true,
37
+ logLevel: config.LOG_INFO,
38
+ autoWatch: true,
39
+ browsers: ['Chrome'],
40
+ singleRun: false,
41
+ restartOnFileChange: true
42
+ });
43
+ };
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/applicationinsights-angularplugin-js",
4
+ "deleteDestPath": false,
5
+ "lib": {
6
+ "entryFile": "src/public-api.ts"
7
+ },
8
+ "allowedNonPeerDependencies": [
9
+ "@microsoft/applicationinsights-common",
10
+ "@microsoft/applicationinsights-core-js",
11
+ "@microsoft/applicationinsights-properties-js",
12
+ "@microsoft/applicationinsights-rollup-es3",
13
+ "@microsoft/applicationinsights-shims"
14
+ ]
15
+ }
package/package.json CHANGED
@@ -1,47 +1,30 @@
1
- {
2
- "name": "@microsoft/applicationinsights-angularplugin-js",
3
- "version": "15.1.0",
4
- "description": "Microsoft Application Insights Angular plugin",
5
- "author": "Microsoft Application Insights Team",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/microsoft/applicationinsights-angularplugin-js"
10
- },
11
- "bugs": {
12
- "url": "https://github.com/microsoft/applicationinsights-angularplugin-js/issues"
13
- },
14
- "homepage": "https://github.com/microsoft/applicationinsights-angularplugin-js#readme",
15
- "dependencies": {
16
- "@microsoft/applicationinsights-shims": "^3.0.1",
17
- "@microsoft/applicationinsights-common": "^3.1.0",
18
- "@microsoft/applicationinsights-core-js": "^3.1.0",
19
- "@microsoft/applicationinsights-properties-js": "^3.1.0",
20
- "tslib": "^2.0.0"
21
- },
22
- "peerDependencies": {
23
- "@microsoft/applicationinsights-analytics-js": "^3.1.0",
24
- "@angular/common": ">= 14.0.3",
25
- "@angular/core": ">= 14.0.3"
26
- },
27
- "module": "fesm2015/microsoft-applicationinsights-angularplugin-js.mjs",
28
- "es2020": "fesm2020/microsoft-applicationinsights-angularplugin-js.mjs",
29
- "esm2020": "esm2020/microsoft-applicationinsights-angularplugin-js.mjs",
30
- "fesm2020": "fesm2020/microsoft-applicationinsights-angularplugin-js.mjs",
31
- "fesm2015": "fesm2015/microsoft-applicationinsights-angularplugin-js.mjs",
32
- "typings": "index.d.ts",
33
- "exports": {
34
- "./package.json": {
35
- "default": "./package.json"
36
- },
37
- ".": {
38
- "types": "./index.d.ts",
39
- "esm2020": "./esm2020/microsoft-applicationinsights-angularplugin-js.mjs",
40
- "es2020": "./fesm2020/microsoft-applicationinsights-angularplugin-js.mjs",
41
- "es2015": "./fesm2015/microsoft-applicationinsights-angularplugin-js.mjs",
42
- "node": "./fesm2015/microsoft-applicationinsights-angularplugin-js.mjs",
43
- "default": "./fesm2020/microsoft-applicationinsights-angularplugin-js.mjs"
44
- }
45
- },
46
- "sideEffects": false
47
- }
1
+ {
2
+ "name": "@microsoft/applicationinsights-angularplugin-js",
3
+ "version": "15.1.1",
4
+ "description": "Microsoft Application Insights Angular plugin",
5
+ "author": "Microsoft Application Insights Team",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/microsoft/applicationinsights-angularplugin-js"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/microsoft/applicationinsights-angularplugin-js/issues"
13
+ },
14
+ "homepage": "https://github.com/microsoft/applicationinsights-angularplugin-js#readme",
15
+ "dependencies": {
16
+ "@microsoft/applicationinsights-shims": "^3.0.1",
17
+ "@microsoft/applicationinsights-common": "^3.1.1",
18
+ "@microsoft/applicationinsights-core-js": "^3.1.1",
19
+ "@microsoft/applicationinsights-properties-js": "^3.1.1",
20
+ "tslib": "^2.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "@microsoft/applicationinsights-analytics-js": "^3.1.1"
24
+ },
25
+ "peerDependencies": {
26
+ "@microsoft/applicationinsights-analytics-js": "^3.1.1",
27
+ "@angular/common": ">= 14.0.3",
28
+ "@angular/core": ">= 14.0.3"
29
+ }
30
+ }
@@ -1,4 +1,5 @@
1
1
  import { ErrorHandler } from "@angular/core";
2
+
2
3
  export interface IErrorService extends ErrorHandler {
3
4
  handleError(error: any): void;
4
5
  }
@@ -0,0 +1,245 @@
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
+ }
@@ -0,0 +1,113 @@
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
+ }