Skip to content

Commit 5543c58

Browse files
authored
[node] Update ESLint setup (#8939)
* chore: Update ESLint setup Bump to latest ESLint plugins and dependencies * fix: NPM audit warnings
1 parent 08b0ae9 commit 5543c58

File tree

8 files changed

+335
-193
lines changed

8 files changed

+335
-193
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
devtools/generator/

javascript/node/selenium-webdriver/.eslintrc.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ module.exports = {
44
node: true,
55
es6: true,
66
},
7-
extends: ['eslint:recommended', 'plugin:node/recommended', 'prettier'],
8-
plugins: ['prettier', 'no-only-tests'],
7+
extends: [
8+
'eslint:recommended',
9+
'plugin:node/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
plugins: ['no-only-tests'],
913
rules: {
10-
'prettier/prettier': 'error',
1114
'no-const-assign': 'error',
1215
'no-this-before-super': 'error',
1316
'no-undef': 'error',

javascript/node/selenium-webdriver/chromium.js

+91-34
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ class Options extends Capabilities {
569569
return extension.toString('base64')
570570
}
571571
return io
572-
.read(/** @type {string} */(extension))
572+
.read(/** @type {string} */ (extension))
573573
.then((buffer) => buffer.toString('base64'))
574574
})
575575
}
@@ -622,7 +622,7 @@ class Driver extends webdriver.WebDriver {
622622
* implementation.
623623
* @override
624624
*/
625-
setFileDetector() { }
625+
setFileDetector() {}
626626

627627
/**
628628
* Schedules a command to launch Chrome App with given ID.
@@ -776,34 +776,52 @@ class Driver extends webdriver.WebDriver {
776776
* @param connection CDP Connection
777777
*/
778778
async register(username, password, connection) {
779-
await connection.execute("Network.setCacheDisabled", this.getRandomNumber(1, 10), {
780-
cacheDisabled: true,
781-
}, null);
779+
await connection.execute(
780+
'Network.setCacheDisabled',
781+
this.getRandomNumber(1, 10),
782+
{
783+
cacheDisabled: true,
784+
},
785+
null
786+
)
782787

783788
this._wsConnection.on('message', (message) => {
784789
const params = JSON.parse(message)
785790

786791
if (params.method === 'Fetch.authRequired') {
787792
const requestParams = params['params']
788-
connection.execute('Fetch.continueWithAuth', this.getRandomNumber(1, 10), {
789-
requestId: requestParams['requestId'],
790-
authChallengeResponse: {
791-
response: 'ProvideCredentials',
792-
username: username,
793-
password: password,
793+
connection.execute(
794+
'Fetch.continueWithAuth',
795+
this.getRandomNumber(1, 10),
796+
{
797+
requestId: requestParams['requestId'],
798+
authChallengeResponse: {
799+
response: 'ProvideCredentials',
800+
username: username,
801+
password: password,
802+
},
794803
}
795-
})
804+
)
796805
} else if (params.method === 'Fetch.requestPaused') {
797806
const requestPausedParams = params['params']
798-
connection.execute('Fetch.continueRequest', this.getRandomNumber(1, 10), {
799-
requestId: requestPausedParams['requestId'],
800-
})
807+
connection.execute(
808+
'Fetch.continueRequest',
809+
this.getRandomNumber(1, 10),
810+
{
811+
requestId: requestPausedParams['requestId'],
812+
}
813+
)
801814
}
802815
})
803816

804-
await connection.execute('Fetch.enable', 1, {
805-
handleAuthRequests: true,
806-
}, null)
817+
await connection.execute(
818+
'Fetch.enable',
819+
1,
820+
{
821+
handleAuthRequests: true,
822+
},
823+
null
824+
)
807825
}
808826

809827
/**
@@ -813,7 +831,12 @@ class Driver extends webdriver.WebDriver {
813831
* @returns {Promise<void>}
814832
*/
815833
async onLogEvent(connection, callback) {
816-
await connection.execute('Runtime.enable', this.getRandomNumber(1, 10), {}, null)
834+
await connection.execute(
835+
'Runtime.enable',
836+
this.getRandomNumber(1, 10),
837+
{},
838+
null
839+
)
817840

818841
this._wsConnection.on('message', (message) => {
819842
const params = JSON.parse(message)
@@ -823,7 +846,7 @@ class Driver extends webdriver.WebDriver {
823846
let event = {
824847
type: consoleEventParams['type'],
825848
timestamp: new Date(consoleEventParams['timestamp']),
826-
args: consoleEventParams['args']
849+
args: consoleEventParams['args'],
827850
}
828851

829852
callback(event)
@@ -856,7 +879,12 @@ class Driver extends webdriver.WebDriver {
856879
* @returns {Promise<void>}
857880
*/
858881
async onLogException(connection, callback) {
859-
await connection.execute('Runtime.enable', this.getRandomNumber(1, 10), {}, null)
882+
await connection.execute(
883+
'Runtime.enable',
884+
this.getRandomNumber(1, 10),
885+
{},
886+
null
887+
)
860888

861889
this._wsConnection.on('message', (message) => {
862890
const params = JSON.parse(message)
@@ -879,33 +907,62 @@ class Driver extends webdriver.WebDriver {
879907
* @returns {Promise<void>}
880908
*/
881909
async logMutationEvents(connection, callback) {
882-
await connection.execute('Runtime.enable', this.getRandomNumber(1, 10), {}, null)
883-
await connection.execute('Page.enable', this.getRandomNumber(1, 10), {}, null)
910+
await connection.execute(
911+
'Runtime.enable',
912+
this.getRandomNumber(1, 10),
913+
{},
914+
null
915+
)
916+
await connection.execute(
917+
'Page.enable',
918+
this.getRandomNumber(1, 10),
919+
{},
920+
null
921+
)
884922

885-
await connection.execute('Runtime.addBinding', this.getRandomNumber(1, 10), {
886-
name: '__webdriver_attribute',
887-
}, null)
923+
await connection.execute(
924+
'Runtime.addBinding',
925+
this.getRandomNumber(1, 10),
926+
{
927+
name: '__webdriver_attribute',
928+
},
929+
null
930+
)
888931

889-
const mutationListener
932+
let mutationListener = ''
890933
try {
891934
// Depending on what is running the code it could appear in 2 different places which is why we try
892935
// here and then the other location
893-
mutationListener = fs.readFileSync('./javascript/node/selenium-webdriver/lib/atoms/mutation-listener.js', 'utf-8').toString()
936+
mutationListener = fs
937+
.readFileSync(
938+
'./javascript/node/selenium-webdriver/lib/atoms/mutation-listener.js',
939+
'utf-8'
940+
)
941+
.toString()
894942
} catch {
895-
mutationListener = fs.readFileSync('./lib/atoms/mutation-listener.js', 'utf-8').toString()
943+
mutationListener = fs
944+
.readFileSync('./lib/atoms/mutation-listener.js', 'utf-8')
945+
.toString()
896946
}
897947

898948
this.executeScript(mutationListener)
899949

900-
await connection.execute('Page.addScriptToEvaluateOnNewDocument', this.getRandomNumber(1, 10), {
901-
source: mutationListener,
902-
}, null)
950+
await connection.execute(
951+
'Page.addScriptToEvaluateOnNewDocument',
952+
this.getRandomNumber(1, 10),
953+
{
954+
source: mutationListener,
955+
},
956+
null
957+
)
903958

904959
this._wsConnection.on('message', async (message) => {
905960
const params = JSON.parse(message)
906961
if (params.method === 'Runtime.bindingCalled') {
907962
let payload = JSON.parse(params['params']['payload'])
908-
let elements = await this.findElements({ css: "*[data-__webdriver_id=" + payload['target'] })
963+
let elements = await this.findElements({
964+
css: '*[data-__webdriver_id=' + payload['target'],
965+
})
909966

910967
if (elements.length === 0) {
911968
return
@@ -915,7 +972,7 @@ class Driver extends webdriver.WebDriver {
915972
element: elements[0],
916973
attribute_name: payload['name'],
917974
current_value: payload['value'],
918-
old_value: payload['oldValue']
975+
old_value: payload['oldValue'],
919976
}
920977
callback(event)
921978
}

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

+16-14
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ exports.alertIsPresent = function alertIsPresent() {
137137
* @return {!Condition<boolean>} The new condition.
138138
*/
139139
exports.titleIs = function titleIs(title) {
140-
return new Condition('for title to be ' + JSON.stringify(title), function (
141-
driver
142-
) {
143-
return driver.getTitle().then(function (t) {
144-
return t === title
145-
})
146-
})
140+
return new Condition(
141+
'for title to be ' + JSON.stringify(title),
142+
function (driver) {
143+
return driver.getTitle().then(function (t) {
144+
return t === title
145+
})
146+
}
147+
)
147148
}
148149

149150
/**
@@ -188,13 +189,14 @@ exports.titleMatches = function titleMatches(regex) {
188189
* @return {!Condition<boolean>} The new condition.
189190
*/
190191
exports.urlIs = function urlIs(url) {
191-
return new Condition('for URL to be ' + JSON.stringify(url), function (
192-
driver
193-
) {
194-
return driver.getCurrentUrl().then(function (u) {
195-
return u === url
196-
})
197-
})
192+
return new Condition(
193+
'for URL to be ' + JSON.stringify(url),
194+
function (driver) {
195+
return driver.getCurrentUrl().then(function (u) {
196+
return u === url
197+
})
198+
}
199+
)
198200
}
199201

200202
/**

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ function isFree(port, opt_host) {
5252

5353
function findFreePort(opt_host) {
5454
return new Promise((resolve, reject) => {
55-
const server = net.createServer();
56-
server.on('listening', function() {
57-
resolve(server.address().port);
58-
server.close();
59-
});
55+
const server = net.createServer()
56+
server.on('listening', function () {
57+
resolve(server.address().port)
58+
server.close()
59+
})
6060
server.on('error', (e) => {
6161
if (e.code === 'EADDRINUSE' || e.code === 'EACCES') {
6262
resolve('Unable to find a free port')
6363
} else {
6464
reject(e)
6565
}
66-
});
66+
})
6767
// By providing 0 we let the operative system find an arbitrary port
68-
server.listen(0, opt_host);
69-
});
68+
server.listen(0, opt_host)
69+
})
7070
}
7171

7272
// PUBLIC API

0 commit comments

Comments
 (0)