add macro for invoking Jest

This commit is contained in:
Damien Elmes 2021-04-16 23:46:31 +10:00
parent c3fc07ac20
commit d158450e89
4 changed files with 48 additions and 83 deletions

View file

@ -5,7 +5,7 @@ load("//ts/svelte:svelte.bzl", "compile_svelte", "svelte", "svelte_check")
load("//ts:esbuild.bzl", "esbuild") load("//ts:esbuild.bzl", "esbuild")
load("//ts:vendor.bzl", "copy_bootstrap_icons") load("//ts:vendor.bzl", "copy_bootstrap_icons")
load("//ts:compile_sass.bzl", "compile_sass") load("//ts:compile_sass.bzl", "compile_sass")
load("@npm//jest-cli:index.bzl", "jest_test") load("//ts:jest.bzl", "jest_test")
compile_sass( compile_sass(
srcs = ["deckconfig-base.scss"], srcs = ["deckconfig-base.scss"],
@ -125,35 +125,12 @@ svelte_check(
], ],
) )
ts_library( jest_test(
name = "test_lib", data = [
srcs = glob(["*.test.ts"]), "@npm//protobufjs",
tsconfig = "//ts:tsconfig.json", ],
deps = [ deps = [
":lib", ":lib",
"//ts/lib:backend_proto", "//ts/lib:backend_proto",
"@npm//@types/jest",
], ],
) )
jest_test(
name = "test",
args = [
"--no-cache",
"--no-watchman",
"--ci",
"--colors",
"--config",
"$(location //ts:jest.config.js)",
],
data = [
":test_lib",
"//ts:jest.config.js",
"@npm//protobufjs",
],
target_compatible_with = select({
"@platforms//os:osx": [],
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//os:linux"],
}),
)

View file

@ -1,5 +1,5 @@
load("@npm//@bazel/typescript:index.bzl", "ts_library") load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("@npm//jest-cli:index.bzl", "jest_test") load("//ts:jest.bzl", "jest_test")
load("//ts:prettier.bzl", "prettier_test") load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test") load("//ts:eslint.bzl", "eslint_test")
@ -15,38 +15,12 @@ ts_library(
deps = [], deps = [],
) )
ts_library( jest_test(
name = "test_lib",
srcs = glob(["*.test.ts"]),
tsconfig = "//ts:tsconfig.json",
deps = [ deps = [
"html-filter", "html-filter",
"@npm//@types/jest",
], ],
) )
jest_test(
name = "test",
args = [
"--no-cache",
"--no-watchman",
"--ci",
"--colors",
"--config",
"$(location //ts:jest.config.js)",
],
data = [
":test_lib",
"//ts:jest.config.js",
"//ts:package.json",
],
target_compatible_with = select({
"@platforms//os:osx": [],
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//os:linux"],
}),
)
# Tests # Tests
################ ################

37
ts/jest.bzl Normal file
View file

@ -0,0 +1,37 @@
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("@npm//jest-cli:index.bzl", _jest_test = "jest_test")
def jest_test(deps, data = [], name = "jest"):
"Build *.test.ts into a library, then test it with Jest."
# compile sources
ts_library(
name = name + "_lib",
srcs = native.glob(["*.test.ts"]),
tsconfig = "//ts:tsconfig.json",
deps = deps + [
"@npm//@types/jest",
],
)
# then test them
_jest_test(
name = name,
args = [
"--no-cache",
"--no-watchman",
"--ci",
"--colors",
"--config",
"$(location //ts:jest.config.js)",
],
data = data + [
name + "_lib",
"//ts:jest.config.js",
],
target_compatible_with = select({
"@platforms//os:osx": [],
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//os:linux"],
}),
)

View file

@ -2,7 +2,7 @@ load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("//ts:prettier.bzl", "prettier_test") load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test") load("//ts:eslint.bzl", "eslint_test")
load("//ts:protobuf.bzl", "protobufjs_library") load("//ts:protobuf.bzl", "protobufjs_library")
load("@npm//jest-cli:index.bzl", "jest_test") load("//ts:jest.bzl", "jest_test")
# Protobuf # Protobuf
############# #############
@ -77,34 +77,11 @@ eslint_test(
srcs = glob(["*.ts"]), srcs = glob(["*.ts"]),
) )
ts_library(
name = "test_lib",
srcs = glob(["*.test.ts"]),
tsconfig = "//ts:tsconfig.json",
deps = [
":lib",
"@npm//@types/jest",
],
)
jest_test( jest_test(
name = "test",
args = [
"--no-cache",
"--no-watchman",
"--ci",
"--colors",
"--config",
"$(location //ts:jest.config.js)",
],
data = [ data = [
":test_lib",
"//ts:jest.config.js",
"@npm//protobufjs", "@npm//protobufjs",
], ],
target_compatible_with = select({ deps = [
"@platforms//os:osx": [], ":lib",
"@platforms//os:linux": [], ],
"//conditions:default": ["@platforms//os:linux"],
}),
) )