This commit is contained in:
Kamil Szostak 2017-07-19 10:53:26 -07:00
Родитель 7dd2f0b57d
Коммит ff2e71f449
8 изменённых файлов: 53 добавлений и 54 удалений

Просмотреть файл

@ -64,11 +64,6 @@ class UserContextTests extends TestClass {
Assert.equal(true, expiration.substr(0, "expires=".length) === "expires=", "ai_user cookie expiration part should start with expires=");
var expirationDate = new Date(expiration.substr("expires=".length));
Assert.equal(true, expirationDate > (new Date), "ai_user cookie expiration should be in the future");
// cleanup
}
});
@ -102,11 +97,6 @@ class UserContextTests extends TestClass {
Assert.equal(true, expiration.substr(0, "expires=".length) === "expires=", "ai_user cookie expiration part should start with expires=");
var expirationDate = new Date(expiration.substr("expires=".length));
Assert.equal(true, expirationDate > (new Date), "ai_user cookie expiration should be in the future");
// cleanup
}
});
@ -126,7 +116,6 @@ class UserContextTests extends TestClass {
// verify
Assert.equal(authId, user.authenticatedId, "user auth id was set from cookie");
Assert.equal(accountId, user.accountId, "user account id was not set from cookie");
}
});
@ -142,7 +131,6 @@ class UserContextTests extends TestClass {
// verify
Assert.equal(authId, user.authenticatedId, "user auth id was set from cookie");
}
});
@ -158,7 +146,6 @@ class UserContextTests extends TestClass {
// verify
Assert.equal(undefined, user.authenticatedId, "user auth id was not set");
Assert.equal(undefined, user.accountId, "user account id was not set");
}
});
@ -176,7 +163,6 @@ class UserContextTests extends TestClass {
// verify
Assert.equal(config.accountId(), user.accountId, "user account id was set from back compat");
}
});
@ -194,7 +180,6 @@ class UserContextTests extends TestClass {
// verify
Assert.equal(authAndAccountId[0], user.authenticatedId, "user auth id was set");
Assert.equal(cookieStub.calledWithExactly('ai_authUser', encodeURI(authAndAccountId.join('|')), null), true, "user auth id and account id cookie was set");
}
});
@ -212,7 +197,6 @@ class UserContextTests extends TestClass {
// verify
Assert.equal(authAndAccountId[0], user.authenticatedId, "user auth id was set");
Assert.equal(cookieStub.calledWithExactly('ai_authUser', encodeURI(authAndAccountId.join('|')), null), true, "user auth id cookie was set");
}
});
@ -231,7 +215,6 @@ class UserContextTests extends TestClass {
Assert.equal(authAndAccountId[0], user.authenticatedId, "user auth id was set");
Assert.equal(null, user.accountId, "user account id was not set");
Assert.equal(cookieStub.calledWithExactly('ai_authUser', encodeURI(authAndAccountId[0]), null), true, "user auth id cookie was set");
}
});
@ -243,6 +226,7 @@ class UserContextTests extends TestClass {
var user = new Microsoft.ApplicationInsights.Context.User(this.getEmptyConfig());
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternal");
cookieStub.reset();
loggingStub.reset();
// act
user.setAuthenticatedUserContext(null);
@ -252,8 +236,6 @@ class UserContextTests extends TestClass {
Assert.equal(undefined, user.accountId, "user account id was not set");
Assert.equal(cookieStub.notCalled, true, "cookie was not set");
Assert.equal(loggingStub.calledOnce, true, "Warning was logged");
}
});
@ -264,6 +246,8 @@ class UserContextTests extends TestClass {
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie");
var user = new Microsoft.ApplicationInsights.Context.User(this.getEmptyConfig());
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternal");
cookieStub.reset();
loggingStub.reset();
// act
user.setAuthenticatedUserContext(undefined, undefined);
@ -273,8 +257,6 @@ class UserContextTests extends TestClass {
Assert.equal(undefined, user.accountId, "user account id was not set");
Assert.equal(cookieStub.notCalled, true, "cookie was not set");
Assert.equal(loggingStub.calledOnce, true, "Warning was logged");
}
});
@ -285,6 +267,8 @@ class UserContextTests extends TestClass {
var cookieStub = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "setCookie");
var user = new Microsoft.ApplicationInsights.Context.User(this.getEmptyConfig());
var loggingStub = this.sandbox.stub(Microsoft.ApplicationInsights._InternalLogging, "throwInternal");
cookieStub.reset();
loggingStub.reset();
// act
user.setAuthenticatedUserContext(undefined, '1234');
@ -294,8 +278,6 @@ class UserContextTests extends TestClass {
Assert.equal(undefined, user.accountId, "user account id was not set");
Assert.equal(cookieStub.notCalled, true, "cookie was not set");
Assert.equal(loggingStub.calledOnce, true, "Warning was logged");
}
});
@ -316,8 +298,6 @@ class UserContextTests extends TestClass {
Assert.equal(undefined, user.accountId, "user account id was not set");
Assert.equal(cookieStub.notCalled, true, "cookie was not set");
Assert.equal(loggingStub.calledOnce, true, "Warning was logged");
}
});
@ -339,8 +319,6 @@ class UserContextTests extends TestClass {
Assert.equal(undefined, user.accountId, "user account id was not set");
Assert.equal(cookieStub.notCalled, true, "cookie was not set");
Assert.equal(loggingStub.calledOnce, true, "Warning was logged");
}
});
@ -361,8 +339,6 @@ class UserContextTests extends TestClass {
Assert.equal(authAndAccountId[1], user.accountId, "user account id was set");
Assert.equal(cookieStub.calledWithExactly('ai_authUser', encodeURI(authAndAccountId.join('|')), null), true, "user auth id cookie was set");
Assert.equal(loggingStub.notCalled, true, "No warnings");
}
});
@ -381,7 +357,6 @@ class UserContextTests extends TestClass {
Assert.equal(undefined, user.authenticatedId, "user auth id was cleared");
Assert.equal(undefined, user.accountId, "user account id was cleared");
Assert.equal(cookieStub.calledWithExactly('ai_authUser'), true, "cookie was deleted");
}
});
@ -399,7 +374,6 @@ class UserContextTests extends TestClass {
Assert.equal(undefined, user.authenticatedId, "user auth id was cleared");
Assert.equal(undefined, user.accountId, "user account id was cleared");
Assert.equal(cookieStub.calledWithExactly('ai_authUser'), true, "cookie was deleted");
}
});
}

Просмотреть файл

@ -1111,6 +1111,10 @@ class SenderTests extends TestClass {
this.testCase({
name: "SenderTests: send() is using BeaconAPI sender if the BeaconAPI is enabled",
test: () => {
if (!(<any>navigator).sendBeacon) {
(<any>navigator)['sendBeacon'] = (url: any, data: any) => {};
}
// enable beacon API and mock sender
var config = this.getDefaultConfig();
config.isBeaconApiDisabled = () => false;
@ -1134,6 +1138,10 @@ class SenderTests extends TestClass {
this.testCase({
name: "SenderTests: send() is not using BeaconAPI sender if the BeaconAPI is disabled",
test: () => {
if (!(<any>navigator).sendBeacon) {
(<any>navigator)['sendBeacon'] = (url: any, data: any) => {};
}
// enable beacon API and mock sender
var config = this.getDefaultConfig();
config.isBeaconApiDisabled = () => true;

Просмотреть файл

@ -154,7 +154,12 @@ class PageViewPerformanceTelemetryTests extends ContractTestHelper {
test: () => {
// mock user agent
let originalUserAgent = navigator.userAgent;
this.setUserAgent("Googlebot/2.1");
try {
this.setUserAgent("Googlebot/2.1");
} catch (ex) {
Assert.ok(true, 'cannot run this test in the current setup - try Chrome');
return;
}
var timing = <PerformanceTiming>{};
(<any>timing).navigationStart = 1;

Просмотреть файл

@ -667,7 +667,12 @@ class AppInsightsTests extends TestClass {
// mock user agent
let originalUserAgent = navigator.userAgent;
this.setUserAgent("Googlebot/2.1");
try {
this.setUserAgent("Googlebot/2.1");
} catch (ex) {
Assert.ok(true, 'cannot run this test in the current setup - try Chrome');
return;
}
// act
appInsights.trackPageView();
@ -856,9 +861,15 @@ class AppInsightsTests extends TestClass {
var appInsights = new Microsoft.ApplicationInsights.AppInsights(snippet);
Assert.equal(false, appInsights.context._config.isBeaconApiDisabled(), "Beacon API enabled");
Assert.equal(false, appInsights.context._config.enableSessionStorageBuffer(), "Session storage disabled");
Assert.equal(65536, appInsights.context._config.maxBatchSizeInBytes(), "Max batch size overriden by Beacon API payload limitation");
if (Microsoft.ApplicationInsights.Util.IsBeaconApiSupported()) {
Assert.equal(false, appInsights.context._config.isBeaconApiDisabled(), "Beacon API enabled");
Assert.equal(false, appInsights.context._config.enableSessionStorageBuffer(), "Session storage disabled");
Assert.equal(65536, appInsights.context._config.maxBatchSizeInBytes(), "Max batch size overriden by Beacon API payload limitation");
} else {
Assert.equal(false, appInsights.context._config.isBeaconApiDisabled(), "Beacon API enabled");
Assert.equal(true, appInsights.context._config.enableSessionStorageBuffer(), "Session storage disabled");
Assert.equal(1000000, appInsights.context._config.maxBatchSizeInBytes(), "Max batch size overriden by Beacon API payload limitation");
}
}
});
@ -866,7 +877,7 @@ class AppInsightsTests extends TestClass {
name: "AppInsights._onerror creates a dump of unexpected error thrown by trackException for logging",
test: () => {
var sut = new Microsoft.ApplicationInsights.AppInsights(this.getAppInsightsSnippet());
var dumpSpy = this.sandbox.spy(Microsoft.ApplicationInsights.Util, "dump")
var dumpSpy = this.sandbox.stub(Microsoft.ApplicationInsights.Util, "dump")
var unexpectedError = new Error();
var stub = this.sandbox.stub(sut, "trackException").throws(unexpectedError);

Просмотреть файл

@ -6,11 +6,7 @@
<meta http-equiv="Cache-control" content="no-Cache" />
<title>Tests for Application Insights JavaScript API</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-1.23.1.css">
<!--<script src="https://code.jquery.com/qunit/qunit-1.23.1.js"></script>-->
<script>
QUnit.config.autostart = false;
</script>
<script src="http://sinonjs.org/releases/sinon-1.17.2.js"></script>
<script src="http://sinonjs.org/releases/sinon-2.3.8.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.js"></script>
<script>
@ -27,8 +23,6 @@
QUnit.start();
}
);
QUnit.start();
</script>
</head>

Просмотреть файл

@ -0,0 +1,7 @@
page = require('webpage').create();
page.open('file:///E:/Dev/ApplicationInsights-JS/JavaScript/JavaScriptSDK.Tests/Selenium/Tests.html?hidepassed', function () {
debugger;
page.evaluateAsync(function () {
debugger; // wait here in the second web browser tab
});
});

Просмотреть файл

@ -99,14 +99,13 @@ See:
* `npm install`
* `grunt` or Ctrl+Shift+B in VisualStudio Code
* `grunt module` to build the npm module
* compiled files are dropped into a `/bundle` folder
* Run check-in tests
* `grunt test` to build tests
* run tests, phantomJS?
* `grunt test` to build and run tests
* You can also open `JavaScriptSDK.Tests/Selenium/Tests.html` directly in your browser to debug failing tests.
* `powershell "& .\scripts\RunTestsInBrowser.ps1"` to run `Tests.html` in a browser (you might need to call Set-ExecutionPolicy to be able to execute the script)
* Don't forget to build the solution after changing TypeScript files
* Refresh Tests.html in the browser to re-run tests
To debug tests in PhantomJS use a remote debugger: `phantomjs.exe --remote-debugger-port=9000 \JavaScript\JavaScriptSDK.Tests\phantomJS.debug.js`. If webkit console isn't working execute the following code in the browser's console: `function isEnterKey(event) { return (event.keyCode !== 229 && event.keyIdentifier === "Enter") || event.keyCode === 13; }`.
## Contributing

Просмотреть файл

@ -40,7 +40,7 @@ module.exports = function (grunt) {
src: [
'JavaScript/JavaScriptSDK.Tests/DefinitionTypes/*.ts'
],
out: 'bundle/DefinitionTypes/ai.types.js',
out: 'bundle/test/ai.types.js',
options: {
module: 'amd'
}
@ -70,8 +70,8 @@ module.exports = function (grunt) {
all: {
options: {
urls: [
'http://localhost:8000/JavaScript/JavaScriptSDK.Tests/Selenium/Tests.html',
// 'JavaScript/JavaScriptSDK.Tests/Selenium/Tests.html'
// 'http://localhost:8000/JavaScript/JavaScriptSDK.Tests/Selenium/Tests.html',
'JavaScript/JavaScriptSDK.Tests/Selenium/Tests.html'
],
timeout: 15 * 1000,
console: false,
@ -89,7 +89,8 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.registerTask("default", ["ts:default", "uglify"]);
grunt.registerTask("module", ["ts:module"]);
grunt.registerTask("test", ["ts:test", "ts:types", "connect", "qunit"]);
grunt.registerTask("test", ["ts:test", "ts:types", /*"connect"*/ "qunit"]);
};