From 9139398d465f5899cc31bc4cdd54daa7392ca550 Mon Sep 17 00:00:00 2001 From: Doan Luu Duc Tai Date: Sat, 31 Oct 2026 12:25:30 -0500 Subject: Migrate browser code and tests to strict TypeScript --- tests/browser-support.ts | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/browser-support.ts (limited to 'tests/browser-support.ts') 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 +// +// 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 . + +import assert from 'node:assert/strict'; +import type { Server } from 'node:http'; + +export function required(value: T | undefined | null, message: string): T { + assert.ok(value !== undefined && value !== null, message); + return value; +} + +function isRecord(value: unknown): value is Record { + return typeof value === 'object' && value !== null && !Array.isArray(value); +} + +export function record(value: unknown): Record { + 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; +} -- cgit v1.2.3