Skip to content

Commit e70e223

Browse files
authored
[js] update code format, public API exports, remove deprecated legacy (#10110)
1 parent 5dfaa6a commit e70e223

5 files changed

Lines changed: 19 additions & 89 deletions

File tree

javascript/node/selenium-webdriver/lib/error.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -495,23 +495,6 @@ function encodeError(err) {
495495
return { error: code, message: message }
496496
}
497497

498-
/**
499-
* Checks a response object from a server that adheres to the W3C WebDriver
500-
* protocol.
501-
* @param {*} data The response data to check.
502-
* @return {*} The response data if it was not an encoded error.
503-
* @throws {WebDriverError} the decoded error, if present in the data object.
504-
* @deprecated Use {@link #throwDecodedError(data)} instead.
505-
* @see https://w3c.github.io/webdriver/webdriver-spec.html#protocol
506-
*/
507-
function checkResponse(data) {
508-
if (data && typeof data.error === 'string') {
509-
let ctor = ERROR_CODE_TO_TYPE.get(data.error) || WebDriverError
510-
throw new ctor(data.message)
511-
}
512-
return data
513-
}
514-
515498
/**
516499
* Tests if the given value is a valid error response object according to the
517500
* W3C WebDriver spec.
@@ -620,8 +603,6 @@ module.exports = {
620603
UnknownCommandError,
621604
UnknownMethodError,
622605
UnsupportedOperationError,
623-
624-
checkResponse,
625606
checkLegacyResponse,
626607
encodeError,
627608
isErrorResponse,

javascript/node/selenium-webdriver/net/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ function getLoInterface() {
3535
* @param {string} family The IP family (IPv4 or IPv6). Defaults to IPv4.
3636
* @return {(string|undefined)} The located IP address or undefined.
3737
*/
38-
function getAddress(loopback, family) {
38+
function getIPAddress(loopback, family) {
3939
let interfaces
4040
if (loopback) {
41-
let lo = getLoInterface()
41+
const lo = getLoInterface()
4242
interfaces = lo ? [lo] : null
4343
}
4444
interfaces = interfaces || os.networkInterfaces()
@@ -63,17 +63,17 @@ function getAddress(loopback, family) {
6363
* @param {string=} family The IP family to retrieve. Defaults to "IPv4".
6464
* @return {(string|undefined)} The IP address or undefined if not available.
6565
*/
66-
exports.getAddress = function (family = 'IPv4') {
67-
return getAddress(false, family)
66+
function getAddress(family = 'IPv4') {
67+
return getIPAddress(false, family)
6868
}
6969

7070
/**
7171
* Retrieves a loopback address for this machine.
7272
* @param {string=} family The IP family to retrieve. Defaults to "IPv4".
7373
* @return {(string|undefined)} The IP address or undefined if not available.
7474
*/
75-
exports.getLoopbackAddress = function (family = 'IPv4') {
76-
return getAddress(true, family)
75+
function getLoopbackAddress(family = 'IPv4') {
76+
return getIPAddress(true, family)
7777
}
7878

7979
/**
@@ -84,7 +84,7 @@ exports.getLoopbackAddress = function (family = 'IPv4') {
8484
* @return {{host: string, port: ?number}} A host and port. If no port is
8585
* present in the argument `hostport`, port is null.
8686
*/
87-
exports.splitHostAndPort = function (hostport) {
87+
function splitHostAndPort(hostport) {
8888
let lastIndex = hostport.lastIndexOf(':')
8989
if (lastIndex < 0) {
9090
return { host: hostport, port: null }
@@ -105,3 +105,10 @@ exports.splitHostAndPort = function (hostport) {
105105
let port = parseInt(hostport.slice(lastIndex + 1), 10)
106106
return { host, port }
107107
}
108+
109+
// PUBLIC API
110+
module.exports = {
111+
splitHostAndPort,
112+
getLoopbackAddress,
113+
getAddress,
114+
}

javascript/node/selenium-webdriver/net/portprober.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function findFreePort(opt_host) {
7070
}
7171

7272
// PUBLIC API
73-
74-
exports.findFreePort = findFreePort
75-
exports.isFree = isFree
73+
module.exports = {
74+
findFreePort,
75+
isFree,
76+
}

javascript/node/selenium-webdriver/remote/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,5 +623,5 @@ module.exports = {
623623
FileDetector,
624624
SeleniumServer,
625625
// Exported for API docs.
626-
ServiceOptions
626+
ServiceOptions,
627627
}

javascript/node/selenium-webdriver/test/lib/error_test.js

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,6 @@ describe('error', function () {
2121
let assert = require('assert')
2222
let error = require('../../lib/error')
2323

24-
describe('checkResponse', function () {
25-
it('defaults to WebDriverError if type is unrecognized', function () {
26-
assert.throws(
27-
() => error.checkResponse({ error: 'foo', message: 'hi there' }),
28-
(e) => {
29-
assert.strictEqual(e.constructor, error.WebDriverError)
30-
return true
31-
}
32-
)
33-
})
34-
35-
it('does not throw if error property is not a string', function () {
36-
let resp = { error: 123, message: 'abc123' }
37-
let out = error.checkResponse(resp)
38-
assert.strictEqual(out, resp)
39-
})
40-
41-
test('unknown error', error.WebDriverError)
42-
test('element not interactable', error.ElementNotInteractableError)
43-
test('element not selectable', error.ElementNotSelectableError)
44-
test('insecure certificate', error.InsecureCertificateError)
45-
test('invalid argument', error.InvalidArgumentError)
46-
test('invalid cookie domain', error.InvalidCookieDomainError)
47-
test('invalid coordinates', error.InvalidCoordinatesError)
48-
test('invalid element state', error.InvalidElementStateError)
49-
test('invalid selector', error.InvalidSelectorError)
50-
test('invalid session id', error.NoSuchSessionError)
51-
test('javascript error', error.JavascriptError)
52-
test('move target out of bounds', error.MoveTargetOutOfBoundsError)
53-
test('no such alert', error.NoSuchAlertError)
54-
test('no such cookie', error.NoSuchCookieError)
55-
test('no such element', error.NoSuchElementError)
56-
test('no such frame', error.NoSuchFrameError)
57-
test('no such window', error.NoSuchWindowError)
58-
test('script timeout', error.ScriptTimeoutError)
59-
test('session not created', error.SessionNotCreatedError)
60-
test('stale element reference', error.StaleElementReferenceError)
61-
test('timeout', error.TimeoutError)
62-
test('unable to set cookie', error.UnableToSetCookieError)
63-
test('unable to capture screen', error.UnableToCaptureScreenError)
64-
test('unexpected alert open', error.UnexpectedAlertOpenError)
65-
test('unknown command', error.UnknownCommandError)
66-
test('unknown method', error.UnknownMethodError)
67-
test('unsupported operation', error.UnsupportedOperationError)
68-
69-
function test(status, expectedType) {
70-
it(`"${status}" => ${expectedType.name}`, function () {
71-
assert.throws(
72-
() => error.checkResponse({ error: status, message: 'oops' }),
73-
(e) => {
74-
assert.strictEqual(expectedType, e.constructor)
75-
assert.strictEqual(e.message, 'oops')
76-
return true
77-
}
78-
)
79-
})
80-
}
81-
})
82-
8324
describe('encodeError', function () {
8425
describe('defaults to an unknown error', function () {
8526
it('for a generic error value', function () {

0 commit comments

Comments
 (0)