Skip to content

Commit 745a049

Browse files
fix(eslint): update ESLint configuration and improve test structure
- Modified ESLint rules to allow console error logging while maintaining warnings for other console methods. - Refactored test imports for better organization and clarity. - Enhanced the `handleRunError` test to ensure proper error logging and process exit behavior, improving test reliability. These changes improve code quality and testing practices, ensuring better adherence to ESLint rules and more robust error handling tests.
1 parent 509d906 commit 745a049

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

workers/main/eslint.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export default [
4242

4343
'prettier/prettier': 'error',
4444
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
45-
'no-console': 'warn',
45+
'@typescript-eslint/require-await': 'off',
46+
'no-console': ['warn', { allow: ['error'] }],
4647
'no-debugger': 'warn',
4748
'import/no-unresolved': 'error',
4849
'padding-line-between-statements': [
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
2+
import { vi } from 'vitest';
23

3-
import { run, handleRunError } from '../index';
4+
import { handleRunError, run } from '../index';
45

56
describe('run', () => {
67
it('should return true', async () => {
78
await expect(run()).resolves.toBe(true);
89
});
910
});
1011

11-
// Test for top-level error handling
12-
import * as indexModule from '../index';
13-
1412
describe('handleRunError', () => {
15-
const originalError = console.error;
16-
const originalExit = process.exit;
17-
18-
beforeEach(() => {
19-
console.error = vi.fn();
20-
process.exit = vi.fn() as never;
21-
});
13+
it('should log error and exit process', () => {
14+
const error = new Error('test error');
15+
const consoleErrorSpy = vi
16+
.spyOn(console, 'error')
17+
.mockImplementation(() => {});
18+
const processExitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
19+
throw new Error('exit');
20+
});
2221

23-
afterEach(() => {
24-
console.error = originalError;
25-
process.exit = originalExit;
26-
});
22+
expect(() => handleRunError(error)).toThrow('exit');
23+
expect(consoleErrorSpy).toHaveBeenCalledWith(
24+
'Unhandled error in main:',
25+
error,
26+
);
27+
expect(processExitSpy).toHaveBeenCalledWith(1);
2728

28-
it('should log error and exit on unhandled error', () => {
29-
const error = new Error('Test error');
30-
handleRunError(error);
31-
expect(console.error).toHaveBeenCalledWith('Unhandled error in main:', error);
32-
expect(process.exit).toHaveBeenCalledWith(1);
29+
consoleErrorSpy.mockRestore();
30+
processExitSpy.mockRestore();
3331
});
3432
});

0 commit comments

Comments
 (0)