mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 03:49:11 +00:00
fix(common): fix utils tests by improving jest dependency resolution
This commit is contained in:
parent
5b440ffa8d
commit
61f6c3b34b
4 changed files with 37 additions and 32 deletions
|
@ -1,7 +1,9 @@
|
||||||
# Copied from https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/jest.bzl
|
# 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("@npm//jest-cli:index.bzl", "jest", _jest_test = "jest_test")
|
||||||
|
load("//:hack/utils.bzl", "render_deps")
|
||||||
|
|
||||||
DEFAULT_DEPS = [
|
DEFAULT_DEPS = [
|
||||||
"@npm//ts-jest",
|
"@npm//ts-jest",
|
||||||
|
@ -25,7 +27,7 @@ def _impl_jest_test(name, srcs, deps, jest_config, **kwargs):
|
||||||
"--no-cache",
|
"--no-cache",
|
||||||
"--no-watchman",
|
"--no-watchman",
|
||||||
"--ci",
|
"--ci",
|
||||||
"--colors",
|
"--no-colors",
|
||||||
]
|
]
|
||||||
templated_args.extend(["--config", "$(rootpath %s)" % jest_config])
|
templated_args.extend(["--config", "$(rootpath %s)" % jest_config])
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
|
@ -51,6 +53,6 @@ def jest_test(src, deps = []):
|
||||||
_impl_jest_test(
|
_impl_jest_test(
|
||||||
name = src[1:] + "_test",
|
name = src[1:] + "_test",
|
||||||
srcs = native.glob(["*.spec.ts", "*.spec.tsx"]),
|
srcs = native.glob(["*.spec.ts", "*.spec.tsx"]),
|
||||||
deps = [src] + deps + DEFAULT_DEPS,
|
deps = [src] + render_deps(deps) + DEFAULT_DEPS,
|
||||||
jest_config = "//:jest.config.js",
|
jest_config = "//:jest.config.js",
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,26 +1,5 @@
|
||||||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||||
|
load("//:hack/utils.bzl", "render_deps")
|
||||||
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
|
|
||||||
|
|
||||||
def react_library(name, deps = [], **kwargs):
|
def react_library(name, deps = [], **kwargs):
|
||||||
ts_library(
|
ts_library(
|
||||||
|
@ -36,6 +15,6 @@ def react_library(name, deps = [], **kwargs):
|
||||||
"*.stories.tsx",
|
"*.stories.tsx",
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
deps = _render_deps(deps),
|
deps = render_deps(deps),
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
22
hack/utils.bzl
Normal file
22
hack/utils.bzl
Normal file
|
@ -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
|
|
@ -1,4 +1,5 @@
|
||||||
load("//:hack/react.bzl", "react_library")
|
load("//:hack/react.bzl", "react_library")
|
||||||
|
load("//:hack/jest.bzl", "jest_test")
|
||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
|
@ -15,9 +16,10 @@ react_library(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# jest_test(
|
jest_test(
|
||||||
# src = ":utils",
|
src = ":utils",
|
||||||
# deps = [
|
deps = [
|
||||||
# "//hack/fixtures",
|
"//hack/fixtures",
|
||||||
# ],
|
"//src/rpc/shared",
|
||||||
# )
|
],
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue