From b31dd1b11afcace79d4d4c95b8a825f48e9fb665 Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Wed, 7 Aug 2024 19:23:46 +0530 Subject: [PATCH 1/5] [JS]: Handle optional dependency for @bazel/runfiles --- javascript/node/selenium-webdriver/testing/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/javascript/node/selenium-webdriver/testing/index.js b/javascript/node/selenium-webdriver/testing/index.js index 116009e26ea22..df3c21ce13b0b 100644 --- a/javascript/node/selenium-webdriver/testing/index.js +++ b/javascript/node/selenium-webdriver/testing/index.js @@ -35,7 +35,6 @@ const fs = require('node:fs') const path = require('node:path') const { isatty } = require('node:tty') -const { runfiles } = require('@bazel/runfiles') const chrome = require('../chrome') const edge = require('../edge') const firefox = require('../firefox') @@ -46,6 +45,18 @@ const { Browser } = require('../lib/capabilities') const { Builder } = require('../index') const { getBinaryPaths } = require('../common/driverFinder') +let runfiles; +try { + // Attempt to require @bazel/runfiles + runfiles = require('@bazel/runfiles').runfiles; +} catch (error) { + // Handle error if @bazel/runfiles is not supported by mocha + console.error('Error requiring @bazel/runfiles:', error.message); + console.error('Note: If you are running tests with Mocha or Jasmine, this module is not needed.'); + console.error('For more details, see: https://github.com/bazelbuild/rules_nodejs/issues/3770'); + runfiles = null; // Set to null if not available +} + /** * Describes a browser targeted by a {@linkplain suite test suite}. * @record From 3947ee2dc4cfef9c046c095a9883af48d3ea3e61 Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Wed, 7 Aug 2024 19:54:12 +0530 Subject: [PATCH 2/5] fix lint issue --- javascript/node/selenium-webdriver/testing/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/javascript/node/selenium-webdriver/testing/index.js b/javascript/node/selenium-webdriver/testing/index.js index df3c21ce13b0b..62423903fb2fb 100644 --- a/javascript/node/selenium-webdriver/testing/index.js +++ b/javascript/node/selenium-webdriver/testing/index.js @@ -45,16 +45,17 @@ const { Browser } = require('../lib/capabilities') const { Builder } = require('../index') const { getBinaryPaths } = require('../common/driverFinder') -let runfiles; +let runfiles try { // Attempt to require @bazel/runfiles - runfiles = require('@bazel/runfiles').runfiles; + runfiles = require('@bazel/runfiles').runfiles } catch (error) { // Handle error if @bazel/runfiles is not supported by mocha - console.error('Error requiring @bazel/runfiles:', error.message); - console.error('Note: If you are running tests with Mocha or Jasmine, this module is not needed.'); - console.error('For more details, see: https://github.com/bazelbuild/rules_nodejs/issues/3770'); - runfiles = null; // Set to null if not available + const errorMessage = `Error requiring @bazel/runfiles: ${error.message}\n + Note: If you are running tests with Mocha or Jasmine, this module is not needed.\n + For more details, see: https://github.com/bazelbuild/rules_nodejs/issues/3770` + console.error(errorMessage) + runfiles = null // Set to null if not available } /** From f8a137bbd5a66d227de993ceaa6df3a3f8464b0b Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Thu, 8 Aug 2024 21:02:20 +0530 Subject: [PATCH 3/5] [js]: remove console msg and safe exit if runfiles never found --- .../node/selenium-webdriver/testing/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/javascript/node/selenium-webdriver/testing/index.js b/javascript/node/selenium-webdriver/testing/index.js index 62423903fb2fb..757d2cec493a8 100644 --- a/javascript/node/selenium-webdriver/testing/index.js +++ b/javascript/node/selenium-webdriver/testing/index.js @@ -44,18 +44,14 @@ const safari = require('../safari') const { Browser } = require('../lib/capabilities') const { Builder } = require('../index') const { getBinaryPaths } = require('../common/driverFinder') +const { process } = require('node:process') let runfiles try { // Attempt to require @bazel/runfiles runfiles = require('@bazel/runfiles').runfiles -} catch (error) { - // Handle error if @bazel/runfiles is not supported by mocha - const errorMessage = `Error requiring @bazel/runfiles: ${error.message}\n - Note: If you are running tests with Mocha or Jasmine, this module is not needed.\n - For more details, see: https://github.com/bazelbuild/rules_nodejs/issues/3770` - console.error(errorMessage) - runfiles = null // Set to null if not available +} catch { + // Fall through } /** @@ -552,6 +548,11 @@ function getTestHook(name) { } function locate(fileLike) { + if (!runfiles) { + // eslint-disable-next-line n/no-process-exit + process.exit(1) + } + if (fs.existsSync(fileLike)) { return fileLike } From f8888f065727d7bb6309c18c5a75f832a9a32633 Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Fri, 9 Aug 2024 00:48:48 +0530 Subject: [PATCH 4/5] [js]: fix rbe build(use global node process) --- javascript/node/selenium-webdriver/testing/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/javascript/node/selenium-webdriver/testing/index.js b/javascript/node/selenium-webdriver/testing/index.js index 757d2cec493a8..02005087f5e14 100644 --- a/javascript/node/selenium-webdriver/testing/index.js +++ b/javascript/node/selenium-webdriver/testing/index.js @@ -44,7 +44,6 @@ const safari = require('../safari') const { Browser } = require('../lib/capabilities') const { Builder } = require('../index') const { getBinaryPaths } = require('../common/driverFinder') -const { process } = require('node:process') let runfiles try { From cf34a5c884b5b231c049dcb8e50de292bff76fd0 Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Sat, 10 Aug 2024 15:42:22 +0530 Subject: [PATCH 5/5] [JS]:Fix error handling for missing runfiles --- javascript/node/selenium-webdriver/testing/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/javascript/node/selenium-webdriver/testing/index.js b/javascript/node/selenium-webdriver/testing/index.js index 02005087f5e14..c96f18d453592 100644 --- a/javascript/node/selenium-webdriver/testing/index.js +++ b/javascript/node/selenium-webdriver/testing/index.js @@ -547,15 +547,14 @@ function getTestHook(name) { } function locate(fileLike) { - if (!runfiles) { - // eslint-disable-next-line n/no-process-exit - process.exit(1) - } - if (fs.existsSync(fileLike)) { return fileLike } + if (!runfiles) { + throw new Error('Unable to find ' + fileLike) + } + try { return runfiles.resolve(fileLike) } catch {