From f02b1dfdbe82beaf723f42ac51bd6eea2a2d3202 Mon Sep 17 00:00:00 2001 From: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com> Date: Tue, 1 Sep 2026 15:02:45 +0200 Subject: [PATCH] chore(tests): remove orphaned jest-era custom matchers file The jest -> vitest migration already completed in an earlier PR (see vitest.setup.ts's own header: "Ported from jest.setup.ts when the runner moved from jest 30 + ts-jest (CJS) to Vitest"). One file was never cleaned up: tests/setup/custom-matchers.ts imported `expect` from `@jest/globals`, a package that is not even installed anymore (confirmed: not in package.json, not in node_modules). It also was never wired into vitest.setup.ts's setupFiles and no test imported it directly, so it was fully dead -- it would only ever have thrown MODULE_NOT_FOUND if something had tried to load it. Deleted rather than ported: none of its matchers (toBeValidBitcoinAddress, toBeValidUUID, toBeSanitized, etc.) are referenced by any test, so porting it forward would be adding new, unused surface rather than fixing something broken. Full local vitest run confirms this repo's test suite was already green before this change: 279/279 test files, 2631/2631 tests passing. --- tests/setup/custom-matchers.ts | 195 --------------------------------- 1 file changed, 195 deletions(-) delete mode 100644 tests/setup/custom-matchers.ts diff --git a/tests/setup/custom-matchers.ts b/tests/setup/custom-matchers.ts deleted file mode 100644 index b8416acaf..000000000 --- a/tests/setup/custom-matchers.ts +++ /dev/null @@ -1,195 +0,0 @@ -/** - * Custom Jest Matchers for OrangeCat - * Extended matchers for better testing experience - * - * Created: 2025-09-24 - * Last Modified: 2025-09-24 - * Last Modified Summary: Custom Jest matchers for comprehensive testing - */ - -import { expect } from '@jest/globals'; - -/** - * Custom matcher to check if a value is a valid Bitcoin address - */ -expect.extend({ - toBeValidBitcoinAddress(received: string) { - const bitcoinAddressRegex = /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/; - - const pass = typeof received === 'string' && bitcoinAddressRegex.test(received); - - return { - message: () => `expected ${received} to be a valid Bitcoin address`, - pass - }; - }, - - /** - * Custom matcher to check if a value is a valid email - */ - toBeValidEmail(received: string) { - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - - const pass = typeof received === 'string' && emailRegex.test(received); - - return { - message: () => `expected ${received} to be a valid email address`, - pass - }; - }, - - /** - * Custom matcher to check if a value is a valid UUID - */ - toBeValidUUID(received: string) { - const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; - - const pass = typeof received === 'string' && uuidRegex.test(received); - - return { - message: () => `expected ${received} to be a valid UUID`, - pass - }; - }, - - /** - * Custom matcher to check if a value is a valid URL - */ - toBeValidUrl(received: string) { - try { - new URL(received); - return { - message: () => `expected ${received} to be a valid URL`, - pass: true - }; - } catch { - return { - message: () => `expected ${received} to be a valid URL`, - pass: false - }; - } - }, - - /** - * Custom matcher to check if an object has required properties - */ - toHaveRequiredProperties(received: any, requiredProps: string[]) { - const missingProps = requiredProps.filter(prop => !(prop in received)); - - const pass = missingProps.length === 0; - - return { - message: () => `expected ${JSON.stringify(received)} to have required properties: ${requiredProps.join(', ')}${missingProps.length > 0 ? ` (missing: ${missingProps.join(', ')})` : ''}`, - pass - }; - }, - - /** - * Custom matcher to check if a string contains HTML - */ - toContainHtml(received: string) { - const htmlRegex = /<[^>]*>/; - - const pass = typeof received === 'string' && htmlRegex.test(received); - - return { - message: () => `expected ${received} to contain HTML`, - pass - }; - }, - - /** - * Custom matcher to check if a string is sanitized (no dangerous HTML) - */ - toBeSanitized(received: string) { - const dangerousPatterns = [ - /]*>.*?<\/script>/gi, - /]*>.*?<\/iframe>/gi, - /javascript:/gi, - /on\w+\s*=/gi, - /]*>.*?<\/object>/gi, - /]*>.*?<\/embed>/gi - ]; - - const hasDangerousContent = dangerousPatterns.some(pattern => pattern.test(received)); - - const pass = !hasDangerousContent; - - return { - message: () => `expected ${received} to be sanitized HTML`, - pass - }; - }, - - /** - * Custom matcher to check if a number is within a range - */ - toBeWithinRange(received: number, min: number, max: number) { - const pass = received >= min && received <= max; - - return { - message: () => `expected ${received} to be within range ${min} - ${max}`, - pass - }; - }, - - /** - * Custom matcher to check if an array contains objects with specific properties - */ - toContainObjectsWith(received: any[], requiredProps: string[]) { - const pass = Array.isArray(received) && received.every(item => - typeof item === 'object' && item !== null && - requiredProps.every(prop => prop in item) - ); - - return { - message: () => `expected ${JSON.stringify(received)} to contain objects with properties: ${requiredProps.join(', ')}`, - pass - }; - }, - - /** - * Custom matcher to check if a response is successful - */ - toBeSuccessfulResponse(received: any) { - const pass = received && typeof received === 'object' && - 'ok' in received && received.ok === true; - - return { - message: () => `expected ${JSON.stringify(received)} to be a successful response`, - pass - }; - }, - - /** - * Custom matcher to check if an error response is properly formatted - */ - toBeErrorResponse(received: any) { - const pass = received && typeof received === 'object' && - 'error' in received && typeof received.error === 'string'; - - return { - message: () => `expected ${JSON.stringify(received)} to be a properly formatted error response`, - pass - }; - } -}); - -// Type declarations for TypeScript -declare global { - namespace jest { - interface Matchers { - toBeValidBitcoinAddress(): R; - toBeValidEmail(): R; - toBeValidUUID(): R; - toBeValidUrl(): R; - toHaveRequiredProperties(props: string[]): R; - toContainHtml(): R; - toBeSanitized(): R; - toBeWithinRange(min: number, max: number): R; - toContainObjectsWith(props: string[]): R; - toBeSuccessfulResponse(): R; - toBeErrorResponse(): R; - } - } -}