diff --git a/jest.bzl b/jest.bzl new file mode 100644 index 0000000..43e82e7 --- /dev/null +++ b/jest.bzl @@ -0,0 +1,29 @@ +load("@npm//jest-cli:index.bzl", "jest", _jest_test = "jest_test") + +def jest_test(name, srcs, deps, jest_config, **kwargs): + "A macro around the autogenerated jest_test rule" + templated_args = [ + "--no-cache", + "--no-watchman", + "--ci", + "--colors", + ] + templated_args.extend(["--config", "$(rootpath %s)" % jest_config]) + for src in srcs: + templated_args.extend(["--runTestsByPath", "$(rootpaths %s)" % src]) + + data = [jest_config] + srcs + deps + _jest_test( + name = name, + data = data, + templated_args = templated_args, + **kwargs + ) + + # This rule is used specifically to update snapshots via `bazel run` + jest( + name = "%s.update" % name, + data = data, + templated_args = templated_args + ["-u"], + **kwargs + ) diff --git a/jest.config.js b/jest.config.js index c0a7a41..1ddea6e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,4 @@ module.exports = { reporters: ['default'], testEnvironment: 'node', - testMatch: ['**/*.test.js'], }; diff --git a/ts/lib/greet/BUILD.bazel b/ts/lib/greet/BUILD.bazel index 0ec00d8..d173daa 100644 --- a/ts/lib/greet/BUILD.bazel +++ b/ts/lib/greet/BUILD.bazel @@ -1,6 +1,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "js_library") load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project") -load("@npm//jest-cli:index.bzl", "jest_test") +load("//:jest.bzl", "jest_test") package(default_visibility = ["//visibility:public"]) @@ -28,18 +28,7 @@ js_library( jest_test( name = "ts_greet_test", - args = [ - "--no-cache", - "--no-watchman", - "--ci", - "--colors", - "--config", - "jest.config.js", - ], - data = [ - ":greet", - ":package.json", - ":tsconfig-greet", - "//:jest.config.js", - ], + srcs = [":tsconfig"], + jest_config = "//:jest.config.js", + deps = [], )