Fix local tests to use web_test_runner

These have been broken for a while since Gerrit removed karma
test runner.

Bug: 415387031
Change-Id: I9283525a62d18864e076fd4e3009f5dbf3dc283b
diff --git a/web/BUILD b/web/BUILD
index 009f4bd..3beddd5 100644
--- a/web/BUILD
+++ b/web/BUILD
@@ -1,5 +1,5 @@
 load("//tools/js:eslint.bzl", "plugin_eslint")
-load("//tools/bzl:js.bzl", "gerrit_js_bundle", "karma_test")
+load("//tools/bzl:js.bzl", "gerrit_js_bundle", "web_test_runner")
 load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
 
 package_group(
@@ -52,10 +52,14 @@
     entry_point = "_bazel_ts_out/plugin.js",
 )
 
-karma_test(
-    name = "karma_test",
-    srcs = ["karma_test.sh"],
-    data = [":binary-size-ts-tests"],
+web_test_runner(
+    name = "web_test_runner",
+    srcs = ["web_test_runner.sh"],
+    data = [
+        ":tsconfig",
+        ":binary-size-ts-tests",
+        "@plugins_npm//:node_modules",
+    ],
 )
 
 plugin_eslint()
diff --git a/web/Makefile b/web/Makefile
index b35b682..77f600d 100644
--- a/web/Makefile
+++ b/web/Makefile
@@ -5,7 +5,7 @@
 .PHONY: test
 
 test:
-	bazel test --test_output=all //plugins/binary-size/web:karma_test
+	bazel test --test_output=all //plugins/binary-size/web:web_test_runner
 
 lint_test:
 	bazel test //plugins/binary-size/web:lint_test
diff --git a/web/binary-size-table.ts b/web/binary-size-table.ts
index 876474b..d713348 100644
--- a/web/binary-size-table.ts
+++ b/web/binary-size-table.ts
@@ -6,7 +6,7 @@
  */
 
 import {css, html, LitElement} from 'lit';
-import {customElement, property} from 'lit/decorators';
+import {customElement, property} from 'lit/decorators.js';
 import {BinarySizeInfo} from './binary-size';
 
 const MINUS_SIGN = '\u2212';
diff --git a/web/binary-size-table_test.ts b/web/binary-size-table_test.ts
index ef05efc..6c31027 100644
--- a/web/binary-size-table_test.ts
+++ b/web/binary-size-table_test.ts
@@ -6,6 +6,7 @@
  */
 
 import {assert} from '@open-wc/testing';
+import './test-setup';
 import {
   humanByteSize,
   humanByteSizeDelta,
diff --git a/web/binary-size_test.ts b/web/binary-size_test.ts
index 8f18a24..0c644a1 100644
--- a/web/binary-size_test.ts
+++ b/web/binary-size_test.ts
@@ -6,6 +6,7 @@
  */
 
 import {assert} from '@open-wc/testing';
+import './test-setup';
 import {
   ChecksFetcher,
   BuildbucketBuild,
diff --git a/web/karma_test.sh b/web/karma_test.sh
deleted file mode 100755
index 4125deb..0000000
--- a/web/karma_test.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-./$1 start $2 --single-run \
-  --root 'plugins/binary-size/web/_bazel_ts_out_tests/' \
-  --test-files '*_test.js' \
-  --browsers ${3:-ChromeHeadless}
diff --git a/web/plugin.ts b/web/plugin.ts
index a945a85..b975b5f 100644
--- a/web/plugin.ts
+++ b/web/plugin.ts
@@ -9,7 +9,7 @@
 import {ChecksFetcher} from './binary-size';
 import {installChecksResult} from './checks-result';
 
-window.Gerrit.install(async plugin => {
+window.Gerrit?.install(async plugin => {
   const fetcher = new ChecksFetcher(plugin, 'cr-buildbucket.appspot.com');
   plugin.checks().register({
     fetch: changeData => fetcher.fetchChecks(changeData),
diff --git a/web/test-setup.ts b/web/test-setup.ts
new file mode 100644
index 0000000..9062498
--- /dev/null
+++ b/web/test-setup.ts
@@ -0,0 +1,28 @@
+// Copyright 2025 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import {css} from 'lit';
+import sinon from 'sinon';
+
+declare global {
+  interface Window {
+    sinon: typeof sinon;
+  }
+}
+
+window.sinon = sinon;
+
+window.Gerrit = {
+  install: () => {},
+  styles: {
+    font: css``,
+    form: css``,
+    icon: css``,
+    menuPage: css``,
+    spinner: css``,
+    subPage: css``,
+    table: css``,
+    modal: css``,
+  },
+};
diff --git a/web/web_test_runner.sh b/web/web_test_runner.sh
new file mode 100755
index 0000000..9faa864
--- /dev/null
+++ b/web/web_test_runner.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -euo pipefail
+
+./$1 --config $2 \
+  --dir 'plugins/binary-size/web/_bazel_ts_out_tests' \
+  --test-files 'plugins/binary-size/web/_bazel_ts_out_tests/*_test.js' \
+  --ts-config="plugins/binary-size/web/tsconfig.json"