tests: Speed up `helper.edit()` and `helper.clearPad()`

This commit is contained in:
Richard Hansen 2021-04-01 15:52:39 -04:00 committed by webzwo0i
parent 7a154b1e1d
commit 7cbb3f565d
3 changed files with 33 additions and 6 deletions

View File

@ -44,6 +44,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
let channelState = 'CONNECTING';
let lastCommitTime = 0;
let initialStartConnectTime = 0;
let commitDelay = 500;
const userId = initialUserInfo.userId;
// var socket;
@ -102,7 +103,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
return;
}
const earliestCommit = lastCommitTime + 500;
const earliestCommit = lastCommitTime + commitDelay;
if (now < earliestCommit) {
setTimeout(handleUserChanges, earliestCommit - now);
return;
@ -488,6 +489,8 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
setChannelState,
setStateIdle,
setIsPendingRevision,
set commitDelay(ms) { commitDelay = ms; },
get commitDelay() { return commitDelay; },
};
tellAceAboutHistoricalAuthors(serverVars.historicalAuthorData);

View File

@ -127,6 +127,8 @@ const helper = {};
$('#iframe-container').append($iframe);
await new Promise((resolve) => $iframe.one('load', resolve));
helper.padChrome$ = getFrameJQuery($('#iframe-container iframe'));
helper.padChrome$.padeditor =
helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_editor').padeditor;
if (opts.clearCookies) {
helper.clearPadPrefCookie();
}
@ -260,6 +262,22 @@ const helper = {};
selection.addRange(range);
};
// Temporarily reduces minimum time between commits and calls the provided function with a single
// argument: a function that immediately incorporates all pad edits (as opposed to waiting for the
// idle timer to fire).
helper.withFastCommit = async (fn) => {
const incorp = () => helper.padChrome$.padeditor.ace.callWithAce(
(ace) => ace.ace_inCallStackIfNecessary('helper.edit', () => ace.ace_fastIncorp()));
const cc = helper.padChrome$.window.pad.collabClient;
const {commitDelay} = cc;
cc.commitDelay = 0;
try {
return await fn(incorp);
} finally {
cc.commitDelay = commitDelay;
}
};
const getTextNodeAndOffsetOf = ($targetLine, targetOffsetAtLine) => {
const $textNodes = $targetLine.find('*').contents().filter(function () {
return this.nodeType === Node.TEXT_NODE;

View File

@ -32,8 +32,11 @@ helper.spyOnSocketIO = () => {
helper.edit = async (message, line) => {
const editsNum = helper.commits.length;
line = line ? line - 1 : 0;
helper.linesDiv()[line].sendkeys(message);
return helper.waitForPromise(() => editsNum + 1 === helper.commits.length);
await helper.withFastCommit(async (incorp) => {
helper.linesDiv()[line].sendkeys(message);
incorp();
await helper.waitForPromise(() => editsNum + 1 === helper.commits.length);
});
};
/**
@ -216,7 +219,10 @@ helper.clearPad = async () => {
await helper.waitForPromise(() => !helper.padInner$.document.getSelection().isCollapsed);
const e = new helper.padInner$.Event(helper.evtType);
e.keyCode = 8; // delete key
helper.padInner$('#innerdocbody').trigger(e);
await helper.waitForPromise(helper.padIsEmpty);
await helper.waitForPromise(() => helper.commits.length > commitsBefore);
await helper.withFastCommit(async (incorp) => {
helper.padInner$('#innerdocbody').trigger(e);
incorp();
await helper.waitForPromise(helper.padIsEmpty);
await helper.waitForPromise(() => helper.commits.length > commitsBefore);
});
};