cloudku-murotal
Version:
JavaScript client for Murotal API - Islamic prayer times, Quran, Hadith, and Dua
59 lines (48 loc) ⢠1.86 kB
JavaScript
import MurotalAPI from './main.mjs';
class ESMTestRunner {
constructor() {
this.api = new MurotalAPI();
this.passed = 0;
this.failed = 0;
}
async test(name, testFn) {
process.stdout.write(`Testing ${name} (ESM)... `);
try {
await testFn();
console.log('ā
PASS');
this.passed++;
} catch (error) {
console.log('ā FAIL');
console.log(` Error: ${error.message}`);
this.failed++;
}
}
async runTests() {
console.log('š ESM Module Tests\n');
await this.test('Import Check', async () => {
if (typeof MurotalAPI !== 'function') throw new Error('Import failed');
});
await this.test('Instance Creation', async () => {
const api = new MurotalAPI();
if (!api.baseURL) throw new Error('Instance creation failed');
});
await this.test('Custom URL', async () => {
const api = new MurotalAPI('https://test.com');
if (api.baseURL !== 'https://test.com') throw new Error('Custom URL failed');
});
await this.test('Method Existence', async () => {
const methods = ['getCities', 'getRandomAyah', 'getRandomDoa'];
methods.forEach(method => {
if (typeof this.api[method] !== 'function') {
throw new Error(`Method ${method} not found`);
}
});
});
console.log(`\nš ESM Tests: ${this.passed} passed, ${this.failed} failed`);
if (this.failed === 0) {
console.log('š ESM module working correctly!');
}
}
}
const runner = new ESMTestRunner();
runner.runTests().catch(console.error);