#!/usr/bin/env node /** * SDK Basic Functionality Test Script */ // @ts-expect-error - Node.js types will be available at runtime const TEST_API_KEY = process.env.SUPERTONE_API_KEY || "test_api_key_for_structure_validation"; /** * Test result interface */ interface TestResult { name: string; passed: boolean; } /** * Test SDK import */ async function testSdkImport(): Promise { try { const { Supertone } = await import("../src/index.js"); const models = await import("../src/models/index.js"); console.log("โœ… SDK import successful"); return true; } catch (e) { console.error(`โŒ SDK import failed: ${e}`); return false; } } /** * Test SDK initialization */ async function testSdkInitialization(): Promise { try { const { Supertone } = await import("../src/index.js"); const sdk = new Supertone({ apiKey: TEST_API_KEY }); console.log("โœ… SDK initialization successful"); return true; } catch (e) { console.error(`โŒ SDK initialization failed: ${e}`); return false; } } /** * Test SDK structure */ async function testSdkStructure(): Promise { try { const { Supertone } = await import("../src/index.js"); const sdk = new Supertone({ apiKey: TEST_API_KEY }); console.log("๐Ÿ“‹ SDK structure check:"); // Check text_to_speech client if (sdk.textToSpeech) { const ttsMethods = Object.getOwnPropertyNames( Object.getPrototypeOf(sdk.textToSpeech) ).filter((method) => !method.startsWith("_") && method !== "constructor"); console.log(` โœ… textToSpeech client: ${ttsMethods.join(", ")}`); } else { console.log(" โŒ textToSpeech client not found"); } // Check voices client if (sdk.voices) { const voiceMethods = Object.getOwnPropertyNames( Object.getPrototypeOf(sdk.voices) ).filter((method) => !method.startsWith("_") && method !== "constructor"); console.log(` โœ… voices client: ${voiceMethods.join(", ")}`); } else { console.log(" โŒ voices client not found"); } // Check custom_voices client if (sdk.customVoices) { const customMethods = Object.getOwnPropertyNames( Object.getPrototypeOf(sdk.customVoices) ).filter((method) => !method.startsWith("_") && method !== "constructor"); console.log(` โœ… customVoices client: ${customMethods.join(", ")}`); } else { console.log(" โŒ customVoices client not found"); } // Check usage client if (sdk.usage) { const usageMethods = Object.getOwnPropertyNames( Object.getPrototypeOf(sdk.usage) ).filter((method) => !method.startsWith("_") && method !== "constructor"); console.log(` โœ… usage client: ${usageMethods.join(", ")}`); } else { console.log(" โŒ usage client not found"); } return true; } catch (e) { console.error(`โŒ SDK structure check failed: ${e}`); return false; } } /** * Test model classes */ async function testModels(): Promise { try { const models = await import("../src/models/index.js"); console.log("๐Ÿ“‹ Models check:"); // Check available models const availableModels = Object.keys(models).filter( (key) => !key.startsWith("_") ); console.log(` โœ… Available models: ${availableModels.length} items`); return true; } catch (e) { console.error(`โŒ Models test failed: ${e}`); return false; } } /** * Test SDK methods existence */ async function testSdkMethods(): Promise { try { const { Supertone } = await import("../src/index.js"); const sdk = new Supertone({ apiKey: TEST_API_KEY }); console.log("โœ… SDK instance creation successful"); // Check if SDK methods are callable if ( sdk.textToSpeech && typeof sdk.textToSpeech.createSpeech === "function" ) { console.log(" โœ… createSpeech method exists"); } else { console.log(" โŒ createSpeech method not found"); } if ( sdk.textToSpeech && typeof sdk.textToSpeech.streamSpeech === "function" ) { console.log(" โœ… streamSpeech method exists"); } else { console.log(" โŒ streamSpeech method not found"); } if (sdk.voices && typeof sdk.voices.listVoices === "function") { console.log(" โœ… listVoices method exists"); } else { console.log(" โŒ listVoices method not found"); } return true; } catch (e) { console.error(`โŒ SDK methods test failed: ${e}`); return false; } } /** * Test custom utilities */ async function testCustomUtilities(): Promise { try { const customUtils = await import("../src/lib/custom_utils/index.js"); console.log("๐Ÿ“‹ Custom utilities check:"); const utilities = [ "chunkText", "mergeWavBinary", "mergeMp3Binary", "detectAudioFormat", "mergePhonemeData", ]; let allFound = true; for (const util of utilities) { if (util in customUtils) { console.log(` โœ… ${util} utility exists`); } else { console.log(` โŒ ${util} utility not found`); allFound = false; } } return allFound; } catch (e) { console.error(`โŒ Custom utilities test failed: ${e}`); return false; } } /** * Main test execution */ async function main(): Promise { console.log("๐Ÿงช SDK Basic Test Start"); console.log("=".repeat(50)); const tests: Array<[string, () => Promise]> = [ ["SDK Import", testSdkImport], ["SDK Initialization", testSdkInitialization], ["SDK Structure", testSdkStructure], ["Models", testModels], ["SDK Methods", testSdkMethods], ["Custom Utilities", testCustomUtilities], ]; const results: TestResult[] = []; for (const [testName, testFunc] of tests) { console.log(`\n๐Ÿ” Testing ${testName}...`); const passed = await testFunc(); results.push({ name: testName, passed }); } console.log("\n" + "=".repeat(50)); console.log("๐Ÿงช Test Results Summary:"); const passedCount = results.filter((r) => r.passed).length; const totalCount = results.length; for (const result of results) { const status = result.passed ? "โœ… PASS" : "โŒ FAIL"; console.log(` ${result.name}: ${status}`); } console.log(`\nTotal ${passedCount}/${totalCount} tests passed`); if (passedCount === totalCount) { console.log("๐ŸŽ‰ All tests passed! SDK is working correctly."); // @ts-expect-error - Node.js types will be available at runtime process.exit(0); } else { console.log("โš ๏ธ Some tests failed. Please check the issues."); // @ts-expect-error - Node.js types will be available at runtime process.exit(1); } } // Run tests main().catch((error) => { console.error("โŒ Test execution failed:", error); // @ts-expect-error - Node.js types will be available at runtime process.exit(1); });