From ef43c7a87fb19144f32d05865453264e33580be1 Mon Sep 17 00:00:00 2001 From: Mark Caudill Date: Wed, 9 Dec 2020 20:05:57 -0500 Subject: [PATCH] Fix issue with jest not supporting symlinks This adds jest.bzl and uses it to pass in specific tests. See https://github.com/facebook/jest/pull/7549 --- jest.bzl | 29 +++++++++++++++++++++++++++++ jest.config.js | 1 - ts/lib/greet/BUILD.bazel | 19 ++++--------------- 3 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 jest.bzl 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 = [], )