Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 6f53b2d

Browse files
authored
Merge pull request #663 from matrix-org/rav/fix_tests
Make tests pass on Chrome again
2 parents be869a8 + cd1cf09 commit 6f53b2d

File tree

6 files changed

+56
-21
lines changed

6 files changed

+56
-21
lines changed

karma.conf.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ module.exports = function (config) {
165165
},
166166
devtool: 'inline-source-map',
167167
},
168+
169+
webpackMiddleware: {
170+
stats: {
171+
// don't fill the console up with a mahoosive list of modules
172+
chunks: false,
173+
},
174+
},
175+
168176
browserNoActivityTimeout: 15000,
169177
});
170178
};

src/components/structures/ScrollPanel.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ module.exports = React.createClass({
570570
var boundingRect = node.getBoundingClientRect();
571571
var scrollDelta = boundingRect.bottom + pixelOffset - wrapperRect.bottom;
572572

573-
debuglog("Scrolling to token '" + node.dataset.scrollToken + "'+" +
573+
debuglog("ScrollPanel: scrolling to token '" + node.dataset.scrollToken + "'+" +
574574
pixelOffset + " (delta: "+scrollDelta+")");
575575

576576
if(scrollDelta != 0) {
@@ -582,7 +582,7 @@ module.exports = React.createClass({
582582
_saveScrollState: function() {
583583
if (this.props.stickyBottom && this.isAtBottom()) {
584584
this.scrollState = { stuckAtBottom: true };
585-
debuglog("Saved scroll state", this.scrollState);
585+
debuglog("ScrollPanel: Saved scroll state", this.scrollState);
586586
return;
587587
}
588588

@@ -601,12 +601,12 @@ module.exports = React.createClass({
601601
trackedScrollToken: node.dataset.scrollToken,
602602
pixelOffset: wrapperRect.bottom - boundingRect.bottom,
603603
};
604-
debuglog("Saved scroll state", this.scrollState);
604+
debuglog("ScrollPanel: saved scroll state", this.scrollState);
605605
return;
606606
}
607607
}
608608

609-
debuglog("Unable to save scroll state: found no children in the viewport");
609+
debuglog("ScrollPanel: unable to save scroll state: found no children in the viewport");
610610
},
611611

612612
_restoreSavedScrollState: function() {
@@ -640,7 +640,7 @@ module.exports = React.createClass({
640640
this._lastSetScroll = scrollNode.scrollTop;
641641
}
642642

643-
debuglog("Set scrollTop:", scrollNode.scrollTop,
643+
debuglog("ScrollPanel: set scrollTop:", scrollNode.scrollTop,
644644
"requested:", scrollTop,
645645
"_lastSetScroll:", this._lastSetScroll);
646646
},

test/components/structures/RoomView-test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,12 @@ describe('RoomView', function () {
4242
it('resolves a room alias to a room id', function (done) {
4343
peg.get().getRoomIdForAlias.returns(q({room_id: "!randomcharacters:aser.ver"}));
4444

45-
var onRoomIdResolved = sinon.spy();
45+
function onRoomIdResolved(room_id) {
46+
expect(room_id).toEqual("!randomcharacters:aser.ver");
47+
done();
48+
}
4649

4750
ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" onRoomIdResolved={onRoomIdResolved} />, parentDiv);
48-
49-
process.nextTick(function() {
50-
// These expect()s don't read very well and don't give very good failure
51-
// messages, but expect's toHaveBeenCalled only takes an expect spy object,
52-
// not a sinon spy object.
53-
expect(onRoomIdResolved.called).toExist();
54-
done();
55-
});
5651
});
5752

5853
it('joins by alias if given an alias', function (done) {

test/components/structures/ScrollPanel-test.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ var Tester = React.createClass({
7373

7474
/* returns a promise which will resolve when the fill happens */
7575
awaitFill: function(dir) {
76+
console.log("ScrollPanel Tester: awaiting " + dir + " fill");
7677
var defer = q.defer();
7778
this._fillDefers[dir] = defer;
7879
return defer.promise;
7980
},
8081

8182
_onScroll: function(ev) {
8283
var st = ev.target.scrollTop;
83-
console.log("Scroll event; scrollTop: " + st);
84+
console.log("ScrollPanel Tester: scroll event; scrollTop: " + st);
8485
this.lastScrollEvent = st;
8586

8687
var d = this._scrollDefer;
@@ -159,10 +160,29 @@ describe('ScrollPanel', function() {
159160
scrollingDiv = ReactTestUtils.findRenderedDOMComponentWithClass(
160161
tester, "gm-scroll-view");
161162

162-
// wait for a browser tick to let the initial paginates complete
163-
setTimeout(function() {
164-
done();
165-
}, 0);
163+
// we need to make sure we don't call done() until q has finished
164+
// running the completion handlers from the fill requests. We can't
165+
// just use .done(), because that will end up ahead of those handlers
166+
// in the queue. We can't use window.setTimeout(0), because that also might
167+
// run ahead of those handlers.
168+
const sp = tester.scrollPanel();
169+
let retriesRemaining = 1;
170+
const awaitReady = function() {
171+
return q().then(() => {
172+
if (sp._pendingFillRequests.b === false &&
173+
sp._pendingFillRequests.f === false
174+
) {
175+
return;
176+
}
177+
178+
if (retriesRemaining == 0) {
179+
throw new Error("fillRequests did not complete");
180+
}
181+
retriesRemaining--;
182+
return awaitReady();
183+
});
184+
};
185+
awaitReady().done(done);
166186
});
167187

168188
afterEach(function() {

test/components/structures/TimelinePanel-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ describe('TimelinePanel', function() {
9999
// the document so that we can interact with it properly.
100100
parentDiv = document.createElement('div');
101101
parentDiv.style.width = '800px';
102-
parentDiv.style.height = '600px';
102+
103+
// This has to be slightly carefully chosen. We expect to have to do
104+
// exactly one pagination to fill it.
105+
parentDiv.style.height = '500px';
106+
103107
parentDiv.style.overflow = 'hidden';
104108
document.body.appendChild(parentDiv);
105109
});
@@ -235,7 +239,7 @@ describe('TimelinePanel', function() {
235239
expect(client.paginateEventTimeline.callCount).toEqual(0);
236240
done();
237241
}, 0);
238-
}, 0);
242+
}, 10);
239243
});
240244

241245
it("should let you scroll down to the bottom after you've scrolled up", function(done) {

test/test-utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ var MatrixEvent = jssdk.MatrixEvent;
1414
*/
1515
export function beforeEach(context) {
1616
var desc = context.currentTest.fullTitle();
17+
1718
console.log();
19+
20+
// this puts a mark in the chrome devtools timeline, which can help
21+
// figure out what's been going on.
22+
if (console.timeStamp) {
23+
console.timeStamp(desc);
24+
}
25+
1826
console.log(desc);
1927
console.log(new Array(1 + desc.length).join("="));
2028
};

0 commit comments

Comments
 (0)