Merge pull request #3966 from vector-im/rav/more_deflakification

More riot-web test deflakification
pull/3967/head
Richard van der Hoff 2017-05-19 13:51:51 +01:00 committed by GitHub
commit 0a920df05d
1 changed files with 34 additions and 18 deletions

View File

@ -115,9 +115,9 @@ describe('loading:', function () {
} }
function routeUrl(location, matrixChat) { function routeUrl(location, matrixChat) {
console.log(Date.now() + "Routing URL " + location); console.log(Date.now() + ` routing URL '${location}'`);
const s = getScreenFromLocation(location); const s = getScreenFromLocation(location);
console.log("Showing screen", s); console.log("Showing screen "+ s);
matrixChat.showScreen(s.screen, s.params); matrixChat.showScreen(s.screen, s.params);
} }
@ -136,6 +136,7 @@ describe('loading:', function () {
enableGuest={true} enableGuest={true}
onLoadCompleted={loadCompleteDefer.resolve} onLoadCompleted={loadCompleteDefer.resolve}
initialScreenAfterLogin={getScreenFromLocation(windowLocation)} initialScreenAfterLogin={getScreenFromLocation(windowLocation)}
makeRegistrationUrl={() => {throw new Error('Not implemented');}}
/>, parentDiv />, parentDiv
); );
@ -151,6 +152,27 @@ describe('loading:', function () {
}, 0); }, 0);
} }
// set an expectation that we will get a call to /sync, then flush
// http requests until we do.
//
// returns a promise resolving to the received request
async function expectAndAwaitSync(response) {
response = response || {};
let syncRequest = null;
httpBackend.when('GET', '/sync')
.check((r) => {syncRequest = r;})
.respond(200, response);
console.log("waiting for /sync");
for (let attempts = 10; attempts > 0; attempts--) {
if (syncRequest) {
return syncRequest;
}
await httpBackend.flush();
}
throw new Error("Gave up waiting for /sync");
}
describe("Clean load with no stored credentials:", function() { describe("Clean load with no stored credentials:", function() {
it('gives a login panel by default', function (done) { it('gives a login panel by default', function (done) {
loadApp(); loadApp();
@ -221,8 +243,7 @@ describe('loading:', function () {
httpBackend.when('GET', '/pushrules').respond(200, {}); httpBackend.when('GET', '/pushrules').respond(200, {});
httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' }); httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' });
httpBackend.when('GET', '/sync').respond(200, {}); return expectAndAwaitSync();
return httpBackend.flush();
}).then(() => { }).then(() => {
// once the sync completes, we should have a room view // once the sync completes, we should have a room view
return awaitRoomView(matrixChat); return awaitRoomView(matrixChat);
@ -250,13 +271,12 @@ describe('loading:', function () {
it('shows a directory by default if we have no joined rooms', function(done) { it('shows a directory by default if we have no joined rooms', function(done) {
httpBackend.when('GET', '/pushrules').respond(200, {}); httpBackend.when('GET', '/pushrules').respond(200, {});
httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' }); httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' });
httpBackend.when('GET', '/sync').respond(200, {});
loadApp(); loadApp();
return awaitSyncingSpinner(matrixChat).then(() => { return awaitSyncingSpinner(matrixChat).then(() => {
// we got a sync spinner - let the sync complete // we got a sync spinner - let the sync complete
return httpBackend.flush(); return expectAndAwaitSync();
}).then(() => { }).then(() => {
// once the sync completes, we should have a directory // once the sync completes, we should have a directory
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
@ -269,7 +289,6 @@ describe('loading:', function () {
it('shows a room view if we followed a room link', function(done) { it('shows a room view if we followed a room link', function(done) {
httpBackend.when('GET', '/pushrules').respond(200, {}); httpBackend.when('GET', '/pushrules').respond(200, {});
httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' }); httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' });
httpBackend.when('GET', '/sync').respond(200, {});
loadApp({ loadApp({
uriFragment: "#/room/!room:id", uriFragment: "#/room/!room:id",
@ -277,7 +296,7 @@ describe('loading:', function () {
return awaitSyncingSpinner(matrixChat).then(() => { return awaitSyncingSpinner(matrixChat).then(() => {
// we got a sync spinner - let the sync complete // we got a sync spinner - let the sync complete
return httpBackend.flush(); return expectAndAwaitSync();
}).then(() => { }).then(() => {
// once the sync completes, we should have a room view // once the sync completes, we should have a room view
return awaitRoomView(matrixChat); return awaitRoomView(matrixChat);
@ -310,8 +329,7 @@ describe('loading:', function () {
return awaitSyncingSpinner(matrixChat); return awaitSyncingSpinner(matrixChat);
}).then(() => { }).then(() => {
// we got a sync spinner - let the sync complete // we got a sync spinner - let the sync complete
httpBackend.when('GET', '/sync').respond(200, {}); return expectAndAwaitSync();
return httpBackend.flush();
}).then(() => { }).then(() => {
// once the sync completes, we should have a directory // once the sync completes, we should have a directory
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
@ -344,11 +362,10 @@ describe('loading:', function () {
}).then(() => { }).then(() => {
return awaitSyncingSpinner(matrixChat); return awaitSyncingSpinner(matrixChat);
}).then(() => { }).then(() => {
httpBackend.when('GET', '/sync').check(function(req) { return expectAndAwaitSync();
expect(req.path).toMatch(new RegExp("^https://homeserver/")); }).then((req) => {
}).respond(200, {}); expect(req.path).toMatch(new RegExp("^https://homeserver/"));
return httpBackend.flush();
}).then(() => {
// once the sync completes, we should have a directory // once the sync completes, we should have a directory
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
ReactTestUtils.findRenderedComponentWithType( ReactTestUtils.findRenderedComponentWithType(
@ -379,8 +396,7 @@ describe('loading:', function () {
}).then(() => { }).then(() => {
return awaitSyncingSpinner(matrixChat); return awaitSyncingSpinner(matrixChat);
}).then(() => { }).then(() => {
httpBackend.when('GET', '/sync').respond(200, {}); return expectAndAwaitSync();
return httpBackend.flush();
}).then(() => { }).then(() => {
// once the sync completes, we should have a room view // once the sync completes, we should have a room view
return awaitRoomView(matrixChat); return awaitRoomView(matrixChat);
@ -450,7 +466,7 @@ function awaitSyncingSpinner(matrixChat, retryLimit, retryCount) {
retryCount = 0; retryCount = 0;
} }
if (matrixChat.state.loading) { if (matrixChat.state.loading || matrixChat.state.loggingIn) {
console.log(Date.now() + " Awaiting sync spinner: still loading."); console.log(Date.now() + " Awaiting sync spinner: still loading.");
if (retryCount >= retryLimit) { if (retryCount >= retryLimit) {
throw new Error("MatrixChat still not loaded after " + throw new Error("MatrixChat still not loaded after " +