fix unit tests
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 12m3s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 12m3s
This commit is contained in:
@@ -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(),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user