From 297150a1b63116d0095c1de97326d68368ef0a6e Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 18 Jun 2021 20:41:54 +0200 Subject: [PATCH 1/2] Cannot create Jest jsdom tests (?) --- ts/html-filter/index.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ts/html-filter/index.test.ts b/ts/html-filter/index.test.ts index 35d33bb3b..c3e2a724b 100644 --- a/ts/html-filter/index.test.ts +++ b/ts/html-filter/index.test.ts @@ -1,6 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -test("it should work", () => { - expect("test").toBe("test"); +import { filterHTML } from "."; + +describe("filterHTML", () => { + test("zero input creates zero output", () => { + expect(filterHTML("", true, false)).toBe(""); + expect(filterHTML("", true, false)).toBe(""); + expect(filterHTML("", false, false)).toBe(""); + }); }); From f2029b8ba825460738fce3d837595cded71b4b59 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 19 Jun 2021 09:43:09 +1000 Subject: [PATCH 2/2] support jsdom tests Alternative would be to switch to jsdom for everything, but TextEncoder is currently missing from jsdom, and jsdom mode is slower IIRC. --- ts/html-filter/BUILD.bazel | 3 ++- ts/jest.bzl | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ts/html-filter/BUILD.bazel b/ts/html-filter/BUILD.bazel index cf5e71d7e..60ec726e8 100644 --- a/ts/html-filter/BUILD.bazel +++ b/ts/html-filter/BUILD.bazel @@ -5,17 +5,18 @@ load("//ts:eslint.bzl", "eslint_test") ts_library( name = "html-filter", - module_name = "html-filter", srcs = glob( ["*.ts"], exclude = ["*.test.ts"], ), + module_name = "html-filter", tsconfig = "//ts:tsconfig.json", visibility = ["//visibility:public"], deps = [], ) jest_test( + env = "jsdom", deps = [ "html-filter", ], diff --git a/ts/jest.bzl b/ts/jest.bzl index d9a09007b..d56115e11 100644 --- a/ts/jest.bzl +++ b/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", protobuf = False): +def jest_test(deps, name = "jest", protobuf = False, env = "node"): "Build *.test.ts into a library, then test it with Jest." ts_sources = native.glob(["*.test.ts"]) @@ -61,6 +61,7 @@ def jest_test(deps, name = "jest", protobuf = False): "--colors", "--config", "$(location //ts:jest.config.js)", + "--env=" + env, ], data = bundled_srcs + [ "//ts:jest.config.js",