mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-29 22:02:02 +00:00
fix(test): Set HOSTNAME in dev server tests for consistent behavior
Dev server test was failing on non-localhost hostnames (e.g., 'fedora') because it expected 'localhost' in the URL. Now sets HOSTNAME env var in test setup and restores it in teardown for consistent test behavior across all environments. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,11 +30,16 @@ import net from 'net';
|
||||
|
||||
describe('dev-server-service.ts', () => {
|
||||
let testDir: string;
|
||||
let originalHostname: string | undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
vi.resetModules();
|
||||
|
||||
// Store and set HOSTNAME for consistent test behavior
|
||||
originalHostname = process.env.HOSTNAME;
|
||||
process.env.HOSTNAME = 'localhost';
|
||||
|
||||
testDir = path.join(os.tmpdir(), `dev-server-test-${Date.now()}`);
|
||||
await fs.mkdir(testDir, { recursive: true });
|
||||
|
||||
@@ -56,6 +61,13 @@ describe('dev-server-service.ts', () => {
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
// Restore original HOSTNAME
|
||||
if (originalHostname === undefined) {
|
||||
delete process.env.HOSTNAME;
|
||||
} else {
|
||||
process.env.HOSTNAME = originalHostname;
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.rm(testDir, { recursive: true, force: true });
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user