fix(tests): update tests and test helpers to current email/DNS APIs, use non-privileged ports, and improve robustness and resilience

This commit is contained in:
2026-02-01 18:10:30 +00:00
parent 2206abd04b
commit b90650c660
23 changed files with 2006 additions and 1756 deletions

View File

@@ -58,7 +58,7 @@ tap.test('DcRouter class - Custom email port configuration', async () => {
// Ensure directory exists and is empty
if (fs.existsSync(customEmailsPath)) {
try {
fs.rmdirSync(customEmailsPath, { recursive: true });
fs.rmSync(customEmailsPath, { recursive: true });
} catch (e) {
console.warn('Could not remove test directory:', e);
}
@@ -123,7 +123,7 @@ tap.test('DcRouter class - Custom email port configuration', async () => {
// Clean up
try {
fs.rmdirSync(customEmailsPath, { recursive: true });
fs.rmSync(customEmailsPath, { recursive: true });
} catch (e) {
console.warn('Could not remove test directory in cleanup:', e);
}
@@ -132,23 +132,24 @@ tap.test('DcRouter class - Custom email port configuration', async () => {
tap.test('DcRouter class - Custom email storage path', async () => {
// Create custom email storage path
const customEmailsPath = path.join(process.cwd(), 'email');
// Ensure directory exists and is empty
if (fs.existsSync(customEmailsPath)) {
try {
fs.rmdirSync(customEmailsPath, { recursive: true });
fs.rmSync(customEmailsPath, { recursive: true });
} catch (e) {
console.warn('Could not remove test directory:', e);
}
}
fs.mkdirSync(customEmailsPath, { recursive: true });
// Create a basic email configuration
// Use high port (2525) to avoid needing root privileges
const emailConfig: IEmailConfig = {
ports: [25],
ports: [2525],
hostname: 'mail.example.com',
defaultMode: 'mta' as EmailProcessingMode,
domainRules: []
domains: [], // Required: domain configurations
routes: [] // Required: email routing rules
};
// Create DcRouter options with custom email storage path
@@ -175,14 +176,14 @@ tap.test('DcRouter class - Custom email storage path', async () => {
expect(fs.existsSync(customEmailsPath)).toEqual(true);
// Verify unified email server was initialized
expect(router.unifiedEmailServer).toBeTruthy();
expect(router.emailServer).toBeTruthy();
// Stop the router
await router.stop();
// Clean up
try {
fs.rmdirSync(customEmailsPath, { recursive: true });
fs.rmSync(customEmailsPath, { recursive: true });
} catch (e) {
console.warn('Could not remove test directory in cleanup:', e);
}