Skip to content

Commit

Permalink
WIP: Jasmine ESM support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgp1130 committed Mar 1, 2023
1 parent dd75b21 commit b130c87
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions tools/patches/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty package.
114 changes: 114 additions & 0 deletions tools/patches/aspect_rules_jasmine-esm.patch
Original file line number Diff line number Diff line change
@@ -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

<pre>
-jasmine_test(<a href="#jasmine_test-jasmine_repository">jasmine_repository</a>, <a href="#jasmine_test-kwargs">kwargs</a>)
+jasmine_test(<a href="#jasmine_test-jasmine_repository">jasmine_repository</a>, <a href="#jasmine_test-module">module</a>, <a href="#jasmine_test-kwargs">kwargs</a>)
</pre>


@@ -18,6 +18,7 @@ jasmine_test(<a href="#jasmine_test-jasmine_repository">jasmine_repository</a>,
| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="jasmine_test-jasmine_repository"></a>jasmine_repository | <p align="center"> - </p> | <code>"jasmine"</code> |
+| <a id="jasmine_test-module"></a>module | <p align="center"> - </p> | <code>"cjs"</code> |
| <a id="jasmine_test-kwargs"></a>kwargs | <p align="center"> - </p> | 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"],
)""",
],

0 comments on commit b130c87

Please sign in to comment.