From 3fe41b606ae29dd13b8ff224dc411b0b8f24e6d7 Mon Sep 17 00:00:00 2001 From: Tomas Grasl Date: Tue, 31 Mar 2026 20:11:06 +0200 Subject: [PATCH] chore: include tests in prettier formatting Extend format and format:check scripts to cover tests/**/*.ts and apply prettier to all existing test files. Co-Authored-By: Claude Opus 4.6 (1M context) --- package.json | 4 +- tests/cli/prefs-parsing.test.ts | 8 +--- tests/firefox/connect-existing.test.ts | 13 ++----- tests/firefox/core.test.ts | 8 +--- tests/firefox/events/network.test.ts | 20 ++++------ .../injected/elementCollector.test.ts | 19 +++++++++- .../injected/snapshot.injected.test.ts | 3 +- .../snapshot/injected/treeWalker.test.ts | 9 +++-- tests/firefox/types.test.ts | 4 +- tests/helpers/firefox.ts | 4 +- tests/integration/console.integration.test.ts | 38 +++++++++++-------- tests/integration/form.integration.test.ts | 7 +++- tests/integration/network.integration.test.ts | 8 +++- .../integration/snapshot.integration.test.ts | 20 +++++++--- tests/integration/tabs.integration.test.ts | 7 +++- tests/smoke.test.ts | 5 +-- tests/tools/console.test.ts | 5 +-- tests/tools/network.test.ts | 5 +-- tests/tools/privileged-context.test.ts | 16 +++----- tests/utils/logger.test.ts | 16 ++------ tests/utils/response-helpers-extended.test.ts | 6 +-- 21 files changed, 114 insertions(+), 111 deletions(-) diff --git a/package.json b/package.json index c466f0d..0e93f9e 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "typecheck": "tsc --noEmit", "lint": "eslint src --ext .ts", "lint:fix": "eslint src --ext .ts --fix", - "format": "prettier --write \"src/**/*.ts\"", - "format:check": "prettier --check \"src/**/*.ts\"", + "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"", + "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"", "check": "npm run lint:fix && npm run typecheck", "check:all": "npm run check && npm run test:run && npm run build", "prepublishOnly": "npm run clean && npm run build", diff --git a/tests/cli/prefs-parsing.test.ts b/tests/cli/prefs-parsing.test.ts index eb00c93..2ec72e4 100644 --- a/tests/cli/prefs-parsing.test.ts +++ b/tests/cli/prefs-parsing.test.ts @@ -54,13 +54,7 @@ describe('parsePrefs', () => { // Multiple prefs it('should parse multiple preferences', () => { - expect( - parsePrefs([ - 'bool.pref=true', - 'int.pref=42', - 'string.pref=hello', - ]) - ).toEqual({ + expect(parsePrefs(['bool.pref=true', 'int.pref=42', 'string.pref=hello'])).toEqual({ 'bool.pref': true, 'int.pref': 42, 'string.pref': 'hello', diff --git a/tests/firefox/connect-existing.test.ts b/tests/firefox/connect-existing.test.ts index 88a291d..eb67afd 100644 --- a/tests/firefox/connect-existing.test.ts +++ b/tests/firefox/connect-existing.test.ts @@ -78,10 +78,7 @@ describe('GeckodriverHttpDriver BiDi support', () => { // Mock fetch for session creation const wsUrl = opts?.webSocketUrl ?? null; - vi.doMock( - 'node:module', - async (importOriginal) => await importOriginal() - ); + vi.doMock('node:module', async (importOriginal) => await importOriginal()); // We need to mock global fetch const mockFetch = vi.fn().mockResolvedValue({ @@ -129,9 +126,7 @@ describe('GeckodriverHttpDriver BiDi support', () => { const { core } = await createConnectExistingCore({ webSocketUrl: undefined }); const driver = core.getDriver(); - await expect(driver.getBidi()).rejects.toThrow( - /BiDi is not available.*webSocketUrl/ - ); + await expect(driver.getBidi()).rejects.toThrow(/BiDi is not available.*webSocketUrl/); }); it('should open WebSocket and return BiDi handle', async () => { @@ -178,9 +173,7 @@ describe('GeckodriverHttpDriver BiDi support', () => { // Simulate response if (wsEventListeners['message']) { - wsEventListeners['message'].forEach((h) => - h(JSON.stringify({ id: sent.id, result: {} })) - ); + wsEventListeners['message'].forEach((h) => h(JSON.stringify({ id: sent.id, result: {} }))); } await expect(subscribePromise).resolves.toBeUndefined(); diff --git a/tests/firefox/core.test.ts b/tests/firefox/core.test.ts index aece07c..5a5f77b 100644 --- a/tests/firefox/core.test.ts +++ b/tests/firefox/core.test.ts @@ -190,9 +190,7 @@ describe('FirefoxCore sendBiDiCommand WebSocket readiness', () => { // ASSERT: send() should now have been called expect(mockSend).toHaveBeenCalledTimes(1); - expect(mockSend).toHaveBeenCalledWith( - expect.stringContaining('"method":"test.method"') - ); + expect(mockSend).toHaveBeenCalledWith(expect.stringContaining('"method":"test.method"')); // Simulate response to complete the promise if (eventListeners['message']) { @@ -236,9 +234,7 @@ describe('FirefoxCore sendBiDiCommand WebSocket readiness', () => { const waitForWebSocketOpen = (core as any).waitForWebSocketOpen.bind(core); // ASSERT: should reject with timeout error (using 50ms timeout for fast test) - await expect(waitForWebSocketOpen(mockWs, 50)).rejects.toThrow( - /timeout.*websocket/i - ); + await expect(waitForWebSocketOpen(mockWs, 50)).rejects.toThrow(/timeout.*websocket/i); }); it('should throw error when WebSocket is CLOSING', async () => { diff --git a/tests/firefox/events/network.test.ts b/tests/firefox/events/network.test.ts index 13646f2..a4cdcff 100644 --- a/tests/firefox/events/network.test.ts +++ b/tests/firefox/events/network.test.ts @@ -91,9 +91,7 @@ describe('NetworkEvents Header Parsing', () => { }); it('should NOT return [object Object] for BiDi header values', () => { - const headers = [ - { name: 'Host', value: { type: 'string', value: 'www.example.com' } }, - ]; + const headers = [{ name: 'Host', value: { type: 'string', value: 'www.example.com' } }]; const result = parseHeaders(headers); @@ -152,9 +150,7 @@ describe('NetworkEvents Header Parsing', () => { }); it('should handle BiDi bytes format (binary data)', () => { - const headers = [ - { name: 'X-Binary', value: { type: 'base64', bytes: 'SGVsbG8gV29ybGQ=' } }, - ]; + const headers = [{ name: 'X-Binary', value: { type: 'base64', bytes: 'SGVsbG8gV29ybGQ=' } }]; const result = parseHeaders(headers); @@ -208,9 +204,7 @@ describe('NetworkEvents Header Parsing', () => { }); it('should handle numeric values in BiDi format', () => { - const headers = [ - { name: 'Content-Length', value: { type: 'string', value: 12345 } }, - ]; + const headers = [{ name: 'Content-Length', value: { type: 'string', value: 12345 } }]; const result = parseHeaders(headers); @@ -234,9 +228,7 @@ describe('NetworkEvents Header Parsing', () => { }); it('should handle array with null and undefined items', () => { - const headers = [ - { name: 'X-Array-Mixed', value: ['valid', null, undefined, 'another', ''] }, - ]; + const headers = [{ name: 'X-Array-Mixed', value: ['valid', null, undefined, 'another', ''] }]; const result = parseHeaders(headers); @@ -327,7 +319,9 @@ describe('NetworkEvents Header Parsing', () => { const result = parseHeaders(headers); - expect(result['x-custom-object']).toBe('{"custom":"property","another":123,"nested":{"deep":true}}'); + expect(result['x-custom-object']).toBe( + '{"custom":"property","another":123,"nested":{"deep":true}}' + ); }); it('should handle deeply nested value extraction', () => { diff --git a/tests/firefox/snapshot/injected/elementCollector.test.ts b/tests/firefox/snapshot/injected/elementCollector.test.ts index 2197891..5e94cff 100644 --- a/tests/firefox/snapshot/injected/elementCollector.test.ts +++ b/tests/firefox/snapshot/injected/elementCollector.test.ts @@ -1,7 +1,12 @@ // @vitest-environment jsdom import { describe, it, expect, vi, beforeAll, afterEach } from 'vitest'; -import { isVisible, isRelevant, isFocusable, isInteractive } from '@/firefox/snapshot/injected/elementCollector.js'; +import { + isVisible, + isRelevant, + isFocusable, + isInteractive, +} from '@/firefox/snapshot/injected/elementCollector.js'; beforeAll(() => { // jsdom getComputedStyle returns '' for opacity (browsers return '1') @@ -81,7 +86,17 @@ describe('elementCollector', () => { }); it('returns true for interactive tags', () => { - for (const tag of ['button', 'input', 'select', 'textarea', 'a', 'img', 'video', 'audio', 'iframe']) { + for (const tag of [ + 'button', + 'input', + 'select', + 'textarea', + 'a', + 'img', + 'video', + 'audio', + 'iframe', + ]) { const el = createElement(tag); expect(isRelevant(el)).toBe(true); } diff --git a/tests/firefox/snapshot/injected/snapshot.injected.test.ts b/tests/firefox/snapshot/injected/snapshot.injected.test.ts index a85188e..3e15745 100644 --- a/tests/firefox/snapshot/injected/snapshot.injected.test.ts +++ b/tests/firefox/snapshot/injected/snapshot.injected.test.ts @@ -63,7 +63,8 @@ describe('snapshot.injected - createSnapshot', () => { describe('selector option', () => { it('scopes to matched element', () => { - document.body.innerHTML = '
'; + document.body.innerHTML = + '
'; const result = createSnapshot(1, { selector: '#app' }); expect(result.tree).not.toBeNull(); diff --git a/tests/firefox/snapshot/injected/treeWalker.test.ts b/tests/firefox/snapshot/injected/treeWalker.test.ts index 344c84c..ffb23d6 100644 --- a/tests/firefox/snapshot/injected/treeWalker.test.ts +++ b/tests/firefox/snapshot/injected/treeWalker.test.ts @@ -78,12 +78,13 @@ describe('treeWalker', () => { const result = walkTree(document.body, 1); expect(result.tree).not.toBeNull(); // Button should bubble up through irrelevant