Skip to content

Commit

Permalink
fix: don't add jest-cli and jest-unit if they are already in user pro…
Browse files Browse the repository at this point in the history
…vided data (#120)
  • Loading branch information
gregmagolan authored Apr 12, 2023
1 parent 369f90e commit 5416c59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions example/simple/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ jest_test(
node_modules = "//:node_modules",
)

jest_test(
name = "test_user_data",
data = [
"index.js",
"index.test.js",
# should be able to add jest-cli & jest-junit explicitly in data
"//:node_modules/jest-cli",
"//:node_modules/jest-junit",
],
node_modules = "//:node_modules",
)

jest_test(
name = "js_config_test",
config = "jest.config.js",
Expand Down
17 changes: 13 additions & 4 deletions jest/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ REFERENCE_BUILD_TARGET_SUFFIX = "_ref_snapshots"
UPDATE_SNAPSHOTS_TARGET_SUFFIX = "_update_snapshots"

def _jest_from_node_modules(jest_rule, name, node_modules, auto_configure_reporters, **kwargs):
data = kwargs.pop("data", []) + ["{}/jest-cli".format(node_modules)]
data = kwargs.pop("data", [])

if auto_configure_reporters:
data.append("{}/jest-junit".format(node_modules))
jest_cli_dep = "{}/jest-cli".format(node_modules)
jest_unit_dep = "{}/jest-junit".format(node_modules)

if jest_cli_dep not in data:
data.append(jest_cli_dep)

if auto_configure_reporters and jest_unit_dep not in data:
data.append(jest_unit_dep)

jest_rule(
name = name,
Expand Down Expand Up @@ -80,7 +86,10 @@ def jest_test(
node_modules: Label pointing to the linked node_modules target where jest is linked, e.g. `//:node_modules`.
`jest-cli` must be linked into the node_modules supplied.
`jest-junit` is also required by default when `auto_configure_reporters` is True
`jest-junit` is also required by default when `auto_configure_reporters` is True.
NB: Only the required npm packages are included in data from `//:node_modules`. Other npm packages
are not included as inputs.
config: "Optional Jest config file. See https://jestjs.io/docs/configuration.
Expand Down

0 comments on commit 5416c59

Please sign in to comment.