fix unit tests
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 12m3s

This commit is contained in:
2025-12-29 17:57:40 -08:00
parent 4a4f349805
commit 2489ec8d2d
5 changed files with 106 additions and 79 deletions

View File

@@ -30,17 +30,15 @@ vi.mock('util', async (importOriginal) => {
};
});
// FIX: Use the simple factory pattern for child_process to avoid default export issues
vi.mock('child_process', () => {
const mockExec = vi.fn((command, callback) => {
if (typeof callback === 'function') {
callback(null, 'PM2 OK', '');
}
return { unref: () => {} };
});
// The `importOriginal` pattern is the robust way to mock built-in Node modules.
// It preserves the module's original structure, preventing "No default export" errors
// that can occur with simple factory mocks when using ESM-based test runners like Vitest.
vi.mock('child_process', async (importOriginal) => {
const actual = await importOriginal<typeof import('child_process')>();
return {
exec: mockExec,
...actual,
// We provide a basic mock function that will be implemented in each test.
exec: vi.fn(),
};
});