diff --git a/eslint.config.js b/eslint.config.js index 0030238..c94ae35 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -72,13 +72,24 @@ export default [ argsIgnorePattern: '^_', varsIgnorePattern: '^_' }], + 'import/exports-last': 2, + 'import/group-exports': 1, + 'id-length': ['error', { + min: 2, + properties: 'never', + exceptions: ['a', 'b', 'i', 'j', 'k', '_'] + }], 'n/no-process-exit': 0, // Disallow console.log/info in runtime to protect STDIO; allow warn/error 'no-console': ['error', { allow: ['warn', 'error'] }] } }, - - // Test files + { + files: ['src/*.d.ts'], + rules: { + 'import/group-exports': 0 + } + }, { files: [ '**/*.test.ts', @@ -87,12 +98,12 @@ export default [ ], rules: { '@typescript-eslint/no-explicit-any': 0, - '@typescript-eslint/ban-ts-comment': 1, + '@typescript-eslint/ban-ts-comment': 0, + 'import/exports-last': 0, + 'import/group-exports': 0, 'no-sparse-arrays': 0, // Allow console usage in tests (spies, debug) - 'no-console': 0, - // Relax stylistic padding in tests to reduce churn - '@stylistic/padding-line-between-statements': 0 + 'no-console': 0 } } ]; diff --git a/src/__tests__/logger.test.ts b/src/__tests__/logger.test.ts index d5f17d8..ec43e01 100644 --- a/src/__tests__/logger.test.ts +++ b/src/__tests__/logger.test.ts @@ -156,6 +156,7 @@ describe('registerStderrSubscriber', () => { const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true as any); const unsubscribe = registerStderrSubscriber(getLoggerOptions()); + publish('debug', getLoggerOptions(), 'debug suppressed'); publish('info', getLoggerOptions(), 'lorem ipsum', 123, { a: 1 }); @@ -210,6 +211,7 @@ describe('createLogger', () => { const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true as any); const unsubscribe = createLogger(getLoggerOptions()); + publish('debug', getLoggerOptions(), 'debug suppressed'); publish('info', getLoggerOptions(), 'lorem ipsum', 123, { a: 1 }); diff --git a/src/__tests__/options.test.ts b/src/__tests__/options.test.ts index b202056..119b735 100644 --- a/src/__tests__/options.test.ts +++ b/src/__tests__/options.test.ts @@ -71,12 +71,14 @@ describe('parseCliOptions', () => { it('parses from a provided argv independent of process.argv', () => { const customArgv = ['node', 'cli', '--http', '--port', '3101']; const result = parseCliOptions(customArgv); + expect(result.http?.port).toBe(3101); }); it('trims spaces in list flags', () => { const argv = ['node', 'cli', '--http', '--allowed-hosts', ' localhost , 127.0.0.1 ']; const result = parseCliOptions(argv); + expect(result.http?.allowedHosts).toEqual(['localhost', '127.0.0.1']); }); }); diff --git a/src/__tests__/server.caching.test.ts b/src/__tests__/server.caching.test.ts index 48da3d5..e4246af 100644 --- a/src/__tests__/server.caching.test.ts +++ b/src/__tests__/server.caching.test.ts @@ -49,8 +49,8 @@ describe('memo', () => { try { successValue = await value(); - } catch (e) { - const error = e as Error; + } catch (err) { + const error = err as Error; errorValue = error.message; } diff --git a/src/__tests__/server.http.test.ts b/src/__tests__/server.http.test.ts index d0b349e..68b1213 100644 --- a/src/__tests__/server.http.test.ts +++ b/src/__tests__/server.http.test.ts @@ -61,6 +61,7 @@ describe('startHttpTransport', () => { MockCreateServer.mockImplementation((handler: any) => { mockRequestHandler = handler; + return mockHttpServer as any; }); }); diff --git a/src/__tests__/server.logger.test.ts b/src/__tests__/server.logger.test.ts index 3151dd5..eee34e4 100644 --- a/src/__tests__/server.logger.test.ts +++ b/src/__tests__/server.logger.test.ts @@ -107,6 +107,7 @@ describe('createServerLogger', () => { setOptions({ logging: { stderr: true, level: 'debug' } as any }); const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true as any); + class MockServer { sendLoggingMessage = jest.fn(async () => {}); } const server = new MockServer() as any; diff --git a/src/logger.ts b/src/logger.ts index 146cbe6..db659a6 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -71,7 +71,7 @@ const publish = (level: LogLevel, options: LoggingSession = getLoggerOptions(), event.args = args; } } else { - const arr = [msg, ...args].filter(v => v !== undefined); + const arr = [msg, ...args].filter(value => value !== undefined); if (arr.length) { event.args = arr as unknown[]; diff --git a/tests/utils/fetchMock.ts b/tests/utils/fetchMock.ts index 4ba1480..5b87669 100644 --- a/tests/utils/fetchMock.ts +++ b/tests/utils/fetchMock.ts @@ -71,6 +71,7 @@ const startHttpFixture = ( // String pattern with wildcards const pattern = regexRoute.url.replace(/\*/g, '.*'); const regex = new RegExp(`^${pattern}$`); + if (regex.test(pathname) || regex.test(`http://${address}${pathname}`)) { route = { status: regexRoute.status || 200, @@ -251,6 +252,7 @@ export const setupFetchMock = async (options: FetchMockSetup = {}): Promise { // Extract pathname from URL for matching let pathname: string; + try { const urlObj = new URL(url); + pathname = urlObj.pathname; } catch { // If URL parsing fails, try to extract pathname manually const match = url.match(/^https?:\/\/[^/]+(\/.*)$/); + pathname = match && match[1] ? match[1] : url; } @@ -307,6 +312,7 @@ export const setupFetchMock = async (options: FetchMockSetup = {}): Promise