xinvoice/test/run-tests.ts

74 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-04-03 15:53:08 +00:00
import * as fs from 'fs';
import * as path from 'path';
2025-04-03 13:26:27 +00:00
import { spawn } from 'child_process';
2025-04-03 15:53:08 +00:00
/**
* Runs all tests in the test directory
*/
2025-04-03 13:26:27 +00:00
async function runTests() {
2025-04-03 15:53:08 +00:00
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
2025-04-03 13:26:27 +00:00
for (const test of tests) {
2025-04-03 15:53:08 +00:00
console.log(`\nRunning ${test}...`);
// Run test with tsx
const result = await runTest(test);
2025-04-03 13:26:27 +00:00
2025-04-03 15:53:08 +00:00
if (result.success) {
console.log(`${test} passed`);
} else {
console.error(`${test} failed: ${result.error}`);
process.exit(1);
2025-04-03 13:26:27 +00:00
}
}
2025-04-03 15:53:08 +00:00
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 });
});
});
2025-04-03 13:26:27 +00:00
}
2025-04-03 15:53:08 +00:00
// Run tests
runTests();