Skip to content

[JS]: Handle optional dependency for @bazel/runfiles #14352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 10, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion javascript/node/selenium-webdriver/testing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -46,6 +45,19 @@ 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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we properly wrap all usages of runfiles later in this file? Maybe we do a check before we use it, and exit quickly if we know it'll never succeed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check for runfiles and implemented a safe, silent exit if not found.

}

/**
* Describes a browser targeted by a {@linkplain suite test suite}.
* @record
Expand Down
Loading