feature/api-development #1
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<void>
|
||||
): Promise<boolean> {
|
||||
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<boolean> {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue