diff --git a/ts/deckconfig/BUILD.bazel b/ts/deckconfig/BUILD.bazel index 7a5d4828b..906fb074b 100644 --- a/ts/deckconfig/BUILD.bazel +++ b/ts/deckconfig/BUILD.bazel @@ -5,7 +5,7 @@ load("//ts/svelte:svelte.bzl", "compile_svelte", "svelte", "svelte_check") load("//ts:esbuild.bzl", "esbuild") load("//ts:vendor.bzl", "copy_bootstrap_icons") load("//ts:compile_sass.bzl", "compile_sass") -load("@npm//jest-cli:index.bzl", "jest_test") +load("//ts:jest.bzl", "jest_test") compile_sass( srcs = ["deckconfig-base.scss"], @@ -125,35 +125,12 @@ svelte_check( ], ) -ts_library( - name = "test_lib", - srcs = glob(["*.test.ts"]), - tsconfig = "//ts:tsconfig.json", +jest_test( + data = [ + "@npm//protobufjs", + ], deps = [ ":lib", "//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"], - }), -) diff --git a/ts/html-filter/BUILD.bazel b/ts/html-filter/BUILD.bazel index 711424e90..d4fed4512 100644 --- a/ts/html-filter/BUILD.bazel +++ b/ts/html-filter/BUILD.bazel @@ -1,5 +1,5 @@ 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:eslint.bzl", "eslint_test") @@ -15,38 +15,12 @@ ts_library( deps = [], ) -ts_library( - name = "test_lib", - srcs = glob(["*.test.ts"]), - tsconfig = "//ts:tsconfig.json", +jest_test( deps = [ "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 ################ diff --git a/ts/jest.bzl b/ts/jest.bzl new file mode 100644 index 000000000..5bb05b010 --- /dev/null +++ b/ts/jest.bzl @@ -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"], + }), + ) diff --git a/ts/lib/BUILD.bazel b/ts/lib/BUILD.bazel index d5bb24e1a..01d538429 100644 --- a/ts/lib/BUILD.bazel +++ b/ts/lib/BUILD.bazel @@ -2,7 +2,7 @@ load("@npm//@bazel/typescript:index.bzl", "ts_library") load("//ts:prettier.bzl", "prettier_test") load("//ts:eslint.bzl", "eslint_test") load("//ts:protobuf.bzl", "protobufjs_library") -load("@npm//jest-cli:index.bzl", "jest_test") +load("//ts:jest.bzl", "jest_test") # Protobuf ############# @@ -77,34 +77,11 @@ eslint_test( srcs = glob(["*.ts"]), ) -ts_library( - name = "test_lib", - srcs = glob(["*.test.ts"]), - tsconfig = "//ts:tsconfig.json", - deps = [ - ":lib", - "@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"], - }), + deps = [ + ":lib", + ], )