import { afterEach, beforeEach, describe, test } from 'bun:test'; import { existsSync } from 'node:fs'; import { mkdir, rm } from 'node:fs/promises'; import { join } from 'node:path'; const TEST_TERRAFORM_DIR = '/tmp/test-terraform-outputs'; beforeEach(async () => { // Create test directory await mkdir(TEST_TERRAFORM_DIR, { recursive: true }); }); afterEach(async () => { // Clean up test directory if (existsSync(TEST_TERRAFORM_DIR)) { await rm(TEST_TERRAFORM_DIR, { recursive: true, force: true }); } }); describe('parseTerraformOutputs', () => { test('parses wrapped Terraform output format', async () => { // Create a mock terraform state directory const tfDir = join(TEST_TERRAFORM_DIR, 'wrapped'); await mkdir(tfDir, { recursive: true }); // Mock terraform output -json by creating a state file // (In reality, terraform reads from .tfstate, but we'll mock the command) // We can't actually test this without mocking executeBuildWithProgress // For now, skip this test - it requires mocking the terraform command // The function is tested indirectly through integration tests }); test('returns null when no outputs defined', async () => { // This would require mocking terraform command that returns "no outputs" // Skip for now - tested through integration tests }); test('throws on invalid JSON output', async () => { // This would require mocking terraform command that returns invalid JSON // Skip for now - tested through integration tests }); }); // Note: These tests are placeholders. The parseTerraformOutputs function // calls executeBuildWithProgress which executes actual terraform commands. // Proper testing requires either: // 1. Mocking executeBuildWithProgress (refactor needed) // 2. Integration tests with real terraform (slow) // 3. Dependency injection of the executor (architectural change) // // We'll rely on: // - Manual testing with real modules // - Integration tests in test-integration/ // - Unit tests of property-extractor (already passing)