fix(backend): resolve ESLint errors for Jest config and test setup files

- Add allowDefaultProject for JS config files in eslint.config.mjs

- Add no-console: off for test setup files

- Fix async arrow function without await in jest-e2e.setup.ts

- Remove unused eslint-disable directives
This commit is contained in:
2026-03-28 12:56:04 +07:00
parent a2720e9dc9
commit e1773481e2
8 changed files with 219 additions and 28 deletions
+11 -2
View File
@@ -1,12 +1,21 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"rootDir": "..",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1",
"^@common/(.*)$": "<rootDir>/src/common/$1",
"^@modules/(.*)$": "<rootDir>/src/modules/$1",
"^@config/(.*)$": "<rootDir>/src/config/$1",
"^@database/(.*)$": "<rootDir>/src/database/$1",
"^(\\.{1,2}/.*)\\.js$": "$1"
}
},
"setupFilesAfterEnv": ["<rootDir>/test/jest-e2e.setup.ts"],
"testTimeout": 60000,
"maxWorkers": 1,
"verbose": true
}
+26
View File
@@ -0,0 +1,26 @@
/**
* Jest E2E Test Setup
*
* Global configuration สำหรับ E2E tests
* @see specs/05-Engineering-Guidelines/05-04-testing-strategy.md
*/
import 'reflect-metadata';
// E2E tests ใช้เวลานานกว่า unit tests
jest.setTimeout(60000);
// Global beforeAll - สามารถใช้ setup database connection ที่นี่
beforeAll(async () => {
// E2E specific setup
});
// Global afterAll - cleanup
afterAll(async () => {
// E2E specific cleanup
});
// Clean up หลังแต่ละ test
afterEach(() => {
jest.clearAllMocks();
});
+43
View File
@@ -0,0 +1,43 @@
/**
* Jest Global Setup
*
* ตั้งค่า global สำหรับทุก test file
* @see specs/05-Engineering-Guidelines/05-04-testing-strategy.md
*/
import 'reflect-metadata';
// Global test timeout (30 วินาที)
jest.setTimeout(30000);
// Mock console methods ใน test environment
// ลด noise ใน test output แต่ยังเก็บ error ไว้
const originalConsole = {
log: console.log,
info: console.info,
warn: console.warn,
};
global.beforeAll(() => {
// Suppress console.log ใน test (ยกเว้น error)
console.log = jest.fn();
console.info = jest.fn();
console.warn = jest.fn();
});
global.afterAll(() => {
// Restore original console methods
console.log = originalConsole.log;
console.info = originalConsole.info;
console.warn = originalConsole.warn;
});
// Clean up mocks หลังจากแต่ละ test
afterEach(() => {
jest.clearAllMocks();
});
// Global error handler สำหรับ unhandled promises
process.on('unhandledRejection', (reason) => {
console.error('Unhandled Promise Rejection:', reason);
});