Skip to content

Commit

Permalink
fix: jest_test rule named the same as the macro
Browse files Browse the repository at this point in the history
Makes the macro less leaky abstraction, since bazel query still shows a jest_test.
  • Loading branch information
alexeagle committed Apr 18, 2023
1 parent 70c3fb0 commit f3d27a1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
6.0.0
6.1.1
# The first line of this file is used by Bazelisk and Bazel to be sure
# the right version of Bazel is used to build and test this repo.
# This also defines which version is used on CI.
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Runs tests with the https://jestjs.io/ test runner under Bazel.

rules_jest is just a part of what Aspect provides:

- _Need help?_ This ruleset has support provided by https://aspect.dev.
- See our other Bazel rules, especially those built for rules_js, such as rules_ts for TypeScript: https://github.com/aspect-build
- _Need help?_ This ruleset has support provided by https://aspect.dev.
- See our other Bazel rules, especially those built for rules_js, such as rules_ts for TypeScript: https://github.com/aspect-build

## Installation

Expand All @@ -15,6 +15,8 @@ copy the WORKSPACE snippet into your `WORKSPACE` file.

## Usage

Run all Jest tests in the workspace: `bazel test --test_lang_filters=jest //...`

See the documentation in the [docs](docs/) folder and the example usages in the [example](example/) folder.

> Note that the example also relies on code in the `/WORKSPACE` file in the root of this repo.
22 changes: 3 additions & 19 deletions jest/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@ load("@aspect_bazel_lib//lib:write_source_files.bzl", _write_source_files = "wri
load("@aspect_bazel_lib//lib:utils.bzl", "default_timeout", "to_label")
load("@aspect_bazel_lib//lib:output_files.bzl", _output_files = "output_files")
load("@aspect_rules_js//js:defs.bzl", _js_run_binary = "js_run_binary")
load("@aspect_rules_js//js:libs.bzl", "js_binary_lib")
load("//jest/private:jest_test.bzl", "lib")

_jest_test = rule(
attrs = lib.attrs,
implementation = lib.implementation,
test = True,
toolchains = js_binary_lib.toolchains,
)

# binary rule used for snapshot updates
_jest_binary = rule(
attrs = lib.attrs,
implementation = lib.implementation,
executable = True,
toolchains = js_binary_lib.toolchains,
)
load("//jest/private:jest_test.bzl", jest_binary_rule = "jest_binary", jest_test_rule = "jest_test")

REFERENCE_SNAPSHOT_SUFFIX = "-out"
REFERENCE_SNAPSHOT_DIRECTORY = "out"
Expand Down Expand Up @@ -256,7 +240,7 @@ def jest_test(

# This is the primary {name} jest_test test target
_jest_from_node_modules(
jest_rule = _jest_test,
jest_rule = jest_test_rule,
name = name,
node_modules = node_modules,
config = config,
Expand Down Expand Up @@ -298,7 +282,7 @@ def jest_test(
# This is the generated reference snapshot generator binary target that is used as the
# `tool` in the `js_run_binary` target below to output the reference snapshots.
_jest_from_node_modules(
jest_rule = _jest_binary,
jest_rule = jest_binary_rule,
name = gen_snapshots_bin,
node_modules = node_modules,
config = config,
Expand Down
15 changes: 15 additions & 0 deletions jest/private/jest_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,18 @@ lib = struct(
attrs = _attrs,
implementation = _impl,
)

jest_test = rule(
attrs = lib.attrs,
implementation = lib.implementation,
test = True,
toolchains = js_binary_lib.toolchains,
)

# binary rule used for snapshot updates
jest_binary = rule(
attrs = lib.attrs,
implementation = lib.implementation,
executable = True,
toolchains = js_binary_lib.toolchains,
)

0 comments on commit f3d27a1

Please sign in to comment.