Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Mar 14, 2020
1 parent cb64179 commit ad8486d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 31 deletions.
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -8,9 +8,10 @@
"files": [
"source"
],
"main": "source/index.js",
"main": "source/index.js",
"types": "source/index.d.ts",
"scripts": {
"test": "xo && nyc ava && tsd"
"test": "xo && nyc ava"
},
"repository": {
"type": "git",
Expand Down
20 changes: 1 addition & 19 deletions source/index.js
Expand Up @@ -181,25 +181,7 @@ class CacheableLookup {
}

async query(hostname) {
let cached = this._hostsResolver.hosts[hostname];

if (!cached) {
cached = this._cache.get(hostname);

if (cached) {
const now = Date.now();

for (let index = 0; index < cached.length;) {
const entry = cached[index];

if (now >= entry.expires || entry.ttl === 0) {
cached.splice(index, 1);
} else {
index++;
}
}
}
}
let cached = this._hostsResolver.hosts[hostname] || this._cache.get(hostname);

if (!cached || cached.length === 0) {
cached = await this.queryAndCache(hostname);
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 4 additions & 10 deletions test.js → tests/test.js
Expand Up @@ -2,9 +2,10 @@ const {V4MAPPED, ADDRCONFIG} = require('dns');
const {Resolver: AsyncResolver} = require('dns').promises;
const {promisify} = require('util');
const http = require('http');
const path = require('path');
const test = require('ava');
const proxyquire = require('proxyquire');
const CacheableLookup = require('.');
const CacheableLookup = require('../source');

const makeRequest = options => new Promise((resolve, reject) => {
http.get(options, resolve).once('error', reject);
Expand Down Expand Up @@ -55,7 +56,7 @@ const mockedInterfaces = options => {
interfaces = createInterfaces(options);
};

const result = proxyquire('.', {
const result = proxyquire('../source', {
os: {
networkInterfaces: () => interfaces
}
Expand Down Expand Up @@ -389,13 +390,6 @@ test('options.throwNotFound', async t => {
await t.throwsAsync(cacheable.lookupAsync('static4', {family: 6}), {code: 'ENOTFOUND'});
});

// eslint-disable-next-line ava/no-skip-test
test.skip('passes errors', async t => {
const cacheable = new CacheableLookup({resolver, customHostsPath: false});

await t.throwsAsync(cacheable.lookupAsync('undefined'), {message: 'no entry'});
});

test('custom servers', async t => {
const cacheable = new CacheableLookup({resolver: createResolver(), customHostsPath: false});

Expand Down Expand Up @@ -717,7 +711,7 @@ test.serial('double tick() has no effect', async t => {

test('respects the `hosts` file', async t => {
const cacheable = new CacheableLookup({
customHostsPath: './hosts.txt'
customHostsPath: path.resolve(__dirname, 'hosts.txt')
});

await sleep(100);
Expand Down

0 comments on commit ad8486d

Please sign in to comment.