summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDoan Luu Duc Tai <doan@luuduct.ai>2026-10-31 13:08:08 -0500
committerDoan Luu Duc Tai <doan@luuduct.ai>2026-10-31 13:08:08 -0500
commita80df869a92c330fbad9695057720b11a18af901 (patch)
tree5307272821cb3adc3f0348413a3b904290890044 /tests
parent9139398d465f5899cc31bc4cdd54daa7392ca550 (diff)
Forbid Rust lints and enforce strict typed TypeScript linting
Diffstat (limited to 'tests')
-rw-r--r--tests/browser-support.ts23
1 files changed, 19 insertions, 4 deletions
diff --git a/tests/browser-support.ts b/tests/browser-support.ts
index 223b2b8..d4ecef9 100644
--- a/tests/browser-support.ts
+++ b/tests/browser-support.ts
@@ -14,7 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import assert from 'node:assert/strict';
-import type { Server } from 'node:http';
+import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';
export function required<T>(value: T | undefined | null, message: string): T {
assert.ok(value !== undefined && value !== null, message);
@@ -43,8 +43,8 @@ export function list(value: unknown): unknown[] {
export function serverOrigin(server: Server): string {
const address = server.address();
- assert.ok(address && typeof address !== 'string');
- return `http://127.0.0.1:${address.port}`;
+ assert.ok(address !== null && typeof address !== 'string');
+ return `http://127.0.0.1:${String(address.port)}`;
}
export function requestBody(text: string): { op: string; count: number; [key: string]: unknown } {
@@ -54,7 +54,7 @@ export function requestBody(text: string): { op: string; count: number; [key: st
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.ok((addon !== undefined));
assert.equal(addon['active'], true);
return { active: true, version: string(addon['version']) };
}
@@ -63,3 +63,18 @@ declare global {
interface Window { unlicensedControl?: boolean; chatInjection?: boolean }
const wasm: Promise<ArrayBuffer>;
}
+
+export function asyncServer(handler: (request: IncomingMessage, response: ServerResponse) => Promise<void>): Server {
+ return createServer((request, response) => {
+ handler(request, response).catch((error: unknown) => {
+ response.destroy(error instanceof Error ? error : new Error('Fixture request failed', { cause: error }));
+ });
+ });
+}
+
+export function closeBrowser(browser: { close(): Promise<void> }): void {
+ browser.close().catch((error: unknown) => {
+ process.exitCode = 1;
+ process.stderr.write(`Browser shutdown failed: ${String(error)}\n`);
+ });
+}