lint: Run eslint --fix on bin/ and tests/

This commit is contained in:
Richard Hansen 2020-11-23 13:21:51 -05:00 committed by John McLear
parent 0625739cb8
commit b8d07a42eb
78 changed files with 4319 additions and 4599 deletions

View file

@ -1,34 +1,34 @@
describe("the test helper", function(){
describe("the newPad method", function(){
xit("doesn't leak memory if you creates iframes over and over again", function(done){
describe('the test helper', function () {
describe('the newPad method', function () {
xit("doesn't leak memory if you creates iframes over and over again", function (done) {
this.timeout(100000);
var times = 10;
let times = 10;
var loadPad = function(){
helper.newPad(function(){
var loadPad = function () {
helper.newPad(() => {
times--;
if(times > 0){
if (times > 0) {
loadPad();
} else {
done();
}
})
}
});
};
loadPad();
});
it("gives me 3 jquery instances of chrome, outer and inner", function(done){
it('gives me 3 jquery instances of chrome, outer and inner', function (done) {
this.timeout(10000);
helper.newPad(function(){
//check if the jquery selectors have the desired elements
expect(helper.padChrome$("#editbar").length).to.be(1);
expect(helper.padOuter$("#outerdocbody").length).to.be(1);
expect(helper.padInner$("#innerdocbody").length).to.be(1);
helper.newPad(() => {
// check if the jquery selectors have the desired elements
expect(helper.padChrome$('#editbar').length).to.be(1);
expect(helper.padOuter$('#outerdocbody').length).to.be(1);
expect(helper.padInner$('#innerdocbody').length).to.be(1);
//check if the document object was set correctly
// check if the document object was set correctly
expect(helper.padChrome$.window.document).to.be(helper.padChrome$.document);
expect(helper.padOuter$.window.document).to.be(helper.padOuter$.document);
expect(helper.padInner$.window.document).to.be(helper.padInner$.document);
@ -43,7 +43,7 @@ describe("the test helper", function(){
// However this doesn't seem to always be easily replicated, so this
// timeout may or may end up in the code. None the less, we test here
// to catch it if the bug comes up again.
it("clears cookies", function(done) {
it('clears cookies', function (done) {
this.timeout(60000);
// set cookies far into the future to make sure they're not expired yet
@ -53,20 +53,20 @@ describe("the test helper", function(){
expect(window.document.cookie).to.contain('token=foo');
expect(window.document.cookie).to.contain('language=bar');
helper.newPad(function(){
helper.newPad(() => {
// helper function seems to have cleared cookies
// NOTE: this doesn't yet mean it's proven to have taken effect by this point in execution
var firstCookie = window.document.cookie
const firstCookie = window.document.cookie;
expect(firstCookie).to.not.contain('token=foo');
expect(firstCookie).to.not.contain('language=bar');
var chrome$ = helper.padChrome$;
const chrome$ = helper.padChrome$;
// click on the settings button to make settings visible
var $userButton = chrome$(".buttonicon-showusers");
const $userButton = chrome$('.buttonicon-showusers');
$userButton.click();
var $usernameInput = chrome$("#myusernameedit");
const $usernameInput = chrome$('#myusernameedit');
$usernameInput.click();
$usernameInput.val('John McLear');
@ -84,9 +84,9 @@ describe("the test helper", function(){
// be sure.
expect(window.document.cookie).to.not.contain('prefsHtml=baz');
setTimeout(function(){ //give it a second to save the username on the server side
helper.newPad(function(){ // get a new pad, let it clear the cookies
var chrome$ = helper.padChrome$;
setTimeout(() => { // give it a second to save the username on the server side
helper.newPad(() => { // get a new pad, let it clear the cookies
const chrome$ = helper.padChrome$;
// helper function seems to have cleared cookies
// NOTE: this doesn't yet mean cookies were cleared effectively.
@ -99,11 +99,11 @@ describe("the test helper", function(){
expect(window.document.cookie).to.not.be(firstCookie);
// click on the settings button to make settings visible
var $userButton = chrome$(".buttonicon-showusers");
const $userButton = chrome$('.buttonicon-showusers');
$userButton.click();
// confirm that the session was actually cleared
var $usernameInput = chrome$("#myusernameedit");
const $usernameInput = chrome$('#myusernameedit');
expect($usernameInput.val()).to.be('');
done();
@ -112,43 +112,41 @@ describe("the test helper", function(){
});
});
it("sets pad prefs cookie", function(done) {
it('sets pad prefs cookie', function (done) {
this.timeout(60000);
helper.newPad({
padPrefs: {foo:"bar"},
cb: function(){
var chrome$ = helper.padChrome$;
padPrefs: {foo: 'bar'},
cb() {
const chrome$ = helper.padChrome$;
expect(chrome$.document.cookie).to.contain('prefsHttp=%7B%22');
expect(chrome$.document.cookie).to.contain('foo%22%3A%22bar');
done();
}
},
});
});
});
describe("the waitFor method", function(){
it("takes a timeout and waits long enough", function(done){
describe('the waitFor method', function () {
it('takes a timeout and waits long enough', function (done) {
this.timeout(2000);
var startTime = Date.now();
const startTime = Date.now();
helper.waitFor(function(){
return false;
}, 1500).fail(function(){
var duration = Date.now() - startTime;
helper.waitFor(() => false, 1500).fail(() => {
const duration = Date.now() - startTime;
expect(duration).to.be.greaterThan(1490);
done();
});
});
it("takes an interval and checks on every interval", function(done){
it('takes an interval and checks on every interval', function (done) {
this.timeout(4000);
var checks = 0;
let checks = 0;
helper.waitFor(function(){
helper.waitFor(() => {
checks++;
return false;
}, 2000, 100).fail(function(){
}, 2000, 100).fail(() => {
// One at the beginning, and 19-20 more depending on whether it's the timeout or the final
// poll that wins at 2000ms.
expect(checks).to.be.greaterThan(15);
@ -157,7 +155,7 @@ describe("the test helper", function(){
});
});
it('rejects if the predicate throws', async function() {
it('rejects if the predicate throws', async function () {
let err;
await helper.waitFor(() => { throw new Error('test exception'); })
.fail(() => {}) // Suppress the redundant uncatchable exception.
@ -166,44 +164,38 @@ describe("the test helper", function(){
expect(err.message).to.be('test exception');
});
describe("returns a deferred object", function(){
it("it calls done after success", function(done){
helper.waitFor(function(){
return true;
}).done(function(){
describe('returns a deferred object', function () {
it('it calls done after success', function (done) {
helper.waitFor(() => true).done(() => {
done();
});
});
it("calls fail after failure", function(done){
helper.waitFor(function(){
return false;
},0).fail(function(){
it('calls fail after failure', function (done) {
helper.waitFor(() => false, 0).fail(() => {
done();
});
});
xit("throws if you don't listen for fails", function(done){
var onerror = window.onerror;
window.onerror = function(){
xit("throws if you don't listen for fails", function (done) {
const onerror = window.onerror;
window.onerror = function () {
window.onerror = onerror;
done();
}
};
helper.waitFor(function(){
return false;
},100);
helper.waitFor(() => false, 100);
});
});
describe('checks first then sleeps', function() {
it('resolves quickly if the predicate is immediately true', async function() {
describe('checks first then sleeps', function () {
it('resolves quickly if the predicate is immediately true', async function () {
const before = Date.now();
await helper.waitFor(() => true, 1000, 900);
expect(Date.now() - before).to.be.lessThan(800);
});
it('polls exactly once if timeout < interval', async function() {
it('polls exactly once if timeout < interval', async function () {
let calls = 0;
await helper.waitFor(() => { calls++; }, 1, 1000)
.fail(() => {}) // Suppress the redundant uncatchable exception.
@ -211,18 +203,18 @@ describe("the test helper", function(){
expect(calls).to.be(1);
});
it('resolves if condition is immediately true even if timeout is 0', async function() {
it('resolves if condition is immediately true even if timeout is 0', async function () {
await helper.waitFor(() => true, 0);
});
});
});
describe('the waitForPromise method', function() {
it('returns a Promise', async function() {
describe('the waitForPromise method', function () {
it('returns a Promise', async function () {
expect(helper.waitForPromise(() => true)).to.be.a(Promise);
});
it('takes a timeout and waits long enough', async function() {
it('takes a timeout and waits long enough', async function () {
this.timeout(2000);
const startTime = Date.now();
let rejected;
@ -233,60 +225,60 @@ describe("the test helper", function(){
expect(duration).to.be.greaterThan(1490);
});
it('takes an interval and checks on every interval', async function() {
it('takes an interval and checks on every interval', async function () {
this.timeout(4000);
let checks = 0;
let rejected;
await helper.waitForPromise(() => { checks++; return false; }, 2000, 100)
.catch(() => { rejected = true; });
expect(rejected).to.be(true);
// `checks` is expected to be 20 or 21: one at the beginning, plus 19 or 20 more depending on
// whether it's the timeout or the final poll that wins at 2000ms. Margin is added to reduce
// flakiness on slow test machines.
// `checks` is expected to be 20 or 21: one at the beginning, plus 19 or 20 more depending on
// whether it's the timeout or the final poll that wins at 2000ms. Margin is added to reduce
// flakiness on slow test machines.
expect(checks).to.be.greaterThan(15);
expect(checks).to.be.lessThan(24);
});
});
describe("the selectLines method", function(){
describe('the selectLines method', function () {
// function to support tests, use a single way to represent whitespaces
var cleanText = function(text){
const cleanText = function (text) {
return text
// IE replaces line breaks with a whitespace, so we need to unify its behavior
// for other browsers, to have all tests running for all browsers
.replace(/\n/gi, "")
.replace(/\s/gi, " ");
}
.replace(/\n/gi, '')
.replace(/\s/gi, ' ');
};
before(function(done){
helper.newPad(function() {
before(function (done) {
helper.newPad(() => {
// create some lines to be used on the tests
var $firstLine = helper.padInner$("div").first();
$firstLine.sendkeys("{selectall}some{enter}short{enter}lines{enter}to test{enter}{enter}");
const $firstLine = helper.padInner$('div').first();
$firstLine.sendkeys('{selectall}some{enter}short{enter}lines{enter}to test{enter}{enter}');
// wait for lines to be split
helper.waitFor(function(){
var $fourthLine = helper.padInner$("div").eq(3);
return $fourthLine.text() === "to test";
helper.waitFor(() => {
const $fourthLine = helper.padInner$('div').eq(3);
return $fourthLine.text() === 'to test';
}).done(done);
});
this.timeout(60000);
});
it("changes editor selection to be between startOffset of $startLine and endOffset of $endLine", function(done){
var inner$ = helper.padInner$;
it('changes editor selection to be between startOffset of $startLine and endOffset of $endLine', function (done) {
const inner$ = helper.padInner$;
var startOffset = 2;
var endOffset = 4;
const startOffset = 2;
const endOffset = 4;
var $lines = inner$("div");
var $startLine = $lines.eq(1);
var $endLine = $lines.eq(3);
const $lines = inner$('div');
const $startLine = $lines.eq(1);
const $endLine = $lines.eq(3);
helper.selectLines($startLine, $endLine, startOffset, endOffset);
var selection = inner$.document.getSelection();
const selection = inner$.document.getSelection();
/*
* replace() is required here because Firefox keeps the line breaks.
@ -295,24 +287,24 @@ describe("the test helper", function(){
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines to t");
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines to t');
done();
});
it("ends selection at beginning of $endLine when it is an empty line", function(done){
var inner$ = helper.padInner$;
it('ends selection at beginning of $endLine when it is an empty line', function (done) {
const inner$ = helper.padInner$;
var startOffset = 2;
var endOffset = 1;
const startOffset = 2;
const endOffset = 1;
var $lines = inner$("div");
var $startLine = $lines.eq(1);
var $endLine = $lines.eq(4);
const $lines = inner$('div');
const $startLine = $lines.eq(1);
const $endLine = $lines.eq(4);
helper.selectLines($startLine, $endLine, startOffset, endOffset);
var selection = inner$.document.getSelection();
const selection = inner$.document.getSelection();
/*
* replace() is required here because Firefox keeps the line breaks.
@ -321,24 +313,24 @@ describe("the test helper", function(){
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines to test");
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines to test');
done();
});
it("ends selection at beginning of $endLine when its offset is zero", function(done){
var inner$ = helper.padInner$;
it('ends selection at beginning of $endLine when its offset is zero', function (done) {
const inner$ = helper.padInner$;
var startOffset = 2;
var endOffset = 0;
const startOffset = 2;
const endOffset = 0;
var $lines = inner$("div");
var $startLine = $lines.eq(1);
var $endLine = $lines.eq(3);
const $lines = inner$('div');
const $startLine = $lines.eq(1);
const $endLine = $lines.eq(3);
helper.selectLines($startLine, $endLine, startOffset, endOffset);
var selection = inner$.document.getSelection();
const selection = inner$.document.getSelection();
/*
* replace() is required here because Firefox keeps the line breaks.
@ -347,24 +339,24 @@ describe("the test helper", function(){
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines ");
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines ');
done();
});
it("selects full line when offset is longer than line content", function(done){
var inner$ = helper.padInner$;
it('selects full line when offset is longer than line content', function (done) {
const inner$ = helper.padInner$;
var startOffset = 2;
var endOffset = 50;
const startOffset = 2;
const endOffset = 50;
var $lines = inner$("div");
var $startLine = $lines.eq(1);
var $endLine = $lines.eq(3);
const $lines = inner$('div');
const $startLine = $lines.eq(1);
const $endLine = $lines.eq(3);
helper.selectLines($startLine, $endLine, startOffset, endOffset);
var selection = inner$.document.getSelection();
const selection = inner$.document.getSelection();
/*
* replace() is required here because Firefox keeps the line breaks.
@ -373,21 +365,21 @@ describe("the test helper", function(){
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("ort lines to test");
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines to test');
done();
});
it("selects all text between beginning of $startLine and end of $endLine when no offset is provided", function(done){
var inner$ = helper.padInner$;
it('selects all text between beginning of $startLine and end of $endLine when no offset is provided', function (done) {
const inner$ = helper.padInner$;
var $lines = inner$("div");
var $startLine = $lines.eq(1);
var $endLine = $lines.eq(3);
const $lines = inner$('div');
const $startLine = $lines.eq(1);
const $endLine = $lines.eq(3);
helper.selectLines($startLine, $endLine);
var selection = inner$.document.getSelection();
const selection = inner$.document.getSelection();
/*
* replace() is required here because Firefox keeps the line breaks.
@ -396,73 +388,73 @@ describe("the test helper", function(){
* is not consistent between browsers but that's the situation so that's
* how I'm covering it in this test.
*/
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm,""))).to.be("short lines to test");
expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('short lines to test');
done();
});
});
describe('helper',function(){
before(function(cb){
helper.newPad(function(){
describe('helper', function () {
before(function (cb) {
helper.newPad(() => {
cb();
})
})
});
});
it(".textLines() returns the text of the pad as strings", async function(){
let lines = helper.textLines();
let defaultText = helper.defaultText();
it('.textLines() returns the text of the pad as strings', async function () {
const lines = helper.textLines();
const defaultText = helper.defaultText();
expect(Array.isArray(lines)).to.be(true);
expect(lines[0]).to.be.an('string');
// @todo
// final "\n" is added automatically, but my understanding is this should happen
// only when the default text does not end with "\n" already
expect(lines.join("\n")+"\n").to.equal(defaultText);
})
expect(`${lines.join('\n')}\n`).to.equal(defaultText);
});
it(".linesDiv() returns the text of the pad as div elements", async function(){
let lines = helper.linesDiv();
let defaultText = helper.defaultText();
it('.linesDiv() returns the text of the pad as div elements', async function () {
const lines = helper.linesDiv();
const defaultText = helper.defaultText();
expect(Array.isArray(lines)).to.be(true);
expect(lines[0]).to.be.an('object');
expect(lines[0].text()).to.be.an('string');
_.each(defaultText.split("\n"), function(line, index){
//last line of default text
if(index === lines.length){
_.each(defaultText.split('\n'), (line, index) => {
// last line of default text
if (index === lines.length) {
expect(line).to.equal('');
} else {
expect(lines[index].text()).to.equal(line);
}
})
})
});
});
it(".edit() defaults to send an edit to the first line", async function(){
let firstLine = helper.textLines()[0];
await helper.edit("line")
it('.edit() defaults to send an edit to the first line', async function () {
const firstLine = helper.textLines()[0];
await helper.edit('line');
expect(helper.textLines()[0]).to.be(`line${firstLine}`);
})
});
it(".edit() to the line specified with parameter lineNo", async function(){
let firstLine = helper.textLines()[0];
await helper.edit("second line", 2);
it('.edit() to the line specified with parameter lineNo', async function () {
const firstLine = helper.textLines()[0];
await helper.edit('second line', 2);
let text = helper.textLines();
const text = helper.textLines();
expect(text[0]).to.equal(firstLine);
expect(text[1]).to.equal("second line");
})
expect(text[1]).to.equal('second line');
});
it(".edit() supports sendkeys syntax ({selectall},{del},{enter})", async function(){
it('.edit() supports sendkeys syntax ({selectall},{del},{enter})', async function () {
expect(helper.textLines()[0]).to.not.equal('');
// select first line
helper.linesDiv()[0].sendkeys("{selectall}")
helper.linesDiv()[0].sendkeys('{selectall}');
// delete first line
await helper.edit("{del}")
await helper.edit('{del}');
expect(helper.textLines()[0]).to.be('');
let noOfLines = helper.textLines().length;
await helper.edit("{enter}")
expect(helper.textLines().length).to.be(noOfLines+1);
})
})
const noOfLines = helper.textLines().length;
await helper.edit('{enter}');
expect(helper.textLines().length).to.be(noOfLines + 1);
});
});
});