From 61f6c3b34b2a6ce83db2ffeb6bc8601b360d6d66 Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Mon, 12 Oct 2020 17:38:33 -0400 Subject: [PATCH] fix(common): fix utils tests by improving jest dependency resolution --- hack/jest.bzl | 8 +++++--- hack/react.bzl | 25 ++----------------------- hack/utils.bzl | 22 ++++++++++++++++++++++ src/common/utils/BUILD.bazel | 14 ++++++++------ 4 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 hack/utils.bzl diff --git a/hack/jest.bzl b/hack/jest.bzl index c08418a..7ccb3bd 100644 --- a/hack/jest.bzl +++ b/hack/jest.bzl @@ -1,7 +1,9 @@ # Copied from https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/jest.bzl -# Licensed under Apache-2.0, not modified. +# Licensed under Apache-2.0, modifications made: +# - improved dependency resolution load("@npm//jest-cli:index.bzl", "jest", _jest_test = "jest_test") +load("//:hack/utils.bzl", "render_deps") DEFAULT_DEPS = [ "@npm//ts-jest", @@ -25,7 +27,7 @@ def _impl_jest_test(name, srcs, deps, jest_config, **kwargs): "--no-cache", "--no-watchman", "--ci", - "--colors", + "--no-colors", ] templated_args.extend(["--config", "$(rootpath %s)" % jest_config]) for src in srcs: @@ -51,6 +53,6 @@ def jest_test(src, deps = []): _impl_jest_test( name = src[1:] + "_test", srcs = native.glob(["*.spec.ts", "*.spec.tsx"]), - deps = [src] + deps + DEFAULT_DEPS, + deps = [src] + render_deps(deps) + DEFAULT_DEPS, jest_config = "//:jest.config.js", ) diff --git a/hack/react.bzl b/hack/react.bzl index 2b1c0f3..90c3c34 100644 --- a/hack/react.bzl +++ b/hack/react.bzl @@ -1,26 +1,5 @@ load("@npm//@bazel/typescript:index.bzl", "ts_library") - -def _render_deps(deps = []): - output_deps = [] - - has_added_grpc_deps = False - - for dep in deps: - if dep.startswith("//src/rpc"): - output_deps.append(dep + ":ts") - if has_added_grpc_deps == False: - output_deps.extend([ - "@npm//google-protobuf", - "@npm//@types/google-protobuf", - "@npm//@improbable-eng/grpc-web", - ]) - has_added_grpc_deps = True - elif dep.startswith("//"): - output_deps.append(dep) - else: - output_deps.append("@npm//" + dep) - - return output_deps +load("//:hack/utils.bzl", "render_deps") def react_library(name, deps = [], **kwargs): ts_library( @@ -36,6 +15,6 @@ def react_library(name, deps = [], **kwargs): "*.stories.tsx", ]), ), - deps = _render_deps(deps), + deps = render_deps(deps), **kwargs ) diff --git a/hack/utils.bzl b/hack/utils.bzl new file mode 100644 index 0000000..fe91aea --- /dev/null +++ b/hack/utils.bzl @@ -0,0 +1,22 @@ +def render_deps(deps = []): + output_deps = [] + + has_added_grpc_deps = False + + for dep in deps: + if dep.startswith("//src/rpc"): + output_deps.append(dep + ":ts") + output_deps.append(dep + ":ts_proto") + if has_added_grpc_deps == False: + output_deps.extend([ + "@npm//google-protobuf", + "@npm//@types/google-protobuf", + "@npm//@improbable-eng/grpc-web", + ]) + has_added_grpc_deps = True + elif dep.startswith("//"): + output_deps.append(dep) + else: + output_deps.append("@npm//" + dep) + + return output_deps diff --git a/src/common/utils/BUILD.bazel b/src/common/utils/BUILD.bazel index 3dc189e..b212b02 100644 --- a/src/common/utils/BUILD.bazel +++ b/src/common/utils/BUILD.bazel @@ -1,4 +1,5 @@ load("//:hack/react.bzl", "react_library") +load("//:hack/jest.bzl", "jest_test") package(default_visibility = ["//visibility:public"]) @@ -15,9 +16,10 @@ react_library( ], ) -# jest_test( -# src = ":utils", -# deps = [ -# "//hack/fixtures", -# ], -# ) +jest_test( + src = ":utils", + deps = [ + "//hack/fixtures", + "//src/rpc/shared", + ], +)