From 0f8a2554dc85dc54c56e551373ef580818f52b4d Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 13 Jul 2017 00:18:10 +0100 Subject: [PATCH 1/2] Enable colours for karma test output I don't really know why we disable colours here. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83d9bd16a8..3b4c16db9c 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "lintall": "eslint src/ test/", "clean": "rimraf lib webapp electron_app/dist", "prepublish": "npm run build:compile", - "test": "karma start --single-run=true --autoWatch=false --browsers ChromeHeadless --colors=false", + "test": "karma start --single-run=true --autoWatch=false --browsers ChromeHeadless", "test-multi": "karma start" }, "dependencies": { From b2403d59b79192900ab6becf7969c74805d0ed24 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 13 Jul 2017 00:18:49 +0100 Subject: [PATCH 2/2] loading tests: wait for login component Rather than a fixed delay, use matrix-react-test-utils to wait for the login component to appear. Hopefully this will deflakify some tests. --- package.json | 1 + test/app-tests/loading.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 3b4c16db9c..88c55bcd58 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,7 @@ "karma-mocha": "^0.2.2", "karma-webpack": "^1.7.0", "matrix-mock-request": "^1.0.0", + "matrix-react-test-utils": "^0.2.0", "minimist": "^1.2.0", "mkdirp": "^0.5.1", "mocha": "^2.4.5", diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index d01836a36a..445105ddf4 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -23,6 +23,7 @@ import ReactDOM from 'react-dom'; import ReactTestUtils from 'react-addons-test-utils'; import expect from 'expect'; import q from 'q'; +import MatrixReactTestUtils from 'matrix-react-test-utils'; import jssdk from 'matrix-js-sdk'; @@ -183,11 +184,8 @@ describe('loading:', function () { return httpBackend.flush(); }).then(() => { // Wait for another trip around the event loop for the UI to update - return q.delay(10); + return awaitLoginComponent(matrixChat); }).then(() => { - // we expect a single component following session load - ReactTestUtils.findRenderedComponentWithType( - matrixChat, sdk.getComponent('structures.login.Login')); expect(windowLocation.hash).toEqual("#/login"); }).done(done, done); }); @@ -232,7 +230,7 @@ describe('loading:', function () { uriFragment: "#/login", }); - return q.delay(100).then(() => { + return awaitLoginComponent(matrixChat).then(() => { // we expect a single component ReactTestUtils.findRenderedComponentWithType( matrixChat, sdk.getComponent('structures.login.Login')); @@ -366,7 +364,7 @@ describe('loading:', function () { }); // give the UI a chance to display - return q.delay(50); + return awaitLoginComponent(matrixChat); }); it('shows a login view', function() { @@ -530,7 +528,7 @@ describe('loading:', function () { dis.dispatch({ action: 'start_login' }); - return q.delay(1); + return awaitLoginComponent(matrixChat); }); }); @@ -607,7 +605,6 @@ describe('loading:', function () { }); }); - // check that we have a Login component, send a 'user:pass' login, // and await the HTTP requests. function completeLogin(matrixChat) { @@ -723,3 +720,9 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) { matrixChat, sdk.getComponent('structures.RoomView')); return q(); } + +function awaitLoginComponent(matrixChat, attempts) { + return MatrixReactTestUtils.waitForRenderedComponentWithType( + matrixChat, sdk.getComponent('structures.login.Login'), attempts, + ); +}