xinvoice/test/run-tests.ts
2025-04-03 15:53:08 +00:00

74 lines
1.7 KiB
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import { spawn } from 'child_process';
/**
* Runs all tests in the test directory
*/
async function runTests() {
console.log('Running tests...');
// Test files to run
const tests = [
// Main tests
'test.pdf-export.ts',
// New tests for refactored code
'test.facturx.ts',
'test.xinvoice.ts',
'test.xinvoice-functionality.ts',
'test.facturx-circular.ts'
];
// Run each test
for (const test of tests) {
console.log(`\nRunning ${test}...`);
// Run test with tsx
const result = await runTest(test);
if (result.success) {
console.log(`${test} passed`);
} else {
console.error(`${test} failed: ${result.error}`);
process.exit(1);
}
}
console.log('\nAll tests passed!');
}
/**
* Runs a single test
* @param testFile Test file to run
* @returns Test result
*/
function runTest(testFile: string): Promise<{ success: boolean; error?: string }> {
return new Promise((resolve) => {
const testPath = path.join(process.cwd(), 'test', testFile);
// Check if test file exists
if (!fs.existsSync(testPath)) {
resolve({ success: false, error: `Test file ${testPath} does not exist` });
return;
}
// Run test with tsx
const child = spawn('tsx', [testPath], { stdio: 'inherit' });
child.on('close', (code) => {
if (code === 0) {
resolve({ success: true });
} else {
resolve({ success: false, error: `Test exited with code ${code}` });
}
});
child.on('error', (error) => {
resolve({ success: false, error: error.message });
});
});
}
// Run tests
runTests();