applicationinsights-js
Advanced tools
Comparing version 0.18.0 to 0.21.5
@@ -39,3 +39,3 @@ <properties | ||
trackPageView(name?: string, url?: string, properties?:{[string]:string}, measurements?: {[string]:number}) | ||
trackPageView(name?: string, url?: string, properties?:{[string]:string}, measurements?: {[string]:number}, duration?: number) | ||
@@ -51,2 +51,3 @@ Logs that a page or similar container was displayed to the user. | ||
`measurements` | Map of string to number: Metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty. | ||
`duration` | The number of milliseconds it took to load this page, displayed in Metrics Explorer on the portal. Defaults to empty. If empty, end of page view duration is recorded when browser page load event is called. | ||
@@ -76,3 +77,3 @@ The standard snippet that you get from the portal includes a call to trackPageView. If you insert your own calls, consider | ||
trackMetric(name: string, average: number, sampleCount?: number, min?: number, max?: number) | ||
trackMetric(name: string, average: number, sampleCount?: number, min?: number, max?: number, properties?: {[string]:string}) | ||
@@ -88,2 +89,3 @@ Log a positive numeric value that is not associated with a specific event. Typically used to send regular reports of performance indicators. | ||
`max` | The largest measurement in the sample. Defaults to the average. Should be >= 0. | ||
`properties` | Map of string to string: Additional data used to [filter events](https://azure.microsoft.com/documentation/articles/app-insights-api-custom-events-metrics/#properties) in the portal. | ||
@@ -208,2 +210,16 @@ In the portal, you can select metrics by name to [chart their values over time](https://azure.microsoft.com/documentation/articles/app-insights-metrics-explorer/). You can't search or view individual trackMetric calls. | ||
diagnosticLogInterval: number; | ||
// If true, exceptions are not monitored. | ||
disableExceptionTracking: boolean; | ||
// If true, ajax calls are not monitored. | ||
disableAjaxTracking: boolean; | ||
// If true, default behavior of trackPageView is changed to record end of page view duration interval when | ||
// trackPageView is called. | ||
overridePageViewDuration: boolean; | ||
// Default 500 - controls how many ajax calls will be monitored per page view. | ||
// Set to -1 to monitor all ajax calls on the page. | ||
maxAjaxCallsPerView: number; | ||
} | ||
@@ -210,0 +226,0 @@ |
{ | ||
"name": "applicationinsights-js", | ||
"version": "0.18.0", | ||
"version": "0.21.5", | ||
"homepage": "https://github.com/Microsoft/ApplicationInsights-JS", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -114,3 +114,3 @@ /// <reference path="../../../JavaScriptSDK/appInsights.ts" /> | ||
var mathRandomSpy = sinon.spy(Math, "random"); | ||
var mathRandomSpy = this.sandbox.spy(Math, "random"); | ||
@@ -122,3 +122,3 @@ // act | ||
Assert.ok(mathRandomSpy.calledOnce); | ||
mathRandomSpy.restore(); | ||
} | ||
@@ -125,0 +125,0 @@ }); |
@@ -8,3 +8,3 @@ /// <reference path="../../../JavaScriptSDK/context/session.ts" /> | ||
private originalDocument; | ||
private originalDocument = Microsoft.ApplicationInsights.Util["document"]; | ||
private results: any[]; | ||
@@ -16,2 +16,3 @@ | ||
this.resetStorage(); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -23,2 +24,3 @@ | ||
this.resetStorage(); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -37,3 +39,3 @@ | ||
var sessionManager = new Microsoft.ApplicationInsights.Context._SessionManager(null, () => { }); | ||
Assert.ok(!sessionManager.automaticSession.isFirst, "isFirst"); | ||
Assert.ok(!sessionManager.automaticSession.isFirst, "isFirst"); | ||
Assert.ok(!sessionManager.automaticSession.id, "id"); | ||
@@ -48,29 +50,29 @@ Assert.ok(!sessionManager.automaticSession.acquisitionDate, "acquisitionDate"); | ||
test: () => { | ||
// no cookie, isNew should be true | ||
Microsoft.ApplicationInsights.Util["document"] = <any>{ | ||
cookie: "" | ||
}; | ||
// no cookie, isNew should be true | ||
Microsoft.ApplicationInsights.Util["document"] = <any>{ | ||
cookie: "" | ||
}; | ||
var sessionManager = new Microsoft.ApplicationInsights.Context._SessionManager(null, () => { }); | ||
// after first update, should be true | ||
this.clock.tick(10); | ||
sessionManager.update(); | ||
Assert.ok(sessionManager.automaticSession.isFirst, "isFirst should be true after 1st update"); | ||
// after second update also true | ||
sessionManager.update(); | ||
Assert.ok(sessionManager.automaticSession.isFirst, "isFirst should be true after 2st update"); | ||
// after renewal, should be false | ||
this.clock.tick(Microsoft.ApplicationInsights.Context._SessionManager.renewalSpan + 1); | ||
sessionManager.update(); | ||
Assert.ok(!sessionManager.automaticSession.isFirst, "isFirst should be false after renewal"); | ||
} | ||
}); | ||
var sessionManager = new Microsoft.ApplicationInsights.Context._SessionManager(null, () => { }); | ||
// after first update, should be true | ||
this.clock.tick(10); | ||
sessionManager.update(); | ||
Assert.ok(sessionManager.automaticSession.isFirst, "isFirst should be true after 1st update"); | ||
// after second update also true | ||
sessionManager.update(); | ||
Assert.ok(sessionManager.automaticSession.isFirst, "isFirst should be true after 2st update"); | ||
// after renewal, should be false | ||
this.clock.tick(Microsoft.ApplicationInsights.Context._SessionManager.renewalSpan + 1); | ||
sessionManager.update(); | ||
Assert.ok(!sessionManager.automaticSession.isFirst, "isFirst should be false after renewal"); | ||
} | ||
}); | ||
this.testCase({ | ||
name: "SessionContext: when sessionmanager initailzes it sets isFirst to false if cookie is present", | ||
test: () => { | ||
// no cookie, isNew should be true | ||
// no cookie, isNew should be true | ||
Microsoft.ApplicationInsights.Util["document"] = <any>{ | ||
@@ -84,4 +86,4 @@ cookie: "" | ||
this.clock.tick(Microsoft.ApplicationInsights.Context._SessionManager.renewalSpan + 1); | ||
// Creating one more instance immulate that browser was closed | ||
// Creating one more instance immulate that browser was closed | ||
var sessionManager2 = new Microsoft.ApplicationInsights.Context._SessionManager(null, () => { }); | ||
@@ -93,3 +95,4 @@ sessionManager2.update(); | ||
this.testCase({ | ||
this.testCase({ | ||
name: "ai_session cookie has correct structure", | ||
@@ -100,5 +103,5 @@ test: () => { | ||
var actualCookieValue: string; | ||
var newGuidStub = sinon.stub(Microsoft.ApplicationInsights.Util, "newGuid", () => "newGuid"); | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie", () => ""); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie", (cookieName, cookieValue) => { | ||
var newIdStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "newId", () => "newId"); | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie", () => ""); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie", (cookieName, cookieValue) => { | ||
actualCookieName = cookieName; | ||
@@ -118,3 +121,3 @@ actualCookieValue = cookieValue; | ||
Assert.equal(3, cookieValueParts[0].split('|').length, "Cookie value before expiration should include user id, acq date and renew date"); | ||
Assert.equal("newGuid", cookieValueParts[0].split('|')[0], "First part of cookie value should be new user id guid"); | ||
Assert.equal("newId", cookieValueParts[0].split('|')[0], "First part of cookie value should be new user id guid"); | ||
@@ -128,5 +131,5 @@ // The cookie should expire 30 minutes after activity by default | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
newGuidStub.restore(); | ||
} | ||
@@ -142,5 +145,5 @@ }); | ||
var actualCookieValue: string; | ||
var newGuidStub = sinon.stub(Microsoft.ApplicationInsights.Util, "newGuid",() => "newGuid"); | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie",(cookieName, cookieValue) => { }); | ||
var newIdStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "newId", () => "newId"); | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie",(cookieName, cookieValue) => { }); | ||
@@ -156,8 +159,8 @@ // act | ||
Assert.equal(3, localStorage["ai_session"].split('|').length, "Cookie value before expiration should include user id, acq date and renew date"); | ||
Assert.equal("newGuid", localStorage["ai_session"].split('|')[0], "First part of cookie value should be new user id guid"); | ||
Assert.equal("newId", localStorage["ai_session"].split('|')[0], "First part of cookie value should be new user id guid"); | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
newGuidStub.restore(); | ||
} else { | ||
@@ -175,8 +178,8 @@ // this might happen on IE when using a file:// url | ||
var storage = {}; | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
cookies[name] = value; | ||
}); | ||
var getStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => storage[name]); | ||
var setStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => { | ||
var getStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => storage[name]); | ||
var setStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => { | ||
storage[name] = value; | ||
@@ -200,6 +203,6 @@ }); | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
getStorageStub.restore(); | ||
setStorageStub.restore(); | ||
} | ||
@@ -213,8 +216,8 @@ }); | ||
var storage = {}; | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
cookies[name] = value; | ||
}); | ||
var getStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => storage[name]); | ||
var setStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => { | ||
var getStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => storage[name]); | ||
var setStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => { | ||
storage[name] = value; | ||
@@ -242,6 +245,6 @@ }); | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
getStorageStub.restore(); | ||
setStorageStub.restore(); | ||
} | ||
@@ -255,11 +258,11 @@ }); | ||
var storage = {}; | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
cookies[name] = value; | ||
}); | ||
var getStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => storage[name]); | ||
var setStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => { | ||
var getStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => storage[name]); | ||
var setStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => { | ||
storage[name] = value; | ||
}); | ||
var removeStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "removeStorage",(name, value) => { | ||
var removeStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "removeStorage",(name, value) => { | ||
storage[name] = undefined; | ||
@@ -287,7 +290,7 @@ }); | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
getStorageStub.restore(); | ||
setStorageStub.restore(); | ||
removeStorageStub.restore(); | ||
} | ||
@@ -301,8 +304,8 @@ }); | ||
var storage = {}; | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",(name) => cookies[name]); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie",(name, value) => { | ||
cookies[name] = value; | ||
}); | ||
var getStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => null); | ||
var setStorageStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => false); | ||
var getStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getStorage",(name) => null); | ||
var setStorageStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setStorage",(name, value) => false); | ||
@@ -333,6 +336,6 @@ // Initialize our user and session cookies | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
getStorageStub.restore(); | ||
setStorageStub.restore(); | ||
} | ||
@@ -344,3 +347,3 @@ }); | ||
test: () => { | ||
// no cookie, isNew should be true | ||
// no cookie, isNew should be true | ||
Microsoft.ApplicationInsights.Util["document"] = <any>{ | ||
@@ -359,4 +362,2 @@ cookie: "" | ||
Assert.ok(!sessionManager.automaticSession.isFirst, "isFirst is false when an existing session was set"); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -401,4 +402,2 @@ }); | ||
Assert.equal(AI.SessionState.Start, this.results[1], "session start generated"); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -428,4 +427,2 @@ }); | ||
Assert.equal(AI.SessionState.Start, this.results[1], "session start generated"); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -452,4 +449,2 @@ }); | ||
Assert.equal(+new Date(renewalDate), sessionManager.automaticSession.renewalDate, "cookie renewalDate was used"); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -482,4 +477,2 @@ }); | ||
Assert.equal(AI.SessionState.Start, this.results[1], "session start generated"); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -509,4 +502,2 @@ }); | ||
Assert.equal(delta, sessionManager.automaticSession.renewalDate, "cookie renewalDate was updated"); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -534,4 +525,2 @@ }); | ||
Assert.equal(10, sessionManager.automaticSession.renewalDate, "cookie renewalDate was updated"); | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -589,4 +578,2 @@ }); | ||
// TODO: CHECK THAT A PARSING ERROR OCCURRED AND WE SENT A DIAGNOSTIC TRACE | ||
this.restoreFakeCookie(); | ||
} | ||
@@ -593,0 +580,0 @@ }); |
@@ -26,3 +26,3 @@ /// <reference path="../../../JavaScriptSDK/context/user.ts" /> | ||
var id = "userId"; | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie", () => id + "||||"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie", () => id + "||||"); | ||
@@ -34,3 +34,3 @@ // act | ||
Assert.equal(id, user.id, "user id was set from cookie"); | ||
cookieStub.restore(); | ||
} | ||
@@ -46,5 +46,5 @@ }); | ||
var actualCookieValue: string; | ||
var newGuidStub = sinon.stub(Microsoft.ApplicationInsights.Util, "newGuid",() => "newGuid"); | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie",(cookieName, cookieValue) => { | ||
var newIdStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "newId", () => "newId"); | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie",(cookieName, cookieValue) => { | ||
actualCookieName = cookieName; | ||
@@ -63,3 +63,3 @@ actualCookieValue = cookieValue; | ||
Assert.equal(2, cookieValueParts[0].split('|').length, "ai_user cookie value before expiration should include user id and acq date"); | ||
Assert.equal("newGuid", cookieValueParts[0].split('|')[0], "First part of ai_user cookie value should be new user id guid"); | ||
Assert.equal("newId", cookieValueParts[0].split('|')[0], "First part of ai_user cookie value should be new user id guid"); | ||
Assert.equal(new Date().toString(),(new Date(cookieValueParts[0].split('|')[1])).toString(), "Second part of ai_user cookie should be parsable as date"); | ||
@@ -73,5 +73,5 @@ | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
newGuidStub.restore(); | ||
} | ||
@@ -87,5 +87,5 @@ }); | ||
var actualCookieValue: string; | ||
var newGuidStub = sinon.stub(Microsoft.ApplicationInsights.Util, "newGuid",() => "newGuid"); | ||
var getCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
var setCookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie",(cookieName, cookieValue) => { | ||
var newIdStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "newId", () => "newId"); | ||
var getCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
var setCookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie",(cookieName, cookieValue) => { | ||
actualCookieName = cookieName; | ||
@@ -104,3 +104,3 @@ actualCookieValue = cookieValue; | ||
Assert.equal(2, cookieValueParts[0].split('|').length, "ai_user cookie value before expiration should include user id and acq date"); | ||
Assert.equal("newGuid", cookieValueParts[0].split('|')[0], "First part of ai_user cookie value should be new user id guid"); | ||
Assert.equal("newId", cookieValueParts[0].split('|')[0], "First part of ai_user cookie value should be new user id guid"); | ||
Assert.equal(new Date().toString(),(new Date(cookieValueParts[0].split('|')[1])).toString(), "Second part of ai_user cookie should be parsable as date"); | ||
@@ -114,5 +114,5 @@ | ||
// cleanup | ||
getCookieStub.restore(); | ||
setCookieStub.restore(); | ||
newGuidStub.restore(); | ||
} | ||
@@ -128,3 +128,3 @@ }); | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => authId + "|" + accountId); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => authId + "|" + accountId); | ||
@@ -137,3 +137,3 @@ // act | ||
Assert.equal(accountId, user.accountId, "user account id was not set from cookie"); | ||
cookieStub.restore(); | ||
} | ||
@@ -147,3 +147,3 @@ }); | ||
var authId = "bla@bla.com"; | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => authId); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => authId); | ||
@@ -155,3 +155,3 @@ // act | ||
Assert.equal(authId, user.authenticatedId, "user auth id was set from cookie"); | ||
cookieStub.restore(); | ||
} | ||
@@ -164,3 +164,3 @@ }); | ||
// setup | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => ""); | ||
@@ -173,3 +173,3 @@ // act | ||
Assert.equal(undefined, user.accountId, "user account id was not set"); | ||
cookieStub.restore(); | ||
} | ||
@@ -183,3 +183,3 @@ }); | ||
var accountIdBackCompat = "account17"; | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => null); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "getCookie",() => null); | ||
@@ -191,3 +191,3 @@ // act | ||
Assert.equal(accountIdBackCompat, user.accountId, "user account id was set from back compat"); | ||
cookieStub.restore(); | ||
} | ||
@@ -201,3 +201,3 @@ }); | ||
var authAndAccountId = ["bla@bla.com"]; | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
@@ -211,3 +211,3 @@ | ||
Assert.equal(cookieStub.calledWithExactly('ai_authUser', encodeURI(authAndAccountId.join('|'))), true, "user auth id nad account id cookie was set"); | ||
cookieStub.restore(); | ||
} | ||
@@ -221,3 +221,3 @@ }); | ||
var authAndAccountId = ['bla@bla.com', 'contoso']; | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
@@ -231,3 +231,3 @@ | ||
Assert.equal(cookieStub.calledWithExactly('ai_authUser', encodeURI(authAndAccountId.join('|'))), true, "user auth id cookie was set"); | ||
cookieStub.restore(); | ||
} | ||
@@ -241,3 +241,3 @@ }); | ||
var authAndAccountId = ['bla@bla.com']; | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
@@ -252,3 +252,3 @@ | ||
Assert.equal(cookieStub.calledWithExactly('ai_authUser', encodeURI(authAndAccountId[0])), true, "user auth id cookie was set"); | ||
cookieStub.restore(); | ||
} | ||
@@ -261,5 +261,5 @@ }); | ||
// setup | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
var loggingStub = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
cookieStub.reset(); | ||
@@ -275,4 +275,4 @@ | ||
Assert.equal(loggingStub.calledOnce, true, "Warning was logged"); | ||
cookieStub.restore(); | ||
loggingStub.restore(); | ||
} | ||
@@ -285,5 +285,5 @@ }); | ||
// setup | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
var loggingStub = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
@@ -298,4 +298,4 @@ // act | ||
Assert.equal(loggingStub.calledOnce, true, "Warning was logged"); | ||
cookieStub.restore(); | ||
loggingStub.restore(); | ||
} | ||
@@ -308,5 +308,5 @@ }); | ||
// setup | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
var loggingStub = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
@@ -321,4 +321,4 @@ // act | ||
Assert.equal(loggingStub.calledOnce, true, "Warning was logged"); | ||
cookieStub.restore(); | ||
loggingStub.restore(); | ||
} | ||
@@ -333,4 +333,4 @@ }); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var loggingStub = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
@@ -345,4 +345,4 @@ // act | ||
Assert.equal(loggingStub.calledOnce, true, "Warning was logged"); | ||
cookieStub.restore(); | ||
loggingStub.restore(); | ||
} | ||
@@ -358,4 +358,4 @@ }); | ||
user.clearAuthenticatedUserContext(); | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var loggingStub = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
@@ -370,4 +370,4 @@ // act | ||
Assert.equal(loggingStub.calledOnce, true, "Warning was logged"); | ||
cookieStub.restore(); | ||
loggingStub.restore(); | ||
} | ||
@@ -382,4 +382,4 @@ }); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var loggingStub = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie"); | ||
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
@@ -394,4 +394,4 @@ // act | ||
Assert.equal(loggingStub.notCalled, true, "No warnings"); | ||
cookieStub.restore(); | ||
loggingStub.restore(); | ||
} | ||
@@ -406,3 +406,3 @@ }); | ||
user.setAuthenticatedUserContext("bla", "123"); | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "deleteCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "deleteCookie"); | ||
@@ -416,3 +416,3 @@ // act | ||
Assert.equal(cookieStub.calledWithExactly('ai_authUser'), true, "cookie was deleted"); | ||
cookieStub.restore(); | ||
} | ||
@@ -426,3 +426,3 @@ }); | ||
var user = new Microsoft.ApplicationInsights.Context.User(undefined); | ||
var cookieStub = sinon.stub(Microsoft.ApplicationInsights.Util, "deleteCookie"); | ||
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "deleteCookie"); | ||
@@ -436,3 +436,3 @@ // act | ||
Assert.equal(cookieStub.calledWithExactly('ai_authUser'), true, "cookie was deleted"); | ||
cookieStub.restore(); | ||
} | ||
@@ -439,0 +439,0 @@ }); |
@@ -24,3 +24,3 @@ | ||
enableDebug: true, | ||
autoCollectErrors: false, | ||
disableExceptionTracking: false, | ||
disableTelemetry: false, | ||
@@ -30,3 +30,6 @@ verboseLogging: true, | ||
autoTrackPageVisitTime: false, | ||
samplingPercentage: 33 | ||
samplingPercentage: 33, | ||
disableAjaxTracking: true, | ||
overridePageViewDuration: false, | ||
maxAjaxCallsPerView: 44 | ||
}; | ||
@@ -68,7 +71,8 @@ | ||
enableDebug: undefined, | ||
autoCollectErrors: undefined, | ||
disableExceptionTracking: undefined, | ||
disableTelemetry: undefined, | ||
verboseLogging: undefined, | ||
diagnosticLogInterval: undefined, | ||
samplingPercentage: undefined | ||
samplingPercentage: undefined, | ||
maxAjaxCallsPerView: undefined | ||
}; | ||
@@ -89,3 +93,3 @@ | ||
Assert.ok(!init.config.enableDebug); | ||
Assert.ok(init.config.autoCollectErrors); | ||
Assert.ok(!init.config.disableExceptionTracking); | ||
Assert.equal(15000, init.config.maxBatchInterval); | ||
@@ -95,2 +99,3 @@ Assert.ok(!init.config.verboseLogging); | ||
Assert.equal(100, init.config.samplingPercentage); | ||
Assert.equal(500, init.config.maxAjaxCallsPerView); | ||
} | ||
@@ -117,3 +122,3 @@ }); | ||
Assert.ok(init.config.enableDebug); | ||
Assert.ok(!init.config.autoCollectErrors); | ||
Assert.ok(!init.config.disableExceptionTracking); | ||
Assert.equal(1, init.config.maxBatchInterval); | ||
@@ -123,2 +128,3 @@ Assert.ok(init.config.verboseLogging); | ||
Assert.equal(33, init.config.samplingPercentage); | ||
Assert.equal(44, init.config.maxAjaxCallsPerView); | ||
} | ||
@@ -168,3 +174,3 @@ }); | ||
var appInsightsLocal = init.loadAppInsights(); | ||
var trackTraceSpy = sinon.stub(appInsightsLocal, "trackTrace"); | ||
var trackTraceSpy = this.sandbox.stub(appInsightsLocal, "trackTrace"); | ||
@@ -191,4 +197,4 @@ var queue: Array<string> = Microsoft.ApplicationInsights._InternalLogging["queue"]; | ||
trackTraceSpy.restore(); | ||
} | ||
@@ -204,3 +210,3 @@ }); | ||
enableDebug: "false", | ||
autoCollectErrors: "false", | ||
disableExceptionTracking: "false", | ||
disableTelemetry: "false", | ||
@@ -214,3 +220,3 @@ verboseLogging: "false", | ||
Assert.ok(!config.enableDebug); | ||
Assert.ok(!config.autoCollectErrors); | ||
Assert.ok(!config.disableExceptionTracking); | ||
Assert.ok(!config.disableTelemetry); | ||
@@ -228,3 +234,3 @@ Assert.ok(!config.verboseLogging); | ||
enableDebug: "true", | ||
autoCollectErrors: "true", | ||
disableExceptionTracking: "true", | ||
disableTelemetry: "true", | ||
@@ -238,3 +244,3 @@ verboseLogging: "true", | ||
Assert.ok(config.enableDebug); | ||
Assert.ok(config.autoCollectErrors); | ||
Assert.ok(config.disableExceptionTracking); | ||
Assert.ok(config.disableTelemetry); | ||
@@ -255,3 +261,3 @@ Assert.ok(config.verboseLogging); | ||
}; | ||
var addEventHandlerStub = sinon.stub(Microsoft.ApplicationInsights.Util, 'addEventHandler').returns(true); | ||
var addEventHandlerStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, 'addEventHandler').returns(true); | ||
var init = new Microsoft.ApplicationInsights.Initialization(snippet); | ||
@@ -258,0 +264,0 @@ var appInsightsLocal = init.loadAppInsights(); |
@@ -39,3 +39,3 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
try { | ||
throwSpy = sinon.spy(console, "warn"); | ||
throwSpy = this.sandbox.spy(console, "warn"); | ||
} catch (e) { | ||
@@ -64,4 +64,3 @@ Assert.ok(true, "IE8 breaks sinon spies \n" + e.toString()); | ||
// cleanup | ||
InternalLogging.enableDebugExceptions = () => false; | ||
!throwSpy || throwSpy.restore(); // IE8 | ||
InternalLogging.enableDebugExceptions = () => false; | ||
} | ||
@@ -125,3 +124,3 @@ }); | ||
try { | ||
throwSpy = sinon.spy(console, "warn"); | ||
throwSpy = this.sandbox.spy(console, "warn"); | ||
@@ -139,3 +138,3 @@ // act | ||
// cleanup | ||
throwSpy.restore(); | ||
} catch (e) { | ||
@@ -153,3 +152,3 @@ Assert.ok(true, "IE8 breaks sinon spies on window objects\n" + e.toString()); | ||
try { | ||
throwSpy = sinon.spy(console, "warn"); | ||
throwSpy = this.sandbox.spy(console, "warn"); | ||
@@ -168,3 +167,3 @@ // act | ||
// cleanup | ||
throwSpy.restore(); | ||
} catch (e) { | ||
@@ -182,3 +181,3 @@ Assert.ok(true, "IE8 breaks sinon spies on window objects\n" + e.toString()); | ||
try { | ||
throwSpy = sinon.spy(console, "warn"); | ||
throwSpy = this.sandbox.spy(console, "warn"); | ||
@@ -194,3 +193,3 @@ // act | ||
// cleanup | ||
throwSpy.restore(); | ||
} catch (e) { | ||
@@ -210,3 +209,3 @@ Assert.ok(true, "IE8 breaks sinon spies on window objects\n" + e.toString()); | ||
console.warn = undefined; | ||
throwSpy = sinon.spy(console, "log"); | ||
throwSpy = this.sandbox.spy(console, "log"); | ||
@@ -221,3 +220,3 @@ // act | ||
// cleanup | ||
throwSpy.restore(); | ||
} catch (e) { | ||
@@ -261,3 +260,3 @@ Assert.ok(true, "IE8 breaks sinon spies on window objects\n" + e.toString()); | ||
var message = "Internal Test Event"; | ||
var logInternalMessageStub = sinon.stub(InternalLogging, 'logInternalMessage'); | ||
var logInternalMessageStub = this.sandbox.stub(InternalLogging, 'logInternalMessage'); | ||
@@ -275,3 +274,3 @@ // setup | ||
// clean | ||
logInternalMessageStub.restore(); | ||
} | ||
@@ -285,3 +284,3 @@ }); | ||
var message = "Internal Test Event"; | ||
var logInternalMessageStub = sinon.stub(InternalLogging, 'logInternalMessage'); | ||
var logInternalMessageStub = this.sandbox.stub(InternalLogging, 'logInternalMessage'); | ||
@@ -299,3 +298,3 @@ // setup | ||
// clean | ||
logInternalMessageStub.restore(); | ||
} | ||
@@ -302,0 +301,0 @@ }); |
@@ -12,14 +12,8 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
var storage = this.getMockStorage(); | ||
this.getStorageObjectStub = sinon.stub(Microsoft.ApplicationInsights.Util, "_getSessionStorageObject",() => storage); | ||
this.getStorageObjectStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "_getSessionStorageObject",() => storage); | ||
this.throwInternalNonUserActionableSpy = sinon.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalNonUserActionable"); | ||
this.throwInternalUserActionableSpy = sinon.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
this.throwInternalNonUserActionableSpy = this.sandbox.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalNonUserActionable"); | ||
this.throwInternalUserActionableSpy = this.sandbox.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
} | ||
/** Method called after each test method has completed */ | ||
public testCleanup() { | ||
this.getStorageObjectStub.restore(); | ||
this.throwInternalNonUserActionableSpy.restore(); | ||
this.throwInternalUserActionableSpy.restore(); | ||
} | ||
@@ -48,3 +42,3 @@ public registerTests() { | ||
var object = { method: function () { } }; | ||
var spy = sinon.spy(object, "method"); | ||
var spy = this.sandbox.spy(object, "method"); | ||
var pageVisitTimeManager = new Microsoft.ApplicationInsights.Telemetry.PageVisitTimeManager(spy); | ||
@@ -69,3 +63,3 @@ | ||
var object = { method: function () { } }; | ||
var spy = sinon.spy(object, "method"); | ||
var spy = this.sandbox.spy(object, "method"); | ||
var pageVisitTimeManager = new Microsoft.ApplicationInsights.Telemetry.PageVisitTimeManager(spy); | ||
@@ -72,0 +66,0 @@ |
@@ -22,4 +22,4 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
public testInitialize() { | ||
this.xhr = window["XMLHttpRequest"]; | ||
this.xdr = window["XDomainRequest"]; | ||
this.xhr = sinon.useFakeXMLHttpRequest(); | ||
this.xdr = sinon.useFakeXMLHttpRequest(); | ||
this.fakeServer = sinon.fakeServer.create(); | ||
@@ -40,26 +40,8 @@ this.endpointUrl = "testUrl"; | ||
this.getSender = () => new Microsoft.ApplicationInsights.Sender(config); | ||
this.errorSpy = sinon.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = sinon.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "warnToConsole"); | ||
this.errorSpy = this.sandbox.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = this.sandbox.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "warnToConsole"); | ||
this.testTelemetry = { aiDataContract: true }; | ||
} | ||
public testCleanup() { | ||
if (this.xhr === undefined) { | ||
delete window["XMLHttpRequest"]; | ||
} else { | ||
window["XMLHttpRequest"] = this.xhr; | ||
} | ||
if (this.xdr === undefined) { | ||
delete window["XDomainRequest"]; | ||
} else { | ||
window["XDomainRequest"] = this.xdr; | ||
} | ||
this.errorSpy.restore(); | ||
this.successSpy.restore(); | ||
this.loggingSpy.restore(); | ||
} | ||
public registerTests() { | ||
@@ -96,4 +78,7 @@ | ||
test: () => { | ||
// setup | ||
XMLHttpRequest = undefined; | ||
var sender: Microsoft.ApplicationInsights.Sender = this.getSender(); | ||
// act | ||
var sender: Microsoft.ApplicationInsights.Sender = this.getSender(); | ||
sender.send(this.testTelemetry); | ||
@@ -177,2 +162,9 @@ | ||
// setup | ||
// pretend that you are IE8/IE9 browser which supports XDomainRequests | ||
XMLHttpRequest = <any>(() => { | ||
var xhr = new this.xhr; | ||
delete xhr.withCredentials; | ||
return xhr; | ||
}); | ||
XDomainRequest = <any>(() => { | ||
@@ -213,3 +205,3 @@ var xdr = new this.xhr; | ||
errorAsserts(); | ||
logAsserts(2); | ||
logAsserts(1); | ||
this.successSpy.reset(); | ||
@@ -268,3 +260,3 @@ this.errorSpy.reset(); | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
this.maxBatchSizeInBytes = Microsoft.ApplicationInsights.Serializer.serialize(this.testTelemetry).length | ||
@@ -297,3 +289,3 @@ this.maxBatchInterval = 1; | ||
senderSpy.restore(); | ||
} | ||
@@ -308,3 +300,3 @@ }); | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
this.maxBatchSizeInBytes = Microsoft.ApplicationInsights.Serializer.serialize(this.testTelemetry).length; | ||
@@ -324,3 +316,3 @@ this.maxBatchInterval = 1; | ||
senderSpy.restore(); | ||
Microsoft.ApplicationInsights._InternalLogging.enableDebugExceptions = () => false; | ||
@@ -336,3 +328,3 @@ } | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
this.maxBatchSizeInBytes = Microsoft.ApplicationInsights.Serializer.serialize(this.testTelemetry).length * 2; | ||
@@ -364,3 +356,3 @@ this.maxBatchInterval = 2; | ||
senderSpy.restore(); | ||
} | ||
@@ -382,3 +374,3 @@ }); | ||
this.testCase({ | ||
name: "SenderTests: enableTracking swtich is set to false. Sender should not send/save data", | ||
name: "SenderTests: enableTracking switch is set to false. Sender should not send/save data", | ||
test: () => { | ||
@@ -389,3 +381,3 @@ // setup | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
@@ -400,3 +392,3 @@ // act | ||
senderSpy.restore(); | ||
} | ||
@@ -406,3 +398,3 @@ }); | ||
this.testCase({ | ||
name: "SenderTests: enableTracking swtich is set to false. Trigger send should not send data", | ||
name: "SenderTests: enableTracking switch is set to false. Trigger send should not send data", | ||
test: () => { | ||
@@ -413,3 +405,3 @@ // setup | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
this.maxBatchInterval = 100; | ||
@@ -425,3 +417,3 @@ | ||
senderSpy.restore(); | ||
} | ||
@@ -436,3 +428,3 @@ }); | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
this.maxBatchInterval = 100; | ||
@@ -447,3 +439,3 @@ | ||
senderSpy.restore(); | ||
} | ||
@@ -458,3 +450,3 @@ }); | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
this.maxBatchInterval = 100; | ||
@@ -469,3 +461,3 @@ | ||
senderSpy.restore(); | ||
} | ||
@@ -480,3 +472,3 @@ }); | ||
sender._sender = () => null; | ||
var senderSpy = sinon.spy(sender, "_sender"); | ||
var senderSpy = this.sandbox.spy(sender, "_sender"); | ||
this.maxBatchInterval = 100; | ||
@@ -491,3 +483,3 @@ | ||
senderSpy.restore(); | ||
} | ||
@@ -494,0 +486,0 @@ }); |
@@ -11,12 +11,6 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
public testInitialize() { | ||
this.throwInternalNonUserActionableSpy = sinon.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalNonUserActionable"); | ||
this.throwInternalUserActionableSpy = sinon.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
this.throwInternalNonUserActionableSpy = this.sandbox.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalNonUserActionable"); | ||
this.throwInternalUserActionableSpy = this.sandbox.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
} | ||
/** Method called after each test method has completed */ | ||
public testCleanup() { | ||
this.throwInternalNonUserActionableSpy.restore(); | ||
this.throwInternalUserActionableSpy.restore(); | ||
} | ||
public registerTests() { | ||
@@ -47,4 +41,4 @@ | ||
aiDataContract: { | ||
str: true, | ||
noContract: true | ||
str: Microsoft.ApplicationInsights.FieldType.Required, | ||
noContract: Microsoft.ApplicationInsights.FieldType.Required | ||
} | ||
@@ -69,3 +63,3 @@ }; | ||
aiDataContract: { | ||
str: true | ||
str: Microsoft.ApplicationInsights.FieldType.Required | ||
} | ||
@@ -88,3 +82,3 @@ }; | ||
// act | ||
var noCycle = { value: "value", aiDataContract: { value: true } }; | ||
var noCycle = { value: "value", aiDataContract: { value: Microsoft.ApplicationInsights.FieldType.Required } }; | ||
var obj = { | ||
@@ -96,3 +90,3 @@ arr: [ | ||
], | ||
aiDataContract: { arr: [] } | ||
aiDataContract: { arr: Microsoft.ApplicationInsights.FieldType.Array } | ||
}; | ||
@@ -116,3 +110,3 @@ var expected = '{"arr":[{"value":"value"},{"value":"value"},{"value":"value"}]}'; | ||
arr: {}, | ||
aiDataContract: { arr: [] } | ||
aiDataContract: { arr: Microsoft.ApplicationInsights.FieldType.Array } | ||
}; | ||
@@ -129,7 +123,54 @@ | ||
this.testCase({ | ||
name: "SerializerTests: hidden fields are not serialized", | ||
test: () => { | ||
// act | ||
var obj = { | ||
str: "yes!", | ||
hiddenStr: "im the invisible man", | ||
hiddenStrRequired: "required fields can also be marked as hidden", | ||
aiDataContract: { | ||
str: Microsoft.ApplicationInsights.FieldType.Required, | ||
hiddenStr: Microsoft.ApplicationInsights.FieldType.Hidden, | ||
hiddenStrRequired: Microsoft.ApplicationInsights.FieldType.Required | Microsoft.ApplicationInsights.FieldType.Hidden, | ||
} | ||
}; | ||
var expected = '{"str":"yes!"}'; | ||
var actual = Microsoft.ApplicationInsights.Serializer.serialize(obj); | ||
// verify | ||
Assert.equal(expected, actual, "Object is serialized correctly"); | ||
} | ||
}); | ||
this.testCase({ | ||
name: "SerializerTests: serialize a field which has a dynamic required state", | ||
test: () => { | ||
// act | ||
var obj = { | ||
str: "required", | ||
strOptional: "optional", | ||
aiDataContract: { | ||
str: { isRequired: () => { return Microsoft.ApplicationInsights.FieldType.Required; } }, | ||
strOptional: { isRequired: () => { return Microsoft.ApplicationInsights.FieldType.Default; } } | ||
} | ||
}; | ||
var expected = '{"str":"required","strOptional":"optional"}'; | ||
var actual = Microsoft.ApplicationInsights.Serializer.serialize(obj); | ||
// verify | ||
Assert.equal(expected, actual, "Object is serialized correctly"); | ||
} | ||
}); | ||
this.testCase({ | ||
name: "SerializerTests: cycles without contracts are handled", | ||
test: () => { | ||
// act | ||
var cyclePt1 = { value: undefined, aiDataContract: { value: true } }; | ||
var cyclePt2 = { value: cyclePt1, aiDataContract: { value: true } }; | ||
var cyclePt1 = { value: undefined, aiDataContract: { value: Microsoft.ApplicationInsights.FieldType.Required } }; | ||
var cyclePt2 = { value: cyclePt1, aiDataContract: { value: Microsoft.ApplicationInsights.FieldType.Required } }; | ||
cyclePt1.value = cyclePt2; | ||
@@ -141,3 +182,3 @@ var obj = { | ||
aiDataContract: { | ||
noContractWithCycle: true, | ||
noContractWithCycle: Microsoft.ApplicationInsights.FieldType.Required, | ||
} | ||
@@ -159,4 +200,4 @@ }; | ||
// act | ||
var cyclePt1 = { value: undefined, aiDataContract: { value: true } }; | ||
var cyclePt2 = { value: cyclePt1, aiDataContract: { value: true } }; | ||
var cyclePt1 = { value: undefined, aiDataContract: { value: Microsoft.ApplicationInsights.FieldType.Required } }; | ||
var cyclePt2 = { value: cyclePt1, aiDataContract: { value: Microsoft.ApplicationInsights.FieldType.Required } }; | ||
cyclePt1.value = cyclePt2; | ||
@@ -166,3 +207,3 @@ var obj = { | ||
aiDataContract: { | ||
aCycleWithContract: true, | ||
aCycleWithContract: Microsoft.ApplicationInsights.FieldType.Required, | ||
} | ||
@@ -189,3 +230,3 @@ }; | ||
aiDataContract: { | ||
str: true, | ||
str: Microsoft.ApplicationInsights.FieldType.Required, | ||
} | ||
@@ -210,3 +251,3 @@ }; | ||
aiDataContract: { | ||
str: true | ||
str: Microsoft.ApplicationInsights.FieldType.Required | ||
} | ||
@@ -248,4 +289,4 @@ }; | ||
aiDataContract: { | ||
properties: false, | ||
measurements: false | ||
properties: Microsoft.ApplicationInsights.FieldType.Default, | ||
measurements: Microsoft.ApplicationInsights.FieldType.Default | ||
} | ||
@@ -283,4 +324,4 @@ }; | ||
aiDataContract: { | ||
properties: false, | ||
measurements: false | ||
properties: Microsoft.ApplicationInsights.FieldType.Default, | ||
measurements: Microsoft.ApplicationInsights.FieldType.Default, | ||
} | ||
@@ -305,5 +346,4 @@ }; | ||
}); | ||
} | ||
} | ||
new SerializerTests().registerTests(); |
@@ -77,2 +77,14 @@ /// <reference path="../../testframework/common.ts" /> | ||
this.testCase({ | ||
name: "DataSanitizerTests: Validate object.toString is truncated if object passed to sanitizeString", | ||
test: () => { | ||
Microsoft.ApplicationInsights.Telemetry.Common.DataSanitizer["MAX_STRING_LENGTH"] = 5; | ||
var expectedValue = "[obje"; | ||
var value = { greeting: "Hello", place: "World" }; | ||
var validatedValue = Microsoft.ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeString(value); | ||
Assert.equal(expectedValue, validatedValue); | ||
} | ||
}); | ||
this.testCase({ | ||
name: "DataSanitizerTests: Validate url is truncated after max length ", | ||
@@ -79,0 +91,0 @@ test: () => { |
@@ -159,4 +159,32 @@ /// <reference path="../../testframework/common.ts" /> | ||
}); | ||
this.testCase({ | ||
name: "CreateSimpleException returns Exception instance with specified properties", | ||
test: () => { | ||
var expectedMessage = "Test Message"; | ||
var expectedTypeName = "Test Type Name"; | ||
var expectedDetails = "Test Details"; | ||
var expectedAssembly = "Test Assembly"; | ||
var expectedFileName = "Test File Name"; | ||
var expectedLineNumber = 42; | ||
var expectedHandledAt = "Test Handled At"; | ||
var actual = Microsoft.ApplicationInsights.Telemetry.Exception.CreateSimpleException(expectedMessage, expectedTypeName, expectedAssembly, expectedFileName, expectedDetails, expectedLineNumber, expectedHandledAt); | ||
Assert.equal(expectedMessage, actual.exceptions[0].message); | ||
Assert.equal(expectedTypeName, actual.exceptions[0].typeName); | ||
Assert.equal(expectedDetails, actual.exceptions[0].stack); | ||
Assert.equal(true, actual.exceptions[0].hasFullStack); | ||
Assert.equal(0, actual.exceptions[0].parsedStack[0].level); | ||
Assert.equal(expectedAssembly, actual.exceptions[0].parsedStack[0].assembly); | ||
Assert.equal(expectedFileName, actual.exceptions[0].parsedStack[0].fileName); | ||
Assert.equal(expectedLineNumber, actual.exceptions[0].parsedStack[0].line); | ||
Assert.equal("unknown", actual.exceptions[0].parsedStack[0].method); | ||
Assert.equal(expectedHandledAt, actual.handledAt); | ||
} | ||
}); | ||
} | ||
} | ||
new ExceptionTelemetryTests().registerTests(); |
@@ -14,3 +14,3 @@ /// <reference path="../../testframework/common.ts" /> | ||
var name = this.name + ": "; | ||
this.testCase({ | ||
@@ -32,4 +32,4 @@ name: name + "PageViewPerformanceTelemetry correct timing data", | ||
Assert.equal(false, check, "isPerformanceTimingSupported returns false when not performance timing is not supported"); | ||
} | ||
} | ||
} | ||
}); | ||
@@ -42,7 +42,14 @@ | ||
Assert.equal("boolean", typeof telemetry.aiDataContract.perfTotal, "perfTotal is set in data contract"); | ||
Assert.equal("boolean", typeof telemetry.aiDataContract.networkConnect, "networkConnect is set in data contract"); | ||
Assert.equal("boolean", typeof telemetry.aiDataContract.receivedResponse, "receivedResponse is set in data contract"); | ||
Assert.equal("boolean", typeof telemetry.aiDataContract.sentRequest, "sentRequest is set in data contract"); | ||
Assert.equal("boolean", typeof telemetry.aiDataContract.domProcessing, "domProcessing is set in data contract"); | ||
Assert.equal(Microsoft.ApplicationInsights.FieldType.Required, telemetry.aiDataContract.ver, "version fields is required"); | ||
// all other fields are optional | ||
for (var field in telemetry.aiDataContract) { | ||
if (field == "ver") { | ||
continue; | ||
} | ||
var contract = telemetry.aiDataContract[field]; | ||
Assert.notEqual(true, contract.isRequired, field + " is not required"); | ||
} | ||
} | ||
@@ -64,4 +71,4 @@ }); | ||
var timingSpy = sinon.stub(Microsoft.ApplicationInsights.Telemetry.PageViewPerformance, "getPerformanceTiming",() => { | ||
return timing; | ||
var timingSpy = this.sandbox.stub(Microsoft.ApplicationInsights.Telemetry.PageViewPerformance, "getPerformanceTiming", () => { | ||
return timing; | ||
}); | ||
@@ -71,3 +78,3 @@ | ||
var telemetry = new Microsoft.ApplicationInsights.Telemetry.PageViewPerformance("name", "url", 0); | ||
Assert.equal(true, telemetry.isValid); | ||
Assert.equal(true, telemetry.getIsValid()); | ||
@@ -82,3 +89,3 @@ var data = telemetry; | ||
timingSpy.restore(); | ||
} | ||
@@ -99,3 +106,3 @@ }); | ||
var timingSpy = sinon.stub(Microsoft.ApplicationInsights.Telemetry.PageViewPerformance, "getPerformanceTiming",() => { | ||
var timingSpy = this.sandbox.stub(Microsoft.ApplicationInsights.Telemetry.PageViewPerformance, "getPerformanceTiming", () => { | ||
return timing; | ||
@@ -105,7 +112,7 @@ }); | ||
var actualLoggedMessage = null; | ||
var loggingSpy = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "warnToConsole",(m) => actualLoggedMessage = m); | ||
var loggingSpy = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "warnToConsole", (m) => actualLoggedMessage = m); | ||
var telemetry = new Microsoft.ApplicationInsights.Telemetry.PageViewPerformance("name", "url", 0); | ||
Assert.equal(false, telemetry.isValid); | ||
Assert.equal(false, telemetry.getIsValid()); | ||
@@ -122,5 +129,5 @@ var data = telemetry; | ||
timingSpy.restore(); | ||
loggingSpy.restore(); | ||
} | ||
@@ -127,0 +134,0 @@ }); |
@@ -49,3 +49,3 @@ /// <reference path="../testframework/common.ts" /> | ||
var tc = new Microsoft.ApplicationInsights.TelemetryContext(this._config); | ||
var logSpy = sinon.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var logSpy = this.sandbox.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
tc.track(undefined); | ||
@@ -55,3 +55,3 @@ Assert.ok(logSpy.calledOnce, "sender throws with undefined"); | ||
Assert.ok(logSpy.calledTwice, "sender throws with null"); | ||
logSpy.restore(); | ||
} | ||
@@ -65,3 +65,3 @@ }); | ||
this._telemetryContext.session.isFirst = true; | ||
var env = new Microsoft.ApplicationInsights.Telemetry.Common.Envelope(null, ""); | ||
@@ -80,29 +80,7 @@ this._telemetryContext.track(env); | ||
} | ||
/** | ||
* Gets the sinon stub for telemetryContext.sample.isSampledIn function. Result is wrapped to an object | ||
* which has a counter of how many times the stub was accessed with expected envelope type. | ||
*/ | ||
function getStub(envelopeType: string, telemetryContext: Microsoft.ApplicationInsights.TelemetryContext) { | ||
var stub = { | ||
sinonStub: null, | ||
isSampledInCallsCount: 0 | ||
}; | ||
var isSampledInStub = sinon.stub(telemetryContext.sample, "isSampledIn", | ||
(envelope: Microsoft.ApplicationInsights.Telemetry.Common.Envelope) => { | ||
if (envelope.name === envelopeType) { | ||
++stub.isSampledInCallsCount; | ||
} | ||
}); | ||
stub.sinonStub = isSampledInStub; | ||
return stub; | ||
} | ||
this.testCase({ | ||
name: "TelemetryContext: page views get sampled", | ||
test: () => { | ||
var stub = getStub(Microsoft.ApplicationInsights.Telemetry.PageView.envelopeType, this._telemetryContext); | ||
var stub = this.getStub(Microsoft.ApplicationInsights.Telemetry.PageView.envelopeType, this._telemetryContext); | ||
@@ -121,11 +99,9 @@ var envelope = getEnvelope<Microsoft.ApplicationInsights.Telemetry.PageView>( | ||
// tear down | ||
stub.sinonStub.restore(); | ||
} | ||
}); | ||
this.testCase({ | ||
name: "TelemetryContext: events get sampled", | ||
test: () => { | ||
var stub = getStub(Microsoft.ApplicationInsights.Telemetry.Event.envelopeType, this._telemetryContext); | ||
var stub = this.getStub(Microsoft.ApplicationInsights.Telemetry.Event.envelopeType, this._telemetryContext); | ||
@@ -144,3 +120,2 @@ var envelope = getEnvelope<Microsoft.ApplicationInsights.Telemetry.Event>( | ||
// tear down | ||
stub.sinonStub.restore(); | ||
} | ||
@@ -152,3 +127,3 @@ }); | ||
test: () => { | ||
var stub = getStub(Microsoft.ApplicationInsights.Telemetry.Exception.envelopeType, this._telemetryContext); | ||
var stub = this.getStub(Microsoft.ApplicationInsights.Telemetry.Exception.envelopeType, this._telemetryContext); | ||
@@ -174,3 +149,2 @@ var exception; | ||
// tear down | ||
stub.sinonStub.restore(); | ||
} | ||
@@ -182,3 +156,3 @@ }); | ||
test: () => { | ||
var stub = getStub(Microsoft.ApplicationInsights.Telemetry.Metric.envelopeType, this._telemetryContext); | ||
var stub = this.getStub(Microsoft.ApplicationInsights.Telemetry.Metric.envelopeType, this._telemetryContext); | ||
@@ -197,3 +171,2 @@ var envelope = getEnvelope<Microsoft.ApplicationInsights.Telemetry.Metric>( | ||
// tear down | ||
stub.sinonStub.restore(); | ||
} | ||
@@ -205,3 +178,3 @@ }); | ||
test: () => { | ||
var stub = getStub(Microsoft.ApplicationInsights.Telemetry.PageViewPerformance.envelopeType, this._telemetryContext); | ||
var stub = this.getStub(Microsoft.ApplicationInsights.Telemetry.PageViewPerformance.envelopeType, this._telemetryContext); | ||
@@ -220,3 +193,2 @@ var envelope = getEnvelope<Microsoft.ApplicationInsights.Telemetry.PageViewPerformance>( | ||
// tear down | ||
stub.sinonStub.restore(); | ||
} | ||
@@ -228,3 +200,3 @@ }); | ||
test: () => { | ||
var stub = getStub(Microsoft.ApplicationInsights.Telemetry.SessionTelemetry.envelopeType, this._telemetryContext); | ||
var stub = this.getStub(Microsoft.ApplicationInsights.Telemetry.SessionTelemetry.envelopeType, this._telemetryContext); | ||
@@ -243,3 +215,2 @@ var envelope = getEnvelope<Microsoft.ApplicationInsights.Telemetry.SessionTelemetry>( | ||
// tear down | ||
stub.sinonStub.restore(); | ||
} | ||
@@ -251,3 +222,3 @@ }); | ||
test: () => { | ||
var stub = getStub(Microsoft.ApplicationInsights.Telemetry.Trace.envelopeType, this._telemetryContext); | ||
var stub = this.getStub(Microsoft.ApplicationInsights.Telemetry.Trace.envelopeType, this._telemetryContext); | ||
@@ -266,5 +237,4 @@ var envelope = getEnvelope<Microsoft.ApplicationInsights.Telemetry.Trace>( | ||
// tear down | ||
stub.sinonStub.restore(); | ||
} | ||
}); | ||
}); | ||
@@ -279,3 +249,3 @@ this.testCase({ | ||
} | ||
var spy = sinon.spy(telemetryInitializer, "initializer"); | ||
var spy = this.sandbox.spy(telemetryInitializer, "initializer"); | ||
this._telemetryContext.addTelemetryInitializer(<any>telemetryInitializer.initializer); | ||
@@ -291,3 +261,3 @@ | ||
// teardown | ||
spy.restore(); | ||
(<any>this._telemetryContext).telemetryInitializers = undefined; | ||
@@ -311,3 +281,3 @@ } | ||
this._telemetryContext.addTelemetryInitializer(<any>telemetryInitializer.initializer); | ||
var stub = sinon.stub(this._telemetryContext._sender, "send"); | ||
var stub = this.sandbox.stub(this._telemetryContext._sender, "send"); | ||
@@ -324,3 +294,3 @@ // act | ||
// teardown | ||
stub.restore(); | ||
(<any>this._telemetryContext).telemetryInitializers = undefined; | ||
@@ -334,3 +304,3 @@ } | ||
var eventEnvelope = this.getTestEventEnvelope(); | ||
var stub = sinon.stub(this._telemetryContext._sender, "send"); | ||
var stub = this.sandbox.stub(this._telemetryContext._sender, "send"); | ||
@@ -345,6 +315,6 @@ // act | ||
// teardown | ||
stub.restore(); | ||
} | ||
}); | ||
this.testCase({ | ||
@@ -370,3 +340,3 @@ name: "TelemetryContext: telemetry initializer can modify the contents of an envelope", | ||
this._telemetryContext.addTelemetryInitializer(<any>telemetryInitializer.init); | ||
var stub = sinon.stub(this._telemetryContext._sender, "send"); | ||
var stub = this.sandbox.stub(this._telemetryContext._sender, "send"); | ||
@@ -383,3 +353,3 @@ // act | ||
// teardown | ||
stub.restore(); | ||
(<any>this._telemetryContext).telemetryInitializers = undefined; | ||
@@ -393,7 +363,7 @@ } | ||
// prepare | ||
var eventEnvelope = this.getTestEventEnvelope(); | ||
var initializer1 = { init: () => { } }; | ||
var eventEnvelope = this.getTestEventEnvelope(); | ||
var initializer1 = { init: () => { } }; | ||
var initializer2 = { init: () => { } }; | ||
var spy1 = sinon.spy(initializer1, "init"); | ||
var spy2 = sinon.spy(initializer2, "init"); | ||
var spy1 = this.sandbox.spy(initializer1, "init"); | ||
var spy2 = this.sandbox.spy(initializer2, "init"); | ||
@@ -403,3 +373,3 @@ // act | ||
this._telemetryContext.addTelemetryInitializer(<any>initializer2.init); | ||
(<any>this._telemetryContext)._track(eventEnvelope); | ||
@@ -417,2 +387,24 @@ | ||
/** | ||
* Gets the sinon stub for telemetryContext.sample.isSampledIn function. Result is wrapped to an object | ||
* which has a counter of how many times the stub was accessed with expected envelope type. | ||
*/ | ||
private getStub(envelopeType: string, telemetryContext: Microsoft.ApplicationInsights.TelemetryContext) { | ||
var stub = { | ||
sinonStub: null, | ||
isSampledInCallsCount: 0 | ||
}; | ||
var isSampledInStub = this.sandbox.stub(telemetryContext.sample, "isSampledIn", | ||
(envelope: Microsoft.ApplicationInsights.Telemetry.Common.Envelope) => { | ||
if (envelope.name === envelopeType) { | ||
++stub.isSampledInCallsCount; | ||
} | ||
}); | ||
stub.sinonStub = isSampledInStub; | ||
return stub; | ||
} | ||
private getTestEventEnvelope(properties?: Object, measurements?: Object) { | ||
@@ -419,0 +411,0 @@ var event = new Microsoft.ApplicationInsights.Telemetry.Event('Test Event', properties, measurements); |
@@ -13,3 +13,3 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
var storage = this.getMockStorage(); | ||
var getStorageObjectStub = sinon.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
var getStorageObjectStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
@@ -21,3 +21,3 @@ storage["test"] = "A"; | ||
getStorageObjectStub.restore(); | ||
} | ||
@@ -30,7 +30,7 @@ }); | ||
var storage = undefined; | ||
var getStorageObjectStub = sinon.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
var getStorageObjectStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
Assert.equal(null, Util.getStorage("test"), "getStorage should return null when storage is unavailable"); | ||
getStorageObjectStub.restore(); | ||
} | ||
@@ -43,7 +43,7 @@ }); | ||
var storage = this.getMockStorage(); | ||
var getStorageObjectStub = sinon.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
var getStorageObjectStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
Assert.ok(Util.setStorage("test","A"), "setStorage should return true if storage is available for writes"); | ||
getStorageObjectStub.restore(); | ||
} | ||
@@ -56,7 +56,7 @@ }); | ||
var storage = undefined; | ||
var getStorageObjectStub = sinon.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
var getStorageObjectStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
Assert.ok(!Util.setStorage("test", "A"), "setStorage should return false if storage is unavailable for writes"); | ||
getStorageObjectStub.restore(); | ||
} | ||
@@ -69,3 +69,3 @@ }); | ||
var storage = this.getMockStorage(); | ||
var getStorageObjectStub = sinon.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
var getStorageObjectStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
@@ -77,3 +77,3 @@ storage["test"] = "A"; | ||
getStorageObjectStub.restore(); | ||
} | ||
@@ -86,7 +86,7 @@ }); | ||
var storage = undefined; | ||
var getStorageObjectStub = sinon.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
var getStorageObjectStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "_getStorageObject",() => storage); | ||
Assert.ok(!Util.removeStorage("test"), "removeStorage should return false if storage is unavailable for writes"); | ||
getStorageObjectStub.restore(); | ||
} | ||
@@ -109,3 +109,3 @@ }); | ||
document.body.appendChild(iframe); | ||
var iframeArray = window.frames[window.frames.length - 1].Array; | ||
var iframeArray = window.frames[window.frames.length - 1]["Array"]; | ||
if (typeof iframeArray === "function") { | ||
@@ -164,16 +164,20 @@ var arr = new iframeArray(1, 2, 3); // [1,2,3] | ||
test: () => { | ||
var test = (cookie, query, expected) => { | ||
Util["document"] = <any>{ | ||
cookie: cookie | ||
}; | ||
try { | ||
var test = (cookie, query, expected) => { | ||
Util["document"] = <any>{ | ||
cookie: cookie | ||
}; | ||
var actual = Util.getCookie(query); | ||
Assert.deepEqual(expected, actual, "cookie is parsed correctly"); | ||
var actual = Util.getCookie(query); | ||
Assert.deepEqual(expected, actual, "cookie is parsed correctly"); | ||
} | ||
test("testCookie=id|acq|renewal", "testCookie", "id|acq|renewal"); | ||
test("other=foo; testCookie=id|acq|renewal", "testCookie", "id|acq|renewal"); | ||
test("another=bar; ;a=testCookie=; testCookie=id|acq|renewal; other=foo|3|testCookie=", "testCookie", "id|acq|renewal"); | ||
test("xtestCookiex=id|acq|renewal", "testCookie", ""); | ||
test("", "testCookie", ""); | ||
} finally { | ||
Util["document"] = document; | ||
} | ||
test("testCookie=id|acq|renewal", "testCookie", "id|acq|renewal"); | ||
test("other=foo; testCookie=id|acq|renewal", "testCookie", "id|acq|renewal"); | ||
test("another=bar; ;a=testCookie=; testCookie=id|acq|renewal; other=foo|3|testCookie=", "testCookie", "id|acq|renewal"); | ||
test("xtestCookiex=id|acq|renewal", "testCookie", ""); | ||
test("", "testCookie", ""); | ||
} | ||
@@ -185,7 +189,10 @@ }); | ||
test: () => { | ||
var randomStub = sinon.stub(Math, "random",() => 0); | ||
var expected = "00000000-0000-4000-8000-000000000000"; | ||
var actual = Util.newGuid(); | ||
Assert.equal(expected, actual, "expected guid was generated"); | ||
randomStub.restore(); | ||
var results = []; | ||
for (var i = 0; i < 100; i++) { | ||
var newId = Util.newId(); | ||
for (var j = 0; j < results.length; j++) { | ||
Assert.notEqual(newId, results[j]); | ||
} | ||
results.push(newId); | ||
} | ||
} | ||
@@ -272,3 +279,3 @@ }); | ||
Assert.ok(Util.isCrossOriginError("Script error.", "http://microsoft.com", 0, 0, null) | ||
=== false); | ||
=== true); | ||
} | ||
@@ -275,0 +282,0 @@ }); |
{ | ||
"Framework": "qunit", | ||
"References": [ | ||
{ "Path": "External/Sinon-1.7.3.js" }, | ||
{ "Path": "External/sinon-1.17.2.js" }, | ||
{ "Path": "Selenium/JSLitmus.js" }, | ||
@@ -6,0 +6,0 @@ { "Path": "E2ETests/testSnippet.js" }, |
@@ -22,2 +22,8 @@ // THIS FILE WAS AUTOGENERATED | ||
QUnit.test("Test property ContextTagKeys.ApplicationId was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.applicationId !== null, "ContextTagKeys.applicationId == null"); | ||
QUnit.ok(temp.applicationId === "ai.application.applicationId", "Issue with ContextTagKeys.applicationId"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.DeviceId was created and default is set", function () { | ||
@@ -161,2 +167,8 @@ var temp = new AI.ContextTagKeys(); | ||
QUnit.test("Test property ContextTagKeys.OperationCorrelationVector was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.operationCorrelationVector !== null, "ContextTagKeys.operationCorrelationVector == null"); | ||
QUnit.ok(temp.operationCorrelationVector === "ai.operation.correlationVector", "Issue with ContextTagKeys.operationCorrelationVector"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.SessionId was created and default is set", function () { | ||
@@ -234,2 +246,44 @@ var temp = new AI.ContextTagKeys(); | ||
QUnit.test("Test property ContextTagKeys.CloudName was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.cloudName !== null, "ContextTagKeys.cloudName == null"); | ||
QUnit.ok(temp.cloudName === "ai.cloud.name", "Issue with ContextTagKeys.cloudName"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.CloudRoleVer was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.cloudRoleVer !== null, "ContextTagKeys.cloudRoleVer == null"); | ||
QUnit.ok(temp.cloudRoleVer === "ai.cloud.roleVer", "Issue with ContextTagKeys.cloudRoleVer"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.CloudEnvironment was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.cloudEnvironment !== null, "ContextTagKeys.cloudEnvironment == null"); | ||
QUnit.ok(temp.cloudEnvironment === "ai.cloud.environment", "Issue with ContextTagKeys.cloudEnvironment"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.CloudLocation was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.cloudLocation !== null, "ContextTagKeys.cloudLocation == null"); | ||
QUnit.ok(temp.cloudLocation === "ai.cloud.location", "Issue with ContextTagKeys.cloudLocation"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.CloudDeploymentUnit was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.cloudDeploymentUnit !== null, "ContextTagKeys.cloudDeploymentUnit == null"); | ||
QUnit.ok(temp.cloudDeploymentUnit === "ai.cloud.deploymentUnit", "Issue with ContextTagKeys.cloudDeploymentUnit"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.ServerDeviceOS was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.serverDeviceOS !== null, "ContextTagKeys.serverDeviceOS == null"); | ||
QUnit.ok(temp.serverDeviceOS === "ai.serverDevice.os", "Issue with ContextTagKeys.serverDeviceOS"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.ServerDeviceOSVer was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.serverDeviceOSVer !== null, "ContextTagKeys.serverDeviceOSVer == null"); | ||
QUnit.ok(temp.serverDeviceOSVer === "ai.serverDevice.osVer", "Issue with ContextTagKeys.serverDeviceOSVer"); | ||
}); | ||
QUnit.test("Test property ContextTagKeys.InternalSdkVersion was created and default is set", function () { | ||
@@ -325,1 +379,7 @@ var temp = new AI.ContextTagKeys(); | ||
QUnit.test("Test property ContextTagKeys.InternalIsDiagnosticExample was created and default is set", function () { | ||
var temp = new AI.ContextTagKeys(); | ||
QUnit.ok(temp.internalIsDiagnosticExample !== null, "ContextTagKeys.internalIsDiagnosticExample == null"); | ||
QUnit.ok(temp.internalIsDiagnosticExample === "ai.internal.isDiagnosticExample", "Issue with ContextTagKeys.internalIsDiagnosticExample"); | ||
}); | ||
@@ -27,2 +27,12 @@ // THIS FILE WAS AUTOGENERATED | ||
QUnit.test("Test property RemoteDependencyData.id was created and default is set", function () { | ||
var temp = new AI.RemoteDependencyData(); | ||
QUnit.ok(temp.id !== null, "RemoteDependencyData.id == null"); | ||
}); | ||
QUnit.test("Test property RemoteDependencyData.resultCode was created and default is set", function () { | ||
var temp = new AI.RemoteDependencyData(); | ||
QUnit.ok(temp.resultCode !== null, "RemoteDependencyData.resultCode == null"); | ||
}); | ||
QUnit.test("Test property RemoteDependencyData.kind was created and default is set", function () { | ||
@@ -29,0 +39,0 @@ var temp = new AI.RemoteDependencyData(); |
@@ -26,2 +26,47 @@ /// <reference path="../../javascriptsdk/telemetry/exception.ts" /> | ||
this.testCaseAsync({ | ||
name: "AutoCollection: ajax", | ||
stepDelay: delay, | ||
steps: [ | ||
() => { | ||
this.loadErrorTest("ajax"); | ||
} | ||
].concat(this.poll(() => { | ||
return this.verifyAjax(this.errorSpy, [ | ||
{ | ||
name: "https://code.jquery.com/jquery-2.1.4.min.js", | ||
success: true, | ||
commandName: "/jquery-2.1.4.min.js", | ||
dependencyTypeName: "Ajax", | ||
dependencyKind: 1, | ||
dependencySource: 2 | ||
}, | ||
{ | ||
name: "http://dc.services.visualstudio.com/v2/track", | ||
success: false, | ||
commandName: "/v2/track", | ||
dependencyTypeName: "Ajax", | ||
dependencyKind: 1, | ||
dependencySource: 2 | ||
}, | ||
{ | ||
name: "http://dc.services.visualstudio.com/v2/track", | ||
commandName: "/v2/track", | ||
success: false, | ||
dependencyTypeName: "Ajax", | ||
dependencyKind: 1, | ||
dependencySource: 2 | ||
}, | ||
{ | ||
name: "http://dc.services.visualstudio.com/v2/track", | ||
commandName: "/v2/track", | ||
success: false, | ||
dependencyTypeName: "Ajax", | ||
dependencyKind: 1, | ||
dependencySource: 2 | ||
} | ||
]); | ||
})) | ||
}); | ||
//var errorDomSpy = this.getListener("errorDom"); | ||
@@ -36,10 +81,10 @@ this.testCaseAsync({ | ||
].concat(this.poll(() => { | ||
return this.verifyErrorMessages(this.errorSpy, [ | ||
return this.verifyErrorMessages(this.errorSpy, [ | ||
//General Error message | ||
"NotFoundError", | ||
"NotFoundError", | ||
// Safari specific error message | ||
"An attempt was made to reference a Node in a context where it does not exist" | ||
], 1); | ||
})) | ||
"An attempt was made to reference a Node in a context where it does not exist" | ||
], 1); | ||
})) | ||
}); | ||
@@ -57,6 +102,6 @@ | ||
return this.verifyErrorMessages(this.errorSpy, [ | ||
// General errors | ||
// General errors | ||
"undefinedObject is not defined", | ||
// IE specific error messages | ||
// IE specific error messages | ||
"Object doesn't support property or method 'unsupportedMethod'", | ||
@@ -70,3 +115,3 @@ "The use of a keyword for an identifier is invalid", | ||
// Chrome specific error messages | ||
// Chrome specific error messages | ||
"Invalid array length", | ||
@@ -78,5 +123,5 @@ "Invalid left-hand side in assignment", | ||
// Firefox specific error messages | ||
// Firefox specific error messages | ||
"obj.unsupportedMethod is not a function", | ||
"invalid array length", | ||
"invalid array length", | ||
"invalid assignment left-hand side", | ||
@@ -86,3 +131,3 @@ "toString method called on incompatible Object", | ||
// Safari specific error messages | ||
// Safari specific error messages | ||
"'undefined' is not a function", | ||
@@ -108,18 +153,18 @@ "Array size is not a small enough positive integer", | ||
return this.verifyErrorMessages(this.errorSpy, [ | ||
//General Error message | ||
//General Error message | ||
"first is not defined", | ||
"afterFullAiLoads", | ||
// IE specific error messages | ||
// IE specific error messages | ||
"'first' is undefined", | ||
"Unable to get property 'exist' of undefined or null reference", | ||
// Chrome specific error messages | ||
// Chrome specific error messages | ||
"Cannot read property 'exist' of undefined", | ||
// Firefox specific error messages | ||
// Firefox specific error messages | ||
"no element found", | ||
"window.doesNot is undefined", | ||
// Safari specific error messages | ||
// Safari specific error messages | ||
"Can't find variable: first", | ||
@@ -141,3 +186,3 @@ "'undefined' is not an object" | ||
return this.verifyErrorMessages(this.errorSpy, [ | ||
// IE specific error messages | ||
// IE specific error messages | ||
"Object doesn't support property or method 'unsupportedMethod'", | ||
@@ -147,3 +192,3 @@ "Expected '}'", | ||
// Chrome specific error messages | ||
// Chrome specific error messages | ||
"undefined is not a function", | ||
@@ -153,3 +198,3 @@ "Unexpected end of input", | ||
// Firefox specific error messages | ||
// Firefox specific error messages | ||
"obj.unsupportedMethod is not a function", | ||
@@ -160,3 +205,3 @@ "missing } in compound statement", | ||
// Safari specific error messages | ||
// Safari specific error messages | ||
"Expected token '}'", | ||
@@ -167,3 +212,3 @@ "Unexpected EOF" | ||
}); | ||
} | ||
@@ -173,3 +218,3 @@ | ||
var listener = { onMessage: () => null }; | ||
var spy = sinon.spy(listener, "onMessage"); | ||
var spy = this.sandbox.spy(listener, "onMessage"); | ||
@@ -179,3 +224,3 @@ if (window.addEventListener) { | ||
} else { | ||
attachEvent("onmessage", listener.onMessage); | ||
window["attachEvent"].call("onmessage", listener.onMessage); | ||
} | ||
@@ -206,3 +251,3 @@ | ||
}); | ||
} | ||
} | ||
@@ -212,2 +257,20 @@ return polling; | ||
private getTelemetryItemsFromMessage(args, telemetryType) { | ||
var items = []; | ||
for (var i = 0; i < args.length; i++) { | ||
var payload = args[i][0]; | ||
try { | ||
var data = JSON.parse(payload.data); | ||
for (var j = 0; j < data.length; j++) { | ||
var d = data[j].data; | ||
if (d && d.baseType === telemetryType) { | ||
items.push(d.baseData); | ||
} | ||
} | ||
} catch (e) { } | ||
} | ||
return items; | ||
} | ||
private getExceptionsFromMessage(args) { | ||
@@ -229,2 +292,26 @@ var exceptions = []; | ||
private verifyAjax(spy: SinonSpy, expectedItems) { | ||
if (spy.called) { | ||
var args = spy.args; | ||
var ajaxItems = this.getTelemetryItemsFromMessage(args, Microsoft.ApplicationInsights.Telemetry.RemoteDependencyData.dataType); | ||
Assert.equal(expectedItems.length, ajaxItems.length, "Number of expected and actual ajax calls must match"); | ||
for (var i = 0; i < ajaxItems.length; ++i) { | ||
var actual = ajaxItems[i]; | ||
var expected = expectedItems[i]; | ||
Assert.equal(expected.name, actual.name, "Name must match"); | ||
Assert.equal(expected.commandName, actual.commandName, "CommandName must match"); | ||
Assert.equal(expected.success, actual.success, "Success property must match"); | ||
Assert.equal(expected.dependencyTypeName, actual.dependencyTypeName, "DependencyTypeName must match"); | ||
Assert.equal(expected.dependencyKind, actual.dependencyKind, "DependencyKind must match"); | ||
Assert.equal(expected.dependencySource, actual.dependencySource, "DependencySource must match"); | ||
} | ||
} | ||
return true; | ||
} | ||
private verifyErrorMessages(spy: SinonSpy, expectedMessages, numberOfTests) { | ||
@@ -251,3 +338,3 @@ var done = false; | ||
} | ||
return done; | ||
@@ -254,0 +341,0 @@ } |
@@ -18,5 +18,5 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
this.clock.restore(); | ||
this.errorSpy = sinon.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = sinon.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
this.errorSpy = this.sandbox.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = this.sandbox.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
} | ||
@@ -29,5 +29,2 @@ | ||
this.useFakeTimers = true; | ||
this.errorSpy.restore(); | ||
this.successSpy.restore(); | ||
this.loggingSpy.restore(); | ||
} | ||
@@ -34,0 +31,0 @@ |
@@ -17,5 +17,5 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
this.clock.restore(); | ||
this.errorSpy = sinon.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = sinon.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
this.errorSpy = this.sandbox.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = this.sandbox.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
} | ||
@@ -27,5 +27,2 @@ | ||
this.useFakeTimers = true; | ||
this.errorSpy.restore(); | ||
this.successSpy.restore(); | ||
this.loggingSpy.restore(); | ||
} | ||
@@ -32,0 +29,0 @@ |
@@ -17,5 +17,5 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
this.clock.restore(); | ||
this.errorSpy = sinon.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = sinon.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = sinon.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
this.errorSpy = this.sandbox.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
this.successSpy = this.sandbox.stub(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
this.loggingSpy = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
} | ||
@@ -27,5 +27,2 @@ | ||
this.useFakeTimers = true; | ||
this.errorSpy.restore(); | ||
this.successSpy.restore(); | ||
this.loggingSpy.restore(); | ||
} | ||
@@ -32,0 +29,0 @@ |
@@ -37,3 +37,3 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
window['queueTest'] = () => null; | ||
this.queueSpy = sinon.spy(window, "queueTest"); | ||
this.queueSpy = this.sandbox.spy(window, "queueTest"); | ||
this.useFakeTimers = false; | ||
@@ -50,3 +50,2 @@ this.clock.restore(); | ||
window[this.name] = this.originalAppInsights; | ||
this.queueSpy.restore(); | ||
} | ||
@@ -86,3 +85,3 @@ | ||
Assert.deepEqual({ measurement: 5 }, pv.measurements, "measurements were set correctly"); | ||
senderSpy71V2.restore(); | ||
} | ||
@@ -111,3 +110,3 @@ ] | ||
this.boilerPlateAsserts(senderSpy66V2V1); | ||
senderSpy66V2V1.restore(); | ||
} | ||
@@ -180,3 +179,3 @@ ] | ||
this.boilerPlateAsserts(sender); | ||
sender.restore(); | ||
} | ||
@@ -225,6 +224,6 @@ ] | ||
var appIn = <Microsoft.ApplicationInsights.AppInsights>window[this.name]; | ||
var sender = sinon.spy(appIn.context._sender, "send"); | ||
var errorSpy = sinon.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
var successSpy = sinon.spy(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
var loggingSpy = sinon.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
var sender = this.sandbox.spy(appIn.context._sender, "send"); | ||
var errorSpy = this.sandbox.spy(Microsoft.ApplicationInsights.Sender, "_onError"); | ||
var successSpy = this.sandbox.spy(Microsoft.ApplicationInsights.Sender, "_onSuccess"); | ||
var loggingSpy = this.sandbox.spy(Microsoft.ApplicationInsights._InternalLogging, "throwInternalUserActionable"); | ||
@@ -237,6 +236,6 @@ return { | ||
restore: () => { | ||
sender.restore(); | ||
errorSpy.restore(); | ||
successSpy.restore(); | ||
loggingSpy.restore(); | ||
} | ||
@@ -243,0 +242,0 @@ }; |
@@ -1,6 +0,7 @@ | ||
// Type definitions for Sinon 1.5 | ||
// Type definitions for Sinon 1.16.0 | ||
// Project: http://sinonjs.org/ | ||
// Definitions by: William Sears <https://github.com/mrbigdog2u> | ||
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
interface SinonSpyCallApi { | ||
@@ -17,5 +18,5 @@ // Properties | ||
calledWithExactly(...args: any[]): boolean; | ||
calledWithMatch(...args: SinonMatcher[]): boolean; | ||
calledWithMatch(...args: any[]): boolean; | ||
notCalledWith(...args: any[]): boolean; | ||
notCalledWithMatch(...args: SinonMatcher[]): boolean; | ||
notCalledWithMatch(...args: any[]): boolean; | ||
returned(value: any): boolean; | ||
@@ -63,12 +64,12 @@ threw(): boolean; | ||
calledWithNew(spy: SinonSpy): boolean; | ||
withArgs(...args: any[]): void; | ||
alwaysCalledOn(obj: any); | ||
alwaysCalledWith(...args: any[]); | ||
alwaysCalledWithExactly(...args: any[]); | ||
alwaysCalledWithMatch(...args: SinonMatcher[]); | ||
neverCalledWith(...args: any[]); | ||
neverCalledWithMatch(...args: SinonMatcher[]); | ||
withArgs(...args: any[]): SinonSpy; | ||
alwaysCalledOn(obj: any): boolean; | ||
alwaysCalledWith(...args: any[]): boolean; | ||
alwaysCalledWithExactly(...args: any[]): boolean; | ||
alwaysCalledWithMatch(...args: any[]): boolean; | ||
neverCalledWith(...args: any[]): boolean; | ||
neverCalledWithMatch(...args: any[]): boolean; | ||
alwaysThrew(): boolean; | ||
alwaysThrew(type: string); | ||
alwaysThrew(obj: any); | ||
alwaysThrew(type: string): boolean; | ||
alwaysThrew(obj: any): boolean; | ||
alwaysReturned(): boolean; | ||
@@ -78,3 +79,3 @@ invokeCallback(...args: any[]): void; | ||
reset(): void; | ||
printf(format: string, ...args: any[]); | ||
printf(format: string, ...args: any[]): string; | ||
restore(): void; | ||
@@ -107,2 +108,6 @@ } | ||
callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub; | ||
onCall(n: number): SinonStub; | ||
onFirstCall(): SinonStub; | ||
onSecondCall(): SinonStub; | ||
onThirdCall(): SinonStub; | ||
yields(...args: any[]): SinonStub; | ||
@@ -116,2 +121,3 @@ yieldsOn(context: any, ...args: any[]): SinonStub; | ||
yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub; | ||
withArgs(...args: any[]): SinonStub; | ||
} | ||
@@ -130,3 +136,3 @@ | ||
interface SinonExpectation { | ||
interface SinonExpectation extends SinonStub { | ||
atLeast(n: number): SinonExpectation; | ||
@@ -184,2 +190,15 @@ atMost(n: number): SinonExpectation; | ||
restore(): void; | ||
/** | ||
* Simulate the user changing the system clock while your program is running. It changes the 'now' timestamp | ||
* without affecting timers, intervals or immediates. | ||
* @param now The new 'now' in unix milliseconds | ||
*/ | ||
setSystemTime(now: number): void; | ||
/** | ||
* Simulate the user changing the system clock while your program is running. It changes the 'now' timestamp | ||
* without affecting timers, intervals or immediates. | ||
* @param now The new 'now' as a JavaScript Date | ||
*/ | ||
setSystemTime(date: Date): void; | ||
} | ||
@@ -198,2 +217,15 @@ | ||
interface SinonFakeUploadProgress { | ||
eventListeners: { | ||
progress: any[]; | ||
load: any[]; | ||
abort: any[]; | ||
error: any[]; | ||
}; | ||
addEventListener(event: string, listener: (e: Event) => any): void; | ||
removeEventListener(event: string, listener: (e: Event) => any): void; | ||
dispatchEvent(event: Event): void; | ||
} | ||
interface SinonFakeXMLHttpRequest { | ||
@@ -211,2 +243,4 @@ // Properties | ||
password: string; | ||
withCredentials: boolean; | ||
upload: SinonFakeUploadProgress; | ||
responseXML: Document; | ||
@@ -219,3 +253,3 @@ getResponseHeader(header: string): string; | ||
useFilters: boolean; | ||
addFilter(filter: (method, url, async, username, password) => boolean): void; | ||
addFilter(filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean): void; | ||
setResponseHeaders(headers: any): void; | ||
@@ -243,2 +277,3 @@ setResponseBody(body: string): void; | ||
requests: SinonFakeXMLHttpRequest[]; | ||
respondImmediately: boolean; | ||
@@ -248,15 +283,15 @@ // Methods | ||
respondWith(response: any[]): void; | ||
respondWith(fn: (SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(fn: (xhr: SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(url: string, body: string): void; | ||
respondWith(url: string, response: any[]): void; | ||
respondWith(url: string, fn: (SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(method: string, url: string, body: string): void; | ||
respondWith(method: string, url: string, response: any[]): void; | ||
respondWith(method: string, url: string, fn: (SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(method: string, url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(url: RegExp, body: string): void; | ||
respondWith(url: RegExp, response: any[]): void; | ||
respondWith(url: RegExp, fn: (SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(method: string, url: RegExp, body: string): void; | ||
respondWith(method: string, url: RegExp, response: any[]): void; | ||
respondWith(method: string, url: RegExp, fn: (SinonFakeXMLHttpRequest) => void): void; | ||
respondWith(method: string, url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void; | ||
respond(): void; | ||
@@ -276,3 +311,3 @@ restore(): void; | ||
interface SinonExposeOptions { | ||
snippet?: string; | ||
prefix?: string; | ||
includeFail?: boolean; | ||
@@ -284,4 +319,4 @@ } | ||
failException: string; | ||
fail: (message?: string) => void; // Overridable | ||
pass: (assertion: any) => void; // Overridable | ||
fail: (message?: string) => void; // Overridable | ||
pass: (assertion: any) => void; // Overridable | ||
@@ -303,5 +338,5 @@ // Methods | ||
alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void; | ||
calledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void; | ||
alwaysCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void; | ||
neverCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void; | ||
calledWithMatch(spy: SinonSpy, ...args: any[]): void; | ||
alwaysCalledWithMatch(spy: SinonSpy, ...args: any[]): void; | ||
neverCalledWithMatch(spy: SinonSpy, ...args: any[]): void; | ||
threw(spy: SinonSpy): void; | ||
@@ -335,3 +370,3 @@ threw(spy: SinonSpy, exception: string): void; | ||
falsy: SinonMatcher; | ||
boolean: SinonMatcher; | ||
bool: SinonMatcher; | ||
number: SinonMatcher; | ||
@@ -363,13 +398,12 @@ string: SinonMatcher; | ||
interface SinonSandbox { | ||
args: any[]; | ||
clock: SinonFakeTimers; | ||
requests: SinonFakeXMLHttpRequest; | ||
server: SinonFakeServer; | ||
spy(): SinonSpy; | ||
stub(): SinonStub; | ||
mock(): SinonMock; | ||
useFakeTimers: SinonFakeTimers; | ||
useFakeXMLHttpRequest: SinonFakeXMLHttpRequest; | ||
spy: SinonSpyStatic; | ||
stub: SinonStubStatic; | ||
mock: SinonMockStatic; | ||
useFakeTimers: SinonFakeTimersStatic; | ||
useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic; | ||
useFakeServer(): SinonFakeServer; | ||
restore(): void; | ||
verifyAndRestore(): void; | ||
} | ||
@@ -400,3 +434,3 @@ | ||
config: SinonTestConfig; | ||
test(fn: Function): SinonTestWrapper; | ||
test(fn: (...args: any[]) => any): SinonTestWrapper; | ||
testCase(tests: any): any; | ||
@@ -407,7 +441,13 @@ } | ||
interface SinonStatic { | ||
createStubInstance(constructorFunction: any): any; | ||
format: (obj: any) => string; | ||
log: (message: string) => void; | ||
createStubInstance(constructor: any): SinonStub; | ||
format(obj: any): string; | ||
log(message: string): void; | ||
restore(object: any): void; | ||
} | ||
declare var sinon: SinonStatic; | ||
declare module "sinon" { | ||
export = sinon; | ||
} |
@@ -146,3 +146,3 @@ /// <reference path="../testframework/performancetesthelper.ts" /> | ||
var listener = { onMessage: (data) => null }; | ||
var spy = sinon.spy(listener, "onMessage"); | ||
var spy = this.sandbox.spy(listener, "onMessage"); | ||
@@ -152,3 +152,3 @@ if (window.addEventListener) { | ||
} else { | ||
attachEvent("onmessage", listener.onMessage); | ||
window["attachEvent"].call("onmessage", listener.onMessage); | ||
} | ||
@@ -155,0 +155,0 @@ |
@@ -12,2 +12,3 @@ /// <reference path="../checkintests/context/SamplingScoreGenerator.tests.ts" /> | ||
/// <reference path="../checkintests/telemetry/trace.tests.ts" /> | ||
/// <reference path="../checkintests/telemetry/RemoteDependency.tests.ts" /> | ||
/// <reference path="../checkintests/telemetry/DataSanitizer.tests.ts" /> | ||
@@ -23,1 +24,2 @@ | ||
/// <reference path="../checkintests/initialization.tests.ts" /> | ||
/// <reference path="../checkintests/ajax.tests.ts" /> |
@@ -79,3 +79,3 @@ /// <reference path="../../JavaScriptSDK/serializer.ts" /> | ||
for (var field in subject.aiDataContract) { | ||
if (subject.aiDataContract[field]) { | ||
if (subject.aiDataContract[field] & Microsoft.ApplicationInsights.FieldType.Required) { | ||
Assert.ok(subject[field] != null, "The required field '" + field + "' is constructed for: '" + name + "'"); | ||
@@ -82,0 +82,0 @@ } |
@@ -27,2 +27,3 @@ /// <reference path="..\TestFramework\Common.ts" /> | ||
secondsPerOp: number; | ||
browser: string; | ||
} | ||
@@ -29,0 +30,0 @@ |
@@ -68,11 +68,7 @@ module Microsoft.ApplicationInsights.Context { | ||
//get resolution | ||
if (typeof screen !== "undefined" && screen.width && screen.height) { | ||
this.resolution = screen.width + "X" + screen.height; | ||
} | ||
//get locale | ||
this.locale = (typeof screen !== "undefined" && navigator.browserLanguage) ? navigator.browserLanguage : "unknown"; | ||
// Device type is a dimension in our data platform | ||
// Setting it to 'Browser' allows to separate client and server dependencies/exceptions | ||
this.type = "Browser"; | ||
} | ||
} | ||
} |
@@ -13,7 +13,10 @@ /// <reference path="../util.ts" /> | ||
public syntheticSource: string; | ||
constructor() { | ||
this.id = Util.newGuid(); | ||
this.id = Util.newId(); | ||
if (window && window.location && window.location.pathname) { | ||
this.name = window.location.pathname; | ||
} | ||
} | ||
} | ||
} |
@@ -18,6 +18,6 @@ /// <reference path="../util.ts" /> | ||
/** | ||
* The true if this is the first session | ||
/** | ||
* The true if this is the first session | ||
*/ | ||
public isFirst: boolean; | ||
public isFirst: boolean; | ||
@@ -44,5 +44,5 @@ /** | ||
public config: ISessionConfig; | ||
public _sessionHandler: (sessionState: AI.SessionState, timestamp: number) => void; | ||
constructor(config: ISessionConfig, sessionHandler: (sessionState: AI.SessionState, timestamp: number) => void) { | ||
@@ -84,3 +84,3 @@ | ||
} | ||
this.automaticSession.isFirst = undefined; | ||
this.automaticSession.isFirst = undefined; | ||
this.renew(); | ||
@@ -122,3 +122,3 @@ } else { | ||
if (!this.automaticSession.id) { | ||
this.automaticSession.isFirst = true; | ||
this.automaticSession.isFirst = true; | ||
this.renew(); | ||
@@ -137,23 +137,23 @@ } | ||
if (params.length > 0) { | ||
this.automaticSession.id = params[0]; | ||
if (params.length > 0) { | ||
this.automaticSession.id = params[0]; | ||
} | ||
try { | ||
if (params.length > 1) { | ||
var acq = +params[1]; | ||
this.automaticSession.acquisitionDate = +new Date(acq); | ||
this.automaticSession.acquisitionDate = this.automaticSession.acquisitionDate > 0 ? this.automaticSession.acquisitionDate : 0; | ||
} | ||
try { | ||
if (params.length > 1) { | ||
var acq = +params[1]; | ||
this.automaticSession.acquisitionDate = +new Date(acq); | ||
this.automaticSession.acquisitionDate = this.automaticSession.acquisitionDate > 0 ? this.automaticSession.acquisitionDate : 0; | ||
} | ||
if (params.length > 2) { | ||
var renewal = +params[2]; | ||
this.automaticSession.renewalDate = +new Date(renewal); | ||
this.automaticSession.renewalDate = this.automaticSession.renewalDate > 0 ? this.automaticSession.renewalDate : 0; | ||
} | ||
} catch (e) { | ||
if (params.length > 2) { | ||
var renewal = +params[2]; | ||
this.automaticSession.renewalDate = +new Date(renewal); | ||
this.automaticSession.renewalDate = this.automaticSession.renewalDate > 0 ? this.automaticSession.renewalDate : 0; | ||
} | ||
} catch (e) { | ||
_InternalLogging.throwInternalNonUserActionable(LoggingSeverity.CRITICAL, "Error parsing ai_session cookie, session will be reset: " + Util.dump(e)); | ||
} | ||
} | ||
if (this.automaticSession.renewalDate == 0) { | ||
if (this.automaticSession.renewalDate == 0) { | ||
_InternalLogging.throwInternalNonUserActionable(LoggingSeverity.WARNING, "AI session renewal date is 0, session will be reset."); | ||
@@ -166,3 +166,3 @@ } | ||
this.automaticSession.id = Util.newGuid(); | ||
this.automaticSession.id = Util.newId(); | ||
this.automaticSession.acquisitionDate = now; | ||
@@ -196,3 +196,3 @@ this.automaticSession.renewalDate = now; | ||
} | ||
Util.setCookie('ai_session', cookie.join('|') + ';expires=' + cookieExpiry.toUTCString()); | ||
@@ -199,0 +199,0 @@ } |
@@ -93,3 +93,3 @@ /// <reference path="../util.ts" /> | ||
if (!this.id) { | ||
this.id = Util.newGuid(); | ||
this.id = Util.newId(); | ||
var date = new Date(); | ||
@@ -96,0 +96,0 @@ var acqStr = Util.toISOStringForIE8(date); |
@@ -10,2 +10,3 @@ // THIS TYPE WAS AUTOGENERATED | ||
public applicationTypeId: string; | ||
public applicationId: string; | ||
public deviceId: string; | ||
@@ -34,2 +35,3 @@ public deviceIp: string; | ||
public operationIsSynthetic: string; | ||
public operationCorrelationVector: string; | ||
public sessionId: string; | ||
@@ -47,2 +49,9 @@ public sessionIsFirst: string; | ||
public sampleRate: string; | ||
public cloudName: string; | ||
public cloudRoleVer: string; | ||
public cloudEnvironment: string; | ||
public cloudLocation: string; | ||
public cloudDeploymentUnit: string; | ||
public serverDeviceOS: string; | ||
public serverDeviceOSVer: string; | ||
public internalSdkVersion: string; | ||
@@ -63,2 +72,3 @@ public internalAgentVersion: string; | ||
public internalTrackingType: string; | ||
public internalIsDiagnosticExample: string; | ||
@@ -70,2 +80,3 @@ constructor() | ||
this.applicationTypeId = "ai.application.typeId"; | ||
this.applicationId = "ai.application.applicationId"; | ||
this.deviceId = "ai.device.id"; | ||
@@ -94,2 +105,3 @@ this.deviceIp = "ai.device.ip"; | ||
this.operationIsSynthetic = "ai.operation.isSynthetic"; | ||
this.operationCorrelationVector = "ai.operation.correlationVector"; | ||
this.sessionId = "ai.session.id"; | ||
@@ -107,2 +119,9 @@ this.sessionIsFirst = "ai.session.isFirst"; | ||
this.sampleRate = "ai.sample.sampleRate"; | ||
this.cloudName = "ai.cloud.name"; | ||
this.cloudRoleVer = "ai.cloud.roleVer"; | ||
this.cloudEnvironment = "ai.cloud.environment"; | ||
this.cloudLocation = "ai.cloud.location"; | ||
this.cloudDeploymentUnit = "ai.cloud.deploymentUnit"; | ||
this.serverDeviceOS = "ai.serverDevice.os"; | ||
this.serverDeviceOSVer = "ai.serverDevice.osVer"; | ||
this.internalSdkVersion = "ai.internal.sdkVersion"; | ||
@@ -123,4 +142,5 @@ this.internalAgentVersion = "ai.internal.agentVersion"; | ||
this.internalTrackingType = "ai.internal.trackingType"; | ||
this.internalIsDiagnosticExample = "ai.internal.isDiagnosticExample"; | ||
} | ||
} | ||
} |
@@ -13,2 +13,4 @@ // THIS TYPE WAS AUTOGENERATED | ||
public name: string; | ||
public id: string; | ||
public resultCode: string; | ||
public kind: AI.DataPointType; | ||
@@ -31,6 +33,6 @@ public value: number; | ||
this.ver = 2; | ||
this.kind = AI.DataPointType.Measurement; | ||
this.kind = AI.DataPointType.Aggregation; | ||
this.dependencyKind = AI.DependencyKind.Other; | ||
this.success = true; | ||
this.dependencySource = AI.DependencySourceType.Undefined; | ||
this.dependencySource = AI.DependencySourceType.Apmc; | ||
this.properties = {}; | ||
@@ -37,0 +39,0 @@ |
/// <reference path="initialization.ts" /> | ||
function initializeAppInsights() { | ||
module Microsoft.ApplicationInsights { | ||
"use strict"; | ||
try { | ||
@@ -37,3 +39,1 @@ // only initialize if we are running in a browser that supports JSON serialization (ie7<, node.js, cordova) | ||
} | ||
initializeAppInsights(); |
@@ -111,7 +111,7 @@ /// <reference path="appinsights.ts" /> | ||
} | ||
public addHousekeepingBeforeUnload(appInsightsInstance: AppInsights): void { | ||
// Add callback to push events when the user navigates away | ||
if ('onbeforeunload' in window) { | ||
if ('onbeforeunload' in window) { | ||
var performHousekeeping = function () { | ||
@@ -130,3 +130,3 @@ // Adds the ability to flush all data before the page unloads. | ||
}; | ||
if (!Microsoft.ApplicationInsights.Util.addEventHandler('beforeunload', performHousekeeping)) { | ||
@@ -152,5 +152,5 @@ Microsoft.ApplicationInsights._InternalLogging.throwInternalNonUserActionable(Microsoft.ApplicationInsights.LoggingSeverity.CRITICAL, 'Could not add handler for beforeunload'); | ||
config.enableDebug = Util.stringToBoolOrDefault(config.enableDebug); | ||
config.autoCollectErrors = (config.autoCollectErrors !== undefined && config.autoCollectErrors !== null) ? | ||
Util.stringToBoolOrDefault(config.autoCollectErrors) : | ||
true; | ||
config.disableExceptionTracking = (config.disableExceptionTracking !== undefined && config.disableExceptionTracking !== null) ? | ||
Util.stringToBoolOrDefault(config.disableExceptionTracking) : | ||
false; | ||
config.disableTelemetry = Util.stringToBoolOrDefault(config.disableTelemetry); | ||
@@ -166,2 +166,8 @@ config.verboseLogging = Util.stringToBoolOrDefault(config.verboseLogging); | ||
config.disableAjaxTracking = (config.disableAjaxTracking !== undefined && config.disableAjaxTracking !== null) ? | ||
Util.stringToBoolOrDefault(config.disableAjaxTracking) : | ||
false; | ||
config.maxAjaxCallsPerView = !isNaN(config.maxAjaxCallsPerView) ? config.maxAjaxCallsPerView : 500; | ||
return config; | ||
@@ -168,0 +174,0 @@ } |
module Microsoft.ApplicationInsights { | ||
export enum LoggingSeverity { | ||
/** | ||
* Error will be sent as internal telemetry | ||
*/ | ||
CRITICAL = 0, | ||
/** | ||
* Error will NOT be sent as internal telemetry, and will only be shown in browser console | ||
*/ | ||
WARNING = 1 | ||
@@ -6,0 +13,0 @@ } |
@@ -5,4 +5,4 @@ c:\src\ApplicationInsights-JS\JavaScript\JavaScriptSDK\bin\JavaScriptSDK.dll.config | ||
c:\src\ApplicationInsights-JS\JavaScript\JavaScriptSDK\bin\AjaxMin.dll | ||
c:\src\ApplicationInsights-JS\JavaScript\JavaScriptSDK\obj\Debug\JavaScriptSDK.csprojResolveAssemblyReference.cache | ||
c:\src\ApplicationInsights-JS\JavaScript\JavaScriptSDK\obj\Debug\JavaScriptSDK.dll | ||
c:\src\ApplicationInsights-JS\JavaScript\JavaScriptSDK\obj\Debug\JavaScriptSDK.pdb | ||
C:\src\ApplicationInsights-JS\JavaScript\JavaScriptSDK\obj\Debug\JavaScriptSDK.csprojResolveAssemblyReference.cache |
@@ -13,3 +13,16 @@ /// <reference path="serializer.ts" /> | ||
/// <reference path="Context/User.ts"/> | ||
/// <reference path="ajax/ajax.ts"/> | ||
interface XDomainRequest extends XMLHttpRequestEventTarget { | ||
responseText: string; | ||
send(payload: string); | ||
open(method: string, url: string); | ||
}; | ||
declare var XDomainRequest: { | ||
prototype: XDomainRequest; | ||
new (): XDomainRequest; | ||
create(): XDomainRequest; | ||
}; | ||
module Microsoft.ApplicationInsights { | ||
@@ -185,2 +198,3 @@ "use strict"; | ||
var xhr = new XMLHttpRequest(); | ||
xhr[AjaxMonitor.DisabledPropertyName] = true; | ||
xhr.open("POST", this._config.endpointUrl(), isAsync); | ||
@@ -187,0 +201,0 @@ xhr.setRequestHeader("Content-type", "application/json"); |
@@ -7,2 +7,8 @@ /// <reference path="logging.ts" /> | ||
/** | ||
* Enum is used in aiDataContract to describe how fields are serialized. | ||
* For instance: (Fieldtype.Required | FieldType.Array) will mark the field as required and indicate it's an array | ||
*/ | ||
export enum FieldType { Default = 0, Required = 1, Array = 2, Hidden = 4 }; | ||
export interface ISerializable { | ||
@@ -69,4 +75,8 @@ /** | ||
for (var field in source.aiDataContract) { | ||
var isRequired = source.aiDataContract[field]; | ||
var isArray = typeof isRequired !== "boolean"; | ||
var contract = source.aiDataContract[field]; | ||
var isRequired = (typeof contract === "function") ? (contract() & FieldType.Required) : (contract & FieldType.Required); | ||
var isHidden = (typeof contract === "function") ? (contract() & FieldType.Hidden) : (contract & FieldType.Hidden); | ||
var isArray = contract & FieldType.Array; | ||
var isPresent = source[field] !== undefined; | ||
@@ -84,2 +94,7 @@ var isObject = typeof source[field] === "object" && source[field] !== null; | ||
if (isHidden) { | ||
// Don't serialize hidden fields | ||
continue; | ||
} | ||
var value; | ||
@@ -86,0 +101,0 @@ if (isObject) { |
var appInsights = window.appInsights || (function(aiConfig) { | ||
var appInsights = { | ||
@@ -33,3 +32,3 @@ config: aiConfig | ||
var method = ["Event", "Exception", "Metric", "PageView", "Trace"]; | ||
var method = ["Event", "Exception", "Metric", "PageView", "Trace", "Ajax"]; | ||
while (method.length) { | ||
@@ -36,0 +35,0 @@ createLazyMethod("track" + method.pop()); |
@@ -11,4 +11,4 @@ /// <reference path="../../Contracts/Generated/Data.ts"/> | ||
public aiDataContract = { | ||
baseType: true, | ||
baseData: true | ||
baseType: FieldType.Required, | ||
baseData: FieldType.Required | ||
} | ||
@@ -15,0 +15,0 @@ |
@@ -11,11 +11,11 @@ /// <reference path="../../Contracts/Generated/DataPoint.ts"/> | ||
public aiDataContract = { | ||
name: true, | ||
kind: false, | ||
value: true, | ||
count: false, | ||
min: false, | ||
max: false, | ||
stdDev: false | ||
name: FieldType.Required, | ||
kind: FieldType.Default, | ||
value: FieldType.Required, | ||
count: FieldType.Default, | ||
min: FieldType.Default, | ||
max: FieldType.Default, | ||
stdDev: FieldType.Default | ||
} | ||
} | ||
} |
@@ -80,3 +80,3 @@ /// <reference path="../../logging.ts" /> | ||
if (value.toString().length > DataSanitizer.MAX_STRING_LENGTH) { | ||
value = value.substring(0, DataSanitizer.MAX_STRING_LENGTH); | ||
value = value.toString().substring(0, DataSanitizer.MAX_STRING_LENGTH); | ||
_InternalLogging.throwInternalUserActionable( | ||
@@ -83,0 +83,0 @@ LoggingSeverity.WARNING, |
@@ -23,9 +23,12 @@ /// <reference path="../../Contracts/Generated/Envelope.ts" /> | ||
this.time = Util.toISOStringForIE8(new Date()); | ||
this.aiDataContract = { | ||
time: true, | ||
iKey: true, | ||
name: true, | ||
tags: true, | ||
data: true | ||
time: FieldType.Required, | ||
iKey: FieldType.Required, | ||
name: FieldType.Required, | ||
sampleRate: () => { | ||
return (this.sampleRate == 100) ? FieldType.Hidden : FieldType.Required; | ||
}, | ||
tags: FieldType.Required, | ||
data: FieldType.Required, | ||
}; | ||
@@ -32,0 +35,0 @@ } |
@@ -13,6 +13,6 @@ /// <reference path="../Contracts/Generated/EventData.ts" /> | ||
public aiDataContract = { | ||
ver: true, | ||
name: true, | ||
properties: false, | ||
measurements: false, | ||
ver: FieldType.Required, | ||
name: FieldType.Required, | ||
properties: FieldType.Default, | ||
measurements: FieldType.Default, | ||
} | ||
@@ -19,0 +19,0 @@ |
@@ -15,8 +15,8 @@ /// <reference path="../Contracts/Generated/ExceptionData.ts" /> | ||
public aiDataContract = { | ||
ver: true, | ||
handledAt: true, | ||
exceptions: true, | ||
severityLevel: false, | ||
properties: false, | ||
measurements: false | ||
ver: FieldType.Required, | ||
handledAt: FieldType.Required, | ||
exceptions: FieldType.Required, | ||
severityLevel: FieldType.Default, | ||
properties: FieldType.Default, | ||
measurements: FieldType.Default, | ||
} | ||
@@ -44,26 +44,22 @@ | ||
// We can't override constructors, so throwing a fake error to use existing constructor and override all fields after that. | ||
var exceptionTelemetry; | ||
try { | ||
throw new Error(); | ||
} catch (e) { | ||
exceptionTelemetry = new Telemetry.Exception(e); | ||
} | ||
var stack = exceptionTelemetry.exceptions[0].parsedStack[0]; | ||
stack.assembly = assembly; | ||
stack.fileName = fileName; | ||
stack.level = 0; | ||
stack.line = line; | ||
stack.method = "unknown"; | ||
var exception = exceptionTelemetry.exceptions[0]; | ||
exception.hasFullStack = true; | ||
exception.message = message; | ||
exception.parsedStack = null; | ||
exception.stack = details; | ||
exception.typeName = typeName; | ||
exceptionTelemetry.handledAt = handledAt || "unhandled"; | ||
return exceptionTelemetry; | ||
return <Telemetry.Exception> { | ||
handledAt: handledAt || "unhandled", | ||
exceptions: [ | ||
<AI.ExceptionDetails> { | ||
hasFullStack: true, | ||
message: message, | ||
stack: details, | ||
typeName: typeName, | ||
parsedStack: [ | ||
<AI.StackFrame> { | ||
level: 0, | ||
assembly: assembly, | ||
fileName: fileName, | ||
line: line, | ||
method: "unknown" | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
} | ||
@@ -75,9 +71,9 @@ } | ||
public aiDataContract = { | ||
id: false, | ||
outerId: false, | ||
typeName: true, | ||
message: true, | ||
hasFullStack: false, | ||
stack: false, | ||
parsedStack: [] | ||
id: FieldType.Default, | ||
outerId: FieldType.Default, | ||
typeName: FieldType.Required, | ||
message: FieldType.Required, | ||
hasFullStack: FieldType.Default, | ||
stack: FieldType.Default, | ||
parsedStack: FieldType.Array, | ||
}; | ||
@@ -159,7 +155,7 @@ | ||
public aiDataContract = { | ||
level: true, | ||
method: true, | ||
assembly: false, | ||
fileName: false, | ||
line: false | ||
level: FieldType.Required, | ||
method: FieldType.Required, | ||
assembly: FieldType.Default, | ||
fileName: FieldType.Default, | ||
line: FieldType.Default, | ||
}; | ||
@@ -166,0 +162,0 @@ |
@@ -14,5 +14,5 @@ /// <reference path="../Contracts/Generated/MetricData.ts" /> | ||
public aiDataContract = { | ||
ver: true, | ||
metrics: true, | ||
properties: false | ||
ver: FieldType.Required, | ||
metrics: FieldType.Required, | ||
properties: FieldType.Default, | ||
} | ||
@@ -19,0 +19,0 @@ |
@@ -13,8 +13,8 @@ /// <reference path="../Contracts/Generated/PageViewData.ts" /> | ||
public aiDataContract = { | ||
ver: true, | ||
name: false, | ||
url: false, | ||
duration: false, | ||
properties: false, | ||
measurements: false | ||
ver: FieldType.Required, | ||
name: FieldType.Default, | ||
url: FieldType.Default, | ||
duration: FieldType.Default, | ||
properties: FieldType.Default, | ||
measurements: FieldType.Default, | ||
} | ||
@@ -21,0 +21,0 @@ |
@@ -14,13 +14,13 @@ /// <reference path="../Contracts/Generated/PageViewPerfData.ts"/> | ||
public aiDataContract = { | ||
ver: true, | ||
name: false, | ||
url: false, | ||
duration: false, | ||
perfTotal: false, | ||
networkConnect: false, | ||
sentRequest: false, | ||
receivedResponse: false, | ||
domProcessing: false, | ||
properties: false, | ||
measurements: false | ||
ver: FieldType.Required, | ||
name: FieldType.Default, | ||
url: FieldType.Default, | ||
duration: FieldType.Default, | ||
perfTotal: FieldType.Default, | ||
networkConnect: FieldType.Default, | ||
sentRequest: FieldType.Default, | ||
receivedResponse: FieldType.Default, | ||
domProcessing: FieldType.Default, | ||
properties: FieldType.Default, | ||
measurements: FieldType.Default | ||
}; | ||
@@ -31,8 +31,24 @@ | ||
*/ | ||
public isValid: boolean; | ||
private isValid: boolean; | ||
/** | ||
* Indicates whether this instance of PageViewPerformance is valid and should be sent | ||
*/ | ||
public getIsValid() { | ||
return this.isValid; | ||
} | ||
private durationMs: number; | ||
/** | ||
* Gets the total duration (PLT) in milliseconds. Check getIsValid() before using this method. | ||
*/ | ||
public getDurationMs() { | ||
return this.durationMs; | ||
} | ||
/** | ||
* Constructs a new instance of the PageEventTelemetry object | ||
*/ | ||
constructor(name: string, url: string, durationMs: number, properties?: any, measurements?: any) { | ||
constructor(name: string, url: string, unused: number, properties?: any, measurements?: any) { | ||
super(); | ||
@@ -62,3 +78,2 @@ | ||
if (total == 0) { | ||
@@ -72,14 +87,11 @@ _InternalLogging.throwInternalNonUserActionable( | ||
// some browsers may report individual components incorrectly so that the sum of the parts will be bigger than total PLT | ||
// in this case, don't report client performance from this page | ||
// in this case, don't report client performance from this page | ||
_InternalLogging.throwInternalNonUserActionable( | ||
LoggingSeverity.WARNING, | ||
"client performance math error:" + total + " < " + network + " + " + request + " + " + response + " + " + dom); | ||
} else { | ||
this.durationMs = total; | ||
// use timing data for duration if possible | ||
durationMs = total; | ||
// convert to timespans | ||
this.perfTotal = Util.msToTimeSpan(total); | ||
this.perfTotal = this.duration = Util.msToTimeSpan(total); | ||
this.networkConnect = Util.msToTimeSpan(network); | ||
@@ -93,12 +105,8 @@ this.sentRequest = Util.msToTimeSpan(request); | ||
} | ||
this.url = Common.DataSanitizer.sanitizeUrl(url); | ||
this.name = Common.DataSanitizer.sanitizeString(name || Util.NotSpecified); | ||
if (!isNaN(durationMs)) { | ||
this.duration = Util.msToTimeSpan(durationMs); | ||
} | ||
this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties); | ||
this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements); | ||
} | ||
@@ -125,3 +133,3 @@ | ||
*/ | ||
public static isPerformanceTimingDataReady() { | ||
public static isPerformanceTimingDataReady() { | ||
var timing = window.performance.timing; | ||
@@ -128,0 +136,0 @@ |
@@ -14,4 +14,4 @@ /// <reference path="../Contracts/Generated/SessionStateData.ts" /> | ||
public aiDataContract = { | ||
ver: true, | ||
state: true | ||
ver: FieldType.Required, | ||
state: FieldType.Required, | ||
} | ||
@@ -18,0 +18,0 @@ |
@@ -13,7 +13,7 @@ /// <reference path="../Contracts/Generated/MessageData.ts" /> | ||
public aiDataContract = { | ||
ver: true, | ||
message: true, | ||
severityLevel: false, | ||
measurements: false, | ||
properties: false | ||
ver: FieldType.Required, | ||
message: FieldType.Required, | ||
severityLevel: FieldType.Default, | ||
measurements: FieldType.Default, | ||
properties: FieldType.Default | ||
}; | ||
@@ -20,0 +20,0 @@ |
@@ -21,2 +21,4 @@ /// <reference path="sender.ts"/> | ||
sampleRate: () => number; | ||
appUserId: () => string; | ||
endpointUrl: () => string; | ||
} | ||
@@ -78,3 +80,3 @@ | ||
public _sessionManager: Microsoft.ApplicationInsights.Context._SessionManager; | ||
constructor(config: ITelemetryConfig) { | ||
@@ -119,3 +121,3 @@ this._config = config; | ||
} | ||
if (this.session) { | ||
@@ -194,3 +196,3 @@ // If customer did not provide custom session id update sessionmanager | ||
tc._track(sessionStateEnvelope); | ||
tc._track(sessionStateEnvelope); | ||
} | ||
@@ -295,6 +297,5 @@ | ||
if (sampleContext) { | ||
var tagKeys: AI.ContextTagKeys = new AI.ContextTagKeys(); | ||
envelope.tags[tagKeys.sampleRate] = sampleContext.sampleRate; | ||
} | ||
envelope.sampleRate = sampleContext.sampleRate; | ||
} | ||
} | ||
@@ -316,5 +317,2 @@ private _applySessionContext(envelope: Microsoft.Telemetry.Envelope, sessionContext: Microsoft.ApplicationInsights.Context.Session) { | ||
var tagKeys: AI.ContextTagKeys = new AI.ContextTagKeys(); | ||
if (typeof userContext.accountAcquisitionDate === "string") { | ||
envelope.tags[tagKeys.userAccountAcquisitionDate] = userContext.accountAcquisitionDate; | ||
} | ||
if (typeof userContext.accountId === "string") { | ||
@@ -321,0 +319,0 @@ envelope.tags[tagKeys.userAccountId] = userContext.accountId; |
@@ -18,3 +18,3 @@ /// <reference path="./logging.ts" /> | ||
return null; | ||
} | ||
} | ||
} catch (e) { | ||
@@ -41,3 +41,3 @@ _InternalLogging.warnToConsole('Failed to get client localStorage: ' + e.message); | ||
*/ | ||
public static getStorage(name:string):string { | ||
public static getStorage(name: string): string { | ||
var storage = Util._getStorageObject(); | ||
@@ -61,3 +61,3 @@ if (storage !== null) { | ||
*/ | ||
public static setStorage(name:string, data:string):boolean { | ||
public static setStorage(name: string, data: string): boolean { | ||
var storage = Util._getStorageObject(); | ||
@@ -81,3 +81,3 @@ if (storage !== null) { | ||
*/ | ||
public static removeStorage(name: string):boolean { | ||
public static removeStorage(name: string): boolean { | ||
var storage = Util._getStorageObject(); | ||
@@ -234,15 +234,14 @@ if (storage !== null) { | ||
*/ | ||
public static newGuid() { | ||
var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]; | ||
public static newId(): string { | ||
var base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
// c.f. rfc4122 (UUID version 4 = xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx) | ||
var oct = "", tmp; | ||
for (var a = 0; a < 4; a++) { | ||
tmp = (4294967296 * Math.random()) | 0; | ||
oct += hexValues[tmp & 0xF] + hexValues[tmp >> 4 & 0xF] + hexValues[tmp >> 8 & 0xF] + hexValues[tmp >> 12 & 0xF] + hexValues[tmp >> 16 & 0xF] + hexValues[tmp >> 20 & 0xF] + hexValues[tmp >> 24 & 0xF] + hexValues[tmp >> 28 & 0xF]; | ||
var result = ""; | ||
var random = Math.random() * 1073741824; //5 symbols in base64, almost maxint | ||
while (random > 0) { | ||
var char = base64chars.charAt(random % 64); | ||
result += char; | ||
random = Math.floor(random / 64); | ||
} | ||
// "Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively" | ||
var clockSequenceHi = hexValues[8 + (Math.random() * 4) | 0]; | ||
return oct.substr(0, 8) + "-" + oct.substr(9, 4) + "-4" + oct.substr(13, 3) + "-" + clockSequenceHi + oct.substr(16, 3) + "-" + oct.substr(19, 12); | ||
return result; | ||
} | ||
@@ -326,7 +325,3 @@ | ||
public static isCrossOriginError(message: string, url: string, lineNumber: number, columnNumber: number, error: Error): boolean { | ||
return (message == "Script error." || message == "Script error") | ||
&& url == "" | ||
&& lineNumber == 0 | ||
&& columnNumber == 0 | ||
&& error == null; | ||
return (message === "Script error." || message === "Script error") && error === null; | ||
} | ||
@@ -364,11 +359,46 @@ | ||
window.addEventListener(eventName, callback, false); | ||
} else if (window.attachEvent) { // For older browsers | ||
window.attachEvent(verbEventName, callback); | ||
} else if (window["attachEvent"]) { // For older browsers | ||
window["attachEvent"].call(verbEventName, callback); | ||
} else { // if all else fails | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
export class UrlHelper { | ||
private static document: any = typeof document !== "undefined" ? document : {}; | ||
private static htmlAnchorElement: HTMLAnchorElement; | ||
public static parseUrl(url): HTMLAnchorElement { | ||
if (!UrlHelper.htmlAnchorElement) { | ||
UrlHelper.htmlAnchorElement = UrlHelper.document.createElement('a'); | ||
} | ||
UrlHelper.htmlAnchorElement.href = url; | ||
return UrlHelper.htmlAnchorElement; | ||
} | ||
public static getAbsoluteUrl(url): string { | ||
var result: string; | ||
var a = UrlHelper.parseUrl(url); | ||
if (a) { | ||
result = a.href; | ||
} | ||
return result; | ||
} | ||
public static getPathName(url): string { | ||
var result: string; | ||
var a = UrlHelper.parseUrl(url); | ||
if (a) { | ||
result = a.pathname; | ||
} | ||
return result; | ||
} | ||
} | ||
} |
{ | ||
"name": "applicationinsights-js", | ||
"version": "0.18.0", | ||
"version": "0.21.5", | ||
"description": "[Application Insights](https://azure.microsoft.com/services/application-insights/) tells you about your app's performance and usage. By adding a few lines of code to your web pages, you get data about how many users you have, which pages are most popular, how fast pages load, whether they throw exceptions, and more. And you can add code to track more detailed user activity.", | ||
@@ -5,0 +5,0 @@ "main": "dist/ai.0.js", |
@@ -49,1 +49,5 @@ # Microsoft Application Insights JavaScript SDK | ||
We strongly welcome and encourage contributions to this project. Please read the [contributor's guide][ContribGuide] located in the ApplicationInsights-Home repository. If making a large change we request that you open an [issue][GitHubIssue] first. We follow the [Git Flow][GitFlow] approach to branching. | ||
[ContribGuide]: https://github.com/Microsoft/ApplicationInsights-Home/blob/master/CONTRIBUTING.md | ||
[GitFlow]: http://nvie.com/posts/a-successful-git-branching-model/ | ||
[GitHubIssue]: https://github.com/Microsoft/ApplicationInsights-JS/issues |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
12949664
206
34307
53
2