Skip to content

Commit

Permalink
Bump dependencies, swap tap for node:test
Browse files Browse the repository at this point in the history
Node's built-in test runner works great!
  • Loading branch information
bhousel committed Dec 21, 2023
1 parent 749b626 commit d4c70c6
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 493 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"build:browser": "esbuild ./index.mjs --platform=browser --format=iife --global-name=LocationConflation --bundle --sourcemap --outfile=./dist/location-conflation.iife.js",
"build:cjs": "esbuild ./index.mjs --platform=node --format=cjs --sourcemap --outfile=./dist/location-conflation.cjs",
"lint": "eslint index.mjs test/*.js",
"tap": "c8 tap --reporter terse --no-cov test/*.js",
"test": "run-s build tap"
"test": "run-s build test:node",
"test:node": "c8 node --test test/"
},
"dependencies": {
"@aitodotai/json-stringify-pretty-compact": "^1.3.0",
Expand All @@ -50,8 +50,7 @@
"esbuild": "^0.19.10",
"eslint": "^8.56.0",
"npm-run-all": "^4.1.5",
"shx": "^0.3.4",
"tap": "^16.3.10"
"shx": "^0.3.4"
},
"publishConfig": {
"access": "public"
Expand Down
168 changes: 81 additions & 87 deletions test/resolveLocation.test.js
Original file line number Diff line number Diff line change
@@ -1,134 +1,128 @@
import { test } from 'tap';
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { LocationConflation } from '../index.mjs';

import features from './fixtures/features.json' assert {type: 'json'};
const loco = new LocationConflation(features);
const locoNS = new LocationConflation(features);
locoNS.strict = false;

test('resolveLocation', t => {
test('resolveLocation', async t => {

t.test('points', t => {
t.test('a valid [lon, lat] Array returns a feature match', t => {
await t.test('points', async t => {
await t.test('a valid [lon, lat] Array returns a feature match', t => {
const location = [0, 0];
const result = loco.resolveLocation(location);
t.not(result, null);
t.equal(result.type, 'point');
t.equal(result.location, location);
t.type(result.feature, 'object'); // result includes a `feature`
t.equal(result.feature.id, '[0,0]'); // feature has an `id`
t.type(result.feature.properties, 'object'); // feature has `properties`
t.equal(result.feature.properties.id, '[0,0]'); // properties has an `id` property
t.equal(result.feature.properties.area, 1963.5); // area = Pi * 25 * 25
t.end();
assert.notEqual(result, null);
assert.equal(result.type, 'point');
assert.equal(result.location, location);
assert.equal(typeof result.feature, 'object'); // result includes a `feature`
assert.equal(result.feature.id, '[0,0]'); // feature has an `id`
assert.equal(typeof result.feature.properties, 'object'); // feature has `properties`
assert.equal(result.feature.properties.id, '[0,0]'); // properties has an `id` property
assert.equal(result.feature.properties.area, 1963.5); // area = Pi * 25 * 25
});
t.test('a valid [lon, lat, radius] Array returns a feature match', t => {

await t.test('a valid [lon, lat, radius] Array returns a feature match', t => {
const location = [0, 0, 100];
const result = loco.resolveLocation(location);
t.not(result, null);
t.equal(result.type, 'point');
t.equal(result.location, location);
t.type(result.feature, 'object'); // result includes a `feature`
t.equal(result.feature.id, '[0,0,100]'); // feature has an `id`
t.type(result.feature.properties, 'object'); // feature has `properties`
t.equal(result.feature.properties.id, '[0,0,100]'); // properties has an `id` property
t.equal(result.feature.properties.area, 31415.93); // area = Pi * 100 * 100
t.end();
assert.notEqual(result, null);
assert.equal(result.type, 'point');
assert.equal(result.location, location);
assert.equal(typeof result.feature, 'object'); // result includes a `feature`
assert.equal(result.feature.id, '[0,0,100]'); // feature has an `id`
assert.equal(typeof result.feature.properties, 'object'); // feature has `properties`
assert.equal(result.feature.properties.id, '[0,0,100]'); // properties has an `id` property
assert.equal(result.feature.properties.area, 31415.93); // area = Pi * 100 * 100
});
t.test('(strict mode) an invalid [lon, lat] Array throws an error', t => {

await t.test('(strict mode) an invalid [lon, lat] Array throws an error', t => {
const location = [];
t.throws(() => loco.resolveLocation(location));
t.end();
assert.throws(() => loco.resolveLocation(location));
});
t.test('(non strict mode) an invalid [lon, lat] Array returns falsy', t => {

await t.test('(non strict mode) an invalid [lon, lat] Array returns null', t => {
const location = [];
t.notOk(locoNS.resolveLocation(location));
t.end();
assert.equal(locoNS.resolveLocation(location), null);
});
t.end();
});


t.test('`.geojson` filenames', t => {
t.test('a known `.geojson` filename with id returns a feature match', t => {
await t.test('`.geojson` filenames', async t => {
await t.test('a known `.geojson` filename with id returns a feature match', t => {
const location = 'dc_metro.geojson';
const result = loco.resolveLocation(location);
t.not(result, null);
t.equal(result.type, 'geojson');
t.equal(result.location, location);
t.type(result.feature, 'object'); // result includes a `feature`
t.equal(result.feature.id, 'dc_metro.geojson'); // feature has an `id`
t.type(result.feature.properties, 'object'); // feature has `properties`
t.equal(result.feature.properties.id, 'dc_metro.geojson'); // properties has an `id` property
t.match(result.feature.properties, { area: /\d+/ }); // properties has a numeric `area` property
t.end();
assert.notEqual(result, null);
assert.equal(result.type, 'geojson');
assert.equal(result.location, location);
assert.equal(typeof result.feature, 'object'); // result includes a `feature`
assert.equal(result.feature.id, 'dc_metro.geojson'); // feature has an `id`
assert.equal(typeof result.feature.properties, 'object'); // feature has `properties`
assert.equal(result.feature.properties.id, 'dc_metro.geojson'); // properties has an `id` property
assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property
});
t.test('a known `.geojson` filename with id property returns a feature match', t => {

await t.test('a known `.geojson` filename with id property returns a feature match', t => {
const location = 'philly_metro.geojson';
const result = loco.resolveLocation(location);
t.not(result, null);
t.equal(result.type, 'geojson');
t.equal(result.location, location);
t.type(result.feature, 'object'); // result includes a `feature`
t.equal(result.feature.id, 'philly_metro.geojson'); // feature has an `id`
t.type(result.feature.properties, 'object'); // feature has `properties`
t.equal(result.feature.properties.id, 'philly_metro.geojson'); // properties has an `id` property
t.match(result.feature.properties, { area: /\d+/ }); // properties has a numeric `area` property
t.end();
assert.notEqual(result, null);
assert.equal(result.type, 'geojson');
assert.equal(result.location, location);
assert.equal(typeof result.feature, 'object'); // result includes a `feature`
assert.equal(result.feature.id, 'philly_metro.geojson'); // feature has an `id`
assert.equal(typeof result.feature.properties, 'object'); // feature has `properties`
assert.equal(result.feature.properties.id, 'philly_metro.geojson'); // properties has an `id` property
assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property
});
t.test('`.geojson` identifiers compare as lowercase', t => {

await t.test('`.geojson` identifiers compare as lowercase', t => {
const location = 'PHiLLy_MeTRo.GeoJSoN';
const result = loco.resolveLocation(location);
t.not(result, null);
t.equal(result.type, 'geojson');
t.equal(result.location, location);
t.type(result.feature, 'object'); // result includes a `feature`
t.equal(result.feature.id, 'philly_metro.geojson'); // feature has an `id`
t.type(result.feature.properties, 'object'); // feature has `properties`
t.equal(result.feature.properties.id, 'philly_metro.geojson'); // properties has an `id` property
t.match(result.feature.properties, { area: /\d+/ }); // properties has a numeric `area` property
t.end();
assert.notEqual(result, null);
assert.equal(result.type, 'geojson');
assert.equal(result.location, location);
assert.equal(typeof result.feature, 'object'); // result includes a `feature`
assert.equal(result.feature.id, 'philly_metro.geojson'); // feature has an `id`
assert.equal(typeof result.feature.properties, 'object'); // feature has `properties`
assert.equal(result.feature.properties.id, 'philly_metro.geojson'); // properties has an `id` property
assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property
});
t.test('(strict mode) an invalid `.geojson` filename throws an error', t => {

await t.test('(strict mode) an invalid `.geojson` filename throws an error', t => {
const location = 'fake.geojson';
t.throws(() => loco.resolveLocation(location));
t.end();
assert.throws(() => loco.resolveLocation(location));
});
t.test('(non strict mode) an invalid `.geojson` filename returns falsy', t => {

await t.test('(non strict mode) an invalid `.geojson` filename returns null', t => {
const location = 'fake.geojson';
t.notOk(locoNS.resolveLocation(location));
t.end();
assert.equal(locoNS.resolveLocation(location), null);
});
t.end();
});


t.test('country coder feature identifiers', t => {
t.test('a valid country coder feature identifier returns a feature match', t => {
await t.test('country coder feature identifiers', async t => {
await t.test('a valid country coder feature identifier returns a feature match', t => {
const location = 'gb';
const result = loco.resolveLocation(location);
t.not(result, null);
t.equal(result.type, 'countrycoder');
t.equal(result.location, location);
t.type(result.feature, 'object'); // result includes a `feature`
t.equal(result.feature.id, 'Q145'); // feature has an `id`
t.type(result.feature.properties, 'object'); // feature has `properties`
t.equal(result.feature.properties.id, 'Q145'); // properties has an `id` property
t.match(result.feature.properties, { area: /\d+/ }); // properties has a numeric `area` property
t.end();
assert.notEqual(result, null);
assert.equal(result.type, 'countrycoder');
assert.equal(result.location, location);
assert.equal(typeof result.feature, 'object'); // result includes a `feature`
assert.equal(result.feature.id, 'Q145'); // feature has an `id`
assert.equal(typeof result.feature.properties, 'object'); // feature has `properties`
assert.equal(result.feature.properties.id, 'Q145'); // properties has an `id` property
assert.equal(typeof result.feature.properties.area, 'number'); // properties has a numeric `area` property
});
t.test('(strict mode) an invalid country coder feature identifier throws an error', t => {

await t.test('(strict mode) an invalid country coder feature identifier throws an error', t => {
const location = 'fake';
t.throws(() => loco.resolveLocation(location));
t.end();
assert.throws(() => loco.resolveLocation(location));
});
t.test('(non strict mode) an invalid country coder feature identifier returns falsy', t => {

await t.test('(non strict mode) an invalid country coder feature identifier returns null', t => {
const location = 'fake';
t.notOk(locoNS.resolveLocation(location));
t.end();
assert.equal(locoNS.resolveLocation(location), null);
});
t.end();
});

t.end();
});
Loading

0 comments on commit d4c70c6

Please sign in to comment.