Skip to content

Commit

Permalink
[js + bazel]: Run Node browser tests on the RBE (SeleniumHQ#14194)
Browse files Browse the repository at this point in the history
If you `cd` into `javascript/node/selenium-webdriver` a `pnpm`-based workflow should still work.

This PR also removes a now unused ci-javascript.yml file: everything that this used to do is now handled by the RBE.
  • Loading branch information
shs96c authored and sandeepsuryaprasad committed Oct 29, 2024
1 parent 372aad2 commit a4c0466
Show file tree
Hide file tree
Showing 71 changed files with 433 additions and 306 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ build --nobuild_runfile_links

# More JS magic
build --experimental_allow_unresolved_symlinks
# Avoid a warning about directory tracking being unsound
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1

# Required for faster TS builds
build --@aspect_rules_ts//ts:skipLibCheck=always
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/ci-javascript.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ jobs:
contains(join(github.event.commits.*.message), '[java]') ||
contains(github.event.pull_request.title, '[java]')
javascript:
name: JavaScript
needs: check
uses: ./.github/workflows/ci-javascript.yml
if: >
github.event_name == 'schedule' ||
github.event_name == 'workflow_dispatch' ||
contains(needs.check.outputs.targets, '//javascript') ||
contains(join(github.event.commits.*.message), '[js]') ||
contains(github.event.pull_request.title, '[js]')
python:
name: Python
needs: check
Expand Down
8 changes: 8 additions & 0 deletions .skipped-tests
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
-//javascript/atoms:test-chrome
-//javascript/atoms:test-edge
-//javascript/atoms:test-firefox-beta
-//javascript/node/selenium-webdriver:test-bidi-network-test.js-chrome
-//javascript/node/selenium-webdriver:test-builder-test.js-chrome
-//javascript/node/selenium-webdriver:test-builder-test.js-firefox
-//javascript/node/selenium-webdriver:test-chrome-devtools-test.js-chrome
-//javascript/node/selenium-webdriver:test-chrome-options-test.js-chrome
-//javascript/node/selenium-webdriver:test-chrome-service-test.js-chrome
-//javascript/node/selenium-webdriver:test-firefox-options-test.js-firefox
-//javascript/node/selenium-webdriver:test-lib-capabilities-test.js-chrome
-//py:test-chrome-test/selenium/webdriver/chrome/chrome_launcher_tests.py
-//py:test-chrome-test/selenium/webdriver/chrome/chrome_service_tests.py
-//py:test-chrome-test/selenium/webdriver/chrome/proxy_tests.py
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ linter.configure(
linter.register(name = "rust-rustfmt")

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "18.17.0")
node.toolchain(node_version = "20.9.0")

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm", dev_dependency = True)
use_repo(pnpm, "pnpm")
Expand Down
24 changes: 12 additions & 12 deletions common/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ js_library(
url = "https://storage.googleapis.com/chrome-for-testing-public/126.0.6478.62/linux64/chrome-linux64.zip",
sha256 = "6f42045c9134bdd3cfcea03fb54876ad061da998cabd624c92a25ac6811cd737",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
package(default_visibility = ["//visibility:public"])
filegroup(
Expand All @@ -212,9 +212,9 @@ filegroup(
exports_files(["chrome-linux64/chrome"])
js_library(
copy_to_bin(
name = "chrome-js",
data = [":files"],
srcs = [":files"],
)
""",
)
Expand All @@ -229,14 +229,14 @@ js_library(
"mv 'Chrome.app/Contents/MacOS/Google Chrome for Testing' Chrome.app/Contents/MacOS/Chrome",
],
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
package(default_visibility = ["//visibility:public"])
exports_files(["Chrome.app"])
js_library(
copy_to_bin(
name = "chrome-js",
data = glob(["Chrome.app/**/*"]),
srcs = glob(["Chrome.app/**/*"]),
)
""",
)
Expand All @@ -247,14 +247,14 @@ js_library(
sha256 = "a304e692480c726bae846bf6dee36316305d0b8f4826dfafeab8d6bbbc6e7214",
strip_prefix = "chromedriver-linux64",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
package(default_visibility = ["//visibility:public"])
exports_files(["chromedriver"])
js_library(
copy_to_bin(
name = "chromedriver-js",
data = ["chromedriver"],
srcs = ["chromedriver"],
)
""",
)
Expand All @@ -265,14 +265,14 @@ js_library(
sha256 = "05665a6b5fb71141b5d519998e36f01b650f661942a56dd7f6b929896ae38333",
strip_prefix = "chromedriver-mac-x64",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
package(default_visibility = ["//visibility:public"])
exports_files(["chromedriver"])
js_library(
copy_to_bin(
name = "chromedriver-js",
data = ["chromedriver"],
srcs = ["chromedriver"],
)
""",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void canLocateNodesInAGivenSandbox() {

String sharedId = (String) ((RemoteValue) sharedIdMap.get("sharedId")).getValue().get();
assertThat(sharedId).isEqualTo(nodeId);
}
}

@AfterEach
public void quitDriver() {
Expand Down
27 changes: 11 additions & 16 deletions javascript/node/selenium-webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("@npm//javascript/node/selenium-webdriver:prettier/package_json.bzl", prett
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
load("//common:defs.bzl", "copy_file")
load("//javascript:defs.bzl", "mocha_test")
load("//javascript/private:browsers.bzl", "BROWSERS")

npm_link_all_packages(name = "node_modules")

Expand Down Expand Up @@ -39,6 +40,7 @@ js_library(
"bidi/*.js",
]),
deps = [
":node_modules/@bazel/runfiles",
":node_modules/jszip",
":node_modules/tmp",
":node_modules/ws",
Expand Down Expand Up @@ -117,6 +119,9 @@ js_library(
"test/**/*_test.js",
],
),
deps = [
":node_modules/@bazel/runfiles",
],
)

mocha_test(
Expand Down Expand Up @@ -152,41 +157,31 @@ mocha_test(
],
chdir = package_name(),
data = [
"test-data",
":large-test-srcs",
":node_modules/@bazel/runfiles",
":node_modules/express",
":node_modules/jszip",
":node_modules/mocha",
":node_modules/mocha-junit-reporter",
":node_modules/multer",
":node_modules/serve-index",
":node_modules/sinon",
":node_modules/tmp",
":node_modules/ws",
":test-data",
"//:node_modules/selenium-webdriver",
"//common/extensions:js-lib",
"//common/src/web:js-lib",
"//javascript/node/selenium-webdriver/lib/atoms:find-elements",
"//javascript/node/selenium-webdriver/lib/atoms:get_attribute",
"//javascript/node/selenium-webdriver/lib/atoms:is_displayed",
"//javascript/node/selenium-webdriver/lib/atoms:mutation-listener",
],
] + BROWSERS[browser]["data"],
env = {
"SELENIUM_BROWSER": browser,
},
} | BROWSERS[browser]["env"],
tags = [
browser,
"browser-test",
"no-sandbox",
"requires-network",
"skip-remote",
],
),
]
for test in LARGE_TESTS
for browser in [
"chrome",
"firefox",
]
for browser in BROWSERS.keys()
]

# npm_package does not pick up filegroup sources.
Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/jsdoc_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"destination": "../../../build/docs/api/javascript/",
"recurse": true,
"verbose": true,
"template": "../../../node_modules/clean-jsdoc-theme",
"template": "./node_modules/clean-jsdoc-theme",
"theme_opts": {
"default_theme": "dark",
"displayModuleHeader": true,
Expand Down
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/lib/pinnedScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const crypto = require('node:crypto')
class PinnedScript {
constructor(script) {
this.scriptSource_ = script
// eslint-disable-next-line
this.scriptHandle_ = crypto.randomUUID().replace(/-/gi, '')
}

Expand Down
6 changes: 3 additions & 3 deletions javascript/node/selenium-webdriver/lib/test/httpserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const assert = require('node:assert')
const http = require('node:http')
const url = require('node:url')

const net = require('../../net')
const portprober = require('../../net/portprober')
const promise = require('../..').promise
const net = require('selenium-webdriver/net')
const portprober = require('selenium-webdriver/net/portprober')
const promise = require('selenium-webdriver').promise

/**
* Encapsulates a simple HTTP server for testing. The {@code onrequest}
Expand Down
4 changes: 2 additions & 2 deletions javascript/node/selenium-webdriver/lib/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

//const build = require('./build')
const fileserver = require('./fileserver')
const logging = require('../../lib/logging')
const testing = require('../../testing')
const logging = require('selenium-webdriver/lib/logging')
const testing = require('selenium-webdriver/testing')

//const NO_BUILD = /^1|true$/i.test(process.env['SELENIUM_NO_BUILD'])

Expand Down
14 changes: 11 additions & 3 deletions javascript/node/selenium-webdriver/lib/test/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

const fs = require('node:fs')
const path = require('node:path')
const runfiles = require('@bazel/runfiles')
const { projectRoot } = require('./build')

// PUBLIC API
Expand All @@ -31,8 +32,15 @@ const { projectRoot } = require('./build')
*/
exports.locate = function (filePath) {
const fullPath = path.normalize(path.join(projectRoot(), filePath))
if (!fs.existsSync(fullPath)) {
throw Error('File does not exist: ' + filePath)
if (fs.existsSync(fullPath)) {
return fullPath
}
return fullPath

try {
return runfiles.resolve(filePath)
} catch {
// Fall through
}

throw Error('File does not exist: ' + filePath)
}
9 changes: 5 additions & 4 deletions javascript/node/selenium-webdriver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"node": ">= 14.21.0"
},
"dependencies": {
"@bazel/runfiles": "^5.8.1",
"jszip": "^3.10.1",
"tmp": "^0.2.3",
"ws": "^8.17.1"
},
"devDependencies": {
"@bazel/runfiles": "^5.8.1",
"@eslint/js": "^9.5.0",
"clean-jsdoc-theme": "^4.3.0",
"eslint": "^9.5.0",
Expand All @@ -39,19 +39,20 @@
"eslint-plugin-prettier": "^5.1.3",
"express": "^4.19.2",
"globals": "^15.6.0",
"has-flag": "^4.0.0",
"jsdoc": "^4.0.3",
"mocha": "^10.5.1",
"mocha-junit-reporter": "^2.2.1",
"multer": "1.4.5-lts.1",
"prettier": "^3.3.2",
"serve-index": "^1.9.1",
"sinon": "^17.0.1"
"sinon": "^17.0.1",
"supports-color": "^9.4.0"
},
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "npm run lint && mocha -t 600000 --recursive test",
"test-jasmine": "bazel test //javascript/node/selenium-webdriver:tests",
"test": "bazel test //javascript/node/selenium-webdriver/...",
"generate-docs": "jsdoc --configure jsdoc_conf.json --verbose"
},
"mocha": {
Expand Down
4 changes: 2 additions & 2 deletions javascript/node/selenium-webdriver/test/actions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
const assert = require('node:assert')
const fileServer = require('../lib/test/fileserver')
const { ignore, Pages, suite } = require('../lib/test')
const { Key, Origin } = require('../lib/input')
const { Browser, By, until } = require('..')
const { Key, Origin } = require('selenium-webdriver/lib/input')
const { Browser, By, until } = require('selenium-webdriver')

suite(function (env) {
describe('WebDriver.actions()', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
'use strict'

const assert = require('node:assert')
const { Browser } = require('../../')
const { Browser } = require('selenium-webdriver')
const { suite } = require('../../lib/test')
const Network = require('../../bidi/network')
const { AddInterceptParameters } = require('../../bidi/addInterceptParameters')
const { InterceptPhase } = require('../../bidi/interceptPhase')
const { UrlPattern } = require('../../bidi/urlPattern')
const Network = require('selenium-webdriver/bidi/network')
const { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')
const { InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase')
const { UrlPattern } = require('selenium-webdriver/bidi/urlPattern')

suite(
function (env) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'use strict'

const assert = require('node:assert')
const { Browser } = require('../../')
const { Browser } = require('selenium-webdriver')
const { suite } = require('../../lib/test')

suite(
Expand Down
Loading

0 comments on commit a4c0466

Please sign in to comment.