Skip to content

Commit

Permalink
code cleanup first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
potapovDim committed Feb 8, 2021
1 parent 36efbd0 commit 932be4b
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 149 deletions.
6 changes: 3 additions & 3 deletions javascript/node/selenium-webdriver/io/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ class Command {
* @return {!Command} The launched command.
*/
module.exports = function exec(command, opt_options) {
var options = opt_options || {}
const options = opt_options || {}

var proc = childProcess.spawn(command, options.args || [], {
let proc = childProcess.spawn(command, options.args || [], {
env: options.env || process.env,
stdio: options.stdio || 'ignore',
})
Expand All @@ -133,7 +133,7 @@ module.exports = function exec(command, opt_options) {
proc.unref()
process.once('exit', onProcessExit)

let result = new Promise((resolve) => {
const result = new Promise((resolve) => {
proc.once('exit', (code, signal) => {
proc = null
process.removeListener('exit', onProcessExit)
Expand Down
17 changes: 8 additions & 9 deletions javascript/node/selenium-webdriver/io/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,12 @@ exports.tmpDir = function () {
*/
exports.tmpFile = function (opt_options) {
return checkedCall((callback) => {
// |tmp.file| checks arguments length to detect options rather than doing a
// truthy check, so we must only pass options if there are some to pass.
if (opt_options) {
tmp.file(opt_options, callback)
} else {
tmp.file(callback)
}
/** check fixed in v > 0.2.1 if
* (typeof options === 'function') {
* return [{}, options];
* }
*/
tmp.file(opt_options, callback)
})
}

Expand All @@ -224,7 +223,7 @@ exports.tmpFile = function (opt_options) {
* not be found.
*/
exports.findInPath = function (file, opt_checkCwd) {
let dirs = []
const dirs = []
if (opt_checkCwd) {
dirs.push(process.cwd())
}
Expand Down Expand Up @@ -329,7 +328,7 @@ exports.mkdirp = function mkdirp(dir) {
* will be relative to `rootPath`.
*/
exports.walkDir = function (rootPath) {
let seen = []
const seen = []
return (function walk(dir) {
return checkedCall((callback) => fs.readdir(dir, callback)).then((files) =>
Promise.all(
Expand Down
11 changes: 5 additions & 6 deletions javascript/node/selenium-webdriver/io/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ function load(path) {
*/
function unzip(src, dst) {
return load(src).then((zip) => {
let promisedDirs = new Map()
let promises = []
const promisedDirs = new Map()
const promises = []

zip.z_.forEach((relPath, file) => {
let p
Expand Down Expand Up @@ -218,7 +218,6 @@ function unzip(src, dst) {
}

// PUBLIC API

exports.Zip = Zip
exports.load = load
exports.unzip = unzip
module.exports.Zip = Zip
module.exports.load = load
module.exports.unzip = unzip
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class LegacyActionSequence {
* @private
*/
scheduleKeyboardAction_(description, keys) {
let cmd = new command.Command(
const cmd = new command.Command(
command.Name.LEGACY_ACTION_SEND_KEYS
).setParameter('value', keys)
this.schedule_(description, cmd)
Expand Down
20 changes: 4 additions & 16 deletions javascript/node/selenium-webdriver/lib/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,7 @@
* @return {boolean} Whether the value is a promise.
*/
function isPromise(value) {
try {
// Use array notation so the Closure compiler does not obfuscate away our
// contract.
return (
value &&
(typeof value === 'object' || typeof value === 'function') &&
typeof value['then'] === 'function'
)
} catch (ex) {
return false
}
return Object.prototype.toString.call(value) === '[object Promise]'
}

/**
Expand All @@ -50,9 +40,7 @@ function isPromise(value) {
* @return {!Promise<void>} The promise.
*/
function delayed(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
return new Promise((resolve) => setTimeout(resolve, ms))
}

/**
Expand Down Expand Up @@ -199,8 +187,8 @@ async function filter(array, fn, self = undefined) {

for (let i = 0; i < n; i++) {
if (i in arr) {
let value = arr[i]
let include = await fn.call(self, value, i, arr)
const value = arr[i]
const include = await fn.call(self, value, i, arr)
if (include) {
values[valuesLength++] = value
}
Expand Down
13 changes: 6 additions & 7 deletions javascript/node/selenium-webdriver/remote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ class DriverService {
}

return resolveCommandLineFlags(this.args_).then((args) => {
var command = exec(self.executable_, {
const command = exec(self.executable_, {
args: args,
env: self.env_,
stdio: self.stdio_,
})

resolveCommand(command)

var earlyTermination = command.result().then(function (result) {
var error =
const earlyTermination = command.result().then(function (result) {
const error =
result.code == null
? Error('Server was killed with ' + result.signal)
: Error('Server terminated early with status ' + result.code)
Expand All @@ -229,7 +229,7 @@ class DriverService {
throw error
})

var hostname = self.hostname_
let hostname = self.hostname_
if (!hostname) {
hostname =
(!self.loopbackOnly_ && net.getAddress()) ||
Expand Down Expand Up @@ -338,9 +338,8 @@ DriverService.Builder = class {
* @this {THIS}
* @template THIS
*/
addArguments(var_args) { // eslint-disable-line
let args = Array.prototype.slice.call(arguments, 0)
this.options_.args = this.options_.args.concat(args)
addArguments(...arguments_) {
this.options_.args = this.options_.args.concat(arguments_)
return this
}

Expand Down
8 changes: 4 additions & 4 deletions javascript/node/selenium-webdriver/test/actions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ test.suite(function (env) {

const div = await driver.findElement(By.css('div'))
const rect = await div.getRect()
assert.deepEqual(rect, { width: 500, height: 500, x: 0, y: 0 })
assert.deepStrictEqual(rect, { width: 500, height: 500, x: 0, y: 0 })

await driver.actions().click(div).perform()

const clicks = await driver.executeScript('return clicks')
assert.deepEqual(clicks, [[250, 250]])
assert.deepStrictEqual(clicks, [[250, 250]])
})

it('can move relative to element center', async function () {
await driver.get(fileServer.whereIs('/data/actions/record_click.html'))

const div = await driver.findElement(By.css('div'))
const rect = await div.getRect()
assert.deepEqual(rect, { width: 500, height: 500, x: 0, y: 0 })
assert.deepStrictEqual(rect, { width: 500, height: 500, x: 0, y: 0 })

await driver
.actions()
Expand All @@ -87,7 +87,7 @@ test.suite(function (env) {
.perform()

const clicks = await driver.executeScript('return clicks')
assert.deepEqual(clicks, [[260, 260]])
assert.deepStrictEqual(clicks, [[260, 260]])
})

test
Expand Down
19 changes: 13 additions & 6 deletions javascript/node/selenium-webdriver/test/chrome/options_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ describe('chrome.Options', function () {
describe('addArguments', function () {
it('takes var_args', function () {
let options = new chrome.Options()
assert.deepEqual(options[symbols.serialize](), {
assert.deepStrictEqual(options[symbols.serialize](), {
browserName: 'chrome',
'goog:chromeOptions': {},
})

options.addArguments('a', 'b')
assert.deepEqual(options[symbols.serialize](), {
assert.deepStrictEqual(options[symbols.serialize](), {
browserName: 'chrome',
'goog:chromeOptions': {
args: ['a', 'b'],
Expand All @@ -44,13 +44,13 @@ describe('chrome.Options', function () {

it('flattens input arrays', function () {
let options = new chrome.Options()
assert.deepEqual(options[symbols.serialize](), {
assert.deepStrictEqual(options[symbols.serialize](), {
browserName: 'chrome',
'goog:chromeOptions': {},
})

options.addArguments(['a', 'b'], 'c', [1, 2], 3)
assert.deepEqual(options[symbols.serialize](), {
assert.deepStrictEqual(options[symbols.serialize](), {
browserName: 'chrome',
'goog:chromeOptions': {
args: ['a', 'b', 'c', 1, 2, 3],
Expand All @@ -65,15 +65,22 @@ describe('chrome.Options', function () {
assert.strictEqual(options.options_.extensions, undefined)

options.addExtensions('a', 'b')
assert.deepEqual(options.options_.extensions, ['a', 'b'])
assert.deepStrictEqual(options.options_.extensions, ['a', 'b'])
})

it('flattens input arrays', function () {
let options = new chrome.Options()
assert.strictEqual(options.options_.extensions, undefined)

options.addExtensions(['a', 'b'], 'c', [1, 2], 3)
assert.deepEqual(options.options_.extensions, ['a', 'b', 'c', 1, 2, 3])
assert.deepStrictEqual(options.options_.extensions, [
'a',
'b',
'c',
1,
2,
3,
])
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ suite(function (env) {
for (let i = 0; i < elements.length; i++) {
ids.push(await elements[i].getAttribute('id'))
}
assert.deepEqual(ids, ['mid', 'above'])
assert.deepStrictEqual(ids, ['mid', 'above'])
})

it('should combine filters', async function () {
Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/test/lib/by_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('by', function () {
],
},
}
assert.deepEqual(relative.marshall(), expected)
assert.deepStrictEqual(relative.marshall(), expected)
})
})

Expand Down
11 changes: 7 additions & 4 deletions javascript/node/selenium-webdriver/test/lib/capabilities_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ describe('Capabilities', function () {
['abc', 'def'],
])
let caps = new Capabilities(m)
assert.deepEqual({ one: 123, abc: 'def' }, caps[Symbols.serialize]())
assert.deepStrictEqual(
{ one: 123, abc: 'def' },
caps[Symbols.serialize]()
)
})

it('does not omit capabilities set to a false-like value', function () {
Expand All @@ -117,7 +120,7 @@ describe('Capabilities', function () {
caps.set('number', 0)
caps.set('string', '')

assert.deepEqual(
assert.deepStrictEqual(
{ bool: false, number: 0, string: '' },
caps[Symbols.serialize]()
)
Expand All @@ -127,14 +130,14 @@ describe('Capabilities', function () {
let caps = new Capabilities()
caps.set('foo', null)
caps.set('bar', 123)
assert.deepEqual({ bar: 123 }, caps[Symbols.serialize]())
assert.deepStrictEqual({ bar: 123 }, caps[Symbols.serialize]())
})

it('omits capabilities with an undefined value', function () {
let caps = new Capabilities()
caps.set('foo', undefined)
caps.set('bar', 123)
assert.deepEqual({ bar: 123 }, caps[Symbols.serialize]())
assert.deepStrictEqual({ bar: 123 }, caps[Symbols.serialize]())
})
})
})
Expand Down
8 changes: 4 additions & 4 deletions javascript/node/selenium-webdriver/test/lib/http_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('http', function () {
var parameters = { sessionId: 'foo', url: 'http://www.google.com' }
var finalPath = http.buildPath('/session/:sessionId/url', parameters)
assert.equal(finalPath, '/session/foo/url')
assert.deepEqual(parameters, { url: 'http://www.google.com' })
assert.deepStrictEqual(parameters, { url: 'http://www.google.com' })
})

it('handles web element references', function () {
Expand All @@ -45,7 +45,7 @@ describe('http', function () {
parameters
)
assert.equal(finalPath, '/session/foo/element/bar/click')
assert.deepEqual(parameters, {})
assert.deepStrictEqual(parameters, {})
})

it('throws if missing a parameter', function () {
Expand Down Expand Up @@ -678,8 +678,8 @@ describe('http', function () {
sinon.match(function (value) {
assert.equal(value.method, method)
assert.equal(value.path, path)
assert.deepEqual(value.data, data)
assert.deepEqual(entries(value.headers), headers)
assert.deepStrictEqual(value.data, data)
assert.deepStrictEqual(entries(value.headers), headers)
return true
})
)
Expand Down
Loading

0 comments on commit 932be4b

Please sign in to comment.