-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.test-d.ts
60 lines (48 loc) · 1.8 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {Resolver, lookup} from 'dns';
import {Agent} from 'https';
import {expectType} from 'tsd';
import * as QuickLRU from 'quick-lru';
import CacheableLookup, {EntryObject} from '.';
(async () => {
const cacheable = new CacheableLookup();
const agent = new Agent();
new CacheableLookup({
cache: new QuickLRU({maxSize: 100}),
fallbackDuration: 0,
errorTtl: 0,
maxTtl: 0,
resolver: new Resolver(),
lookup
});
new CacheableLookup({
lookup: false
});
expectType<string[]>(cacheable.servers);
expectType<EntryObject>(await cacheable.lookupAsync('localhost', 4));
expectType<EntryObject>(await cacheable.lookupAsync('localhost', {all: false}));
expectType<ReadonlyArray<EntryObject>>(await cacheable.lookupAsync('localhost', {all: true}));
cacheable.lookup('localhost', 6, (error, address, family) => {
expectType<NodeJS.ErrnoException | null>(error);
expectType<string>(address);
expectType<4 | 6>(family);
});
cacheable.lookup('localhost', {all: false}, (error, address, family) => {
expectType<NodeJS.ErrnoException | null>(error);
expectType<string>(address);
expectType<4 | 6>(family);
});
cacheable.lookup('localhost', {all: true}, (error, results) => {
expectType<NodeJS.ErrnoException | null>(error);
expectType<ReadonlyArray<EntryObject>>(results);
});
// @types/node has invalid typings :(
// expectType<typeof cacheable.lookup>(lookup);
expectType<ReadonlyArray<EntryObject>>(await cacheable.query('localhost'));
expectType<ReadonlyArray<EntryObject>>(await cacheable.queryAndCache('localhost'));
expectType<void>(cacheable.updateInterfaceInfo());
expectType<void>(cacheable.install(agent));
expectType<void>(cacheable.uninstall(agent));
expectType<void>(cacheable.clear('localhost'));
expectType<void>(cacheable.clear());
cacheable.servers = ['127.0.0.1'];
})();