mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -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",
|
"protobuf-shim.js",
|
||||||
"jest.config.js",
|
"jest.config.js",
|
||||||
"package.json",
|
"package.json",
|
||||||
|
"protobuf-no-long.js",
|
||||||
])
|
])
|
||||||
|
|
||||||
alias(
|
alias(
|
||||||
|
|
|
@ -126,6 +126,7 @@ svelte_check(
|
||||||
)
|
)
|
||||||
|
|
||||||
jest_test(
|
jest_test(
|
||||||
|
protobuf = True,
|
||||||
deps = [
|
deps = [
|
||||||
":lib",
|
":lib",
|
||||||
"//ts/lib:backend_proto",
|
"//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("@esbuild_toolchain//:esbuild.bzl", esbuild = "esbuild_macro")
|
||||||
load("@npm//jest-cli:index.bzl", _jest_test = "jest_test")
|
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."
|
"Build *.test.ts into a library, then test it with Jest."
|
||||||
|
|
||||||
ts_sources = native.glob(["*.test.ts"])
|
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
|
# bundle each test file up with its dependencies for jest
|
||||||
bundled_srcs = []
|
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:
|
for ts_src in ts_sources:
|
||||||
base = ts_src.replace(".test.ts", "")
|
base = ts_src.replace(".test.ts", "")
|
||||||
bundle_name = base + ".bundle.test"
|
bundle_name = base + ".bundle.test"
|
||||||
|
@ -31,9 +41,10 @@ def jest_test(deps, name = "jest"):
|
||||||
"--platform=node",
|
"--platform=node",
|
||||||
"--external:protobufjs",
|
"--external:protobufjs",
|
||||||
"--keep-names",
|
"--keep-names",
|
||||||
],
|
] + esbuild_extra_args,
|
||||||
entry_point = ts_src,
|
entry_point = ts_src,
|
||||||
output = bundle_name + ".js",
|
output = bundle_name + ".js",
|
||||||
|
srcs = esbuild_extra_srcs,
|
||||||
deps = [
|
deps = [
|
||||||
name + "_lib",
|
name + "_lib",
|
||||||
] + deps,
|
] + 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