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

This commit is contained in:
2025-12-29 18:27:25 -08:00
parent 7a52bf499e
commit e15d2b6c2f
4 changed files with 78 additions and 90 deletions

View File

@@ -5,43 +5,6 @@ import { exec, type ExecException, type ExecOptions } from 'child_process';
import { geocodingService } from '../services/geocodingService.server';
import { createTestApp } from '../tests/utils/createTestApp';
// FIX: Mock util.promisify to correctly handle child_process.exec's (err, stdout, stderr) signature.
// This is required because the standard util.promisify relies on internal symbols on the real exec function,
// which are missing on our Vitest mock. Without this, promisify(mockExec) drops the stdout/stderr arguments.
vi.mock('util', async (importOriginal) => {
const actual = await importOriginal<typeof import('util')>();
return {
...actual,
promisify: (fn: Function) => {
return (...args: any[]) => {
return new Promise((resolve, reject) => {
fn(...args, (err: Error | null, stdout: string, stderr: string) => {
if (err) {
// Attach stdout/stderr to the error object to mimic child_process.exec behavior
Object.assign(err, { stdout, stderr });
reject(err);
} else {
resolve({ stdout, stderr });
}
});
});
};
},
};
});
// 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 {
...actual,
// We provide a basic mock function that will be implemented in each test.
exec: vi.fn(),
};
});
// 2. Mock Geocoding
vi.mock('../services/geocodingService.server', () => ({
geocodingService: {