@microsoft/applicationinsights-core-js 2.7.2-nightly.2111-08 → 2.7.2-nightly.2111-09

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 (69) hide show
  1. package/CONTRIBUTING.md +14 -0
  2. package/Tests/Perf/src/CorePerfCheck.Tests.ts +828 -0
  3. package/Tests/Perf/src/aiperftests.ts +6 -0
  4. package/Tests/Perf/tsconfig.json +17 -0
  5. package/Tests/PerfTests.html +54 -0
  6. package/Tests/Unit/src/AppInsightsCoreSize.Tests.ts +59 -0
  7. package/Tests/Unit/src/ApplicationInsightsCore.Tests.ts +1015 -0
  8. package/Tests/Unit/src/CookieManager.Tests.ts +477 -0
  9. package/Tests/Unit/src/HelperFunc.Tests.ts +59 -0
  10. package/Tests/Unit/src/aiunittests.ts +13 -0
  11. package/Tests/UnitTests.html +48 -0
  12. package/Tests/tsconfig.json +17 -0
  13. package/api-extractor.json +361 -0
  14. package/applicationinsights-core-js.build.error.log +205 -0
  15. package/applicationinsights-core-js.build.log +612 -0
  16. package/browser/applicationinsights-core-js.integrity.json +9 -9
  17. package/browser/applicationinsights-core-js.js +1 -1
  18. package/browser/applicationinsights-core-js.js.map +1 -1
  19. package/browser/applicationinsights-core-js.min.js +1 -1
  20. package/browser/applicationinsights-core-js.min.js.map +1 -1
  21. package/dist/applicationinsights-core-js.api.json +1 -1
  22. package/dist/applicationinsights-core-js.d.ts +1 -1
  23. package/dist/applicationinsights-core-js.js +1 -1
  24. package/dist/applicationinsights-core-js.js.map +1 -1
  25. package/dist/applicationinsights-core-js.min.js +1 -1
  26. package/dist/applicationinsights-core-js.min.js.map +1 -1
  27. package/dist/applicationinsights-core-js.rollup.d.ts +1 -1
  28. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  29. package/dist-esm/JavaScriptSDK/BaseCore.js +1 -1
  30. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
  31. package/dist-esm/JavaScriptSDK/ChannelController.js +1 -1
  32. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  33. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  34. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  35. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  36. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  37. package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
  38. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  39. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  40. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  41. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
  42. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  43. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
  44. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +1 -1
  45. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  46. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  62. package/dist-esm/applicationinsights-core-js.js +1 -1
  63. package/microsoft-applicationinsights-core-js-2.7.2-nightly.2111-09.tgz +0 -0
  64. package/package.json +1 -1
  65. package/rollup.config.js +138 -0
  66. package/src/applicationinsights-core-js.ts +59 -0
  67. package/temp/applicationinsights-core-js.api.md +934 -0
  68. package/tslint.json +5 -0
  69. package/types/tsdoc-metadata.json +1 -1
@@ -0,0 +1,477 @@
1
+ import { Assert, AITestClass } from "@microsoft/ai-test-framework";
2
+ import { AppInsightsCore, CoreUtils, createCookieMgr, IAppInsightsCore, IConfiguration, ICookieMgrConfig, IPlugin, ITelemetryItem, newId, _legacyCookieMgr } from "../../../src/applicationinsights-core-js"
3
+ import { _InternalMessageId, LoggingSeverity } from "../../../src/JavaScriptSDK.Enums/LoggingEnums";
4
+ import { _InternalLogMessage, DiagnosticLogger } from "../../../src/JavaScriptSDK/DiagnosticLogger";
5
+
6
+ export class CookieManagerTests extends AITestClass {
7
+ private _cookieMgrCfg: ICookieMgrConfig = {};
8
+ private _config: IConfiguration = {
9
+ cookieCfg: this._cookieMgrCfg
10
+ };
11
+ private _testCookies = {};
12
+
13
+ constructor(emulateEs3: boolean) {
14
+ super("CookieManagerTests", emulateEs3);
15
+ }
16
+
17
+ public testInitialize() {
18
+ let _self = this;
19
+ super.testInitialize();
20
+ _self._cookieMgrCfg = {
21
+ getCookie: (name) => {
22
+ let theValue = _self._testCookies[name] || "";
23
+ return theValue.split(";")[0];
24
+ },
25
+ setCookie: (name, value) => {
26
+ _self._testCookies[name] = value;
27
+ },
28
+ delCookie: (name) => {
29
+ delete _self._testCookies[name]
30
+ }
31
+ }
32
+ _self._config.cookieCfg = _self._cookieMgrCfg;
33
+ }
34
+
35
+ public testCleanup() {
36
+ super.testCleanup();
37
+ }
38
+
39
+ public registerTests() {
40
+
41
+ this.testCase({
42
+ name: "CookieManager: Initialization",
43
+ test: () => {
44
+ let manager = createCookieMgr();
45
+
46
+ Assert.equal("", manager.get("Test"), "Getting a non existent cookie returns empty string");
47
+
48
+ manager = createCookieMgr(null);
49
+ Assert.equal("", manager.get("Test"), "Getting a non existent cookie returns empty string");
50
+
51
+ manager = createCookieMgr(undefined);
52
+ Assert.equal("", manager.get("Test"), "Getting a non existent cookie returns empty string");
53
+
54
+ manager = createCookieMgr({});
55
+ Assert.equal("", manager.get("Test"), "Getting a non existent cookie returns empty string");
56
+
57
+ manager = createCookieMgr({
58
+ cookieCfg: null
59
+ });
60
+ Assert.equal("", manager.get("Test"), "Getting a non existent cookie returns empty string");
61
+
62
+ manager = createCookieMgr({
63
+ cookieCfg: undefined
64
+ });
65
+ Assert.equal("", manager.get("Test"), "Getting a non existent cookie returns empty string");
66
+
67
+ manager = createCookieMgr({
68
+ cookieCfg: {}
69
+ });
70
+ Assert.equal("", manager.get("Test"), "Getting a non existent cookie returns empty string");
71
+ }
72
+ });
73
+
74
+ this.testCase({
75
+ name: "CookieManager: Session get set delete",
76
+ test: () => {
77
+ let manager = createCookieMgr(this._config);
78
+
79
+ let newKey = "test." + newId();
80
+ let newValue = newId();
81
+ manager.set(newKey, newValue);
82
+ Assert.equal(newValue, manager.get(newKey));
83
+ Assert.equal(newValue + "; path=/", this._testCookies[newKey]);
84
+
85
+ manager.del(newKey);
86
+ Assert.equal("", manager.get(newKey));
87
+ Assert.equal(undefined, this._testCookies[newKey]);
88
+
89
+ manager.set(newKey, newValue + "; path=/my-path");
90
+ Assert.equal(newValue, manager.get(newKey));
91
+ Assert.equal(newValue + "; path=/my-path", this._testCookies[newKey]);
92
+
93
+ manager.del(newKey);
94
+ Assert.equal("", manager.get(newKey));
95
+ Assert.equal(undefined, this._testCookies[newKey]);
96
+ }
97
+ });
98
+
99
+ this.testCase({
100
+ name: "CookieManager: Session get set delete with configured path",
101
+ test: () => {
102
+ this._cookieMgrCfg.path = "/sub-path";
103
+ let manager = createCookieMgr(this._config);
104
+
105
+ let newKey = "test." + newId();
106
+ let newValue = newId();
107
+ manager.set(newKey, newValue);
108
+ Assert.equal(newValue, manager.get(newKey));
109
+ Assert.equal(newValue + "; path=/sub-path", this._testCookies[newKey]);
110
+
111
+ manager.del(newKey);
112
+ Assert.equal("", manager.get(newKey));
113
+ Assert.equal(undefined, this._testCookies[newKey]);
114
+
115
+ manager.set(newKey, newValue + "; path=/my-path");
116
+ Assert.equal(newValue, manager.get(newKey));
117
+ Assert.equal(newValue + "; path=/my-path", this._testCookies[newKey]);
118
+
119
+ manager.del(newKey);
120
+ Assert.equal("", manager.get(newKey));
121
+ Assert.equal(undefined, this._testCookies[newKey]);
122
+ }
123
+ });
124
+
125
+ this.testCase({
126
+ name: "CookieManager: Session get set delete with configured domain",
127
+ test: () => {
128
+ this._cookieMgrCfg.domain = "MyDomain.com";
129
+ let manager = createCookieMgr(this._config);
130
+
131
+ let newKey = "test." + newId();
132
+ let newValue = newId();
133
+ manager.set(newKey, newValue);
134
+ Assert.equal(newValue, manager.get(newKey));
135
+ Assert.equal(newValue + "; domain=MyDomain.com; path=/", this._testCookies[newKey]);
136
+
137
+ manager.del(newKey);
138
+ Assert.equal("", manager.get(newKey));
139
+ Assert.equal(undefined, this._testCookies[newKey]);
140
+ }
141
+ });
142
+
143
+ this.testCase({
144
+ name: "CookieManager: Encoded expiry value for get set delete",
145
+ test: () => {
146
+ let manager = createCookieMgr(this._config);
147
+
148
+ let newKey = "test." + newId();
149
+ let newValue = newId();
150
+ manager.set(newKey, newValue + "; path=/subfield; expires=Thu, 12 Feb 2190 00:00:00 GMT");
151
+ Assert.equal(newValue, manager.get(newKey));
152
+ Assert.equal(newValue + "; path=/subfield; expires=Thu, 12 Feb 2190 00:00:00 GMT", this._testCookies[newKey]);
153
+
154
+ manager.del(newKey);
155
+ Assert.equal("", manager.get(newKey));
156
+ Assert.equal(undefined, this._testCookies[newKey]);
157
+ }
158
+ });
159
+
160
+ this.testCase({
161
+ name: "CookieManager: Encoded max-age for get set delete",
162
+ test: () => {
163
+ let manager = createCookieMgr(this._config);
164
+
165
+ let newKey = "test." + newId();
166
+ let newValue = newId();
167
+ manager.set(newKey, newValue + "; path=/subfield; max-age=42");
168
+ Assert.equal(newValue, manager.get(newKey));
169
+ Assert.equal(newValue + "; path=/subfield; max-age=42", this._testCookies[newKey]);
170
+
171
+ manager.del(newKey);
172
+ Assert.equal("", manager.get(newKey));
173
+ Assert.equal(undefined, this._testCookies[newKey]);
174
+ }
175
+ });
176
+
177
+ this.testCase({
178
+ name: "CookieManager: Test with setting max-age",
179
+ useFakeTimers: true,
180
+ test: () => {
181
+ let manager = createCookieMgr(this._config);
182
+
183
+ let newKey = "test." + newId();
184
+ let newValue = newId();
185
+ let maxAge = 42 * 24 * 60 * 60;
186
+ manager.set(newKey, newValue, maxAge);
187
+ Assert.equal(newValue, manager.get(newKey));
188
+ if (this.isEmulatingEs3) {
189
+ Assert.equal(newValue + "; expires=Thu, 12 Feb 1970 00:00:00 GMT; path=/", this._testCookies[newKey]);
190
+ } else {
191
+ Assert.equal(newValue + "; expires=Thu, 12 Feb 1970 00:00:00 GMT; max-age=" + maxAge + "; path=/", this._testCookies[newKey]);
192
+ }
193
+
194
+ // With existing max-age
195
+ manager.del(newKey);
196
+ Assert.equal("", manager.get(newKey));
197
+ Assert.equal(undefined, this._testCookies[newKey]);
198
+
199
+ manager.set(newKey, newValue + "; expires=Thu, 12 Feb 2170 00:00:00 GMT", maxAge);
200
+ Assert.equal(newValue, manager.get(newKey));
201
+ if (this.isEmulatingEs3) {
202
+ Assert.equal(newValue + "; expires=Thu, 12 Feb 2170 00:00:00 GMT; path=/", this._testCookies[newKey]);
203
+ } else {
204
+ Assert.equal(newValue + "; expires=Thu, 12 Feb 2170 00:00:00 GMT; max-age=" + maxAge + "; path=/", this._testCookies[newKey]);
205
+ }
206
+
207
+ manager.del(newKey);
208
+ Assert.equal("", manager.get(newKey));
209
+ Assert.equal(undefined, this._testCookies[newKey]);
210
+ }
211
+ });
212
+
213
+ this.testCase({
214
+ name: "CookieManager: Set as Disabled",
215
+ test: () => {
216
+ let manager = createCookieMgr({
217
+ cookieCfg: {
218
+ enabled: false,
219
+ getCookie: () => { throw "Should not be called" },
220
+ setCookie: () => { throw "Should not be called" },
221
+ delCookie: () => { throw "Should not be called" }
222
+ }
223
+ });
224
+
225
+ let newKey = "test." + newId();
226
+ let newValue = newId();
227
+ manager.set(newKey, newValue);
228
+ Assert.equal("", manager.get(newKey));
229
+
230
+ manager.del(newKey);
231
+ Assert.equal("", manager.get(newKey));
232
+ }
233
+ });
234
+
235
+ this.testCase({
236
+ name: "CookieManager: disable cookies using the legacy setting",
237
+ test: () => {
238
+
239
+ let core = new AppInsightsCore();
240
+ core.initialize({
241
+ instrumentationKey: "testiKey",
242
+ isCookieUseDisabled: true,
243
+ cookieCfg: {
244
+ getCookie: () => { throw "Should not be called" },
245
+ setCookie: () => { throw "Should not be called" },
246
+ delCookie: () => { throw "Should not be called" }
247
+ }
248
+ } as any, [new ChannelPlugin()]);
249
+
250
+ let manager = core.getCookieMgr();
251
+ let newKey = "test." + newId();
252
+ let newValue = newId();
253
+ manager.set(newKey, newValue);
254
+ Assert.equal("", manager.get(newKey));
255
+
256
+ manager.del(newKey);
257
+ Assert.equal("", manager.get(newKey));
258
+ }
259
+ });
260
+
261
+ this.testCase({
262
+ name: "CookieManager: disable cookies using legacy and new setting both enabled",
263
+ test: () => {
264
+
265
+ let core = new AppInsightsCore();
266
+ core.initialize({
267
+ instrumentationKey: "testiKey",
268
+ isCookieUseDisabled: true,
269
+ disableCookiesUsage: true,
270
+ cookieCfg: {
271
+ getCookie: () => { throw "Should not be called" },
272
+ setCookie: () => { throw "Should not be called" },
273
+ delCookie: () => { throw "Should not be called" }
274
+ }
275
+ } as any, [new ChannelPlugin()]);
276
+
277
+ let manager = core.getCookieMgr();
278
+ let newKey = "test." + newId();
279
+ let newValue = newId();
280
+ manager.set(newKey, newValue);
281
+ Assert.equal("", manager.get(newKey));
282
+
283
+ manager.del(newKey);
284
+ Assert.equal("", manager.get(newKey));
285
+ }
286
+ });
287
+
288
+ this.testCase({
289
+ name: "CookieManager: disable cookies using legacy disabled and new setting enabled",
290
+ test: () => {
291
+
292
+ let core = new AppInsightsCore();
293
+ core.initialize({
294
+ instrumentationKey: "testiKey",
295
+ isCookieUseDisabled: false,
296
+ disableCookiesUsage: true,
297
+ cookieCfg: {
298
+ getCookie: () => { throw "Should not be called" },
299
+ setCookie: () => { throw "Should not be called" },
300
+ delCookie: () => { throw "Should not be called" }
301
+ }
302
+ } as any, [new ChannelPlugin()]);
303
+
304
+ let manager = core.getCookieMgr();
305
+ let newKey = "test." + newId();
306
+ let newValue = newId();
307
+ manager.set(newKey, newValue);
308
+ Assert.equal("", manager.get(newKey));
309
+
310
+ manager.del(newKey);
311
+ Assert.equal("", manager.get(newKey));
312
+ }
313
+ });
314
+
315
+ this.testCase({
316
+ name: "CookieManager: disable cookies using disableCookiesUsage",
317
+ test: () => {
318
+
319
+ let core = new AppInsightsCore();
320
+ core.initialize({
321
+ instrumentationKey: "testiKey",
322
+ disableCookiesUsage: true,
323
+ cookieCfg: {
324
+ getCookie: () => { throw "Should not be called" },
325
+ setCookie: () => { throw "Should not be called" },
326
+ delCookie: () => { throw "Should not be called" }
327
+ }
328
+ }, [new ChannelPlugin()]);
329
+
330
+ let manager = core.getCookieMgr();
331
+ let newKey = "test." + newId();
332
+ let newValue = newId();
333
+ manager.set(newKey, newValue);
334
+ Assert.equal("", manager.get(newKey));
335
+
336
+ manager.del(newKey);
337
+ Assert.equal("", manager.get(newKey));
338
+ }
339
+ });
340
+
341
+ this.testCase({
342
+ name: "CookieManager: set cookie path at the root config setting",
343
+ test: () => {
344
+
345
+ let core = new AppInsightsCore();
346
+ core.initialize({
347
+ instrumentationKey: "testiKey",
348
+ cookiePath: "/sub-path",
349
+ cookieCfg: this._cookieMgrCfg
350
+ }, [new ChannelPlugin()]);
351
+
352
+ let manager = core.getCookieMgr();
353
+
354
+ let newKey = "test." + newId();
355
+ let newValue = newId();
356
+ manager.set(newKey, newValue);
357
+ Assert.equal(newValue, manager.get(newKey));
358
+ Assert.equal(newValue + "; path=/sub-path", this._testCookies[newKey]);
359
+
360
+ manager.del(newKey);
361
+ Assert.equal("", manager.get(newKey));
362
+ Assert.equal(undefined, this._testCookies[newKey]);
363
+
364
+ manager.set(newKey, newValue + "; path=/my-path");
365
+ Assert.equal(newValue, manager.get(newKey));
366
+ Assert.equal(newValue + "; path=/my-path", this._testCookies[newKey]);
367
+
368
+ manager.del(newKey);
369
+ Assert.equal("", manager.get(newKey));
370
+ Assert.equal(undefined, this._testCookies[newKey]);
371
+ }
372
+ });
373
+
374
+ this.testCase({
375
+ name: "CookieManager: set cookie domain at the root config setting",
376
+ test: () => {
377
+
378
+ let core = new AppInsightsCore();
379
+ core.initialize({
380
+ instrumentationKey: "testiKey",
381
+ cookieDomain: "MyDomain.com",
382
+ cookieCfg: this._cookieMgrCfg
383
+ }, [new ChannelPlugin()]);
384
+
385
+ let manager = core.getCookieMgr();
386
+
387
+ let newKey = "test." + newId();
388
+ let newValue = newId();
389
+ manager.set(newKey, newValue);
390
+ Assert.equal(newValue, manager.get(newKey));
391
+ Assert.equal(newValue + "; domain=MyDomain.com; path=/", this._testCookies[newKey]);
392
+
393
+ manager.del(newKey);
394
+ Assert.equal("", manager.get(newKey));
395
+ Assert.equal(undefined, this._testCookies[newKey]);
396
+ }
397
+ });
398
+
399
+
400
+ this.testCase({
401
+ name: "CookieManager: validate setting _canUseCookies correctly enables or blocks cookie usage",
402
+ test: () => {
403
+ CoreUtils._canUseCookies = undefined;
404
+ // initialize the global cookie manager
405
+ let globalMgr = _legacyCookieMgr();
406
+ Assert.equal(true, globalMgr.isEnabled());
407
+ Assert.equal(true, globalMgr.isEnabled());
408
+ CoreUtils._canUseCookies = false;
409
+ Assert.equal(false, globalMgr.isEnabled());
410
+ CoreUtils._canUseCookies = true;
411
+ Assert.equal(true, globalMgr.isEnabled());
412
+
413
+ let core = new AppInsightsCore();
414
+ let manager = core.getCookieMgr();
415
+ manager.setEnabled(true);
416
+ Assert.equal(true, manager.isEnabled());
417
+ CoreUtils._canUseCookies = false;
418
+ Assert.equal(false, manager.isEnabled());
419
+
420
+ manager.setEnabled(false);
421
+ CoreUtils._canUseCookies = true;
422
+ Assert.equal(true, globalMgr.isEnabled());
423
+ Assert.equal(false, manager.isEnabled());
424
+
425
+ manager.setEnabled(true);
426
+ Assert.equal(true, globalMgr.isEnabled());
427
+ Assert.equal(true, manager.isEnabled());
428
+ }
429
+ });
430
+ }
431
+ }
432
+
433
+ class ChannelPlugin implements IPlugin {
434
+ public isFlushInvoked = false;
435
+ public isTearDownInvoked = false;
436
+ public isResumeInvoked = false;
437
+ public isPauseInvoked = false;
438
+
439
+ public identifier = "Sender";
440
+
441
+ public priority: number = 1001;
442
+
443
+ constructor() {
444
+ this.processTelemetry = this._processTelemetry.bind(this);
445
+ }
446
+ public pause(): void {
447
+ this.isPauseInvoked = true;
448
+ }
449
+
450
+ public resume(): void {
451
+ this.isResumeInvoked = true;
452
+ }
453
+
454
+ public teardown(): void {
455
+ this.isTearDownInvoked = true;
456
+ }
457
+
458
+ flush(async?: boolean, callBack?: () => void): void {
459
+ this.isFlushInvoked = true;
460
+ if (callBack) {
461
+ callBack();
462
+ }
463
+ }
464
+
465
+ public processTelemetry(env: ITelemetryItem) { }
466
+
467
+ setNextPlugin(next: any) {
468
+ // no next setup
469
+ }
470
+
471
+ public initialize = (config: IConfiguration, core: IAppInsightsCore, plugin: IPlugin[]) => {
472
+ }
473
+
474
+ private _processTelemetry(env: ITelemetryItem) {
475
+
476
+ }
477
+ }
@@ -0,0 +1,59 @@
1
+ import { Assert, AITestClass } from "@microsoft/ai-test-framework";
2
+ import { _InternalMessageId, LoggingSeverity } from "../../../src/JavaScriptSDK.Enums/LoggingEnums";
3
+ import { _InternalLogMessage, DiagnosticLogger } from "../../../src/JavaScriptSDK/DiagnosticLogger";
4
+ import { isObject, objForEachKey, objForEachKey as objKeys, optimizeObject, setValue, strEndsWith, strStartsWith } from "../../../src/JavaScriptSDK/HelperFuncs";
5
+
6
+ export class HelperFuncTests extends AITestClass {
7
+
8
+ public testInitialize() {
9
+ super.testInitialize();
10
+ }
11
+
12
+ public testCleanup() {
13
+ super.testCleanup();
14
+ }
15
+
16
+ public registerTests() {
17
+
18
+ this.testCase({
19
+ name: "strEndsWith",
20
+ test: () => {
21
+ Assert.ok(!strEndsWith(null, null));
22
+ Assert.ok(!strEndsWith("", null));
23
+ Assert.ok(!strEndsWith(null, ""));
24
+ Assert.ok(!strEndsWith("", ""));
25
+ Assert.ok(!strEndsWith("", "a"));
26
+ Assert.ok(!strEndsWith("a", "b"));
27
+ Assert.ok(!strEndsWith("a", ""));
28
+ Assert.ok(!strEndsWith("a", "ab"));
29
+ Assert.ok(strEndsWith("a", "a"));
30
+ Assert.ok(strEndsWith("ba", "a"));
31
+ Assert.ok(strEndsWith("zyxyvutsrqponmlkjihgfedcba", "cba"));
32
+ Assert.ok(!strEndsWith("a", "ba"));
33
+ Assert.ok(!strEndsWith("abba", "cba"));
34
+ Assert.ok(!strEndsWith("abba", "bb"));
35
+ }
36
+ });
37
+
38
+ this.testCase({
39
+ name: "strStartsWith",
40
+ test: () => {
41
+ Assert.ok(!strStartsWith(null, null));
42
+ Assert.ok(!strStartsWith("", null));
43
+ Assert.ok(!strStartsWith(null, ""));
44
+ Assert.ok(!strStartsWith("", ""));
45
+ Assert.ok(!strStartsWith("", "a"));
46
+ Assert.ok(!strStartsWith("a", ""));
47
+ Assert.ok(!strStartsWith("a", "b"));
48
+ Assert.ok(!strStartsWith("a", "ba"));
49
+ Assert.ok(strStartsWith("ab", "a"));
50
+ Assert.ok(!strStartsWith("zyxyvutsrqponmlkjihgfedcba", "a"));
51
+ Assert.ok(strStartsWith("zyxwvutsrqponmlkjihgfedcba", "zyxw"));
52
+ Assert.ok(!strStartsWith("a", "ab"));
53
+ Assert.ok(!strStartsWith("abba", "abc"));
54
+ Assert.ok(!strStartsWith("abba", "bb"));
55
+ }
56
+ });
57
+
58
+ }
59
+ }
@@ -0,0 +1,13 @@
1
+ import '@microsoft/applicationinsights-shims';
2
+ import { ApplicationInsightsCoreTests } from "./ApplicationInsightsCore.Tests";
3
+ import { CookieManagerTests } from "./CookieManager.Tests";
4
+ import { HelperFuncTests } from './HelperFunc.Tests';
5
+ import { AppInsightsCoreSizeCheck } from "./AppInsightsCoreSize.Tests";
6
+
7
+ export function runTests() {
8
+ new ApplicationInsightsCoreTests().registerTests();
9
+ new CookieManagerTests(false).registerTests();
10
+ new CookieManagerTests(true).registerTests();
11
+ new HelperFuncTests().registerTests();
12
+ new AppInsightsCoreSizeCheck().registerTests();
13
+ }
@@ -0,0 +1,48 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="Cache-control" content="no-Cache" />
7
+ <title>Tests for Application Insights JavaScript Core SDK</title>
8
+ <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-1.23.1.css">
9
+ <script src="http://sinonjs.org/releases/sinon-2.3.8.js"></script>
10
+ <!-- <script src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.js"></script> -->
11
+ <script src="../../../common/Tests/External/require-2.2.0.js"></script>
12
+ <script src="../../../common/Tests/Selenium/ModuleLoader.js"></script>
13
+ <script src="../../../common/Tests/Selenium/SimpleSyncPromise.js"></script>
14
+
15
+ <script>
16
+ var modules = new ModuleLoader({
17
+ baseUrl: '../',
18
+ paths: {
19
+ qunit: "../../common/Tests/External/qunit-1.23.1",
20
+ "whatwg-fetch": "../../common/Tests/External/whatwg-fetch.3.0.0"
21
+ }
22
+ });
23
+
24
+ // Load qunit here instead of with tests, otherwise will not work
25
+ modules.add("qunit");
26
+ modules.add("pako","./node_modules/pako/dist/pako");
27
+
28
+ loadFetchModule(modules, "whatwg-fetch");
29
+ loadCommonModules(modules);
30
+
31
+ var testModule = modules.add("Tests/Unit/src/aiunittests", "./Unit/dist/aicoreunit.tests.js")
32
+ testModule.run = function (tests) {
33
+ console && console.log("Starting tests");
34
+ QUnit.start();
35
+ tests.runTests();
36
+ };
37
+
38
+ modules.run();
39
+ </script>
40
+ </head>
41
+
42
+ <body>
43
+ <div id="qunit"></div>
44
+ <div id="qunit-fixture"></div>
45
+ <div id="error-message"></div>
46
+ </body>
47
+
48
+ </html>
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "sourceMap": true,
4
+ "inlineSources": true,
5
+ "noImplicitAny": false,
6
+ "module": "amd",
7
+ "moduleResolution": "node",
8
+ "target": "es6",
9
+ "importHelpers": true,
10
+ "noEmitHelpers": true,
11
+ "skipLibCheck": true,
12
+ "alwaysStrict": true,
13
+ "declaration": true
14
+ },
15
+ "files": []
16
+ }
17
+