diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index ba2b5eb3..b46ee6b1 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -66,6 +66,7 @@ http_archive( sha256 = "089250b6afda54099d7a3bc4e0f0765451356f329d105a32d1a78703edf70320", strip_prefix = "rules_jasmine-0.3.0", url = "https://github.com/aspect-build/rules_jasmine/archive/refs/tags/v0.3.0.tar.gz", + patches = ["//tools/patches:aspect_rules_jasmine-esm.patch"], ) load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependencies") diff --git a/dependencies.bzl b/dependencies.bzl index 80d398f6..0169e215 100644 --- a/dependencies.bzl +++ b/dependencies.bzl @@ -27,6 +27,7 @@ def rules_prerender_dependencies(): sha256 = "089250b6afda54099d7a3bc4e0f0765451356f329d105a32d1a78703edf70320", strip_prefix = "rules_jasmine-0.3.0", url = "https://github.com/aspect-build/rules_jasmine/archive/refs/tags/v0.3.0.tar.gz", + patches = ["@rules_prerender//tools/patches:aspect_rules_jasmine-esm.patch"], ) maybe( diff --git a/tools/patches/BUILD.bazel b/tools/patches/BUILD.bazel new file mode 100644 index 00000000..f418a3ab --- /dev/null +++ b/tools/patches/BUILD.bazel @@ -0,0 +1 @@ +# Empty package. diff --git a/tools/patches/aspect_rules_jasmine-esm.patch b/tools/patches/aspect_rules_jasmine-esm.patch new file mode 100644 index 00000000..26b7f54c --- /dev/null +++ b/tools/patches/aspect_rules_jasmine-esm.patch @@ -0,0 +1,114 @@ +diff --git docs/rules.md docs/rules.md +index 898c858..b24ca30 100644 +--- docs/rules.md ++++ docs/rules.md +@@ -7,7 +7,7 @@ Public API re-exports + ## jasmine_test + +
+-jasmine_test(jasmine_repository, kwargs)
++jasmine_test(jasmine_repository, module, kwargs)
+ 
+ + +@@ -18,6 +18,7 @@ jasmine_test(jasmine_repository, + | Name | Description | Default Value | + | :------------- | :------------- | :------------- | + | jasmine_repository |

-

| "jasmine" | ++| module |

-

| "cjs" | + | kwargs |

-

| none | + + +diff --git jasmine/defs.bzl jasmine/defs.bzl +index c67bfde..156aa64 100644 +--- jasmine/defs.bzl ++++ jasmine/defs.bzl +@@ -11,14 +11,14 @@ _jasmine_test = rule( + toolchains = js_binary_lib.toolchains, + ) + +-def jasmine_test(jasmine_repository = "jasmine", **kwargs): ++def jasmine_test(jasmine_repository = "jasmine", module = "cjs", **kwargs): + _jasmine_test( + enable_runfiles = select({ + "@aspect_rules_js//js/private:enable_runfiles": True, + "//conditions:default": False, + }), + entry_point = "@{}//:jasmine_entrypoint".format(jasmine_repository), +- junit_reporter = "@{}//:junit_reporter".format(jasmine_repository), ++ junit_reporter = _get_junit_reporter(module, jasmine_repository), + data = kwargs.pop("data", []) + [ + "@{}//:node_modules/jasmine".format(jasmine_repository), + "@{}//:node_modules/jasmine-core".format(jasmine_repository), +@@ -26,3 +26,11 @@ def jasmine_test(jasmine_repository = "jasmine", **kwargs): + ], + **kwargs + ) ++ ++def _get_junit_reporter(module, jasmine_repository): ++ if module == "cjs": ++ return "@{}//:junit_reporter_cjs".format(jasmine_repository) ++ elif module == "esm": ++ return "@{}//:junit_reporter_mjs".format(jasmine_repository) ++ else: ++ fail("Unknown `module` value \"{}\", allowed values are: [\"cjs\", \"esm\"]".format(module)) +diff --git jasmine/private/BUILD.bazel jasmine/private/BUILD.bazel +index 55d7a1c..61339e4 100644 +--- jasmine/private/BUILD.bazel ++++ jasmine/private/BUILD.bazel +@@ -2,7 +2,8 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + + exports_files([ + "runner.js", +- "junit_reporter.js" ++ "junit_reporter.cjs", ++ "junit_reporter.mjs", + ]) + + # gazelle:exclude v*.*.*/* +diff --git jasmine/private/junit_reporter.js jasmine/private/junit_reporter.cjs +similarity index 100% +rename from jasmine/private/junit_reporter.js +rename to jasmine/private/junit_reporter.cjs +diff --git jasmine/private/junit_reporter.mjs jasmine/private/junit_reporter.mjs +new file mode 100644 +index 0000000..a5991d0 +--- /dev/null ++++ jasmine/private/junit_reporter.mjs +@@ -0,0 +1,13 @@ ++import { JUnitXmlReporter } from "jasmine-reporters"; ++import * as path from "path"; ++ ++const xmlOutputFile = process.env.XML_OUTPUT_FILE; ++ ++jasmine.getEnv().addReporter( ++ new JUnitXmlReporter({ ++ filePrefix: path.basename(xmlOutputFile), ++ savePath: path.dirname(xmlOutputFile), ++ consolidate: true, ++ consolidateAll: true, ++ }) ++); +diff --git jasmine/repositories.bzl jasmine/repositories.bzl +index eafc981..314c7aa 100644 +--- jasmine/repositories.bzl ++++ jasmine/repositories.bzl +@@ -50,9 +50,15 @@ If you need custom versions, please file an issue.""".format(jasmine_version, TO + visibility = ["//visibility:public"], + )""", + """copy_file( +- name = "junit_reporter", +- src = "@aspect_rules_jasmine//jasmine/private:junit_reporter.js", +- out = "junit_reporter.js", ++ name = "junit_reporter_cjs", ++ src = "@aspect_rules_jasmine//jasmine/private:junit_reporter.cjs", ++ out = "junit_reporter.cjs", ++ visibility = ["//visibility:public"], ++)""", ++ """copy_file( ++ name = "junit_reporter_mjs", ++ src = "@aspect_rules_jasmine//jasmine/private:junit_reporter.mjs", ++ out = "junit_reporter.mjs", + visibility = ["//visibility:public"], + )""", + ],