diff options
Diffstat (limited to 'tests/browser-support.ts')
| -rw-r--r-- | tests/browser-support.ts | 23 |
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`); + }); +} |
