Wire up Dead Domain CI Check for Node.js 26 [skip ci]

This commit is contained in:
SukkaW
2026-08-09 18:32:00 +08:00
parent 14f5811242
commit f141253cfe
5 changed files with 41 additions and 13 deletions

View File

@@ -174,6 +174,8 @@ const agent = new Agent({
})
);
export { agent as fetchAgent };
export interface FetchResponseProgress {
onResponseStart?: (contentEncoding: string | null) => void,
onEncodedBodyChunk?: (bytes: number) => void,

View File

@@ -0,0 +1,20 @@
import { describe, it } from 'mocha';
import { expect } from 'earl';
import { DOMAIN_ALIVE_REASON_MESSAGES, DOMAIN_ALIVE_REASONS } from 'domain-alive';
import { createDomainAliveMethods } from './is-domain-alive';
describe('domain-alive integration', () => {
it('constructs the checkers with the custom DoH agent', async () => {
const { isDomainAlive, isRegisterableDomainAlive } = createDomainAliveMethods({});
const [domainResult, registerableDomainResult] = await Promise.all([
isDomainAlive(''),
isRegisterableDomainAlive('')
]);
expect(domainResult.reason).toEqual(DOMAIN_ALIVE_REASONS.INVALID_DOMAIN);
expect(registerableDomainResult.reason).toEqual(DOMAIN_ALIVE_REASONS.INVALID_DOMAIN);
expect(DOMAIN_ALIVE_REASON_MESSAGES[domainResult.reason]).toEqual(
'No registerable domain could be extracted.'
);
});
});

View File

@@ -1,5 +1,5 @@
import { createDomainAliveChecker, createRegisterableDomainAliveChecker } from 'domain-alive';
import { $$fetch, fetchForDoH } from './fetch-retry';
import { $$fetch, fetchAgent, fetchForDoH } from './fetch-retry';
const dnsServers = [
'https://8.8.8.8/dns-query', 'https://8.8.4.4/dns-query',
@@ -55,14 +55,13 @@ const dnsServers = [
const resultCache = new Map();
const registerableDomainResultCache = new Map();
export async function getMethods() {
const customWhoisServersMapping = await (await ($$fetch('https://cdn.jsdelivr.net/npm/whois-servers-list@latest/list.json'))).json() as any;
export function createDomainAliveMethods(customWhoisServersMapping: Record<string, string>) {
const isRegisterableDomainAlive = createRegisterableDomainAliveChecker({
dns: {
dnsServers,
maxAttempts: 6,
customFetchForDoH: fetchForDoH as typeof fetch
customFetchForDoH: fetchForDoH as typeof fetch,
customAgentForDoH: fetchAgent
},
registerableDomainResultCache,
whois: {
@@ -74,7 +73,8 @@ export async function getMethods() {
dns: {
dnsServers,
maxAttempts: 6,
customFetchForDoH: fetchForDoH as typeof fetch
customFetchForDoH: fetchForDoH as typeof fetch,
customAgentForDoH: fetchAgent
},
registerableDomainResultCache,
resultCache,
@@ -84,4 +84,10 @@ export async function getMethods() {
});
return { isRegisterableDomainAlive, isDomainAlive };
}
export async function getMethods() {
const customWhoisServersMapping = await (await ($$fetch('https://cdn.jsdelivr.net/npm/whois-servers-list@latest/list.json'))).json() as Record<string, string>;
return createDomainAliveMethods(customWhoisServersMapping);
};