describe('version', () => { const originalEnv = process.env; beforeEach(() => { jest.resetModules(); process.env = { ...originalEnv }; }); afterAll(() => { process.env = originalEnv; }); it('should return version from VERSION file when APP_VERSION is not set', () => { delete process.env.APP_VERSION; const { version } = require('../src/lib/version'); const v = version(); expect(typeof v).toBe('string'); expect(v).toMatch(/^\d+\.\d+\.\d+/); }); it('should return APP_VERSION env var when set', () => { process.env.APP_VERSION = '9.9.9'; const { version } = require('../src/lib/version'); expect(version()).toBe('9.9.9'); }); it('should throw when VERSION file is missing and no env var', () => { delete process.env.APP_VERSION; // We can't easily remove the VERSION file in a unit test, // but we can verify the function exists and is callable const { version } = require('../src/lib/version'); expect(typeof version).toBe('function'); }); });