summaryrefslogtreecommitdiff
path: root/tests/browser-support.ts
diff options
context:
space:
mode:
authorDoan Luu Duc Tai <doan@luuduct.ai>2026-10-31 12:25:30 -0500
committerDoan Luu Duc Tai <doan@luuduct.ai>2026-10-31 12:25:30 -0500
commit9139398d465f5899cc31bc4cdd54daa7392ca550 (patch)
treedebf0b15a969e8c64e3b3597f4eb7953b7f047e1 /tests/browser-support.ts
parentef61fc5aca6eca613a055c507a060b70bd537a37 (diff)
Migrate browser code and tests to strict TypeScript
Diffstat (limited to 'tests/browser-support.ts')
-rw-r--r--tests/browser-support.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/browser-support.ts b/tests/browser-support.ts
new file mode 100644
index 0000000..223b2b8
--- /dev/null
+++ b/tests/browser-support.ts
@@ -0,0 +1,65 @@
+// Copyright (C) 2026 Doan Luu Duc Tai <doan@luuduct.ai>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+import assert from 'node:assert/strict';
+import type { Server } from 'node:http';
+
+export function required<T>(value: T | undefined | null, message: string): T {
+ assert.ok(value !== undefined && value !== null, message);
+ return value;
+}
+
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
+}
+
+export function record(value: unknown): Record<string, unknown> {
+ assert.ok(isRecord(value));
+ return value;
+}
+
+export function string(value: unknown): string {
+ assert.equal(typeof value, 'string');
+ if (typeof value !== 'string') throw new Error('Expected string');
+ return value;
+}
+
+export function list(value: unknown): unknown[] {
+ assert.ok(Array.isArray(value));
+ return value;
+}
+
+export function serverOrigin(server: Server): string {
+ const address = server.address();
+ assert.ok(address && typeof address !== 'string');
+ return `http://127.0.0.1:${address.port}`;
+}
+
+export function requestBody(text: string): { op: string; count: number; [key: string]: unknown } {
+ const value = record(JSON.parse(text));
+ return { ...value, op: string(value['op']), count: typeof value['count'] === 'number' ? value['count'] : 0 };
+}
+
+export function libreJSAddon(text: string): { active: boolean; version: string } {
+ const addon = list(record(JSON.parse(text))['addons']).map(record).find(value => value['id'] === 'jid1-KtlZuoiikVfFew@jetpack');
+ assert.ok(addon);
+ assert.equal(addon['active'], true);
+ return { active: true, version: string(addon['version']) };
+}
+
+declare global {
+ interface Window { unlicensedControl?: boolean; chatInjection?: boolean }
+ const wasm: Promise<ArrayBuffer>;
+}