Fixed eslint errors.

This commit is contained in:
Tomas Bures 2017-05-28 18:55:01 +02:00
parent c11d1a1cbf
commit c17bc9f2cf
10 changed files with 268 additions and 280 deletions

View file

@ -1,7 +1,7 @@
'use strict';
require('./lib/exit-unless-test');
const { mocha, driver } = require('./lib/mocha-e2e');
const { mocha } = require('./lib/mocha-e2e');
const path = require('path');
global.USE_SHARED_DRIVER = true;

View file

@ -12,8 +12,8 @@ module.exports = (...extras) => page({
await this.waitUntilVisible();
},
async ensureUrl(path) {
async ensureUrl() {
throw new Error('Unsupported method.');
},
}
}, ...extras);

View file

@ -1,217 +1,215 @@
'use strict';
const Mocha = require('mocha');
const color = Mocha.reporters.Base.color;
const Semaphore = require('./semaphore');
const fs = require('fs-extra');
const config = require('./config');
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
.forBrowser(config.app.seleniumwebdriver.browser || 'phantomjs')
.build();
const failHandlerRunning = new Semaphore();
function UseCaseReporter(runner) {
Mocha.reporters.Base.call(this, runner);
const self = this;
let indents = 0;
function indent () {
return Array(indents).join(' ');
}
runner.on('start', function () {
console.log();
});
runner.on('suite', suite => {
++indents;
console.log(color('suite', '%s%s'), indent(), suite.title);
});
runner.on('suite end', () => {
--indents;
if (indents === 1) {
console.log();
}
});
runner.on('use-case', useCase => {
++indents;
console.log();
console.log(color('suite', '%sUse case: %s'), indent(), useCase.title);
});
runner.on('use-case end', () => {
--indents;
});
runner.on('steps', useCase => {
++indents;
console.log(color('pass', '%s%s'), indent(), useCase.title);
});
runner.on('steps end', () => {
--indents;
});
runner.on('step pass', step => {
console.log(indent() + color('checkmark', ' ' + Mocha.reporters.Base.symbols.ok) + color('pass', ' %s'), step.title);
});
runner.on('step fail', step => {
console.log(indent() + color('fail', ' %s'), step.title);
});
runner.on('pending', test => {
const fmt = indent() + color('pending', ' - %s');
console.log(fmt, test.title);
});
runner.on('pass', test => {
let fmt;
if (test.speed === 'fast') {
fmt = indent() +
color('checkmark', ' ' + Mocha.reporters.Base.symbols.ok) +
color('pass', ' %s');
console.log(fmt, test.title);
} else {
fmt = indent() +
color('checkmark', ' ' + Mocha.reporters.Base.symbols.ok) +
color('pass', ' %s') +
color(test.speed, ' (%dms)');
console.log(fmt, test.title, test.duration);
}
});
runner.on('fail', (test, err) => {
failHandlerRunning.enter();
(async () => {
const currentUrl = await driver.getCurrentUrl();
const info = `URL: ${currentUrl}`;
await fs.writeFile('last-failed-e2e-test.info', info);
await fs.writeFile('last-failed-e2e-test.html', await driver.getPageSource());
await fs.writeFile('last-failed-e2e-test.png', new Buffer(await driver.takeScreenshot(), 'base64'));
failHandlerRunning.exit();
})();
console.log(indent() + color('fail', ' %s'), test.title);
console.log();
console.log(err);
console.log();
console.log(`Snaphot of and info about the current page are in last-failed-e2e-test.*`);
});
runner.on('end', () => {
const stats = self.stats;
let fmt;
console.log();
// passes
fmt = color('bright pass', ' ') + color('green', ' %d passing');
console.log(fmt, stats.passes);
// pending
if (stats.pending) {
fmt = color('pending', ' ') + color('pending', ' %d pending');
console.log(fmt, stats.pending);
}
// failures
if (stats.failures) {
fmt = color('fail', ' %d failing');
console.log(fmt, stats.failures);
}
console.log();
});
}
const mocha = new Mocha()
.timeout(120000)
.reporter(UseCaseReporter)
.ui('tdd');
mocha._originalRun = mocha.run;
let runner;
mocha.run = fn => {
runner = mocha._originalRun(async () => {
await failHandlerRunning.waitForEmpty();
await driver.quit();
fn();
});
};
async function useCaseExec(name, asyncFn) {
runner.emit('use-case', {title: name});
try {
await asyncFn();
runner.emit('use-case end');
} catch (err) {
runner.emit('use-case end');
throw err;
}
}
function useCase(name, asyncFn) {
if (asyncFn) {
return test('Use case: ' + name, () => useCaseExec(name, asyncFn));
} else {
// Pending test
return test('Use case: ' + name);
}
}
useCase.only = (name, asyncFn) => {
return test.only('Use case: ' + name, () => useCaseExec(name, asyncFn));
};
useCase.skip = (name, asyncFn) => {
return test.skip('Use case: ' + name, () => useCaseExec(name, asyncFn));
};
async function step(name, asyncFn) {
try {
await asyncFn();
runner.emit('step pass', {title: name});
} catch (err) {
runner.emit('step fail', {title: name});
throw err;
}
}
async function steps(name, asyncFn) {
try {
runner.emit('steps', {title: name});
await asyncFn();
runner.emit('steps end');
} catch (err) {
runner.emit('step end');
throw err;
}
}
async function precondition(preConditionName, useCaseName, asyncFn) {
await steps(`Including use case "${useCaseName}" to satisfy precondition "${preConditionName}"`, asyncFn);
}
module.exports = {
mocha,
useCase,
step,
steps,
precondition,
driver
'use strict';
/* eslint-disable no-console */
const Mocha = require('mocha');
const color = Mocha.reporters.Base.color;
const WorkerCounter = require('./worker-counter');
const fs = require('fs-extra');
const config = require('./config');
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
.forBrowser(config.app.seleniumwebdriver.browser || 'phantomjs')
.build();
const failHandlerRunning = new WorkerCounter();
function UseCaseReporter(runner) {
Mocha.reporters.Base.call(this, runner);
const self = this;
let indents = 0;
function indent () {
return Array(indents).join(' ');
}
runner.on('start', () => {
console.log();
});
runner.on('suite', suite => {
++indents;
console.log(color('suite', '%s%s'), indent(), suite.title);
});
runner.on('suite end', () => {
--indents;
if (indents === 1) {
console.log();
}
});
runner.on('use-case', useCase => {
++indents;
console.log();
console.log(color('suite', '%sUse case: %s'), indent(), useCase.title);
});
runner.on('use-case end', () => {
--indents;
});
runner.on('steps', useCase => {
++indents;
console.log(color('pass', '%s%s'), indent(), useCase.title);
});
runner.on('steps end', () => {
--indents;
});
runner.on('step pass', step => {
console.log(indent() + color('checkmark', ' ' + Mocha.reporters.Base.symbols.ok) + color('pass', ' %s'), step.title);
});
runner.on('step fail', step => {
console.log(indent() + color('fail', ' %s'), step.title);
});
runner.on('pending', test => {
const fmt = indent() + color('pending', ' - %s');
console.log(fmt, test.title);
});
runner.on('pass', test => {
let fmt;
if (test.speed === 'fast') {
fmt = indent() +
color('checkmark', ' ' + Mocha.reporters.Base.symbols.ok) +
color('pass', ' %s');
console.log(fmt, test.title);
} else {
fmt = indent() +
color('checkmark', ' ' + Mocha.reporters.Base.symbols.ok) +
color('pass', ' %s') +
color(test.speed, ' (%dms)');
console.log(fmt, test.title, test.duration);
}
});
runner.on('fail', (test, err) => {
failHandlerRunning.enter();
(async () => {
const currentUrl = await driver.getCurrentUrl();
const info = `URL: ${currentUrl}`;
await fs.writeFile('last-failed-e2e-test.info', info);
await fs.writeFile('last-failed-e2e-test.html', await driver.getPageSource());
await fs.writeFile('last-failed-e2e-test.png', new Buffer(await driver.takeScreenshot(), 'base64'));
failHandlerRunning.exit();
})();
console.log(indent() + color('fail', ' %s'), test.title);
console.log();
console.log(err);
console.log();
console.log('Snaphot of and info about the current page are in last-failed-e2e-test.*');
});
runner.on('end', () => {
const stats = self.stats;
let fmt;
console.log();
// passes
fmt = color('bright pass', ' ') + color('green', ' %d passing');
console.log(fmt, stats.passes);
// pending
if (stats.pending) {
fmt = color('pending', ' ') + color('pending', ' %d pending');
console.log(fmt, stats.pending);
}
// failures
if (stats.failures) {
fmt = color('fail', ' %d failing');
console.log(fmt, stats.failures);
}
console.log();
});
}
const mocha = new Mocha()
.timeout(120000)
.reporter(UseCaseReporter)
.ui('tdd');
mocha._originalRun = mocha.run;
let runner;
mocha.run = fn => {
runner = mocha._originalRun(async () => {
await failHandlerRunning.waitForEmpty();
await driver.quit();
fn();
});
};
async function useCaseExec(name, asyncFn) {
runner.emit('use-case', {title: name});
try {
await asyncFn();
runner.emit('use-case end');
} catch (err) {
runner.emit('use-case end');
throw err;
}
}
function useCase(name, asyncFn) {
if (asyncFn) {
return test('Use case: ' + name, () => useCaseExec(name, asyncFn));
} else {
// Pending test
return test('Use case: ' + name);
}
}
useCase.only = (name, asyncFn) => test.only('Use case: ' + name, () => useCaseExec(name, asyncFn));
useCase.skip = (name, asyncFn) => test.skip('Use case: ' + name, () => useCaseExec(name, asyncFn));
async function step(name, asyncFn) {
try {
await asyncFn();
runner.emit('step pass', {title: name});
} catch (err) {
runner.emit('step fail', {title: name});
throw err;
}
}
async function steps(name, asyncFn) {
try {
runner.emit('steps', {title: name});
await asyncFn();
runner.emit('steps end');
} catch (err) {
runner.emit('step end');
throw err;
}
}
async function precondition(preConditionName, useCaseName, asyncFn) {
await steps(`Including use case "${useCaseName}" to satisfy precondition "${preConditionName}"`, asyncFn);
}
module.exports = {
mocha,
useCase,
step,
steps,
precondition,
driver
};

View file

@ -1,6 +1,5 @@
'use strict';
const config = require('./config');
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const until = webdriver.until;
@ -33,7 +32,7 @@ module.exports = (...extras) => Object.assign({
return params;
},
async waitUntilVisible(selector) {
async waitUntilVisible() {
await driver.wait(until.elementLocated(By.css('body')), waitTimeout);
for (const elem of (this.elementsToWaitFor || [])) {
@ -45,9 +44,7 @@ module.exports = (...extras) => Object.assign({
}
for (const text of (this.textsToWaitFor || [])) {
await driver.wait(new webdriver.Condition(`for text "${text}"`, async (driver) => {
return await this.containsText(text);
}), waitTimeout);
await driver.wait(new webdriver.Condition(`for text "${text}"`, async () => await this.containsText(text)), waitTimeout);
}
if (this.url) {
@ -57,13 +54,13 @@ module.exports = (...extras) => Object.assign({
await driver.executeScript('document.mailTrainRefreshAcknowledged = true;');
},
async waitUntilVisibleAfterRefresh(selector) {
await driver.wait(new webdriver.Condition('for refresh', async (driver) => {
async waitUntilVisibleAfterRefresh() {
await driver.wait(new webdriver.Condition('for refresh', async driver => {
const val = await driver.executeScript('return document.mailTrainRefreshAcknowledged;');
return !val;
}), waitTimeout);
await this.waitUntilVisible(selector);
await this.waitUntilVisible();
},
async click(key) {

View file

@ -15,7 +15,7 @@ module.exports = (...extras) => page({
path = pathOrParams;
} else {
const urlPattern = new UrlPattern(this.requestUrl || this.url);
path = urlPattern.stringify(pathOrParams)
path = urlPattern.stringify(pathOrParams);
}
const parsedUrl = url.parse(path);

View file

@ -1,35 +1,35 @@
'use strict';
const Promise = require('bluebird');
class Semaphore {
constructor() {
this.counter = 0;
}
enter() {
this.counter++;
}
exit() {
this.counter--;
}
async waitForEmpty() {
const self = this;
function wait(resolve) {
if (self.counter == 0) {
resolve();
} else {
setTimeout(wait, 500, resolve);
}
}
return new Promise(resolve => {
setTimeout(wait, 500, resolve);
})
}
}
module.exports = Semaphore;
'use strict';
const Promise = require('bluebird');
class WorkerCounter {
constructor() {
this.counter = 0;
}
enter() {
this.counter++;
}
exit() {
this.counter--;
}
async waitForEmpty() {
const self = this;
function wait(resolve) {
if (self.counter === 0) {
resolve();
} else {
setTimeout(wait, 500, resolve);
}
}
return new Promise(resolve => {
setTimeout(wait, 500, resolve);
});
}
}
module.exports = WorkerCounter;

View file

@ -88,7 +88,7 @@ module.exports = list => ({
form: `form[action="/subscription/${list.cid}/manage-address"]`,
emailInput: '#main-form input[name="email"]',
emailNewInput: '#main-form input[name="email-new"]',
submitButton: 'a[href="#submit"]',
submitButton: 'a[href="#submit"]'
}
}),
@ -102,12 +102,12 @@ module.exports = list => ({
webUpdatedNotice: web({
url: `/subscription/${list.cid}/updated-notice`,
textsToWaitFor: ['Profile Updated'],
textsToWaitFor: ['Profile Updated']
}),
webUnsubscribedNotice: web({
url: `/subscription/${list.cid}/unsubscribed-notice`,
textsToWaitFor: ['Unsubscribe Successful'],
textsToWaitFor: ['Unsubscribe Successful']
}),
mailUnsubscriptionConfirmed: mail({
@ -116,17 +116,6 @@ module.exports = list => ({
elements: {
resubscribeLink: `a[href^="${config.settings['service-url']}subscription/${list.cid}"]`
}
}),
/*
webUnsubscribe: web({ // FIXME
elementsToWaitFor: ['submitButton'],
elements: {
submitButton: 'a[href="#submit"]'
}
}),
*/
})
});

View file

@ -22,8 +22,8 @@ module.exports = {
url: '/users/account',
elementsToWaitFor: ['form'],
elements: {
form: `form[action="/users/account"]`,
form: 'form[action="/users/account"]',
emailInput: 'form[action="/users/account"] input[name="email"]'
}
}),
})
};

View file

@ -1,5 +1,7 @@
'use strict';
/* eslint-disable prefer-arrow-callback */
const config = require('../lib/config');
const { useCase, step, driver } = require('../lib/mocha-e2e');
const expect = require('chai').expect;

View file

@ -1,5 +1,7 @@
'use strict';
/* eslint-disable prefer-arrow-callback */
const config = require('../lib/config');
const { useCase, step, precondition, driver } = require('../lib/mocha-e2e');
const shortid = require('shortid');