mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
add a hack to avoid Long.js in Jest tests
This commit is contained in:
parent
377ba1471e
commit
25c52444b5
4 changed files with 18 additions and 2 deletions
|
@ -32,6 +32,7 @@ exports_files([
|
|||
"protobuf-shim.js",
|
||||
"jest.config.js",
|
||||
"package.json",
|
||||
"protobuf-no-long.js",
|
||||
])
|
||||
|
||||
alias(
|
||||
|
|
|
@ -126,6 +126,7 @@ svelte_check(
|
|||
)
|
||||
|
||||
jest_test(
|
||||
protobuf = True,
|
||||
deps = [
|
||||
":lib",
|
||||
"//ts/lib:backend_proto",
|
||||
|
|
15
ts/jest.bzl
15
ts/jest.bzl
|
@ -2,7 +2,7 @@ load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
|||
load("@esbuild_toolchain//:esbuild.bzl", esbuild = "esbuild_macro")
|
||||
load("@npm//jest-cli:index.bzl", _jest_test = "jest_test")
|
||||
|
||||
def jest_test(deps, name = "jest"):
|
||||
def jest_test(deps, name = "jest", protobuf = False):
|
||||
"Build *.test.ts into a library, then test it with Jest."
|
||||
|
||||
ts_sources = native.glob(["*.test.ts"])
|
||||
|
@ -19,6 +19,16 @@ def jest_test(deps, name = "jest"):
|
|||
|
||||
# bundle each test file up with its dependencies for jest
|
||||
bundled_srcs = []
|
||||
esbuild_extra_args = []
|
||||
esbuild_extra_srcs = []
|
||||
if protobuf:
|
||||
esbuild_extra_args.append(
|
||||
"--inject:$(location //ts:protobuf-no-long.js)",
|
||||
)
|
||||
esbuild_extra_srcs.append(
|
||||
"//ts:protobuf-no-long.js",
|
||||
)
|
||||
|
||||
for ts_src in ts_sources:
|
||||
base = ts_src.replace(".test.ts", "")
|
||||
bundle_name = base + ".bundle.test"
|
||||
|
@ -31,9 +41,10 @@ def jest_test(deps, name = "jest"):
|
|||
"--platform=node",
|
||||
"--external:protobufjs",
|
||||
"--keep-names",
|
||||
],
|
||||
] + esbuild_extra_args,
|
||||
entry_point = ts_src,
|
||||
output = bundle_name + ".js",
|
||||
srcs = esbuild_extra_srcs,
|
||||
deps = [
|
||||
name + "_lib",
|
||||
] + deps,
|
||||
|
|
3
ts/protobuf-no-long.js
Normal file
3
ts/protobuf-no-long.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
let protobuf = require("protobufjs");
|
||||
protobuf.util.Long = undefined;
|
||||
protobuf.configure();
|
Loading…
Reference in a new issue