# Copied from https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/jest.bzl # Licensed under Apache-2.0, modifications made: # - improved dependency resolution load("@npm//jest-cli:index.bzl", "jest", _jest_test = "jest_test") load("//hack/bazel:utils.bzl", "render_deps") DEFAULT_DEPS = [ "@npm//ts-jest", "@npm//enzyme", "@npm//enzyme-adapter-react-16", "@npm//@types/enzyme", "@npm//jest-environment-enzyme", "@npm//jsdom", "@npm//jest", "@npm//@types/jest", "@npm//jest-enzyme", "@npm//jest-styled-components", "@npm//enzyme-to-json", "@npm//react-dom", "@npm//@types/react-dom", "//:tsconfig.json", ] def _impl_jest_test(name, srcs, deps, jest_config, **kwargs): "A macro around the autogenerated jest_test rule" templated_args = [ "--no-cache", "--no-watchman", "--ci", "--no-colors", ] templated_args.extend(["--config", "$(rootpath %s)" % jest_config]) for src in srcs: templated_args.extend(["--runTestsByPath", "$(rootpath %s)" % src]) data = [jest_config] + srcs + deps + ["//:jest-reporter.js"] _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 ) def jest_test(src, deps = []): _impl_jest_test( name = src[1:] + "_test", srcs = native.glob(["*.spec.ts", "*.spec.tsx"]), deps = [src] + render_deps(deps) + DEFAULT_DEPS, jest_config = "//:jest.config.js", )