fix(client,testing,build): improve TypeScript compatibility for DNS client parsing and test suite
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import * as plugins from '../ts_server/plugins.js';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { tapNodeTools } from '@git.zone/tstest/tapbundle_serverside';
|
||||
import { TapNodeTools } from '@git.zone/tstest/tapbundle_serverside';
|
||||
import * as dnsPacket from 'dns-packet';
|
||||
import * as dgram from 'dgram';
|
||||
|
||||
import * as smartdns from '../ts_server/index.js';
|
||||
|
||||
let dnsServer: smartdns.DnsServer;
|
||||
const tapNodeTools = new TapNodeTools(tap);
|
||||
|
||||
let dnsServer: smartdns.DnsServer | null;
|
||||
|
||||
// Port management for tests
|
||||
let nextHttpsPort = 8200;
|
||||
@@ -34,7 +36,7 @@ async function stopServer(server: smartdns.DnsServer | null | undefined) {
|
||||
|
||||
await Promise.race([stopPromise, timeoutPromise]);
|
||||
} catch (e) {
|
||||
console.log('Handled error when stopping server:', e.message || e);
|
||||
console.log('Handled error when stopping server:', e instanceof Error ? e.message : e);
|
||||
|
||||
// Force close if normal stop fails
|
||||
try {
|
||||
@@ -49,7 +51,7 @@ async function stopServer(server: smartdns.DnsServer | null | undefined) {
|
||||
(server as any).udpServer = null;
|
||||
}
|
||||
} catch (forceError) {
|
||||
console.log('Force cleanup error:', forceError.message || forceError);
|
||||
console.log('Force cleanup error:', forceError instanceof Error ? forceError.message : forceError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,12 +130,12 @@ tap.test('should properly return multiple NS records', async () => {
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
console.log('Current behavior - NS records returned:', dnsResponse.answers.length);
|
||||
console.log('NS records:', dnsResponse.answers.map(a => (a as any).data));
|
||||
console.log('Current behavior - NS records returned:', dnsResponse.answers!.length);
|
||||
console.log('NS records:', dnsResponse.answers!.map(a => (a as any).data));
|
||||
|
||||
// Should return all registered NS records
|
||||
expect(dnsResponse.answers.length).toEqual(2);
|
||||
const nsData = dnsResponse.answers.map(a => (a as any).data).sort();
|
||||
expect(dnsResponse.answers!.length).toEqual(2);
|
||||
const nsData = dnsResponse.answers!.map(a => (a as any).data).sort();
|
||||
expect(nsData).toEqual(['ns1.example.com', 'ns2.example.com']);
|
||||
|
||||
await stopServer(dnsServer);
|
||||
@@ -225,12 +227,12 @@ tap.test('should properly return multiple A records for round-robin DNS', async
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
console.log('Current behavior - A records returned:', dnsResponse.answers.length);
|
||||
console.log('A records:', dnsResponse.answers.map(a => (a as any).data));
|
||||
console.log('Current behavior - A records returned:', dnsResponse.answers!.length);
|
||||
console.log('A records:', dnsResponse.answers!.map(a => (a as any).data));
|
||||
|
||||
// Should return all registered A records for round-robin DNS
|
||||
expect(dnsResponse.answers.length).toEqual(3);
|
||||
const aData = dnsResponse.answers.map(a => (a as any).data).sort();
|
||||
expect(dnsResponse.answers!.length).toEqual(3);
|
||||
const aData = dnsResponse.answers!.map(a => (a as any).data).sort();
|
||||
expect(aData).toEqual(['10.0.0.1', '10.0.0.2', '10.0.0.3']);
|
||||
|
||||
await stopServer(dnsServer);
|
||||
@@ -322,12 +324,12 @@ tap.test('should properly return multiple TXT records', async () => {
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
console.log('Current behavior - TXT records returned:', dnsResponse.answers.length);
|
||||
console.log('TXT records:', dnsResponse.answers.map(a => (a as any).data));
|
||||
console.log('Current behavior - TXT records returned:', dnsResponse.answers!.length);
|
||||
console.log('TXT records:', dnsResponse.answers!.map(a => (a as any).data));
|
||||
|
||||
// Should return all registered TXT records
|
||||
expect(dnsResponse.answers.length).toEqual(3);
|
||||
const txtData = dnsResponse.answers.map(a => (a as any).data[0]).sort();
|
||||
expect(dnsResponse.answers!.length).toEqual(3);
|
||||
const txtData = dnsResponse.answers!.map(a => (a as any).data[0]).sort();
|
||||
expect(txtData[0]).toInclude('google-site-verification');
|
||||
expect(txtData[1]).toInclude('DKIM1');
|
||||
expect(txtData[2]).toInclude('spf1');
|
||||
@@ -408,17 +410,17 @@ tap.test('should rotate between records when using a single handler', async () =
|
||||
|
||||
const [response1, response2] = await Promise.all([responsePromise1, responsePromise2]);
|
||||
|
||||
console.log('First query NS:', (response1.answers[0] as any).data);
|
||||
console.log('Second query NS:', (response2.answers[0] as any).data);
|
||||
console.log('First query NS:', (response1.answers![0] as any).data);
|
||||
console.log('Second query NS:', (response2.answers![0] as any).data);
|
||||
|
||||
// This pattern rotates between records but returns one at a time per query
|
||||
expect(response1.answers.length).toEqual(1);
|
||||
expect(response2.answers.length).toEqual(1);
|
||||
expect((response1.answers[0] as any).data).toEqual('ns1.example.com');
|
||||
expect((response2.answers[0] as any).data).toEqual('ns2.example.com');
|
||||
expect(response1.answers!.length).toEqual(1);
|
||||
expect(response2.answers!.length).toEqual(1);
|
||||
expect((response1.answers![0] as any).data).toEqual('ns1.example.com');
|
||||
expect((response2.answers![0] as any).data).toEqual('ns2.example.com');
|
||||
|
||||
await stopServer(dnsServer);
|
||||
dnsServer = null;
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user