Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/modernize'
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalia Kowalczyk committed Jan 26, 2025
2 parents e13d0c6 + b72530b commit f04f735
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 84 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"eqnull": true,
"immed": true,
"latedef": "nofunc",
"mocha" : true,
"newcap": true,
"noarg": true,
"node": true,
Expand Down
17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ lint:
./node_modules/.bin/jshint *.js lib test

test:
./node_modules/.bin/mocha \
--recursive \
--node-option no-experimental-fetch \
--require should \
--require test/replay \
--require isomorphic-fetch

.PHONY: check lint test
node --test \
$(TEST_OPTS) \
--require ./test/replay/index.js

test-cov: TEST_OPTS := --experimental-test-coverage
test-cov: test

.PHONY: check lint test test-cov

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
"limiter-component": "~1"
},
"devDependencies": {
"@pirxpilot/jshint": "^3.1.0",
"@pirxpilot/replay": "^2.2.1",
"isomorphic-fetch": "^3.0.0",
"jshint": "~2",
"mocha": "~10",
"should": "~13"
"chai": "~4",
"node-fetch": "~2"
},
"scripts": {
"test": "make check"
Expand Down
17 changes: 10 additions & 7 deletions test/geocode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const should = require('should');
const { describe, it } = require('node:test');
const should = require('chai').should();
const furkotGeocode = require('../lib/geocode');

/* global AbortController */
Expand Down Expand Up @@ -78,8 +79,7 @@ describe('furkot-geocode node module', function () {
geocode.options.should.have.property('reverse').with.length(1);
});

it('timeout', async function () {
this.slow(200);
it('timeout', { timeout: 200 }, async function () {
const service = timeService(100);
const geocode = furkotGeocode({
forward: [
Expand All @@ -88,12 +88,13 @@ describe('furkot-geocode node module', function () {
reverse: [],
timeout: 50
});
return geocode({}).should.be.rejectedWith({ cause: Symbol.for('timeout') });
return geocode({})
.then(() => should.fail('exception expected'))
.catch(err => err.should.have.property('cause', Symbol.for('timeout')));
});


it('abort', async function () {
this.slow(200);
it('abort', { timeout: 200 }, async function () {
const service = timeService(100);
const geocode = furkotGeocode({
forward: [
Expand All @@ -104,7 +105,9 @@ describe('furkot-geocode node module', function () {
const ac = new AbortController();
const p = geocode({}, { signal: ac.signal });
ac.abort();
return p.should.be.rejectedWith({ name: 'AbortError' });
return p
.then(() => should.fail('exception expected'))
.catch(err => err.should.have.property('name', 'AbortError'));
});


Expand Down
9 changes: 9 additions & 0 deletions test/replay/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
require('chai').should();

const legacyFetch = require('node-fetch');

globalThis.fetch = legacyFetch;
globalThis.Response = legacyFetch.Response;
globalThis.Headers = legacyFetch.Headers;
globalThis.Request = legacyFetch.Request;

const Replay = require('@pirxpilot/replay');
Replay.fixtures = __dirname;

Expand Down
7 changes: 4 additions & 3 deletions test/service/geocodio/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const should = require('should');
const { describe, it } = require('node:test');
const should = require('chai').should();
const geocodio = require('../../../lib/service/geocodio');

describe('geocodio geocoding', function () {
Expand All @@ -15,7 +16,7 @@ describe('geocodio geocoding', function () {
const result = await geocode('forward', 1, query);
should.exist(result);
result.should.have.property('places').with.length(2);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-87.12502, 39.52365],
address: 'Brazil, IN',
normal: 'Brazil,IN,US',
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('geocodio geocoding', function () {
const result = await geocode('reverse', 1, query);
should.exist(result);
result.should.have.property('places').with.length(8);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-111.400596, 45.284265],
address: '50 Big Sky Resort Rd, Big Sky, MT',
normal: '50 Big Sky Resort Rd,Big Sky,MT,US',
Expand Down
29 changes: 15 additions & 14 deletions test/service/graphhopper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const should = require('should');
const { describe, it } = require('node:test');
const should = require('chai').should();
const graphhopper = require('../../../lib/service/graphhopper');

describe('graphhopper geocoding', function () {
Expand All @@ -17,7 +18,7 @@ describe('graphhopper geocoding', function () {
const result = await geocode('forward', 1, query);
should.exist(result);
result.should.have.property('places').with.length(1);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-46.8359735, -23.5370962],
type: 'residential',
street: 'Rua Cafelândia',
Expand All @@ -38,7 +39,7 @@ describe('graphhopper geocoding', function () {
const result = await geocode('forward', 1, query);
should.exist(result);
result.should.have.property('places').with.length(4);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [18.65868924925842, 54.351528200000004],
place: 'SS Sołdek',
type: 'museum',
Expand All @@ -61,23 +62,23 @@ describe('graphhopper geocoding', function () {
const result = await geocode('forward', 1, query);
should.exist(result);
result.should.have.property('places').with.length(5);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-73.1745473, 42.4750847],
type: 'peak',
country: 'USA',
place: 'Main Street Cemetery',
address: 'United States',
normal: 'US'
});
result.places[1].should.deepEqual({
result.places[1].should.deep.equal({
ll: [-69.2728254, 44.8350646],
type: 'dam',
country: 'USA',
place: 'Main Street Dam',
address: 'United States',
normal: 'US'
});
result.places[2].should.deepEqual({
result.places[2].should.deep.equal({
ll: [-71.086670478147, 42.36274665],
type: 'construction',
house: '325',
Expand All @@ -89,15 +90,15 @@ describe('graphhopper geocoding', function () {
address: '325 Main Street, Cambridge, MA',
normal: '325 Main Street,Cambridge,MA,US'
});
result.places[3].should.deepEqual({
result.places[3].should.deep.equal({
ll: [-71.6192199, 42.5524712],
type: 'dam',
country: 'USA',
place: 'West Main Street Dam',
address: 'United States',
normal: 'US'
});
result.places[4].should.deepEqual({
result.places[4].should.deep.equal({
ll: [-10.6756677, 6.5080848],
type: 'hamlet',
province: 'Montserrado County',
Expand All @@ -116,7 +117,7 @@ describe('graphhopper geocoding', function () {
const result = await geocode('reverse', 1, query);
should.exist(result);
result.should.have.property('places').with.length(5);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [14.5268016, -22.6791826],
place: 'Beryl\'s Restaurant',
type: 'restaurant',
Expand All @@ -137,7 +138,7 @@ describe('graphhopper geocoding', function () {
const result = await geocode('reverse', 1, query);
should.exist(result);
result.should.have.property('places').with.length(5);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-111.40065600201527, 45.284264],
type: 'yes',
street: 'Black Eagle',
Expand All @@ -147,7 +148,7 @@ describe('graphhopper geocoding', function () {
address: 'Black Eagle, MT',
normal: 'Black Eagle,,MT,US'
});
result.places[1].should.deepEqual({
result.places[1].should.deep.equal({
ll: [-111.4011158, 45.2839783],
type: 'sports_centre',
house: '50',
Expand All @@ -159,7 +160,7 @@ describe('graphhopper geocoding', function () {
address: '50 Big Sky Resort Road, Big Sky, MT',
normal: '50 Big Sky Resort Road,Big Sky,MT,US'
});
result.places[2].should.deepEqual({
result.places[2].should.deep.equal({
ll: [-111.40110501870444, 45.284622],
type: 'yes',
street: 'Black Eagle',
Expand All @@ -169,7 +170,7 @@ describe('graphhopper geocoding', function () {
address: 'Black Eagle, MT',
normal: 'Black Eagle,,MT,US'
});
result.places[3].should.deepEqual({
result.places[3].should.deep.equal({
ll: [-111.4015212, 45.2842756],
type: 'bicycle_rental',
street: 'Mountain to Meadow',
Expand All @@ -180,7 +181,7 @@ describe('graphhopper geocoding', function () {
address: 'Mountain to Meadow, Big Sky, MT',
normal: 'Mountain to Meadow,Big Sky,MT,US'
});
result.places[4].should.deepEqual({
result.places[4].should.deep.equal({
ll: [-111.40158763890292, 45.284196300000005],
type: 'yes',
street: 'Mountain to Meadow',
Expand Down
7 changes: 4 additions & 3 deletions test/service/hogfish/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const should = require('should');
const { describe, it } = require('node:test');
const should = require('chai').should();
const hogfish = require('../../../lib/service/hogfish');

describe('hogfish geocoding', function () {
Expand Down Expand Up @@ -29,7 +30,7 @@ describe('hogfish geocoding', function () {
const result = await geocode('reverse', 1, query);
should.exist(result);
result.should.have.property('places').with.length(1);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-104.86063, 39.59278],
place: 'Murphy Express',
url: 'https://www.pure-gas.org/station?station_id=40499',
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('hogfish geocoding', function () {
const result = await geocode('reverse', 1, query);
should.exist(result);
result.should.have.property('places').with.length(1);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-104.879164, 39.591416],
place: 'Hyatt House Denver Tech Center',
street: '9280 E Costilla Ave',
Expand Down
11 changes: 6 additions & 5 deletions test/service/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const should = require('should');
const { describe, it } = require('node:test');
const should = require('chai').should();
const service = require('../../lib/service');

describe('geocoding service', function () {
Expand Down Expand Up @@ -29,8 +30,7 @@ describe('geocoding service', function () {
});
});

it('abort', async function () {
this.slow(200);
it('abort', { timeout: 200 }, async function () {
const { abort, geocode } = service({
name: 'test',
prepareRequest: () => ({}),
Expand All @@ -39,10 +39,11 @@ it('abort', async function () {
const query = {};
for (let queryId = 0; queryId < 3; queryId++) {
abortAfter(queryId);
await geocode('forward', queryId, query).should.be.fulfilledWith(undefined);
const r = await geocode('forward', queryId, query);
should.not.exist(r);
}

let result = await geocode('forward', 'after 3 aborts', query);
const result = await geocode('forward', 'after 3 aborts', query);
should.not.exist(result);

function abortAfter(queryId) {
Expand Down
17 changes: 9 additions & 8 deletions test/service/locationiq/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const should = require('should');
const { describe, it } = require('node:test');
const should = require('chai').should();
const locationiq = require('../../../lib/service/locationiq');

describe('locationiq geocoding', function () {
Expand All @@ -17,7 +18,7 @@ describe('locationiq geocoding', function () {
const result = await geocode('forward', 1, query);
should.exist(result);
result.should.have.property('places').with.length(1);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [-46.8359735, -23.5370962],
type: 'road',
address: 'Rua Cafelândia, Carapicuíba, São Paulo, Brazil',
Expand All @@ -38,7 +39,7 @@ describe('locationiq geocoding', function () {
const result = await geocode('forward', 1, query);
should.exist(result);
result.should.have.property('places').with.length(1);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [18.658631239705393, 54.35145095],
place: 'SS Sołdek',
type: 'museum',
Expand All @@ -64,7 +65,7 @@ describe('locationiq geocoding', function () {
const result = await geocode('forward', 10, query);
should.exist(result);
result.should.have.property('places').with.length(8);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
place: 'Hill Country Barbecue Market',
type: 'restaurant',
ll: [-73.9904326, 40.7442736],
Expand All @@ -76,7 +77,7 @@ describe('locationiq geocoding', function () {
province: 'NY',
country: 'USA'
});
result.places[1].should.deepEqual({
result.places[1].should.deep.equal({
place: 'Mapzen',
type: 'disused',
ll: [-73.9903515, 40.7442363],
Expand All @@ -88,7 +89,7 @@ describe('locationiq geocoding', function () {
province: 'NY',
country: 'USA'
});
result.places[2].should.deepEqual({
result.places[2].should.deep.equal({
place: 'Samsung Accelerator',
type: 'company',
ll: [-73.9903727, 40.7442104],
Expand All @@ -110,7 +111,7 @@ describe('locationiq geocoding', function () {
const result = await geocode('reverse', 1, query);
should.exist(result);
result.should.have.property('places').with.length(1);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
ll: [14.5268016, -22.6791826],
place: 'Beryl\'s Restaurant',
type: 'restaurant',
Expand All @@ -136,7 +137,7 @@ describe('locationiq geocoding', function () {
const result = await geocode('forward', 10, query);
should.exist(result);
result.should.have.property('places').with.length(1);
result.places[0].should.deepEqual({
result.places[0].should.deep.equal({
type: 'house_number',
ll: [-104.999354, 39.676536],
address: '2200 South Jason Street, Denver, CO',
Expand Down
Loading

0 comments on commit f04f735

Please sign in to comment.