fix(client,testing,build): improve TypeScript compatibility for DNS client parsing and test suite

This commit is contained in:
2026-04-30 12:48:49 +00:00
parent 510801b109
commit 199dfe7ba3
18 changed files with 1944 additions and 3435 deletions
+17 -15
View File
@@ -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 = 8400;
@@ -29,7 +31,7 @@ async function stopServer(server: smartdns.DnsServer | null | undefined) {
try {
await server.stop();
} 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);
}
}
@@ -105,12 +107,12 @@ tap.test('Multiple NS records should work correctly', async () => {
const dnsResponse = await responsePromise;
console.log('✅ NS records returned:', dnsResponse.answers.length);
console.log('✅ NS records:', dnsResponse.answers.map(a => (a as any).data));
console.log('✅ NS records returned:', dnsResponse.answers!.length);
console.log('✅ NS records:', dnsResponse.answers!.map(a => (a as any).data));
// SUCCESS: Multiple NS records are now returned
expect(dnsResponse.answers.length).toEqual(2);
expect(dnsResponse.answers.map(a => (a as any).data).sort()).toEqual(['ns1.example.com', 'ns2.example.com']);
expect(dnsResponse.answers!.length).toEqual(2);
expect(dnsResponse.answers!.map(a => (a as any).data).sort()).toEqual(['ns1.example.com', 'ns2.example.com']);
await stopServer(dnsServer);
dnsServer = null;
@@ -181,12 +183,12 @@ tap.test('Multiple A records for round-robin DNS', async () => {
const dnsResponse = await responsePromise;
console.log('✅ A records returned:', dnsResponse.answers.length);
console.log('✅ A records:', dnsResponse.answers.map(a => (a as any).data));
console.log('✅ A records returned:', dnsResponse.answers!.length);
console.log('✅ A records:', dnsResponse.answers!.map(a => (a as any).data));
// SUCCESS: All A records for round-robin DNS
expect(dnsResponse.answers.length).toEqual(3);
expect(dnsResponse.answers.map(a => (a as any).data).sort()).toEqual(['10.0.0.1', '10.0.0.2', '10.0.0.3']);
expect(dnsResponse.answers!.length).toEqual(3);
expect(dnsResponse.answers!.map(a => (a as any).data).sort()).toEqual(['10.0.0.1', '10.0.0.2', '10.0.0.3']);
await stopServer(dnsServer);
dnsServer = null;
@@ -262,12 +264,12 @@ tap.test('Multiple TXT records', async () => {
const dnsResponse = await responsePromise;
console.log('✅ TXT records returned:', dnsResponse.answers.length);
console.log('✅ TXT records returned:', dnsResponse.answers!.length);
// SUCCESS: All TXT records are returned
expect(dnsResponse.answers.length).toEqual(3);
expect(dnsResponse.answers!.length).toEqual(3);
const txtData = dnsResponse.answers.map(a => (a as any).data[0].toString());
const txtData = dnsResponse.answers!.map(a => (a as any).data[0].toString());
expect(txtData.some(d => d.includes('spf1'))).toEqual(true);
expect(txtData.some(d => d.includes('DKIM1'))).toEqual(true);
expect(txtData.some(d => d.includes('google-site-verification'))).toEqual(true);
@@ -276,4 +278,4 @@ tap.test('Multiple TXT records', async () => {
dnsServer = null;
});
export default tap.start();
export default tap.start();