From 273159eb64384ef7fea2bfe3be8a5ad572bc8381 Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Wed, 1 May 2024 17:09:17 +1000 Subject: [PATCH 1/3] [bazel + js] Allow `bazel build //javascript/...` to work --- .../node/selenium-webdriver/BUILD.bazel | 140 +++++++++++------- 1 file changed, 86 insertions(+), 54 deletions(-) diff --git a/javascript/node/selenium-webdriver/BUILD.bazel b/javascript/node/selenium-webdriver/BUILD.bazel index 86ffcfe90d1e3..74797808e3c2d 100644 --- a/javascript/node/selenium-webdriver/BUILD.bazel +++ b/javascript/node/selenium-webdriver/BUILD.bazel @@ -1,4 +1,5 @@ load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") +load("@aspect_rules_js//js:defs.bzl", "js_library") load("@aspect_rules_js//npm:defs.bzl", "npm_package") load("@npm//:defs.bzl", "npm_link_all_packages") load("@npm//javascript/node/selenium-webdriver:eslint/package_json.bzl", eslint_bin = "bin") @@ -18,31 +19,86 @@ BROWSER_VERSIONS = [ "v124", ] -SRC_FILES = [ - "CHANGES.md", - "README.md", - "package.json", -] + glob([ - "*.js", - "example/*.js", - "http/*.js", - "io/*.js", - "lib/*.js", - "net/*.js", - "remote/*.js", - "testing/*.js", - "devtools/*.js", - "common/*.js", - "bidi/*.js", -]) +XSMALL_TESTS = [ + "test/io/io_test.js", + "test/io/zip_test.js", + "test/lib/by_test.js", + "test/lib/credentials_test.js", + "test/lib/error_test.js", + "test/lib/http_test.js", + "test/lib/input_test.js", + "test/lib/logging_test.js", + "test/lib/promise_test.js", + "test/lib/until_test.js", + "test/lib/virtualauthenticatoroptions_test.js", + "test/lib/webdriver_test.js", + "test/net/index_test.js", + "test/net/portprober_test.js", +] + +js_library( + name = "small-test-srcs", + srcs = XSMALL_TESTS, +) + +js_library( + name = "large-test-srcs", + srcs = glob( + ["test/**/*_test.js"], + exclude = XSMALL_TESTS, + ), +) + +js_library( + name = "test-data", + srcs = glob( + [ + "lib/test/**", + "test/**", + ], + exclude = [ + "test/**/*_test.js", + ], + ), +) + +#TEST_DATA = SRC_FILES + glob( +# [ +# "lib/test/**", +# "test/**", +# ], +# exclude = LARGE_TESTS + SMALL_TESTS, +#) + +js_library( + name = "prod-src-files", + srcs = [ + "CHANGES.md", + "README.md", + "package.json", + ] + glob([ + "*.js", + "example/*.js", + "http/*.js", + "io/*.js", + "lib/*.js", + "net/*.js", + "remote/*.js", + "testing/*.js", + "devtools/*.js", + "common/*.js", + "bidi/*.js", + ]), +) npm_package( name = "selenium-webdriver", - srcs = SRC_FILES + [ + srcs = [ ":license", ":manager-linux", ":manager-macos", ":manager-windows", + ":prod-src-files", "//javascript/node/selenium-webdriver/lib/atoms:find-elements", "//javascript/node/selenium-webdriver/lib/atoms:get_attribute", "//javascript/node/selenium-webdriver/lib/atoms:is_displayed", @@ -64,38 +120,6 @@ pkg_tar( strip_prefix = "selenium-webdriver", ) -#TEST_FILES = glob(["test/**/*_test.js"]) -# -SMALL_TESTS = [ - "test/io/io_test.js", - "test/io/zip_test.js", - "test/lib/by_test.js", - "test/lib/credentials_test.js", - "test/lib/error_test.js", - "test/lib/http_test.js", - "test/lib/input_test.js", - "test/lib/logging_test.js", - "test/lib/promise_test.js", - "test/lib/until_test.js", - "test/lib/virtualauthenticatoroptions_test.js", - "test/lib/webdriver_test.js", - "test/net/index_test.js", - "test/net/portprober_test.js", -] - -LARGE_TESTS = glob( - ["test/**/*_test.js"], - exclude = SMALL_TESTS, -) - -TEST_DATA = SRC_FILES + glob( - [ - "lib/test/**", - "test/**", - ], - exclude = LARGE_TESTS + SMALL_TESTS, -) - mocha_test( name = "small-tests", size = "small", @@ -108,6 +132,8 @@ mocha_test( ":node_modules/sinon", ":node_modules/tmp", ":node_modules/ws", + ":small-test-srcs", + ":test-data", "//:node_modules/selenium-webdriver", "//common/extensions:js-lib", "//common/src/web:js-lib", @@ -115,7 +141,7 @@ mocha_test( "//javascript/node/selenium-webdriver/lib/atoms:get_attribute", "//javascript/node/selenium-webdriver/lib/atoms:is_displayed", "//javascript/node/selenium-webdriver/lib/atoms:mutation-listener", - ] + SMALL_TESTS + TEST_DATA, + ], tags = [ "skip-remote", ], @@ -127,7 +153,9 @@ mocha_test( size = "large", args = ["--retries 1"], chdir = package_name(), - data = LARGE_TESTS + TEST_DATA + [ + data = [ + "test-data", + ":large-test-srcs", ":node_modules/@bazel/runfiles", ":node_modules/express", ":node_modules/jszip", @@ -198,7 +226,7 @@ copy_to_bin( eslint_bin.eslint_test( name = "eslint-test", chdir = package_name(), - data = SRC_FILES + [ + data = [ ":eslint-config", ":node_modules/@eslint/js", ":node_modules/eslint-plugin-mocha", @@ -211,6 +239,7 @@ eslint_bin.eslint_test( ":node_modules/tmp", ":node_modules/ws", ":package-json", + ":prod-src-files", ], tags = [ "lint", @@ -231,9 +260,12 @@ prettier_bin.prettier_test( "--config=.prettierrc", ], chdir = package_name(), - data = SRC_FILES + SMALL_TESTS + LARGE_TESTS + [ + data = [ + ":large-test-srcs", ":prettier-config", ":prettier-ignore", + ":prod-src-files", + ":small-test-srcs", ], tags = [ "lint", From 7cfae91879b6082e1032e546546592ea9abb54a3 Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Wed, 1 May 2024 19:12:17 +1000 Subject: [PATCH 2/3] cp: hackity hack --- javascript/grid-ui/BUILD.bazel | 3 ++- javascript/grid-ui/tsconfig.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/javascript/grid-ui/BUILD.bazel b/javascript/grid-ui/BUILD.bazel index c5441026c51de..19a1095d13d1e 100644 --- a/javascript/grid-ui/BUILD.bazel +++ b/javascript/grid-ui/BUILD.bazel @@ -33,7 +33,6 @@ SRCS = glob( exclude = [ "src/simple.ts", "src/**/*.test.tsx", - # "src/assets/**/*", ], ) @@ -54,7 +53,9 @@ DEPS = [ ts_project( name = "transpile_ts", srcs = SRCS, + allow_js = True, assets = glob(["src/assets/**/*"]), + resolve_json_module = True, tsconfig = "tsconfig.json", deps = DEPS, ) diff --git a/javascript/grid-ui/tsconfig.json b/javascript/grid-ui/tsconfig.json index faa271910723a..544c5472c9891 100644 --- a/javascript/grid-ui/tsconfig.json +++ b/javascript/grid-ui/tsconfig.json @@ -22,7 +22,7 @@ "types": [ "@types/node" ], - "sourceMap": false, + "sourceMap": false }, "include": [ "src" From 096978d59f7731ce7812f332a919d6bb0b02805c Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Wed, 1 May 2024 19:17:55 +1000 Subject: [PATCH 3/3] Reorganise the build file --- .../node/selenium-webdriver/BUILD.bazel | 94 +++++++++---------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/javascript/node/selenium-webdriver/BUILD.bazel b/javascript/node/selenium-webdriver/BUILD.bazel index 74797808e3c2d..bffd19b5f47c4 100644 --- a/javascript/node/selenium-webdriver/BUILD.bazel +++ b/javascript/node/selenium-webdriver/BUILD.bazel @@ -19,57 +19,6 @@ BROWSER_VERSIONS = [ "v124", ] -XSMALL_TESTS = [ - "test/io/io_test.js", - "test/io/zip_test.js", - "test/lib/by_test.js", - "test/lib/credentials_test.js", - "test/lib/error_test.js", - "test/lib/http_test.js", - "test/lib/input_test.js", - "test/lib/logging_test.js", - "test/lib/promise_test.js", - "test/lib/until_test.js", - "test/lib/virtualauthenticatoroptions_test.js", - "test/lib/webdriver_test.js", - "test/net/index_test.js", - "test/net/portprober_test.js", -] - -js_library( - name = "small-test-srcs", - srcs = XSMALL_TESTS, -) - -js_library( - name = "large-test-srcs", - srcs = glob( - ["test/**/*_test.js"], - exclude = XSMALL_TESTS, - ), -) - -js_library( - name = "test-data", - srcs = glob( - [ - "lib/test/**", - "test/**", - ], - exclude = [ - "test/**/*_test.js", - ], - ), -) - -#TEST_DATA = SRC_FILES + glob( -# [ -# "lib/test/**", -# "test/**", -# ], -# exclude = LARGE_TESTS + SMALL_TESTS, -#) - js_library( name = "prod-src-files", srcs = [ @@ -120,6 +69,49 @@ pkg_tar( strip_prefix = "selenium-webdriver", ) +SMALL_TESTS = [ + "test/io/io_test.js", + "test/io/zip_test.js", + "test/lib/by_test.js", + "test/lib/credentials_test.js", + "test/lib/error_test.js", + "test/lib/http_test.js", + "test/lib/input_test.js", + "test/lib/logging_test.js", + "test/lib/promise_test.js", + "test/lib/until_test.js", + "test/lib/virtualauthenticatoroptions_test.js", + "test/lib/webdriver_test.js", + "test/net/index_test.js", + "test/net/portprober_test.js", +] + +js_library( + name = "small-test-srcs", + srcs = SMALL_TESTS, +) + +js_library( + name = "large-test-srcs", + srcs = glob( + ["test/**/*_test.js"], + exclude = SMALL_TESTS, + ), +) + +js_library( + name = "test-data", + srcs = glob( + [ + "lib/test/**", + "test/**", + ], + exclude = [ + "test/**/*_test.js", + ], + ), +) + mocha_test( name = "small-tests", size = "small",