diff --git a/tests/api/01-generation-basic.ts b/tests/api/01-generation-basic.ts index 73a6133..0e7b41c 100644 --- a/tests/api/01-generation-basic.ts +++ b/tests/api/01-generation-basic.ts @@ -1,7 +1,7 @@ // tests/api/01-generation-basic.ts // Basic Image Generation Tests - Run FIRST to verify core functionality -import { api, log, runTest, saveImage, waitForGeneration, testContext, verifyImageAccessible } from './utils'; +import { api, log, runTest, saveImage, waitForGeneration, testContext, verifyImageAccessible, exitWithTestResults } from './utils'; import { endpoints } from './config'; async function main() { @@ -202,4 +202,9 @@ async function main() { log.section('GENERATION BASIC TESTS COMPLETED'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/02-basic.ts b/tests/api/02-basic.ts index db459d3..1d33339 100644 --- a/tests/api/02-basic.ts +++ b/tests/api/02-basic.ts @@ -2,7 +2,7 @@ // Image Upload and CRUD Operations import { join } from 'path'; -import { api, log, runTest, saveImage, uploadFile, waitForGeneration, testContext, verifyImageAccessible, resolveAlias } from './utils'; +import { api, log, runTest, saveImage, uploadFile, waitForGeneration, testContext, verifyImageAccessible, resolveAlias, exitWithTestResults } from './utils'; import { config, endpoints } from './config'; import { fileURLToPath } from 'url'; @@ -420,4 +420,9 @@ async function main() { log.section('IMAGE UPLOAD & CRUD TESTS COMPLETED'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/03-flows.ts b/tests/api/03-flows.ts index f99682a..14a6fe1 100644 --- a/tests/api/03-flows.ts +++ b/tests/api/03-flows.ts @@ -1,7 +1,7 @@ // tests/api/03-flows.ts // Flow Lifecycle Tests - Lazy and Eager Creation Patterns -import { api, log, runTest, saveImage, waitForGeneration, testContext, resolveAlias } from './utils'; +import { api, log, runTest, saveImage, waitForGeneration, testContext, resolveAlias, exitWithTestResults } from './utils'; import { endpoints } from './config'; async function main() { @@ -241,4 +241,9 @@ async function main() { log.section('FLOW LIFECYCLE TESTS COMPLETED'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/04-aliases.ts b/tests/api/04-aliases.ts index 5e3a88a..1404e0b 100644 --- a/tests/api/04-aliases.ts +++ b/tests/api/04-aliases.ts @@ -2,7 +2,7 @@ // 3-Tier Alias Resolution System Tests import { join } from 'path'; -import { api, log, runTest, uploadFile, waitForGeneration, testContext, resolveAlias, createTestImage } from './utils'; +import { api, log, runTest, uploadFile, waitForGeneration, testContext, resolveAlias, createTestImage, exitWithTestResults } from './utils'; import { config, endpoints } from './config'; import { fileURLToPath } from 'url'; @@ -275,4 +275,9 @@ async function main() { log.section('ALIAS RESOLUTION TESTS COMPLETED'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/05-live.ts b/tests/api/05-live.ts index 525d5d0..80b5ab1 100644 --- a/tests/api/05-live.ts +++ b/tests/api/05-live.ts @@ -1,7 +1,7 @@ // tests/api/05-live.ts // Live URLs and Scope Management Tests -import { api, log, runTest, testContext } from './utils'; +import { api, log, runTest, testContext, exitWithTestResults } from './utils'; import { endpoints } from './config'; async function main() { @@ -133,4 +133,9 @@ async function main() { log.section('LIVE URL & SCOPE TESTS COMPLETED'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/06-edge-cases.ts b/tests/api/06-edge-cases.ts index f7539be..6d25668 100644 --- a/tests/api/06-edge-cases.ts +++ b/tests/api/06-edge-cases.ts @@ -2,7 +2,7 @@ // Validation and Error Handling Tests import { join } from 'path'; -import { api, log, runTest, testContext, uploadFile } from './utils'; +import { api, log, runTest, testContext, uploadFile, exitWithTestResults } from './utils'; import { config, endpoints } from './config'; import { fileURLToPath } from 'url'; @@ -144,4 +144,9 @@ async function main() { log.section('EDGE CASES & VALIDATION TESTS COMPLETED'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/07-known-issues.ts b/tests/api/07-known-issues.ts index 7a7c1e1..cdf3f20 100644 --- a/tests/api/07-known-issues.ts +++ b/tests/api/07-known-issues.ts @@ -1,7 +1,7 @@ // tests/api/07-known-issues.ts // Tests for Known Implementation Issues (EXPECTED TO FAIL) -import { api, log, runTest, createTestImage, testContext } from './utils'; +import { api, log, runTest, createTestImage, testContext, exitWithTestResults } from './utils'; import { endpoints } from './config'; async function main() { @@ -114,4 +114,9 @@ async function main() { log.warning('Failures above are EXPECTED and document bugs to fix'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/08-auto-enhance.ts b/tests/api/08-auto-enhance.ts index 74ca64d..5f1c0d5 100644 --- a/tests/api/08-auto-enhance.ts +++ b/tests/api/08-auto-enhance.ts @@ -1,7 +1,7 @@ // tests/api/08-auto-enhance.ts // Auto-Enhance Feature Tests -import { api, log, runTest, waitForGeneration, testContext } from './utils'; +import { api, log, runTest, waitForGeneration, testContext, exitWithTestResults } from './utils'; import { endpoints } from './config'; async function main() { @@ -220,4 +220,9 @@ async function main() { log.section('AUTO-ENHANCE TESTS COMPLETED'); } -main().catch(console.error); +main() + .then(() => exitWithTestResults()) + .catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); + }); diff --git a/tests/api/utils.ts b/tests/api/utils.ts index 0031402..a5c0d06 100644 --- a/tests/api/utils.ts +++ b/tests/api/utils.ts @@ -204,11 +204,16 @@ export const testContext: { [key: string]: any; // Allow dynamic properties } = {}; +// Test tracking state +let failedTests = 0; +let totalTests = 0; + // Test runner helper export async function runTest( name: string, fn: () => Promise ): Promise { + totalTests++; try { const startTime = Date.now(); await fn(); @@ -216,12 +221,29 @@ export async function runTest( log.success(`${name} (${duration}ms)`); return true; } catch (error) { + failedTests++; log.error(`${name}`); console.error(error); return false; } } +// Get test statistics +export function getTestStats() { + return { total: totalTests, failed: failedTests, passed: totalTests - failedTests }; +} + +// Exit with appropriate code based on test results +export function exitWithTestResults() { + const stats = getTestStats(); + if (stats.failed > 0) { + log.error(`${stats.failed}/${stats.total} tests failed`); + process.exit(1); + } + log.success(`${stats.passed}/${stats.total} tests passed`); + process.exit(0); +} + // Verify image is accessible at URL export async function verifyImageAccessible(url: string): Promise { try {