diff --git a/lib/commands/chooseFile.js b/lib/commands/chooseFile.js index 75cf821e336..43ce802066a 100644 --- a/lib/commands/chooseFile.js +++ b/lib/commands/chooseFile.js @@ -43,9 +43,9 @@ let chooseFile = function (selector, localPath) { } return new Promise((resolve, reject) => { - fs.exists(localPath, (exists) => { + fs.stat(localPath, (err) => { /* istanbul ignore next */ - if (!exists) { + if (err) { return reject(new CommandError('File to upload does not exists on your system')) } diff --git a/lib/commands/saveScreenshot.js b/lib/commands/saveScreenshot.js index 7dd72d69b5c..63f55ccd0db 100644 --- a/lib/commands/saveScreenshot.js +++ b/lib/commands/saveScreenshot.js @@ -28,6 +28,7 @@ */ import fs from 'fs' +import { Buffer } from 'safe-buffer' let saveScreenshot = function (filename) { return this.screenshot().then((res) => { diff --git a/lib/runner.js b/lib/runner.js index 8957dd55447..a1542aa96ee 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -40,7 +40,7 @@ class Runner { this.initialiseServices(config) config.beforeSession.forEach( - async (hook) => await hook(config, this.caps, this.specs) + async (hook) => hook(config, this.caps, this.specs) ) this.framework = this.initialiseFramework(config) @@ -183,7 +183,7 @@ class Runner { await this.end(this.failures) config.afterSession.forEach( - async (hook) => await hook(config, this.caps, this.specs) + async (hook) => hook(config, this.caps, this.specs) ) process.exit(this.failures === 0 ? 0 : 1) } catch (e) { diff --git a/lib/scripts/createSelectorScript.js b/lib/scripts/createSelectorScript.js index 597b836aa92..0ea04ced6b5 100644 --- a/lib/scripts/createSelectorScript.js +++ b/lib/scripts/createSelectorScript.js @@ -150,7 +150,7 @@ var executeClientSide = function (fn, sArr, args) { sArgs.push(arg) } - var parameter = args && sArgs.concat(args) || sArgs + var parameter = (args && sArgs.concat(args)) || sArgs if (parameter.length === 0 || (parameter.length === 1 && parameter[0].length === 0)) { if (typeof cb === 'function') { return cb('NoSuchElement') && new Error('NoSuchElement') diff --git a/lib/scripts/eventSimulator.js b/lib/scripts/eventSimulator.js index 77c6e9c2061..7f754630963 100644 --- a/lib/scripts/eventSimulator.js +++ b/lib/scripts/eventSimulator.js @@ -27,7 +27,30 @@ let eventSimulator = function () { break } - document.createEvent ? (b = document.createEvent(a), a === 'HTMLEvents' ? b.initEvent(c, !0, !0) : b.initMouseEvent(c, !0, !0, document.defaultView, 0, xto, yto, xto, yto, !1, !1, !1, !1, btnCode, null), f.dispatchEvent(b)) : (a = document.createEventObject(), a.detail = 0, a.screenX = xto, a.screenY = yto, a.clientX = xto, a.clientY = yto, a.ctrlKey = !1, a.altKey = !1, a.shiftKey = !1, a.metaKey = !1, a.button = 1, f.fireEvent('on' + c, a)) + if (document.createEvent) { + b = document.createEvent(a) + + if (a === 'HTMLEvents') { + b.initEvent(c, !0, !0) + } else { + b.initMouseEvent(c, !0, !0, document.defaultView, 0, xto, yto, xto, yto, !1, !1, !1, !1, btnCode, null) + } + + f.dispatchEvent(b) + } else { + a = document.createEventObject() + a.detail = 0 + a.screenX = xto + a.screenY = yto + a.clientX = xto + a.clientY = yto + a.ctrlKey = !1 + a.altKey = !1 + a.shiftKey = !1 + a.metaKey = !1 + a.button = 1 + f.fireEvent('on' + c, a) + } return true } var eventMatchers = { diff --git a/lib/webdriverio.js b/lib/webdriverio.js index a11a577c1aa..41c798ba04c 100644 --- a/lib/webdriverio.js +++ b/lib/webdriverio.js @@ -6,6 +6,7 @@ import path from 'path' import merge from 'deepmerge' import mkdirp from 'mkdirp' import events from 'events' +import { Buffer } from 'safe-buffer' import RequestHandler from './utils/RequestHandler' import { RuntimeError } from './utils/ErrorHandler' @@ -272,7 +273,7 @@ let WebdriverIO = function (args, modifier) { e = new Error(e) } - const message = e.seleniumStack && e.seleniumStack.message || e.message + const message = (e.seleniumStack && e.seleniumStack.message) || e.message let stack = stacktrace.slice().map(trace => ' at ' + trace) e.stack = e.name + ': ' + message + '\n' + stack.reverse().join('\n') diff --git a/test/.eslintrc b/test/.eslintrc index c7ad47875d4..eee4392aaf4 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -8,6 +8,8 @@ "chai-expect" ], "rules": { + "no-unused-expressions": 0, + "mocha/no-exclusive-tests": [2], "mocha/no-pending-tests": [2], "mocha/handle-done-callback": [2], diff --git a/test/fixtures/custom.commands.wdio.conf.js b/test/fixtures/custom.commands.wdio.conf.js index 4e66e76eb67..196f26bfc72 100644 --- a/test/fixtures/custom.commands.wdio.conf.js +++ b/test/fixtures/custom.commands.wdio.conf.js @@ -10,7 +10,7 @@ const CUSTOM_COMMANDS = { return new Promise(function (resolve, reject) { self.elements(selector).then(function (res) { if (!res || res.status === -1) { - reject() + return reject(new Error('no element found')) } resolve(res.value.length) }) diff --git a/test/fixtures/specs/waitUntil.async.spec.js b/test/fixtures/specs/waitUntil.async.spec.js index f7578f776a6..d5a38c7e9fa 100644 --- a/test/fixtures/specs/waitUntil.async.spec.js +++ b/test/fixtures/specs/waitUntil.async.spec.js @@ -28,7 +28,7 @@ describe('waitUntil async', () => { it('should allow to define own error message', () => { const errorMsg = 'my own error message' - return browser.waitUntil(() => Promise.reject(), 100, errorMsg).catch((e) => { + return browser.waitUntil(() => Promise.reject(new Error('buu')), 100, errorMsg).catch((e) => { expect(e.message).to.be.equal(errorMsg) /** diff --git a/test/setup.js b/test/setup.js index 2d0132bccbb..900c2b47b0f 100644 --- a/test/setup.js +++ b/test/setup.js @@ -44,7 +44,7 @@ before(async function () { await this.client.init() }) -beforeEach(async function() { +beforeEach(async function () { if (process.env._ENV && process.env._ENV.match(/(android|ios)/)) { return } @@ -54,7 +54,7 @@ beforeEach(async function() { after(async function () { const sessionId = this.client.requestHandler.sessionID - await this.client[process.env._ENV && process.env._ENV.match(/(multibrowser|android)/) || process.env.CI ? 'end' : 'endAll']() + await this.client[(process.env._ENV && process.env._ENV.match(/(multibrowser|android)/)) || process.env.CI ? 'end' : 'endAll']() /** * if we are not running on travis we are done here diff --git a/test/spec/unit/timer.js b/test/spec/unit/timer.js index 42affb8acde..c07bf719ce0 100644 --- a/test/spec/unit/timer.js +++ b/test/spec/unit/timer.js @@ -25,7 +25,7 @@ describe('timer', () => { }) it('should be rejected', () => { - let timer = new Timer(20, 30, () => Promise.reject('err')) + let timer = new Timer(20, 30, () => Promise.reject(new Error('err'))) return timer.then(assert.fail).catch((msg) => { expect(msg).to.be.equal('err') diff --git a/test/spec/unit/waitUntil.js b/test/spec/unit/waitUntil.js index a71cec68a98..eb8de329fa0 100644 --- a/test/spec/unit/waitUntil.js +++ b/test/spec/unit/waitUntil.js @@ -22,7 +22,12 @@ describe('waitUntil', () => { it('should get rejected', async function () { let error try { - await this.client.waitUntil(() => new Promise((resolve, reject) => setTimeout(() => reject('foobar'), 500)), 1000) + await this.client.waitUntil(() => + new Promise((resolve, reject) => + setTimeout( + () => reject(new Error('foobar')), + 500) + ), 1000) } catch (e) { error = e } finally {