feat: improve tests
This commit is contained in:
parent
504b1f8395
commit
e70610e00d
|
|
@ -1,7 +1,7 @@
|
||||||
// tests/api/01-generation-basic.ts
|
// tests/api/01-generation-basic.ts
|
||||||
// Basic Image Generation Tests - Run FIRST to verify core functionality
|
// 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';
|
import { endpoints } from './config';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
@ -202,4 +202,9 @@ async function main() {
|
||||||
log.section('GENERATION BASIC TESTS COMPLETED');
|
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
|
// Image Upload and CRUD Operations
|
||||||
|
|
||||||
import { join } from 'path';
|
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 { config, endpoints } from './config';
|
||||||
|
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
@ -420,4 +420,9 @@ async function main() {
|
||||||
log.section('IMAGE UPLOAD & CRUD TESTS COMPLETED');
|
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
|
// tests/api/03-flows.ts
|
||||||
// Flow Lifecycle Tests - Lazy and Eager Creation Patterns
|
// 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';
|
import { endpoints } from './config';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
@ -241,4 +241,9 @@ async function main() {
|
||||||
log.section('FLOW LIFECYCLE TESTS COMPLETED');
|
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
|
// 3-Tier Alias Resolution System Tests
|
||||||
|
|
||||||
import { join } from 'path';
|
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 { config, endpoints } from './config';
|
||||||
|
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
@ -275,4 +275,9 @@ async function main() {
|
||||||
log.section('ALIAS RESOLUTION TESTS COMPLETED');
|
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
|
// tests/api/05-live.ts
|
||||||
// Live URLs and Scope Management Tests
|
// 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';
|
import { endpoints } from './config';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
@ -133,4 +133,9 @@ async function main() {
|
||||||
log.section('LIVE URL & SCOPE TESTS COMPLETED');
|
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
|
// Validation and Error Handling Tests
|
||||||
|
|
||||||
import { join } from 'path';
|
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 { config, endpoints } from './config';
|
||||||
|
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
@ -144,4 +144,9 @@ async function main() {
|
||||||
log.section('EDGE CASES & VALIDATION TESTS COMPLETED');
|
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/api/07-known-issues.ts
|
||||||
// Tests for Known Implementation Issues (EXPECTED TO FAIL)
|
// 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';
|
import { endpoints } from './config';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
@ -114,4 +114,9 @@ async function main() {
|
||||||
log.warning('Failures above are EXPECTED and document bugs to fix');
|
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
|
// tests/api/08-auto-enhance.ts
|
||||||
// Auto-Enhance Feature Tests
|
// 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';
|
import { endpoints } from './config';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
@ -220,4 +220,9 @@ async function main() {
|
||||||
log.section('AUTO-ENHANCE TESTS COMPLETED');
|
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
|
[key: string]: any; // Allow dynamic properties
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
|
// Test tracking state
|
||||||
|
let failedTests = 0;
|
||||||
|
let totalTests = 0;
|
||||||
|
|
||||||
// Test runner helper
|
// Test runner helper
|
||||||
export async function runTest(
|
export async function runTest(
|
||||||
name: string,
|
name: string,
|
||||||
fn: () => Promise<void>
|
fn: () => Promise<void>
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
totalTests++;
|
||||||
try {
|
try {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
await fn();
|
await fn();
|
||||||
|
|
@ -216,12 +221,29 @@ export async function runTest(
|
||||||
log.success(`${name} (${duration}ms)`);
|
log.success(`${name} (${duration}ms)`);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
failedTests++;
|
||||||
log.error(`${name}`);
|
log.error(`${name}`);
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return false;
|
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
|
// Verify image is accessible at URL
|
||||||
export async function verifyImageAccessible(url: string): Promise<boolean> {
|
export async function verifyImageAccessible(url: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue