From 4c18bd64c6953fee51718a37c188607e7be9a5d6 Mon Sep 17 00:00:00 2001 From: Marcello Perathoner Date: Thu, 5 Mar 2026 09:33:49 +0100 Subject: [PATCH 1/2] Update NodeJS test --- test/nodejs/benchmark.js | 58 +- test/nodejs/constants.js | 43 +- test/nodejs/index.js | 268 +++---- test/nodejs/match.js | 799 ++++++++++--------- test/nodejs/nearest.js | 237 +++--- test/nodejs/route.js | 1588 +++++++++++++++++++------------------- test/nodejs/table.js | 717 +++++++++-------- test/nodejs/tile.js | 63 +- test/nodejs/trip.js | 764 +++++++++--------- 9 files changed, 2254 insertions(+), 2283 deletions(-) diff --git a/test/nodejs/benchmark.js b/test/nodejs/benchmark.js index 56b3423a5e6..7b50f0c2b05 100644 --- a/test/nodejs/benchmark.js +++ b/test/nodejs/benchmark.js @@ -1,7 +1,6 @@ // Performance benchmarking tool for OSRM routing services -import OSRM from '../../lib/index.js'; import { performance, createHistogram } from 'node:perf_hooks'; -import { mld_data_path } from './constants.js'; +import { OSRM, mld_data_path } from './constants.js'; // usage: node test/nodejs/benchmark.js berlin-latest.osrm 13.388860,52.517037;13.385983,52.496891 const args = process.argv.slice(2); @@ -9,47 +8,46 @@ const path = args[0] || mld_data_path; // Parse semicolon-separated waypoints from command line arguments function parseWaypoints(waypoints) { - if (waypoints == undefined) { - return undefined; - } - return waypoints.split(';').map((waypoint) => { - const [lon, lat] = waypoint.split(','); - return [parseFloat(lon), parseFloat(lat)]; - }); + if (waypoints == undefined) { + return undefined; + } + return waypoints.split(';').map((waypoint) => { + const [lon, lat] = waypoint.split(','); + return [parseFloat(lon), parseFloat(lat)]; + }); } const waypoints = parseWaypoints(args[1]) || [[7.41337, 43.72956],[7.41546, 43.73077]]; const osrm = new OSRM({path, algorithm: 'MLD'}); // Promisify the OSRM route callback for async/await usage async function route(coordinates) { - const promise = new Promise((resolve, reject) => { - osrm.route({coordinates, steps: true, overview: 'full'}, (err, result) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); + const promise = new Promise((resolve, reject) => { + osrm.route({coordinates, steps: true, overview: 'full'}, (err, result) => { + if (err) { + reject(err); + } else { + resolve(result); + } }); - return promise; + }); + return promise; } async function benchmark() { - // warmup - await route(waypoints); + // warmup + await route(waypoints); - const performanceHistorgram = createHistogram(); + const performanceHistorgram = createHistogram(); - for (let i = 0; i < 1000; i++) { - const start = performance.now(); - await route(waypoints); - const end = performance.now(); - // record result in microseconds - performanceHistorgram.record(Math.ceil((end - start) * 1000)); - } + for (let i = 0; i < 1000; i++) { + const start = performance.now(); + await route(waypoints); + const end = performance.now(); + // record result in microseconds + performanceHistorgram.record(Math.ceil((end - start) * 1000)); + } - console.log(performanceHistorgram); + console.log(performanceHistorgram); } benchmark(); - diff --git a/test/nodejs/constants.js b/test/nodejs/constants.js index 4d2f690189d..8c3e89d031d 100644 --- a/test/nodejs/constants.js +++ b/test/nodejs/constants.js @@ -1,32 +1,29 @@ -import path from 'path'; -import { fileURLToPath } from 'url'; - -// Constants and fixtures for nodejs tests on our Monaco dataset. -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { osrm } from '../../features/support/fbresult_generated.js'; // Somewhere in Monaco // http://www.openstreetmap.org/#map=18/43.73185/7.41772 export const three_test_coordinates = [[7.41337, 43.72956], - [7.41546, 43.73077], - [7.41862, 43.73216]]; + [7.41546, 43.73077], + [7.41862, 43.73216]]; export const two_test_coordinates = three_test_coordinates.slice(0, 2); export const test_tile = {'at': [17059, 11948, 15], 'size': 159125}; -// Test files generated by the routing engine; check test/data -let data_path, mld_data_path, test_memory_path; - -if (process.env.OSRM_DATA_PATH !== undefined) { - data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/monaco.osrm"); - mld_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "mld/monaco.osrm"); - test_memory_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "test_memory"); - console.log('Setting custom data path to ' + data_path); -} else { - data_path = path.resolve(path.join(__dirname, "../data/ch/monaco.osrm")); - mld_data_path = path.resolve(path.join(__dirname, "../data/mld/monaco.osrm")); - test_memory_path = path.resolve(path.join(__dirname, "../data/test_memory")); -} - -export { data_path, mld_data_path, test_memory_path }; +const install_dir = process.env.OSRM_NODEJS_INSTALL_DIR || '.'; +const test_data_dir = process.env.OSRM_DATA_PATH || process.env.OSRM_TEST_DATA_DIR || 'test/data'; + +console.log(`# Setting installation path to: ${test_data_dir}`); +console.log(`# Setting custom data path to: ${test_data_dir}`); + +const data_path = path.resolve(path.join(test_data_dir, 'ch', 'monaco.osrm')); +const mld_data_path = path.resolve(path.join(test_data_dir, 'mld', 'monaco.osrm')); +const test_memory_path = path.resolve(path.join(test_data_dir, 'test_memory')); + +const { default: OSRM, version } = await import(pathToFileURL(path.join(install_dir, 'lib', 'index.js')).href); + +const FBResult = osrm.engine.api.fbresult.FBResult; + +export { OSRM, FBResult, version, data_path, mld_data_path, test_memory_path }; diff --git a/test/nodejs/index.js b/test/nodejs/index.js index b9a3727af2d..bfa2954b703 100644 --- a/test/nodejs/index.js +++ b/test/nodejs/index.js @@ -1,7 +1,7 @@ // Test OSRM constructor and basic functionality -import OSRM from '../../lib/index.js'; import test from 'tape'; -import { data_path as monaco_path, test_memory_path as test_memory_file, mld_data_path as monaco_mld_path } from './constants.js'; +import { OSRM, data_path as monaco_path, test_memory_path as test_memory_file, mld_data_path as monaco_mld_path } from './constants.js'; + // Import all test modules import './route.js'; import './trip.js'; @@ -10,184 +10,184 @@ import './tile.js'; import './table.js'; import './nearest.js'; -test('constructor: throws if new keyword is not used', function(assert) { - assert.plan(1); - assert.throws(function() { OSRM(); }, - /Class constructors cannot be invoked without 'new'/); +test('constructor: throws if new keyword is not used', (assert) => { + assert.plan(1); + assert.throws(() => { OSRM(); }, + /Class constructors cannot be invoked without 'new'/); }); -test('constructor: uses defaults with no parameter', function(assert) { - assert.plan(1); - const osrm = new OSRM(); - assert.ok(osrm); +test('constructor: uses defaults with no parameter', (assert) => { + assert.plan(1); + const osrm = new OSRM(); + assert.ok(osrm); }); -test('constructor: does not accept more than one parameter', function(assert) { - assert.plan(1); - assert.throws(function() { new OSRM({}, {}); }, - /Only accepts one parameter/); +test('constructor: does not accept more than one parameter', (assert) => { + assert.plan(1); + assert.throws(() => { new OSRM({}, {}); }, + /Only accepts one parameter/); }); -test('constructor: throws if necessary files do not exist', function(assert) { - assert.plan(2); - assert.throws(function() { new OSRM('missing.osrm'); }, - /Required files are missing, cannot continue/); +test('constructor: throws if necessary files do not exist', (assert) => { + assert.plan(2); + assert.throws(() => { new OSRM('missing.osrm'); }, + /Required files are missing, cannot continue/); + + assert.throws(() => { new OSRM({path: 'missing.osrm', algorithm: 'MLD'}); }, + /Required files are missing, cannot continue/); +}); - assert.throws(function() { new OSRM({path: 'missing.osrm', algorithm: 'MLD'}); }, - /Required files are missing, cannot continue/); +test('constructor: takes a shared memory argument', (assert) => { + assert.plan(1); + const osrm = new OSRM({path: monaco_path, shared_memory: false}); + assert.ok(osrm); }); -test('constructor: takes a shared memory argument', function(assert) { - assert.plan(1); - const osrm = new OSRM({path: monaco_path, shared_memory: false}); - assert.ok(osrm); +test('constructor: takes a memory file', (assert) => { + assert.plan(1); + const osrm = new OSRM({path: monaco_path, memory_file: test_memory_file}); + assert.ok(osrm); }); -test('constructor: takes a memory file', function(assert) { - assert.plan(1); - const osrm = new OSRM({path: monaco_path, memory_file: test_memory_file}); - assert.ok(osrm); +test('constructor: throws if shared_memory==false with no path defined', (assert) => { + assert.plan(1); + assert.throws(() => { new OSRM({shared_memory: false}); }, + /Shared_memory must be enabled if no path is specified/); }); -test('constructor: throws if shared_memory==false with no path defined', function(assert) { - assert.plan(1); - assert.throws(function() { new OSRM({shared_memory: false}); }, - /Shared_memory must be enabled if no path is specified/); +test('constructor: throws if given a non-bool shared_memory option', (assert) => { + assert.plan(1); + assert.throws(() => { new OSRM({path: monaco_path, shared_memory: 'a'}); }, + /Shared_memory option must be a boolean/); }); -test('constructor: throws if given a non-bool shared_memory option', function(assert) { - assert.plan(1); - assert.throws(function() { new OSRM({path: monaco_path, shared_memory: 'a'}); }, - /Shared_memory option must be a boolean/); +test('constructor: throws if given a non-string/obj argument', (assert) => { + assert.plan(1); + assert.throws(() => { new OSRM(true); }, + /Parameter must be a path or options object/); }); -test('constructor: throws if given a non-string/obj argument', function(assert) { - assert.plan(1); - assert.throws(function() { new OSRM(true); }, - /Parameter must be a path or options object/); +test('constructor: throws if given an unkown algorithm', (assert) => { + assert.plan(1); + assert.throws(() => { new OSRM({algorithm: 'Foo', shared_memory: true}); }, + /algorithm option must be one of 'CH', or 'MLD'/); }); -test('constructor: throws if given an unkown algorithm', function(assert) { - assert.plan(1); - assert.throws(function() { new OSRM({algorithm: 'Foo', shared_memory: true}); }, - /algorithm option must be one of 'CH', or 'MLD'/); +test('constructor: throws if given an invalid algorithm', (assert) => { + assert.plan(1); + assert.throws(() => { new OSRM({algorithm: 3, shared_memory: true}); }, + /algorithm option must be a string and one of 'CH', or 'MLD'/); }); -test('constructor: throws if given an invalid algorithm', function(assert) { - assert.plan(1); - assert.throws(function() { new OSRM({algorithm: 3, shared_memory: true}); }, - /algorithm option must be a string and one of 'CH', or 'MLD'/); +test('constructor: loads MLD if given as algorithm', (assert) => { + assert.plan(1); + const osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path}); + assert.ok(osrm); }); -test('constructor: loads MLD if given as algorithm', function(assert) { - assert.plan(1); - const osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path}); - assert.ok(osrm); +test('constructor: loads CH if given as algorithm', (assert) => { + assert.plan(1); + const osrm = new OSRM({algorithm: 'CH', path: monaco_path}); + assert.ok(osrm); }); -test('constructor: loads CH if given as algorithm', function(assert) { - assert.plan(1); - const osrm = new OSRM({algorithm: 'CH', path: monaco_path}); - assert.ok(osrm); +test('constructor: throws if data doesn\'t match algorithm', (assert) => { + assert.plan(1); + assert.throws(() => { new OSRM({algorithm: 'MLD', path: monaco_path}); }, /Could not find any metrics for MLD/, 'MLD with CH data'); }); -test('constructor: throws if data doesn\'t match algorithm', function(assert) { - assert.plan(1); - assert.throws(function() { new OSRM({algorithm: 'MLD', path: monaco_path}); }, /Could not find any metrics for MLD/, 'MLD with CH data'); +test('constructor: throws if dataset_name is not a string', (assert) => { + assert.plan(3); + assert.throws(() => { new OSRM({dataset_name: 1337, path: monaco_mld_path}); }, /dataset_name needs to be a string/, 'Does not accept int'); + assert.ok(new OSRM({dataset_name: '', shared_memory: true}), 'Does accept string'); + assert.throws(() => { new OSRM({dataset_name: 'unsued_name___', shared_memory: true}); }, /Could not find shared memory region/, 'Does not accept wrong name'); }); -test('constructor: throws if dataset_name is not a string', function(assert) { - assert.plan(3); - assert.throws(function() { new OSRM({dataset_name: 1337, path: monaco_mld_path}); }, /dataset_name needs to be a string/, 'Does not accept int'); - assert.ok(new OSRM({dataset_name: "", shared_memory: true}), 'Does accept string'); - assert.throws(function() { new OSRM({dataset_name: "unsued_name___", shared_memory: true}); }, /Could not find shared memory region/, 'Does not accept wrong name'); +test('constructor: takes a default_radius argument', (assert) => { + assert.plan(1); + const osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 1}); + assert.ok(osrm); }); -test('constructor: takes a default_radius argument', function(assert) { - assert.plan(1); - const osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 1}); - assert.ok(osrm); +test('constructor: takes a default_radius unlimited argument', (assert) => { + assert.plan(1); + const osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'unlimited'}); + assert.ok(osrm); }); -test('constructor: takes a default_radius unlimited argument', function(assert) { - assert.plan(1); - const osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'unlimited'}); - assert.ok(osrm); +test('constructor: throws if default_radius is not a number', (assert) => { + assert.plan(3); + assert.throws(() => { new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'abc'}); }, /default_radius must be unlimited or an integral number/, 'Does not accept invalid string'); + assert.ok(new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 1}), 'Does accept number'); + assert.ok(new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'unlimited'}), 'Does accept unlimited'); }); -test('constructor: throws if default_radius is not a number', function(assert) { - assert.plan(3); - assert.throws(function() { new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'abc'}); }, /default_radius must be unlimited or an integral number/, 'Does not accept invalid string'); - assert.ok(new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 1}), 'Does accept number'); - assert.ok(new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'unlimited'}), 'Does accept unlimited'); +test('constructor: parses custom limits', (assert) => { + assert.plan(1); + const osrm = new OSRM({ + path: monaco_mld_path, + algorithm: 'MLD', + max_locations_trip: 1, + max_locations_viaroute: 1, + max_locations_distance_table: 1, + max_locations_map_matching: 1, + max_results_nearest: 1, + max_alternatives: 1, + default_radius: 1 + }); + assert.ok(osrm); }); -test('constructor: parses custom limits', function(assert) { - assert.plan(1); +test('constructor: throws on invalid custom limits', (assert) => { + assert.plan(1); + assert.throws(() => { const osrm = new OSRM({ - path: monaco_mld_path, - algorithm: 'MLD', - max_locations_trip: 1, - max_locations_viaroute: 1, - max_locations_distance_table: 1, - max_locations_map_matching: 1, - max_results_nearest: 1, - max_alternatives: 1, - default_radius: 1 - }); - assert.ok(osrm); -}); - -test('constructor: throws on invalid custom limits', function(assert) { - assert.plan(1); - assert.throws(function() { - const osrm = new OSRM({ - path: monaco_mld_path, - algorithm: 'MLD', - max_locations_trip: 'unlimited', - max_locations_viaroute: true, - max_locations_distance_table: false, - max_locations_map_matching: 'a lot', - max_results_nearest: null, - max_alternatives: '10', - default_radius: '10' - }) + path: monaco_mld_path, + algorithm: 'MLD', + max_locations_trip: 'unlimited', + max_locations_viaroute: true, + max_locations_distance_table: false, + max_locations_map_matching: 'a lot', + max_results_nearest: null, + max_alternatives: '10', + default_radius: '10' }); + }); }); -test('constructor: throws on invalid disable_feature_dataset option', function(assert) { - assert.plan(1); - assert.throws(function() { - const osrm = new OSRM({ - path: monaco_path, - disable_feature_dataset: ['NOT_EXIST'], - }) +test('constructor: throws on invalid disable_feature_dataset option', (assert) => { + assert.plan(1); + assert.throws(() => { + const osrm = new OSRM({ + path: monaco_path, + disable_feature_dataset: ['NOT_EXIST'], }); + }); }); -test('constructor: throws on non-array disable_feature_dataset', function(assert) { - assert.plan(1); - assert.throws(function() { - const osrm = new OSRM({ - path: monaco_path, - disable_feature_dataset: 'ROUTE_GEOMETRY', - }) +test('constructor: throws on non-array disable_feature_dataset', (assert) => { + assert.plan(1); + assert.throws(() => { + const osrm = new OSRM({ + path: monaco_path, + disable_feature_dataset: 'ROUTE_GEOMETRY', }); + }); }); -test('constructor: ok on valid disable_feature_dataset option', function(assert) { - assert.plan(1); - const osrm = new OSRM({ - path: monaco_path, - disable_feature_dataset: ['ROUTE_GEOMETRY'], - }); - assert.ok(osrm); +test('constructor: ok on valid disable_feature_dataset option', (assert) => { + assert.plan(1); + const osrm = new OSRM({ + path: monaco_path, + disable_feature_dataset: ['ROUTE_GEOMETRY'], + }); + assert.ok(osrm); }); -test('constructor: ok on multiple overlapping disable_feature_dataset options', function(assert) { - assert.plan(1); - const osrm = new OSRM({ - path: monaco_path, - disable_feature_dataset: ['ROUTE_GEOMETRY', 'ROUTE_STEPS'], - }); - assert.ok(osrm); +test('constructor: ok on multiple overlapping disable_feature_dataset options', (assert) => { + assert.plan(1); + const osrm = new OSRM({ + path: monaco_path, + disable_feature_dataset: ['ROUTE_GEOMETRY', 'ROUTE_STEPS'], + }); + assert.ok(osrm); }); diff --git a/test/nodejs/match.js b/test/nodejs/match.js index fc82ea8b452..da2af06690a 100644 --- a/test/nodejs/match.js +++ b/test/nodejs/match.js @@ -1,462 +1,457 @@ // Test map matching service functionality for GPS trace alignment -import OSRM from '../../lib/index.js'; -import test from 'tape'; -import { data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; import flatbuffers from 'flatbuffers'; -import { osrm } from '../../features/support/fbresult_generated.js'; - -const FBResult = osrm.engine.api.fbresult.FBResult; - - -test('match: match in Monaco with flatbuffers format', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - timestamps: [1424684612, 1424684616, 1424684620], - format: 'flatbuffers' - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(response)); - assert.equal(fb.routesLength(), 1); - }); +import test from 'tape'; +import { OSRM, FBResult, data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; + +test('match: match in Monaco with flatbuffers format', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + timestamps: [1424684612, 1424684616, 1424684620], + format: 'flatbuffers' + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(response)); + assert.equal(fb.routesLength(), 1); + }); }); -test('match: match in Monaco', function(assert) { - assert.plan(5); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - timestamps: [1424684612, 1424684616, 1424684620] - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - assert.ok(response.matchings.every(function(m) { - return !!m.distance && !!m.duration && Array.isArray(m.legs) && !!m.geometry && m.confidence > 0; - })) - assert.equal(response.tracepoints.length, 3); - assert.ok(response.tracepoints.every(function(t) { - return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; - })); - }); +test('match: match in Monaco', (assert) => { + assert.plan(5); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + timestamps: [1424684612, 1424684616, 1424684620] + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + assert.ok(response.matchings.every((m) => { + return !!m.distance && !!m.duration && Array.isArray(m.legs) && !!m.geometry && m.confidence > 0; + })); + assert.equal(response.tracepoints.length, 3); + assert.ok(response.tracepoints.every((t) => { + return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; + })); + }); }); -test('match: match in Monaco returning a buffer', function(assert) { - assert.plan(6); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - timestamps: [1424684612, 1424684616, 1424684620] - }; - osrm.match(options, { format: 'json_buffer' }, function(err, response) { - assert.ifError(err); - assert.ok(response instanceof Buffer); - response = JSON.parse(response); - assert.equal(response.matchings.length, 1); - assert.ok(response.matchings.every(function(m) { - return !!m.distance && !!m.duration && Array.isArray(m.legs) && !!m.geometry && m.confidence > 0; - })) - assert.equal(response.tracepoints.length, 3); - assert.ok(response.tracepoints.every(function(t) { - return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; - })); - }); +test('match: match in Monaco returning a buffer', (assert) => { + assert.plan(6); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + timestamps: [1424684612, 1424684616, 1424684620] + }; + osrm.match(options, { format: 'json_buffer' }, (err, response) => { + assert.ifError(err); + assert.ok(response instanceof Buffer); + response = JSON.parse(response); + assert.equal(response.matchings.length, 1); + assert.ok(response.matchings.every((m) => { + return !!m.distance && !!m.duration && Array.isArray(m.legs) && !!m.geometry && m.confidence > 0; + })); + assert.equal(response.tracepoints.length, 3); + assert.ok(response.tracepoints.every((t) => { + return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; + })); + }); }); -test('match: match in Monaco without timestamps', function(assert) { - assert.plan(3); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.tracepoints.length, 3); - assert.equal(response.matchings.length, 1); - }); +test('match: match in Monaco without timestamps', (assert) => { + assert.plan(3); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.tracepoints.length, 3); + assert.equal(response.matchings.length, 1); + }); }); -test('match: match in Monaco without geometry compression', function(assert) { - assert.plan(4); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - geometries: 'geojson' - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - assert.ok(response.matchings[0].geometry instanceof Object); - assert.ok(Array.isArray(response.matchings[0].geometry.coordinates)); - }); +test('match: match in Monaco without geometry compression', (assert) => { + assert.plan(4); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + geometries: 'geojson' + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + assert.ok(response.matchings[0].geometry instanceof Object); + assert.ok(Array.isArray(response.matchings[0].geometry.coordinates)); + }); }); -test('match: match in Monaco with geometry compression', function(assert) { - assert.plan(3); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - assert.equal('string', typeof response.matchings[0].geometry); - }); +test('match: match in Monaco with geometry compression', (assert) => { + assert.plan(3); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + assert.equal('string', typeof response.matchings[0].geometry); + }); }); -test('match: match in Monaco with speed annotations options', function(assert) { - assert.plan(12); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - timestamps: [1424684612, 1424684616, 1424684620], - radiuses: [4.07, 4.07, 4.07], - steps: true, - annotations: ['speed'], - overview: 'false', - geometries: 'geojson' - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - assert.ok(response.matchings[0].confidence > 0, 'has confidence'); - assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.speed; }), 'every leg has annotations for speed'); - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.weight; }), 'has no annotations for weight') - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.datasources; }), 'has no annotations for datasources') - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'has no annotations for duration') - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'has no annotations for distance') - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.nodes; }), 'has no annotations for nodes') - assert.equal(undefined, response.matchings[0].geometry); - }); +test('match: match in Monaco with speed annotations options', (assert) => { + assert.plan(12); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + timestamps: [1424684612, 1424684616, 1424684620], + radiuses: [4.07, 4.07, 4.07], + steps: true, + annotations: ['speed'], + overview: 'false', + geometries: 'geojson' + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + assert.ok(response.matchings[0].confidence > 0, 'has confidence'); + assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.speed; }), 'every leg has annotations for speed'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.weight; }), 'has no annotations for weight'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.datasources; }), 'has no annotations for datasources'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'has no annotations for duration'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'has no annotations for distance'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.nodes; }), 'has no annotations for nodes'); + assert.equal(undefined, response.matchings[0].geometry); + }); }); -test('match: match in Monaco with several (duration, distance, nodes) annotations options', function(assert) { - assert.plan(12); - const osrm = new OSRM(data_path); - const options = { - timestamps: [1424684612, 1424684616, 1424684620], - coordinates: three_test_coordinates, - timestamps: [1424684612, 1424684616, 1424684620], - radiuses: [4.07, 4.07, 4.07], - steps: true, - annotations: ['duration','distance','nodes'], - overview: 'false', - geometries: 'geojson' - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - assert.ok(response.matchings[0].confidence > 0, 'has confidence'); - assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'every leg has annotations for distance'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'every leg has annotations for durations'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.nodes; }), 'every leg has annotations for nodes'); - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.weight; }), 'has no annotations for weight') - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.datasources; }), 'has no annotations for datasources') - assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.speed; }), 'has no annotations for speed') - assert.equal(undefined, response.matchings[0].geometry); - }); +test('match: match in Monaco with several (duration, distance, nodes) annotations options', (assert) => { + assert.plan(12); + const osrm = new OSRM(data_path); + const options = { + timestamps: [1424684612, 1424684616, 1424684620], + coordinates: three_test_coordinates, + timestamps: [1424684612, 1424684616, 1424684620], + radiuses: [4.07, 4.07, 4.07], + steps: true, + annotations: ['duration','distance','nodes'], + overview: 'false', + geometries: 'geojson' + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + assert.ok(response.matchings[0].confidence > 0, 'has confidence'); + assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'every leg has annotations for distance'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'every leg has annotations for durations'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.nodes; }), 'every leg has annotations for nodes'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.weight; }), 'has no annotations for weight'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.datasources; }), 'has no annotations for datasources'); + assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.speed; }), 'has no annotations for speed'); + assert.equal(undefined, response.matchings[0].geometry); + }); }); -test('match: match in Monaco with all options', function(assert) { - assert.plan(8); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - timestamps: [1424684612, 1424684616, 1424684620], - radiuses: [4.07, 4.07, 4.07], - steps: true, - annotations: true, - overview: 'false', - geometries: 'geojson', - gaps: 'split', - tidy: false - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - assert.ok(response.matchings[0].confidence > 0, 'has confidence'); - assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'every leg has annotations for distance'); - assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'every leg has annotations for durations'); - assert.equal(undefined, response.matchings[0].geometry); - }); +test('match: match in Monaco with all options', (assert) => { + assert.plan(8); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + timestamps: [1424684612, 1424684616, 1424684620], + radiuses: [4.07, 4.07, 4.07], + steps: true, + annotations: true, + overview: 'false', + geometries: 'geojson', + gaps: 'split', + tidy: false + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + assert.ok(response.matchings[0].confidence > 0, 'has confidence'); + assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'every leg has annotations for distance'); + assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'every leg has annotations for durations'); + assert.equal(undefined, response.matchings[0].geometry); + }); }); -test('match: throws on missing arguments', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - assert.throws(function() { osrm.match({}) }, - /Two arguments required/); +test('match: throws on missing arguments', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + assert.throws(() => { osrm.match({}); }, + /Two arguments required/); }); -test('match: throws on non-object arg', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - assert.throws(function() { osrm.match(null, function(err, response) {}) }, - /First arg must be an object/); +test('match: throws on non-object arg', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + assert.throws(() => { osrm.match(null, (err, response) => {}); }, + /First arg must be an object/); }); -test('match: throws on invalid coordinates param', function(assert) { - assert.plan(4); - const osrm = new OSRM(data_path); - const options = { - coordinates: '' - }; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - options.coordinates = [three_test_coordinates[0]]; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /At least two coordinates must be provided/); - options.coordinates = three_test_coordinates[0] - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - options.coordinates = [three_test_coordinates[0][0], three_test_coordinates[0][1]]; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); +test('match: throws on invalid coordinates param', (assert) => { + assert.plan(4); + const osrm = new OSRM(data_path); + const options = { + coordinates: '' + }; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + options.coordinates = [three_test_coordinates[0]]; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /At least two coordinates must be provided/); + options.coordinates = three_test_coordinates[0]; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + options.coordinates = [three_test_coordinates[0][0], three_test_coordinates[0][1]]; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); }); -test('match: throws on invalid timestamps param', function(assert) { - assert.plan(3); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - timestamps: 'timestamps' - }; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /Timestamps must be an array of integers \(or undefined\)/); - options.timestamps = ['invalid', 'timestamp', 'array']; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /Timestamps array items must be numbers/); - options.timestamps = [1424684612, 1424684616]; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /Timestamp array must have the same size as the coordinates array/); +test('match: throws on invalid timestamps param', (assert) => { + assert.plan(3); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + timestamps: 'timestamps' + }; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /Timestamps must be an array of integers \(or undefined\)/); + options.timestamps = ['invalid', 'timestamp', 'array']; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /Timestamps array items must be numbers/); + options.timestamps = [1424684612, 1424684616]; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /Timestamp array must have the same size as the coordinates array/); }); -test('match: throws on invalid gaps param', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - gaps: ['invalid gaps param'] - }; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /Gaps must be a string: \[split, ignore\]/); - options.gaps = 'invalid gaps param'; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /'gaps' param must be one of \[split, ignore\]/); +test('match: throws on invalid gaps param', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + gaps: ['invalid gaps param'] + }; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /Gaps must be a string: \[split, ignore\]/); + options.gaps = 'invalid gaps param'; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /'gaps' param must be one of \[split, ignore\]/); }); -test('match: throws on invalid tidy param', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - coordinates: three_test_coordinates, - tidy: 'invalid tidy param' - }; - assert.throws(function() { osrm.match(options, function(err, response) {}) }, - /tidy must be of type Boolean/); +test('match: throws on invalid tidy param', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + coordinates: three_test_coordinates, + tidy: 'invalid tidy param' + }; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + /tidy must be of type Boolean/); }); -test('match: throws on invalid config param', function(assert) { - assert.plan(1); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: three_test_coordinates, - }; - assert.throws(function() { osrm.match(options, { format: 'invalid' }, function(err, response) {}) }, - /format must be a string:/); +test('match: throws on invalid config param', (assert) => { + assert.plan(1); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: three_test_coordinates, + }; + assert.throws(() => { osrm.match(options, { format: 'invalid' }, (err, response) => {}); }, + /format must be a string:/); }); -test('match: match in Monaco without motorways', function(assert) { - assert.plan(3); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: three_test_coordinates, - exclude: ['motorway'] - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.tracepoints.length, 3); - assert.equal(response.matchings.length, 1); - }); +test('match: match in Monaco without motorways', (assert) => { + assert.plan(3); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: three_test_coordinates, + exclude: ['motorway'] + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.tracepoints.length, 3); + assert.equal(response.matchings.length, 1); + }); }); -test('match: throws on invalid waypoints values needs at least two', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [0] - }; - assert.throws(function() { osrm.match(options, function(err, response) {}); }, - 'At least two waypoints must be provided'); +test('match: throws on invalid waypoints values needs at least two', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [0] + }; + assert.throws(() => { osrm.match(options, (err, response) => {}); }, + 'At least two waypoints must be provided'); }); -test('match: throws on invalid waypoints values, needs first and last coordinate indices', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [1, 2] - }; - assert.throws(function() { osrm.match(options, function(err, response) {console.log(err);}); }, - 'First and last waypoints values must correspond to first and last coordinate indices'); +test('match: throws on invalid waypoints values, needs first and last coordinate indices', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [1, 2] + }; + assert.throws(() => { osrm.match(options, (err, response) => {console.log(err);}); }, + 'First and last waypoints values must correspond to first and last coordinate indices'); }); -test('match: throws on invalid waypoints values, order matters', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [2, 0] - }; - assert.throws(function() { osrm.match(options, function(err, response) {console.log(err);}); }, - 'First and last waypoints values must correspond to first and last coordinate indices'); +test('match: throws on invalid waypoints values, order matters', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [2, 0] + }; + assert.throws(() => { osrm.match(options, (err, response) => {console.log(err);}); }, + 'First and last waypoints values must correspond to first and last coordinate indices'); }); -test('match: throws on invalid waypoints values, waypoints must correspond with a coordinate index', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [0, 3, 2] - }; - assert.throws(function() { osrm.match(options, function(err, response) {console.log(err);}); }, - 'Waypoints must correspond with the index of an input coordinate'); +test('match: throws on invalid waypoints values, waypoints must correspond with a coordinate index', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [0, 3, 2] + }; + assert.throws(() => { osrm.match(options, (err, response) => {console.log(err);}); }, + 'Waypoints must correspond with the index of an input coordinate'); }); -test('match: throws on invalid waypoints values, waypoints must be an array', function (assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: "string" - }; - assert.throws(function () { osrm.match(options, function (err, response) { console.log(err); }); }, - 'Waypoints must be an array of integers corresponding to the input coordinates.'); +test('match: throws on invalid waypoints values, waypoints must be an array', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: 'string' + }; + assert.throws(() => { osrm.match(options, (err, response) => { console.log(err); }); }, + 'Waypoints must be an array of integers corresponding to the input coordinates.'); }); -test('match: throws on invalid waypoints values, waypoints must be an array of integers', function (assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [0,1,"string"] - }; - assert.throws(function () { osrm.match(options, function (err, response) { console.log(err); }); }, - 'Waypoint values must be an array of integers'); +test('match: throws on invalid waypoints values, waypoints must be an array of integers', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [0,1,'string'] + }; + assert.throws(() => { osrm.match(options, (err, response) => { console.log(err); }); }, + 'Waypoint values must be an array of integers'); }); -test('match: error on split trace', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const four_coords = Array.from(three_test_coordinates); - four_coords.push([7.41902,43.73487]); - const options = { - steps: true, - coordinates: four_coords, - timestamps: [1700, 1750, 1424684616, 1424684620], - waypoints: [0,3] - }; - osrm.match(options, function(err, response) { - assert.ok(err, 'Errors with NoMatch'); - }); +test('match: error on split trace', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const four_coords = Array.from(three_test_coordinates); + four_coords.push([7.41902,43.73487]); + const options = { + steps: true, + coordinates: four_coords, + timestamps: [1700, 1750, 1424684616, 1424684620], + waypoints: [0,3] + }; + osrm.match(options, (err, response) => { + assert.ok(err, 'Errors with NoMatch'); + }); }); -test('match: match in Monaco with waypoints', function(assert) { - assert.plan(6); - const osrm = new OSRM(data_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [0,2] - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - assert.equal(response.matchings[0].legs.length, 1); - assert.ok(response.matchings.every(function(m) { - return !!m.distance && !!m.duration && Array.isArray(m.legs) && !!m.geometry && m.confidence > 0; - })) - assert.equal(response.tracepoints.length, 3); - assert.ok(response.tracepoints.every(function(t) { - return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; - })); - }); +test('match: match in Monaco with waypoints', (assert) => { + assert.plan(6); + const osrm = new OSRM(data_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [0,2] + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + assert.equal(response.matchings[0].legs.length, 1); + assert.ok(response.matchings.every((m) => { + return !!m.distance && !!m.duration && Array.isArray(m.legs) && !!m.geometry && m.confidence > 0; + })); + assert.equal(response.tracepoints.length, 3); + assert.ok(response.tracepoints.every((t) => { + return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name; + })); + }); }); -test('match: throws on disabled geometry', function (assert) { - assert.plan(1); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.match(options, function(err, route) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); +test('match: throws on disabled geometry', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.match(options, (err, route) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); }); -test('match: ok on disabled geometry', function (assert) { - assert.plan(2); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - steps: false, - overview: 'false', - annotations: false, - skip_waypoints: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.equal(response.matchings.length, 1); - }); +test('match: ok on disabled geometry', (assert) => { + assert.plan(2); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + steps: false, + overview: 'false', + annotations: false, + skip_waypoints: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.equal(response.matchings.length, 1); + }); }); -test('match: throws on disabled steps', function (assert) { - assert.plan(1); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - steps: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.match(options, function(err, route) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); +test('match: throws on disabled steps', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + steps: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.match(options, (err, route) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); }); -test('match: ok on disabled steps', function (assert) { - assert.plan(8); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - steps: false, - overview: 'simplified', - annotations: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.match(options, function(err, response) { - assert.ifError(err); - assert.ok(response.tracepoints); - assert.ok(response.matchings); - assert.equal(response.matchings.length, 1); - assert.ok(response.matchings[0].geometry, "the match has geometry"); - assert.ok(response.matchings[0].legs, "the match has legs"); - assert.notok(response.matchings[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(response.matchings[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); - }); +test('match: ok on disabled steps', (assert) => { + assert.plan(8); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + steps: false, + overview: 'simplified', + annotations: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.match(options, (err, response) => { + assert.ifError(err); + assert.ok(response.tracepoints); + assert.ok(response.matchings); + assert.equal(response.matchings.length, 1); + assert.ok(response.matchings[0].geometry, 'the match has geometry'); + assert.ok(response.matchings[0].legs, 'the match has legs'); + assert.notok(response.matchings[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(response.matchings[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); + }); }); diff --git a/test/nodejs/nearest.js b/test/nodejs/nearest.js index 81b7702949d..6bf1003d115 100644 --- a/test/nodejs/nearest.js +++ b/test/nodejs/nearest.js @@ -1,142 +1,137 @@ // Test nearest service functionality for finding closest waypoints on road network -import OSRM from '../../lib/index.js'; -import test from 'tape'; -import { data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; import flatbuffers from 'flatbuffers'; -import { osrm } from '../../features/support/fbresult_generated.js'; - -const FBResult = osrm.engine.api.fbresult.FBResult; - +import test from 'tape'; +import { OSRM, FBResult, data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; -test('nearest with flatbuffers format', function(assert) { - assert.plan(5); - const osrm = new OSRM(data_path); - osrm.nearest({ - coordinates: [three_test_coordinates[0]], - format: 'flatbuffers' - }, function(err, result) { - assert.ifError(err); - assert.ok(result instanceof Buffer); - const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(result)); - assert.equals(fb.waypointsLength(), 1); - assert.ok(fb.waypoints(0).location()); - assert.ok(fb.waypoints(0).name()); - }); +test('nearest with flatbuffers format', (assert) => { + assert.plan(5); + const osrm = new OSRM(data_path); + osrm.nearest({ + coordinates: [three_test_coordinates[0]], + format: 'flatbuffers' + }, (err, result) => { + assert.ifError(err); + assert.ok(result instanceof Buffer); + const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(result)); + assert.equals(fb.waypointsLength(), 1); + assert.ok(fb.waypoints(0).location()); + assert.ok(fb.waypoints(0).name()); + }); }); -test('nearest', function(assert) { - assert.plan(4); - const osrm = new OSRM(data_path); - osrm.nearest({ - coordinates: [three_test_coordinates[0]] - }, function(err, result) { - assert.ifError(err); - assert.equal(result.waypoints.length, 1); - assert.equal(result.waypoints[0].location.length, 2); - assert.ok(result.waypoints[0].hasOwnProperty('name')); - }); +test('nearest', (assert) => { + assert.plan(4); + const osrm = new OSRM(data_path); + osrm.nearest({ + coordinates: [three_test_coordinates[0]] + }, (err, result) => { + assert.ifError(err); + assert.equal(result.waypoints.length, 1); + assert.equal(result.waypoints[0].location.length, 2); + assert.ok(result.waypoints[0].hasOwnProperty('name')); + }); }); -test('nearest', function(assert) { - assert.plan(5); - const osrm = new OSRM(data_path); - osrm.nearest({ - coordinates: [three_test_coordinates[0]] - }, { format: 'json_buffer' }, function(err, result) { - assert.ifError(err); - assert.ok(result instanceof Buffer); - result = JSON.parse(result); - assert.equal(result.waypoints.length, 1); - assert.equal(result.waypoints[0].location.length, 2); - assert.ok(result.waypoints[0].hasOwnProperty('name')); - }); +test('nearest', (assert) => { + assert.plan(5); + const osrm = new OSRM(data_path); + osrm.nearest({ + coordinates: [three_test_coordinates[0]] + }, { format: 'json_buffer' }, (err, result) => { + assert.ifError(err); + assert.ok(result instanceof Buffer); + result = JSON.parse(result); + assert.equal(result.waypoints.length, 1); + assert.equal(result.waypoints[0].location.length, 2); + assert.ok(result.waypoints[0].hasOwnProperty('name')); + }); }); -test('nearest: can ask for multiple nearest pts', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - osrm.nearest({ - coordinates: [three_test_coordinates[0]], - number: 3 - }, function(err, result) { - assert.ifError(err); - assert.equal(result.waypoints.length, 3); - }); +test('nearest: can ask for multiple nearest pts', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + osrm.nearest({ + coordinates: [three_test_coordinates[0]], + number: 3 + }, (err, result) => { + assert.ifError(err); + assert.equal(result.waypoints.length, 3); + }); }); -test('nearest: throws on invalid args', function(assert) { - assert.plan(7); - const osrm = new OSRM(data_path); - const options = {}; - assert.throws(function() { osrm.nearest(options); }, - /Two arguments required/); - assert.throws(function() { osrm.nearest(null, function(err, res) {}); }, - /First arg must be an object/); - options.coordinates = [43.73072]; - assert.throws(function() { osrm.nearest(options, function(err, res) {}); }, - /Coordinates must be an array of /); - options.coordinates = [three_test_coordinates[0], three_test_coordinates[1]]; - assert.throws(function() { osrm.nearest(options, function(err, res) {}); }, - /Exactly one coordinate pair must be provided/); - options.coordinates = [three_test_coordinates[0]]; - options.number = 3.14159; - assert.throws(function() { osrm.nearest(options, function(err, res) {}); }, - /Number must be an integer greater than or equal to 1/); - options.number = 0; - assert.throws(function() { osrm.nearest(options, function(err, res) {}); }, - /Number must be an integer greater than or equal to 1/); +test('nearest: throws on invalid args', (assert) => { + assert.plan(7); + const osrm = new OSRM(data_path); + const options = {}; + assert.throws(() => { osrm.nearest(options); }, + /Two arguments required/); + assert.throws(() => { osrm.nearest(null, (err, res) => {}); }, + /First arg must be an object/); + options.coordinates = [43.73072]; + assert.throws(() => { osrm.nearest(options, (err, res) => {}); }, + /Coordinates must be an array of /); + options.coordinates = [three_test_coordinates[0], three_test_coordinates[1]]; + assert.throws(() => { osrm.nearest(options, (err, res) => {}); }, + /Exactly one coordinate pair must be provided/); + options.coordinates = [three_test_coordinates[0]]; + options.number = 3.14159; + assert.throws(() => { osrm.nearest(options, (err, res) => {}); }, + /Number must be an integer greater than or equal to 1/); + options.number = 0; + assert.throws(() => { osrm.nearest(options, (err, res) => {}); }, + /Number must be an integer greater than or equal to 1/); - options.number = 1; - assert.throws(function() { osrm.nearest(options, { format: 'invalid' }, function(err, res) {}); }, - /format must be a string:/); + options.number = 1; + assert.throws(() => { osrm.nearest(options, { format: 'invalid' }, (err, res) => {}); }, + /format must be a string:/); }); -test('nearest: nearest in Monaco without motorways', function(assert) { - assert.plan(2); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: [two_test_coordinates[0]], - exclude: ['motorway'] - }; - osrm.nearest(options, function(err, response) { - assert.ifError(err); - assert.equal(response.waypoints.length, 1); - }); +test('nearest: nearest in Monaco without motorways', (assert) => { + assert.plan(2); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: [two_test_coordinates[0]], + exclude: ['motorway'] + }; + osrm.nearest(options, (err, response) => { + assert.ifError(err); + assert.equal(response.waypoints.length, 1); + }); }); -test('nearest: throws on disabled geometry', function(assert) { - assert.plan(1); - const osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - coordinates: [two_test_coordinates[0]], - }; - osrm.nearest(options, function(err, response) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); +test('nearest: throws on disabled geometry', (assert) => { + assert.plan(1); + const osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + coordinates: [two_test_coordinates[0]], + }; + osrm.nearest(options, (err, response) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); }); -test('nearest: ok on disabled geometry', function(assert) { - assert.plan(2); - const osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - coordinates: [two_test_coordinates[0]], - skip_waypoints: true, - }; - osrm.nearest(options, function(err, response) { - assert.ifError(err); - assert.notok(response.waypoints); +test('nearest: ok on disabled geometry', (assert) => { + assert.plan(2); + const osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + coordinates: [two_test_coordinates[0]], + skip_waypoints: true, + }; + osrm.nearest(options, (err, response) => { + assert.ifError(err); + assert.notok(response.waypoints); - }); + }); }); -test('nearest: ok on disabled steps', function(assert) { - assert.plan(2); - const osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - coordinates: [two_test_coordinates[0]], - }; - osrm.nearest(options, function(err, response) { - assert.ifError(err); - assert.equal(response.waypoints.length, 1); - }); +test('nearest: ok on disabled steps', (assert) => { + assert.plan(2); + const osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + coordinates: [two_test_coordinates[0]], + }; + osrm.nearest(options, (err, response) => { + assert.ifError(err); + assert.equal(response.waypoints.length, 1); + }); }); diff --git a/test/nodejs/route.js b/test/nodejs/route.js index 17d4de23a73..44de4ce98a8 100644 --- a/test/nodejs/route.js +++ b/test/nodejs/route.js @@ -1,803 +1,799 @@ // Test route service functionality with turn-by-turn directions -import OSRM from '../../lib/index.js'; -import test from 'tape'; -import { data_path as monaco_path, mld_data_path as monaco_mld_path, three_test_coordinates, two_test_coordinates } from './constants.js'; import flatbuffers from 'flatbuffers'; -import { osrm } from '../../features/support/fbresult_generated.js'; - -const FBResult = osrm.engine.api.fbresult.FBResult; - -test('route: routes Monaco and can return result in flatbuffers', function(assert) { - assert.plan(5); - const osrm = new OSRM(monaco_path); - osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, function(err, result) { - assert.ifError(err); - assert.ok(result instanceof Buffer); - const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(result)); - assert.equals(fb.waypointsLength(), 2); - assert.equals(fb.routesLength(), 1); - assert.ok(fb.routes(0).polyline); - }); -}); - -test('route: routes Monaco and can return result in flatbuffers if output format is passed explicitly', function(assert) { - assert.plan(5); - const osrm = new OSRM(monaco_path); - osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {output: 'buffer'}, function(err, result) { - assert.ifError(err); - assert.ok(result instanceof Buffer); - const buf = new flatbuffers.ByteBuffer(result); - const fb = FBResult.getRootAsFBResult(buf); - assert.equals(fb.waypointsLength(), 2); - assert.equals(fb.routesLength(), 1); - assert.ok(fb.routes(0).polyline); - }); -}); - -test('route: throws error if required output is object in flatbuffers format', function(assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - assert.throws(function() { - osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {format: 'object'}, function(err, result) {}); - }); -}); - -test('route: throws error if required output is json_buffer in flatbuffers format', function(assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - assert.throws(function() { - osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {format: 'json_buffer'}, function(err, result) {}); - }); -}); - - -test('route: routes Monaco', function(assert) { - assert.plan(5); - const osrm = new OSRM(monaco_path); - osrm.route({coordinates: two_test_coordinates}, function(err, route) { - assert.ifError(err); - assert.ok(route.waypoints); - assert.ok(route.routes); - assert.ok(route.routes.length); - assert.ok(route.routes[0].geometry); - }); -}); - -test('route: routes Monaco on MLD', function(assert) { - assert.plan(5); - const osrm = new OSRM({path: monaco_mld_path, algorithm: 'MLD'}); - osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, function(err, route) { - assert.ifError(err); - assert.ok(route.waypoints); - assert.ok(route.routes); - assert.ok(route.routes.length); - assert.ok(route.routes[0].geometry); - }); -}); - -test('route: throws with too few or invalid args', function(assert) { - assert.plan(4); - const osrm = new OSRM(monaco_path); - assert.throws(function() { osrm.route({coordinates: two_test_coordinates}) }, - /Two arguments required/); - assert.throws(function() { osrm.route(null, function(err, route) {}) }, - /First arg must be an object/); - assert.throws(function() { osrm.route({coordinates: two_test_coordinates}, true)}, - /last argument must be a callback function/); - assert.throws(function() { osrm.route({coordinates: two_test_coordinates}, { format: 'invalid' }, function(err, route) {})}, - /format must be a string:/); -}); - -test('route: provides no alternatives by default, but when requested it may (not guaranteed)', function(assert) { - assert.plan(9); - const osrm = new OSRM(monaco_path); - const options = {coordinates: two_test_coordinates}; - - osrm.route(options, function(err, route) { - assert.ifError(err); - assert.ok(route.routes); - assert.equal(route.routes.length, 1); - }); - options.alternatives = true; - osrm.route(options, function(err, route) { - assert.ifError(err); - assert.ok(route.routes); - assert.ok(route.routes.length >= 1); - }); - options.alternatives = 3; - osrm.route(options, function(err, route) { - assert.ifError(err); - assert.ok(route.routes); - assert.ok(route.routes.length >= 1); - }); -}); - -test('route: throws with bad params', function(assert) { - assert.plan(11); - const osrm = new OSRM(monaco_path); - assert.throws(function () { osrm.route({coordinates: []}, function(err) {}) }); - assert.throws(function() { osrm.route({}, function(err, route) {}) }, - /Must provide a coordinates property/); - assert.throws(function() { osrm.route({coordinates: null}, function(err, route) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - assert.throws(function() { osrm.route({coordinates: [[three_test_coordinates[0]], [three_test_coordinates[1]]]}, function(err, route) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - assert.throws(function() { osrm.route({coordinates: [[true, 'stringish'], three_test_coordinates[1]]}, function(err, route) {}) }, - /Each member of a coordinate pair must be a number/); - assert.throws(function() { osrm.route({coordinates: [[213.43864,252.51993],[413.415852,552.513191]]}, function(err, route) {}) }, - /Lng\/Lat coordinates must be within world bounds \(-180 < lng < 180, -90 < lat < 90\)/); - assert.throws(function() { osrm.route({coordinates: [[13.438640], [52.519930]]}, function(err, route) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - assert.throws(function() { osrm.route({coordinates: two_test_coordinates, hints: null}, function(err, route) {}) }, - /Hints must be an array of strings\/null/); - assert.throws(function() { osrm.route({coordinates: two_test_coordinates, steps: null}, function(err, route) {}) }); - assert.throws(function() { osrm.route({coordinates: two_test_coordinates, annotations: null}, function(err, route) {}) }); - const options = { - coordinates: two_test_coordinates, - alternateRoute: false, - hints: three_test_coordinates[0] - }; - assert.throws(function() { osrm.route(options, function(err, route) {}) }, - /Hint must be null or string/); -}); - -test('route: routes Monaco using shared memory', function(assert) { - assert.plan(2); - const osrm = new OSRM(); - osrm.route({coordinates: two_test_coordinates}, function(err, route) { - assert.ifError(err); - assert.ok(Array.isArray(route.routes)); - }); -}); - -test('route: routes Monaco with geometry compression', function(assert) { - assert.plan(2); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - }; - osrm.route(options, function(err, route) { - assert.ifError(err); - assert.equal('string', typeof route.routes[0].geometry); - }); -}); - -test('route: routes Monaco without geometry compression', function(assert) { - assert.plan(4); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - geometries: 'geojson' - }; - osrm.route(options, function(err, route) { - assert.ifError(err); - assert.ok(Array.isArray(route.routes)); - assert.ok(Array.isArray(route.routes[0].geometry.coordinates)); - assert.equal(route.routes[0].geometry.type, 'LineString'); - }); -}); - -test('Test polyline6 geometries option', function(assert) { - assert.plan(6); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - continue_straight: false, - overview: 'false', - geometries: 'polyline6', - steps: true - }; - osrm.route(options, function(err, first) { - assert.ifError(err); - assert.ok(first.routes); - assert.equal(first.routes.length, 1); - assert.notOk(first.routes[0].geometry); - assert.ok(first.routes[0].legs[0]); - assert.equal(typeof first.routes[0].legs[0].steps[0].geometry, 'string'); - }); -}); - -test('route: routes Monaco with speed annotations options', function(assert) { - assert.plan(17); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - continue_straight: false, - overview: 'false', - geometries: 'polyline', - steps: true, - annotations: ['speed'] - }; - osrm.route(options, function(err, first) { - assert.ifError(err); - assert.ok(first.routes); - assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; })); - assert.equal(first.routes.length, 1); - assert.notOk(first.routes[0].geometry); - assert.ok(first.routes[0].legs[0]); - assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.speed;}), 'every leg has annotations for speed'); - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight') - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources') - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.duration; }), 'has no annotations for duration') - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.distance; }), 'has no annotations for distance') - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.nodes; }), 'has no annotations for nodes') - - options.overview = 'full'; - osrm.route(options, function(err, full) { - assert.ifError(err); - options.overview = 'simplified'; - osrm.route(options, function(err, simplified) { - assert.ifError(err); - assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); - }); - }); - }); -}); - -test('route: routes Monaco with several (duration, distance, nodes) annotations options', function(assert) { - assert.plan(17); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - continue_straight: false, - overview: 'false', - geometries: 'polyline', - steps: true, - annotations: ['duration', 'distance', 'nodes'] - }; - osrm.route(options, function(err, first) { - assert.ifError(err); - assert.ok(first.routes); - assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; })); - assert.equal(first.routes.length, 1); - assert.notOk(first.routes[0].geometry); - assert.ok(first.routes[0].legs[0]); - assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.distance;}), 'every leg has annotations for distance'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.duration;}), 'every leg has annotations for durations'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.nodes;}), 'every leg has annotations for nodes'); - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight'); - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources'); - assert.notOk(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'has no annotations for speed'); - - options.overview = 'full'; - osrm.route(options, function(err, full) { - assert.ifError(err); - options.overview = 'simplified'; - osrm.route(options, function(err, simplified) { - assert.ifError(err); - assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); - }); - }); - }); -}); - -test('route: routes Monaco with options', function(assert) { - assert.plan(17); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - continue_straight: false, - overview: 'false', - geometries: 'polyline', - steps: true, - annotations: true - }; - osrm.route(options, function(err, first) { - assert.ifError(err); - assert.ok(first.routes); - assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; })); - assert.equal(first.routes.length, 1); - assert.notOk(first.routes[0].geometry); - assert.ok(first.routes[0].legs[0]); - assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.distance;}), 'every leg has annotations for distance'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.duration;}), 'every leg has annotations for durations'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.nodes;}), 'every leg has annotations for nodes'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'every leg has annotations for weight'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'every leg has annotations for datasources'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'every leg has annotations for speed'); - - options.overview = 'full'; - osrm.route(options, function(err, full) { - assert.ifError(err); - options.overview = 'simplified'; - osrm.route(options, function(err, simplified) { - assert.ifError(err); - assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); - }); - }); - }); -}); - -test('route: routes Monaco with options', function(assert) { - assert.plan(11); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - continue_straight: false, - overview: 'false', - geometries: 'polyline', - steps: true, - annotations: true - }; - osrm.route(options, function(err, first) { - assert.ifError(err); - assert.ok(first.routes); - assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; })); - assert.equal(first.routes.length, 1); - assert.notOk(first.routes[0].geometry); - assert.ok(first.routes[0].legs[0]); - assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); - - options.overview = 'full'; - osrm.route(options, function(err, full) { - assert.ifError(err); - options.overview = 'simplified'; - osrm.route(options, function(err, simplified) { - assert.ifError(err); - assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); - }); - }); - }); -}); - -test('route: invalid route options', function(assert) { - assert.plan(8); - const osrm = new OSRM(monaco_path); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - continue_straight: [] - }, function(err, route) {}); }, - /must be boolean/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - alternatives: [] - }, function(err, route) {}); }, - /must be boolean/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - geometries: true - }, function(err, route) {}); }, - /Geometries must be a string: \[polyline, polyline6, geojson\]/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - overview: false - }, function(err, route) {}); }, - /Overview must be a string: \[simplified, full, false\]/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - overview: false - }, function(err, route) {}); }, - /Overview must be a string: \[simplified, full, false\]/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - overview: 'maybe' - }, function(err, route) {}); }, - /'overview' param must be one of \[simplified, full, false\]/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - geometries: 'maybe' - }, function(err, route) {}); }, - /'geometries' param must be one of \[polyline, polyline6, geojson\]/); - assert.throws(function() { osrm.route({ - coordinates: [[NaN, -NaN],[Infinity, -Infinity]] - }, function(err, route) {}); }, - /Lng\/Lat coordinates must be valid numbers/); -}); - -test('route: integer bearing values no longer supported', function(assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - bearings: [200, 250], - }; - assert.throws(function() { osrm.route(options, function(err, route) {}); }, - /Bearing must be an array of \[bearing, range\] or null/); -}); - -test('route: valid bearing values', function(assert) { - assert.plan(4); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - bearings: [[200, 180], [250, 180]], - }; - osrm.route(options, function(err, route) { - assert.ifError(err); - assert.ok(route.routes[0]); - }); - options.bearings = [null, [360, 180]]; - osrm.route(options, function(err, route) { - assert.ifError(err); - assert.ok(route.routes[0]); - }); -}); - -test('route: invalid bearing values', function(assert) { - assert.plan(6); - const osrm = new OSRM(monaco_path); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - bearings: [[400, 180], [-250, 180]], - }, function(err, route) {}) }, - /Bearing values need to be in range 0..360, 0..180/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - bearings: [[200], [250, 180]], - }, function(err, route) {}) }, - /Bearing must be an array of/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - bearings: [[400, 109], [100, 720]], - }, function(err, route) {}) }, - /Bearing values need to be in range 0..360, 0..180/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - bearings: 400, - }, function(err, route) {}) }, - /Bearings must be an array of arrays of numbers/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - bearings: [[100, 100]], - }, function(err, route) {}) }, - /Bearings array must have the same length as coordinates array/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - bearings: [Infinity, Infinity], - }, function(err, route) {}) }, - /Bearing must be an array of \[bearing, range\] or null/); -}); - -test('route: routes Monaco with hints', function(assert) { - assert.plan(5); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - }; - osrm.route(options, function(err, first) { - assert.ifError(err); - assert.ok(first.waypoints); - const hints = first.waypoints.map(function(wp) { return wp.hint; }); - assert.ok(hints.every(function(h) { return typeof h === 'string'; })); - - options.hints = hints; - - osrm.route(options, function(err, second) { - assert.ifError(err); - assert.deepEqual(first, second); - }); - }); -}); - -test('route: routes Monaco with null hints', function(assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - hints: [null, null] - }; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); -}); - -test('route: throws on bad hints', function(assert) { - assert.plan(2); - const osrm = new OSRM(monaco_path); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - hints: ['', ''] - }, function(err, route) {})}, /Hint cannot be an empty string/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - hints: [null] - }, function(err, route) {})}, /Hints array must have the same length as coordinates array/); -}); - -test('route: routes Monaco with valid radius values', function(assert) { - assert.plan(3); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - radiuses: [100, 100] - }; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); - options.radiuses = [null, null]; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); - options.radiuses = [100, null]; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); -}); - -test('route: throws on bad radiuses', function(assert) { - assert.plan(3); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - radiuses: [10, 10] - }; - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - radiuses: 10 - }, function(err, route) {}) }, - /Radiuses must be an array of non-negative doubles or null/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - radiuses: ['magic', 'numbers'] - }, function(err, route) {}) }, - /Radius must be non-negative double or null/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - radiuses: [10] - }, function(err, route) {}) }, - /Radiuses array must have the same length as coordinates array/); -}); - -test('route: routes Monaco with valid approaches values', function(assert) { - assert.plan(4); - const osrm = new OSRM(monaco_path); - const options = { - coordinates: two_test_coordinates, - approaches: [null, 'curb'] - }; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); - options.approaches = [null, null]; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); - options.approaches = ['opposite', 'opposite']; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); - options.approaches = ['unrestricted', null]; - osrm.route(options, function(err, route) { - assert.ifError(err); - }); -}); - -test('route: throws on bad approaches', function(assert) { - assert.plan(4); - const osrm = new OSRM(monaco_path); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - approaches: 10 - }, function(err, route) {}) }, - /Approaches must be an arrays of strings/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - approaches: ['curb'] - }, function(err, route) {}) }, - /Approaches array must have the same length as coordinates array/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - approaches: ['curb', 'test'] - }, function(err, route) {}) }, - /'approaches' param must be one of \[curb, opposite, unrestricted\]/); - assert.throws(function() { osrm.route({ - coordinates: two_test_coordinates, - approaches: [10, 15] - }, function(err, route) {}) }, - /Approach must be a string: \[curb, opposite, unrestricted\] or null/); -}); - -test('route: routes Monaco with custom limits on MLD', function(assert) { - assert.plan(2); - const osrm = new OSRM({ - path: monaco_mld_path, - algorithm: 'MLD', - max_alternatives: 10, - }); - osrm.route({coordinates: two_test_coordinates, alternatives: 10}, function(err, route) { - assert.ifError(err); - assert.ok(Array.isArray(route.routes)); - }); -}); - -test('route: in Monaco with custom limits on MLD', function(assert) { - assert.plan(1); - const osrm = new OSRM({ - path: monaco_mld_path, - algorithm: 'MLD', - max_alternatives: 10, - }); - osrm.route({coordinates: two_test_coordinates, alternatives: 11}, function(err, route) { - console.log(err) - assert.equal(err.message, 'TooBig'); - }); -}); - -test('route: route in Monaco without motorways', function(assert) { - assert.plan(3); - const osrm = new OSRM({path: monaco_mld_path, algorithm: 'MLD'}); - const options = { - coordinates: two_test_coordinates, - exclude: ['motorway'] - }; - osrm.route(options, function(err, response) { +import test from 'tape'; +import { OSRM, FBResult, data_path as monaco_path, mld_data_path as monaco_mld_path, three_test_coordinates, two_test_coordinates } from './constants.js'; + +test('route: routes Monaco and can return result in flatbuffers', (assert) => { + assert.plan(5); + const osrm = new OSRM(monaco_path); + osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, (err, result) => { + assert.ifError(err); + assert.ok(result instanceof Buffer); + const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(result)); + assert.equals(fb.waypointsLength(), 2); + assert.equals(fb.routesLength(), 1); + assert.ok(fb.routes(0).polyline); + }); +}); + +test('route: routes Monaco and can return result in flatbuffers if output format is passed explicitly', (assert) => { + assert.plan(5); + const osrm = new OSRM(monaco_path); + osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {output: 'buffer'}, (err, result) => { + assert.ifError(err); + assert.ok(result instanceof Buffer); + const buf = new flatbuffers.ByteBuffer(result); + const fb = FBResult.getRootAsFBResult(buf); + assert.equals(fb.waypointsLength(), 2); + assert.equals(fb.routesLength(), 1); + assert.ok(fb.routes(0).polyline); + }); +}); + +test('route: throws error if required output is object in flatbuffers format', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + assert.throws(() => { + osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {format: 'object'}, (err, result) => {}); + }); +}); + +test('route: throws error if required output is json_buffer in flatbuffers format', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + assert.throws(() => { + osrm.route({coordinates: two_test_coordinates, format: 'flatbuffers'}, {format: 'json_buffer'}, (err, result) => {}); + }); +}); + + +test('route: routes Monaco', (assert) => { + assert.plan(5); + const osrm = new OSRM(monaco_path); + osrm.route({coordinates: two_test_coordinates}, (err, route) => { + assert.ifError(err); + assert.ok(route.waypoints); + assert.ok(route.routes); + assert.ok(route.routes.length); + assert.ok(route.routes[0].geometry); + }); +}); + +test('route: routes Monaco on MLD', (assert) => { + assert.plan(5); + const osrm = new OSRM({path: monaco_mld_path, algorithm: 'MLD'}); + osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, (err, route) => { + assert.ifError(err); + assert.ok(route.waypoints); + assert.ok(route.routes); + assert.ok(route.routes.length); + assert.ok(route.routes[0].geometry); + }); +}); + +test('route: throws with too few or invalid args', (assert) => { + assert.plan(4); + const osrm = new OSRM(monaco_path); + assert.throws(() => { osrm.route({coordinates: two_test_coordinates}); }, + /Two arguments required/); + assert.throws(() => { osrm.route(null, (err, route) => {}); }, + /First arg must be an object/); + assert.throws(() => { osrm.route({coordinates: two_test_coordinates}, true);}, + /last argument must be a callback function/); + assert.throws(() => { osrm.route({coordinates: two_test_coordinates}, { format: 'invalid' }, (err, route) => {});}, + /format must be a string:/); +}); + +test('route: provides no alternatives by default, but when requested it may (not guaranteed)', (assert) => { + assert.plan(9); + const osrm = new OSRM(monaco_path); + const options = {coordinates: two_test_coordinates}; + + osrm.route(options, (err, route) => { + assert.ifError(err); + assert.ok(route.routes); + assert.equal(route.routes.length, 1); + }); + options.alternatives = true; + osrm.route(options, (err, route) => { + assert.ifError(err); + assert.ok(route.routes); + assert.ok(route.routes.length >= 1); + }); + options.alternatives = 3; + osrm.route(options, (err, route) => { + assert.ifError(err); + assert.ok(route.routes); + assert.ok(route.routes.length >= 1); + }); +}); + +test('route: throws with bad params', (assert) => { + assert.plan(11); + const osrm = new OSRM(monaco_path); + assert.throws(() => { osrm.route({coordinates: []}, (err) => {}); }); + assert.throws(() => { osrm.route({}, (err, route) => {}); }, + /Must provide a coordinates property/); + assert.throws(() => { osrm.route({coordinates: null}, (err, route) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + assert.throws(() => { osrm.route({coordinates: [[three_test_coordinates[0]], [three_test_coordinates[1]]]}, (err, route) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + assert.throws(() => { osrm.route({coordinates: [[true, 'stringish'], three_test_coordinates[1]]}, (err, route) => {}); }, + /Each member of a coordinate pair must be a number/); + assert.throws(() => { osrm.route({coordinates: [[213.43864,252.51993],[413.415852,552.513191]]}, (err, route) => {}); }, + /Lng\/Lat coordinates must be within world bounds \(-180 < lng < 180, -90 < lat < 90\)/); + assert.throws(() => { osrm.route({coordinates: [[13.438640], [52.519930]]}, (err, route) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + assert.throws(() => { osrm.route({coordinates: two_test_coordinates, hints: null}, (err, route) => {}); }, + /Hints must be an array of strings\/null/); + assert.throws(() => { osrm.route({coordinates: two_test_coordinates, steps: null}, (err, route) => {}); }); + assert.throws(() => { osrm.route({coordinates: two_test_coordinates, annotations: null}, (err, route) => {}); }); + const options = { + coordinates: two_test_coordinates, + alternateRoute: false, + hints: three_test_coordinates[0] + }; + assert.throws(() => { osrm.route(options, (err, route) => {}); }, + /Hint must be null or string/); +}); + +test('route: routes Monaco using shared memory', (assert) => { + assert.plan(2); + const osrm = new OSRM(); + osrm.route({coordinates: two_test_coordinates}, (err, route) => { + assert.ifError(err); + assert.ok(Array.isArray(route.routes)); + }); +}); + +test('route: routes Monaco with geometry compression', (assert) => { + assert.plan(2); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + }; + osrm.route(options, (err, route) => { + assert.ifError(err); + assert.equal('string', typeof route.routes[0].geometry); + }); +}); + +test('route: routes Monaco without geometry compression', (assert) => { + assert.plan(4); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + geometries: 'geojson' + }; + osrm.route(options, (err, route) => { + assert.ifError(err); + assert.ok(Array.isArray(route.routes)); + assert.ok(Array.isArray(route.routes[0].geometry.coordinates)); + assert.equal(route.routes[0].geometry.type, 'LineString'); + }); +}); + +test('Test polyline6 geometries option', (assert) => { + assert.plan(6); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + continue_straight: false, + overview: 'false', + geometries: 'polyline6', + steps: true + }; + osrm.route(options, (err, first) => { + assert.ifError(err); + assert.ok(first.routes); + assert.equal(first.routes.length, 1); + assert.notOk(first.routes[0].geometry); + assert.ok(first.routes[0].legs[0]); + assert.equal(typeof first.routes[0].legs[0].steps[0].geometry, 'string'); + }); +}); + +test('route: routes Monaco with speed annotations options', (assert) => { + assert.plan(17); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + continue_straight: false, + overview: 'false', + geometries: 'polyline', + steps: true, + annotations: ['speed'] + }; + osrm.route(options, (err, first) => { + assert.ifError(err); + assert.ok(first.routes); + assert.ok(first.routes[0].legs.every((l) => { return Array.isArray(l.steps) && l.steps.length > 0; })); + assert.equal(first.routes.length, 1); + assert.notOk(first.routes[0].geometry); + assert.ok(first.routes[0].legs[0]); + assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.speed;}), 'every leg has annotations for speed'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.duration; }), 'has no annotations for duration'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.distance; }), 'has no annotations for distance'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.nodes; }), 'has no annotations for nodes'); + + options.overview = 'full'; + osrm.route(options, (err, full) => { + assert.ifError(err); + options.overview = 'simplified'; + osrm.route(options, (err, simplified) => { assert.ifError(err); - assert.equal(response.waypoints.length, 2); - assert.equal(response.routes.length, 1); - }); -}); - - -test('route: throws on invalid waypoints values needs at least two', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [0] - }; - assert.throws(function () { osrm.route(options, function (err, response) { }); }, - 'At least two waypoints must be provided'); -}); - -test('route: throws on invalid waypoints values, needs first and last coordinate indices', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [1, 2] - }; - assert.throws(function () { osrm.route(options, function (err, response) { console.log(err); }); }, - 'First and last waypoints values must correspond to first and last coordinate indices'); -}); - -test('route: throws on invalid waypoints values, order matters', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [2, 0] - }; - assert.throws(function () { osrm.route(options, function (err, response) { console.log(err); }); }, - 'First and last waypoints values must correspond to first and last coordinate indices'); -}); - -test('route: throws on invalid waypoints values, waypoints must correspond with a coordinate index', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [0, 3, 2] - }; - assert.throws(function () { osrm.route(options, function (err, response) { console.log(err); }); }, - 'Waypoints must correspond with the index of an input coordinate'); -}); - -test('route: throws on invalid waypoints values, waypoints must be an array', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: "string" - }; - assert.throws(function () { osrm.route(options, function (err, response) { console.log(err); }); }, - 'Waypoints must be an array of integers corresponding to the input coordinates.'); -}); - -test('route: throws on invalid waypoints values, waypoints must be an array of integers', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates, - waypoints: [0,1,"string"] - }; - assert.throws(function () { osrm.route(options, function (err, response) { console.log(err); }); }, - 'Waypoint values must be an array of integers'); -}); - -test('route: throws on invalid waypoints values, waypoints must be an array of integers in increasing order', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - waypoints: [0,2,1,5] - }; - assert.throws(function () { osrm.route(options, function (err, response) { console.error(`response: ${response}`); console.error(`error: ${err}`); }); }, - /Waypoints must be supplied in increasing order/); -}); - -test('route: throws on invalid snapping values', function (assert) { - assert.plan(1); - const osrm = new OSRM(monaco_path); - const options = { - steps: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - snapping: "zing" - }; - assert.throws(function () { osrm.route(options, function (err, response) { console.error(`response: ${response}`); console.error(`error: ${err}`); }); }, - /'snapping' param must be one of \[default, any\]/); -}); - -test('route: snapping parameter passed through OK', function(assert) { - assert.plan(2); - const osrm = new OSRM(monaco_path); - osrm.route({snapping: "any", coordinates: [[7.448205209414596,43.754001097311544],[7.447122039202185,43.75306156811368]]}, function(err, route) { + assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); + }); + }); + }); +}); + +test('route: routes Monaco with several (duration, distance, nodes) annotations options', (assert) => { + assert.plan(17); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + continue_straight: false, + overview: 'false', + geometries: 'polyline', + steps: true, + annotations: ['duration', 'distance', 'nodes'] + }; + osrm.route(options, (err, first) => { + assert.ifError(err); + assert.ok(first.routes); + assert.ok(first.routes[0].legs.every((l) => { return Array.isArray(l.steps) && l.steps.length > 0; })); + assert.equal(first.routes.length, 1); + assert.notOk(first.routes[0].geometry); + assert.ok(first.routes[0].legs[0]); + assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.distance;}), 'every leg has annotations for distance'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.duration;}), 'every leg has annotations for durations'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.nodes;}), 'every leg has annotations for nodes'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources'); + assert.notOk(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'has no annotations for speed'); + + options.overview = 'full'; + osrm.route(options, (err, full) => { + assert.ifError(err); + options.overview = 'simplified'; + osrm.route(options, (err, simplified) => { assert.ifError(err); - assert.equal(Math.round(route.routes[0].distance * 10), 1315); // Round it to nearest 0.1m to eliminate floating point comparison error - }); -}); - -test('route: throws on disabled geometry', function (assert) { - assert.plan(1); - const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - coordinates: three_test_coordinates, - }; - osrm.route(options, function(err, route) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); -}); - -test('route: ok on disabled geometry', function (assert) { - assert.plan(2); - const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - steps: false, - overview: 'false', - annotations: false, - skip_waypoints: true, - coordinates: three_test_coordinates, - }; - osrm.route(options, function(err, response) { + assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); + }); + }); + }); +}); + +test('route: routes Monaco with options', (assert) => { + assert.plan(17); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + continue_straight: false, + overview: 'false', + geometries: 'polyline', + steps: true, + annotations: true + }; + osrm.route(options, (err, first) => { + assert.ifError(err); + assert.ok(first.routes); + assert.ok(first.routes[0].legs.every((l) => { return Array.isArray(l.steps) && l.steps.length > 0; })); + assert.equal(first.routes.length, 1); + assert.notOk(first.routes[0].geometry); + assert.ok(first.routes[0].legs[0]); + assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.distance;}), 'every leg has annotations for distance'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.duration;}), 'every leg has annotations for durations'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.nodes;}), 'every leg has annotations for nodes'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'every leg has annotations for weight'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'every leg has annotations for datasources'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'every leg has annotations for speed'); + + options.overview = 'full'; + osrm.route(options, (err, full) => { + assert.ifError(err); + options.overview = 'simplified'; + osrm.route(options, (err, simplified) => { assert.ifError(err); - assert.equal(response.routes.length, 1); - }); -}); - -test('route: throws on disabled steps', function (assert) { - assert.plan(1); - const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - steps: true, - coordinates: three_test_coordinates, - }; - osrm.route(options, function(err, route) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); -}); - -test('route: ok on disabled steps', function (assert) { - assert.plan(8); - const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - steps: false, - overview: 'simplified', - annotations: true, - coordinates: three_test_coordinates, - }; - osrm.route(options, function(err, response) { + assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); + }); + }); + }); +}); + +test('route: routes Monaco with options', (assert) => { + assert.plan(11); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + continue_straight: false, + overview: 'false', + geometries: 'polyline', + steps: true, + annotations: true + }; + osrm.route(options, (err, first) => { + assert.ifError(err); + assert.ok(first.routes); + assert.ok(first.routes[0].legs.every((l) => { return Array.isArray(l.steps) && l.steps.length > 0; })); + assert.equal(first.routes.length, 1); + assert.notOk(first.routes[0].geometry); + assert.ok(first.routes[0].legs[0]); + assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); + + options.overview = 'full'; + osrm.route(options, (err, full) => { + assert.ifError(err); + options.overview = 'simplified'; + osrm.route(options, (err, simplified) => { assert.ifError(err); - assert.ok(response.waypoints); - assert.ok(response.routes); - assert.equal(response.routes.length, 1); - assert.ok(response.routes[0].geometry, "the route has geometry"); - assert.ok(response.routes[0].legs, "the route has legs"); - assert.notok(response.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(response.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); - }); + assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry); + }); + }); + }); +}); + +test('route: invalid route options', (assert) => { + assert.plan(8); + const osrm = new OSRM(monaco_path); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + continue_straight: [] + }, (err, route) => {}); }, + /must be boolean/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + alternatives: [] + }, (err, route) => {}); }, + /must be boolean/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + geometries: true + }, (err, route) => {}); }, + /Geometries must be a string: \[polyline, polyline6, geojson\]/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + overview: false + }, (err, route) => {}); }, + /Overview must be a string: \[simplified, full, false\]/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + overview: false + }, (err, route) => {}); }, + /Overview must be a string: \[simplified, full, false\]/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + overview: 'maybe' + }, (err, route) => {}); }, + /'overview' param must be one of \[simplified, full, false\]/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + geometries: 'maybe' + }, (err, route) => {}); }, + /'geometries' param must be one of \[polyline, polyline6, geojson\]/); + assert.throws(() => { osrm.route({ + coordinates: [[NaN, -NaN],[Infinity, -Infinity]] + }, (err, route) => {}); }, + /Lng\/Lat coordinates must be valid numbers/); +}); + +test('route: integer bearing values no longer supported', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + bearings: [200, 250], + }; + assert.throws(() => { osrm.route(options, (err, route) => {}); }, + /Bearing must be an array of \[bearing, range\] or null/); +}); + +test('route: valid bearing values', (assert) => { + assert.plan(4); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + bearings: [[200, 180], [250, 180]], + }; + osrm.route(options, (err, route) => { + assert.ifError(err); + assert.ok(route.routes[0]); + }); + options.bearings = [null, [360, 180]]; + osrm.route(options, (err, route) => { + assert.ifError(err); + assert.ok(route.routes[0]); + }); +}); + +test('route: invalid bearing values', (assert) => { + assert.plan(6); + const osrm = new OSRM(monaco_path); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + bearings: [[400, 180], [-250, 180]], + }, (err, route) => {}); }, + /Bearing values need to be in range 0..360, 0..180/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + bearings: [[200], [250, 180]], + }, (err, route) => {}); }, + /Bearing must be an array of/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + bearings: [[400, 109], [100, 720]], + }, (err, route) => {}); }, + /Bearing values need to be in range 0..360, 0..180/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + bearings: 400, + }, (err, route) => {}); }, + /Bearings must be an array of arrays of numbers/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + bearings: [[100, 100]], + }, (err, route) => {}); }, + /Bearings array must have the same length as coordinates array/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + bearings: [Infinity, Infinity], + }, (err, route) => {}); }, + /Bearing must be an array of \[bearing, range\] or null/); +}); + +test('route: routes Monaco with hints', (assert) => { + assert.plan(5); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + }; + osrm.route(options, (err, first) => { + assert.ifError(err); + assert.ok(first.waypoints); + const hints = first.waypoints.map((wp) => { return wp.hint; }); + assert.ok(hints.every((h) => { return typeof h === 'string'; })); + + options.hints = hints; + + osrm.route(options, (err, second) => { + assert.ifError(err); + assert.deepEqual(first, second); + }); + }); +}); + +test('route: routes Monaco with null hints', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + hints: [null, null] + }; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); +}); + +test('route: throws on bad hints', (assert) => { + assert.plan(2); + const osrm = new OSRM(monaco_path); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + hints: ['', ''] + }, (err, route) => {});}, /Hint cannot be an empty string/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + hints: [null] + }, (err, route) => {});}, /Hints array must have the same length as coordinates array/); +}); + +test('route: routes Monaco with valid radius values', (assert) => { + assert.plan(3); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + radiuses: [100, 100] + }; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); + options.radiuses = [null, null]; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); + options.radiuses = [100, null]; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); +}); + +test('route: throws on bad radiuses', (assert) => { + assert.plan(3); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + radiuses: [10, 10] + }; + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + radiuses: 10 + }, (err, route) => {}); }, + /Radiuses must be an array of non-negative doubles or null/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + radiuses: ['magic', 'numbers'] + }, (err, route) => {}); }, + /Radius must be non-negative double or null/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + radiuses: [10] + }, (err, route) => {}); }, + /Radiuses array must have the same length as coordinates array/); +}); + +test('route: routes Monaco with valid approaches values', (assert) => { + assert.plan(4); + const osrm = new OSRM(monaco_path); + const options = { + coordinates: two_test_coordinates, + approaches: [null, 'curb'] + }; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); + options.approaches = [null, null]; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); + options.approaches = ['opposite', 'opposite']; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); + options.approaches = ['unrestricted', null]; + osrm.route(options, (err, route) => { + assert.ifError(err); + }); +}); + +test('route: throws on bad approaches', (assert) => { + assert.plan(4); + const osrm = new OSRM(monaco_path); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + approaches: 10 + }, (err, route) => {}); }, + /Approaches must be an arrays of strings/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + approaches: ['curb'] + }, (err, route) => {}); }, + /Approaches array must have the same length as coordinates array/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + approaches: ['curb', 'test'] + }, (err, route) => {}); }, + /'approaches' param must be one of \[curb, opposite, unrestricted\]/); + assert.throws(() => { osrm.route({ + coordinates: two_test_coordinates, + approaches: [10, 15] + }, (err, route) => {}); }, + /Approach must be a string: \[curb, opposite, unrestricted\] or null/); +}); + +test('route: routes Monaco with custom limits on MLD', (assert) => { + assert.plan(2); + const osrm = new OSRM({ + path: monaco_mld_path, + algorithm: 'MLD', + max_alternatives: 10, + }); + osrm.route({coordinates: two_test_coordinates, alternatives: 10}, (err, route) => { + assert.ifError(err); + assert.ok(Array.isArray(route.routes)); + }); +}); + +test('route: in Monaco with custom limits on MLD', (assert) => { + assert.plan(1); + const osrm = new OSRM({ + path: monaco_mld_path, + algorithm: 'MLD', + max_alternatives: 10, + }); + osrm.route({coordinates: two_test_coordinates, alternatives: 11}, (err, route) => { + console.log(err); + assert.equal(err.message, 'TooBig'); + }); +}); + +test('route: route in Monaco without motorways', (assert) => { + assert.plan(3); + const osrm = new OSRM({path: monaco_mld_path, algorithm: 'MLD'}); + const options = { + coordinates: two_test_coordinates, + exclude: ['motorway'] + }; + osrm.route(options, (err, response) => { + assert.ifError(err); + assert.equal(response.waypoints.length, 2); + assert.equal(response.routes.length, 1); + }); +}); + + +test('route: throws on invalid waypoints values needs at least two', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [0] + }; + assert.throws(() => { osrm.route(options, (err, response) => { }); }, + 'At least two waypoints must be provided'); +}); + +test('route: throws on invalid waypoints values, needs first and last coordinate indices', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [1, 2] + }; + assert.throws(() => { osrm.route(options, (err, response) => { console.log(err); }); }, + 'First and last waypoints values must correspond to first and last coordinate indices'); +}); + +test('route: throws on invalid waypoints values, order matters', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [2, 0] + }; + assert.throws(() => { osrm.route(options, (err, response) => { console.log(err); }); }, + 'First and last waypoints values must correspond to first and last coordinate indices'); +}); + +test('route: throws on invalid waypoints values, waypoints must correspond with a coordinate index', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [0, 3, 2] + }; + assert.throws(() => { osrm.route(options, (err, response) => { console.log(err); }); }, + 'Waypoints must correspond with the index of an input coordinate'); +}); + +test('route: throws on invalid waypoints values, waypoints must be an array', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: 'string' + }; + assert.throws(() => { osrm.route(options, (err, response) => { console.log(err); }); }, + 'Waypoints must be an array of integers corresponding to the input coordinates.'); +}); + +test('route: throws on invalid waypoints values, waypoints must be an array of integers', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates, + waypoints: [0,1,'string'] + }; + assert.throws(() => { osrm.route(options, (err, response) => { console.log(err); }); }, + 'Waypoint values must be an array of integers'); +}); + +test('route: throws on invalid waypoints values, waypoints must be an array of integers in increasing order', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + waypoints: [0,2,1,5] + }; + assert.throws(() => { osrm.route(options, (err, response) => { console.error(`response: ${response}`); console.error(`error: ${err}`); }); }, + /Waypoints must be supplied in increasing order/); +}); + +test('route: throws on invalid snapping values', (assert) => { + assert.plan(1); + const osrm = new OSRM(monaco_path); + const options = { + steps: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + snapping: 'zing' + }; + assert.throws(() => { osrm.route(options, (err, response) => { console.error(`response: ${response}`); console.error(`error: ${err}`); }); }, + /'snapping' param must be one of \[default, any\]/); +}); + +test('route: snapping parameter passed through OK', (assert) => { + assert.plan(2); + const osrm = new OSRM(monaco_path); + osrm.route({snapping: 'any', coordinates: [[7.448205209414596,43.754001097311544],[7.447122039202185,43.75306156811368]]}, (err, route) => { + assert.ifError(err); + assert.equal(Math.round(route.routes[0].distance * 10), 1315); // Round it to nearest 0.1m to eliminate floating point comparison error + }); +}); + +test('route: throws on disabled geometry', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + coordinates: three_test_coordinates, + }; + osrm.route(options, (err, route) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); +}); + +test('route: ok on disabled geometry', (assert) => { + assert.plan(2); + const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + steps: false, + overview: 'false', + annotations: false, + skip_waypoints: true, + coordinates: three_test_coordinates, + }; + osrm.route(options, (err, response) => { + assert.ifError(err); + assert.equal(response.routes.length, 1); + }); +}); + +test('route: throws on disabled steps', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + steps: true, + coordinates: three_test_coordinates, + }; + osrm.route(options, (err, route) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); +}); + +test('route: ok on disabled steps', (assert) => { + assert.plan(8); + const osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + steps: false, + overview: 'simplified', + annotations: true, + coordinates: three_test_coordinates, + }; + osrm.route(options, (err, response) => { + assert.ifError(err); + assert.ok(response.waypoints); + assert.ok(response.routes); + assert.equal(response.routes.length, 1); + assert.ok(response.routes[0].geometry, 'the route has geometry'); + assert.ok(response.routes[0].legs, 'the route has legs'); + assert.notok(response.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(response.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); + }); }); diff --git a/test/nodejs/table.js b/test/nodejs/table.js index be4a53b8ba1..3597ce84fb2 100644 --- a/test/nodejs/table.js +++ b/test/nodejs/table.js @@ -1,415 +1,410 @@ // Test table service functionality with distance/duration matrices -import OSRM from '../../lib/index.js'; -import test from 'tape'; -import { data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; import flatbuffers from 'flatbuffers'; -import { osrm } from '../../features/support/fbresult_generated.js'; - -const FBResult = osrm.engine.api.fbresult.FBResult; +import test from 'tape'; +import { OSRM, FBResult, data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; + +test('table: flatbuffer format', (assert) => { + assert.plan(3); + const osrm = new OSRM(data_path); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + format: 'flatbuffers' + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table instanceof Buffer); + const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(table)); + assert.ok(fb.table()); + + }); +}); -test('table: flatbuffer format', function(assert) { - assert.plan(3); - const osrm = new OSRM(data_path); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - format: 'flatbuffers' - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table instanceof Buffer); - const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(table)); - assert.ok(fb.table()); +test('table: test annotations paramater combination', (assert) => { + assert.plan(12); + const osrm = new OSRM(data_path); + let options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + annotations: ['distance'] + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table['distances'], 'distances table result should exist'); + assert.notOk(table['durations'], 'durations table result should not exist'); + }); + + options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + annotations: ['duration'] + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table['durations'], 'durations table result should exist'); + assert.notOk(table['distances'], 'distances table result should not exist'); + }); + + options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + annotations: ['duration', 'distance'] + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table['durations'], 'durations table result should exist'); + assert.ok(table['distances'], 'distances table result should exist'); + }); + + options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]] + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table['durations'], 'durations table result should exist'); + assert.notOk(table['distances'], 'distances table result should not exist'); + }); +}); - }); +test('table: returns buffer', (assert) => { + assert.plan(3); + const osrm = new OSRM(data_path); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + }; + osrm.table(options, { format: 'json_buffer' }, (err, table) => { + assert.ifError(err); + assert.ok(table instanceof Buffer); + table = JSON.parse(table); + assert.ok(table['durations'], 'distances table result should exist'); + }); }); -test('table: test annotations paramater combination', function(assert) { - assert.plan(12); - const osrm = new OSRM(data_path); - let options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - annotations: ['distance'] - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table['distances'], 'distances table result should exist'); - assert.notOk(table['durations'], 'durations table result should not exist'); - }); +test('table: throws on invalid snapping values', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + snapping: 'zing' + }; + assert.throws(() => { osrm.table(options, (err, response) => { }); }, + /'snapping' param must be one of \[default, any\]/); +}); - options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - annotations: ['duration'] - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table['durations'], 'durations table result should exist'); - assert.notOk(table['distances'], 'distances table result should not exist'); - }); +test('table: snapping parameter passed through OK', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + snapping: 'any' + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table['durations'], 'distances table result should exist'); + }); +}); - options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - annotations: ['duration', 'distance'] - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table['durations'], 'durations table result should exist'); - assert.ok(table['distances'], 'distances table result should exist'); - }); +const tables = ['distances', 'durations']; - options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]] +// Generate tests for both 'distances' and 'durations' table types +tables.forEach((annotation) => { + test(`table: ${ annotation } table in Monaco`, (assert) => { + assert.plan(11); + const osrm = new OSRM(data_path); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + annotations: [annotation.slice(0,-1)] }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table['durations'], 'durations table result should exist'); - assert.notOk(table['distances'], 'distances table result should not exist'); + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(Array.isArray(table[annotation]), 'result must be an array'); + const row_count = table[annotation].length; + for (let i = 0; i < row_count; ++i) { + const column = table[annotation][i]; + const column_count = column.length; + assert.equal(row_count, column_count); + for (let j = 0; j < column_count; ++j) { + if (i == j) { + // check that diagonal is zero + assert.equal(0, column[j], 'diagonal must be zero'); + } else { + // everything else is non-zero + assert.notEqual(0, column[j], 'other entries must be non-zero'); + // and finite (not nan, inf etc.) + assert.ok(Number.isFinite(column[j]), 'distance is finite number'); + } + } + } + assert.equal(options.coordinates.length, row_count); }); -}); + }); -test('table: returns buffer', function(assert) { - assert.plan(3); + test(`table: ${ annotation } table in Monaco with sources/destinations`, (assert) => { + assert.plan(7); const osrm = new OSRM(data_path); const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + sources: [0], + destinations: [0,1], + annotations: [annotation.slice(0,-1)] }; - osrm.table(options, { format: 'json_buffer' }, function(err, table) { - assert.ifError(err); - assert.ok(table instanceof Buffer); - table = JSON.parse(table); - assert.ok(table['durations'], 'distances table result should exist'); + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(Array.isArray(table[annotation]), 'result must be an array'); + const row_count = table[annotation].length; + for (let i = 0; i < row_count; ++i) { + const column = table[annotation][i]; + const column_count = column.length; + assert.equal(options.destinations.length, column_count); + for (let j = 0; j < column_count; ++j) { + if (i == j) { + // check that diagonal is zero + assert.equal(0, column[j], 'diagonal must be zero'); + } else { + // everything else is non-zero + assert.notEqual(0, column[j], 'other entries must be non-zero'); + // and finite (not nan, inf etc.) + assert.ok(Number.isFinite(column[j]), 'distance is finite number'); + } + } + } + assert.equal(options.sources.length, row_count); }); -}); + }); -test('table: throws on invalid snapping values', function (assert) { + test(`table: ${ annotation } throws on invalid arguments`, (assert) => { + assert.plan(18); + const osrm = new OSRM(data_path); + const options = {annotations: [annotation.slice(0,-1)]}; + assert.throws(() => { osrm.table(options); }, + /Two arguments required/); + options.coordinates = null; + assert.throws(() => { osrm.table(options, () => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + options.coordinates = [three_test_coordinates[0]]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /At least two coordinates must be provided/); + options.coordinates = three_test_coordinates[0]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + options.coordinates = [three_test_coordinates[0][0], three_test_coordinates[0][1]]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + + options.coordinates = two_test_coordinates; + assert.throws(() => { osrm.table(options, { format: 'invalid' }, (err, response) => {}); }, + /format must be a string:/); + + options.sources = true; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Sources must be an array of indices \(or undefined\)/); + options.sources = [0, 4]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Source indices must be less than the number of coordinates/); + options.sources = [0.3, 1.1]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Source must be an integer/); + options.sources = [0, 1, 2]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Source indices must be less than the number of coordinates/); + + options.destinations = true; + delete options.sources; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Destinations must be an array of indices \(or undefined\)/); + options.destinations = [0, 4]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Destination indices must be less than the number of coordinates/); + options.destinations = [0.3, 1.1]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Destination must be an integer/); + options.destinations = [0, 4]; + assert.throws(() => { osrm.table(options, (err, response) => {}); }, + /Destination indices must be less than the number of coordinates/); + + // does not throw: the following two have been changed in OSRM v5 + options.sources = [0, 1]; + delete options.destinations; + assert.doesNotThrow(() => { osrm.table(options, (err, response) => {}); }, + /Both sources and destinations need to be specified/); + options.destinations = [0, 1]; + assert.doesNotThrow(() => { osrm.table(options, (err, response) => {}); }, + /You can either specify sources and destinations, or coordinates/); + + assert.throws(() => { osrm.route({coordinates: two_test_coordinates, generate_hints: null}, (err, route) => {}); }, + /generate_hints must be of type Boolean/); + assert.throws(() => { osrm.route({coordinates: two_test_coordinates, skip_waypoints: null}, (err, route) => {}); }, + /skip_waypoints must be of type Boolean/); + }); + + test('table: throws on invalid arguments', (assert) => { assert.plan(1); const osrm = new OSRM(data_path); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - snapping: 'zing' - }; - assert.throws(function () { osrm.table(options, function (err, response) { }); }, - /'snapping' param must be one of \[default, any\]/); -}); + assert.throws(() => { osrm.table(null, () => {}); }, + /First arg must be an object/); + }); -test('table: snapping parameter passed through OK', function (assert) { - assert.plan(2); + test(`table: ${ annotation } table in Monaco with hints`, (assert) => { + assert.plan(5); const osrm = new OSRM(data_path); const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - snapping: 'any' + coordinates: two_test_coordinates, + generate_hints: true, // true is default but be explicit here + annotations: [annotation.slice(0,-1)] }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table['durations'], 'distances table result should exist'); - }); -}); + osrm.table(options, (err, table) => { + assert.ifError(err); -const tables = ['distances', 'durations']; + // Helper function to verify waypoint contains hint data + function assertHasHints(waypoint) { + assert.notStrictEqual(waypoint.hint, undefined); + } -// Generate tests for both 'distances' and 'durations' table types -tables.forEach(function(annotation) { - test('table: ' + annotation + ' table in Monaco', function(assert) { - assert.plan(11); - const osrm = new OSRM(data_path); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - annotations: [annotation.slice(0,-1)] - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(Array.isArray(table[annotation]), 'result must be an array'); - const row_count = table[annotation].length; - for (let i = 0; i < row_count; ++i) { - const column = table[annotation][i]; - const column_count = column.length; - assert.equal(row_count, column_count); - for (let j = 0; j < column_count; ++j) { - if (i == j) { - // check that diagonal is zero - assert.equal(0, column[j], 'diagonal must be zero'); - } else { - // everything else is non-zero - assert.notEqual(0, column[j], 'other entries must be non-zero'); - // and finite (not nan, inf etc.) - assert.ok(Number.isFinite(column[j]), 'distance is finite number'); - } - } - } - assert.equal(options.coordinates.length, row_count); - }); - }); - - test('table: ' + annotation + ' table in Monaco with sources/destinations', function(assert) { - assert.plan(7); - const osrm = new OSRM(data_path); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - sources: [0], - destinations: [0,1], - annotations: [annotation.slice(0,-1)] - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(Array.isArray(table[annotation]), 'result must be an array'); - const row_count = table[annotation].length; - for (let i = 0; i < row_count; ++i) { - const column = table[annotation][i]; - const column_count = column.length; - assert.equal(options.destinations.length, column_count); - for (let j = 0; j < column_count; ++j) { - if (i == j) { - // check that diagonal is zero - assert.equal(0, column[j], 'diagonal must be zero'); - } else { - // everything else is non-zero - assert.notEqual(0, column[j], 'other entries must be non-zero'); - // and finite (not nan, inf etc.) - assert.ok(Number.isFinite(column[j]), 'distance is finite number'); - } - } - } - assert.equal(options.sources.length, row_count); - }); + table.sources.map(assertHasHints); + table.destinations.map(assertHasHints); }); + }); - test('table: ' + annotation + ' throws on invalid arguments', function(assert) { - assert.plan(18); - const osrm = new OSRM(data_path); - const options = {annotations: [annotation.slice(0,-1)]}; - assert.throws(function() { osrm.table(options); }, - /Two arguments required/); - options.coordinates = null; - assert.throws(function() { osrm.table(options, function() {}); }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - options.coordinates = [three_test_coordinates[0]]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /At least two coordinates must be provided/); - options.coordinates = three_test_coordinates[0]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - options.coordinates = [three_test_coordinates[0][0], three_test_coordinates[0][1]]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - - options.coordinates = two_test_coordinates; - assert.throws(function() { osrm.table(options, { format: 'invalid' }, function(err, response) {}) }, - /format must be a string:/); - - options.sources = true; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Sources must be an array of indices \(or undefined\)/); - options.sources = [0, 4]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Source indices must be less than the number of coordinates/); - options.sources = [0.3, 1.1]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Source must be an integer/); - options.sources = [0, 1, 2]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Source indices must be less than the number of coordinates/); - - options.destinations = true; - delete options.sources; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Destinations must be an array of indices \(or undefined\)/); - options.destinations = [0, 4]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Destination indices must be less than the number of coordinates/); - options.destinations = [0.3, 1.1]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Destination must be an integer/); - options.destinations = [0, 4]; - assert.throws(function() { osrm.table(options, function(err, response) {}) }, - /Destination indices must be less than the number of coordinates/); - - // does not throw: the following two have been changed in OSRM v5 - options.sources = [0, 1]; - delete options.destinations; - assert.doesNotThrow(function() { osrm.table(options, function(err, response) {}) }, - /Both sources and destinations need to be specified/); - options.destinations = [0, 1]; - assert.doesNotThrow(function() { osrm.table(options, function(err, response) {}) }, - /You can either specify sources and destinations, or coordinates/); - - assert.throws(function() { osrm.route({coordinates: two_test_coordinates, generate_hints: null}, function(err, route) {}) }, - /generate_hints must be of type Boolean/); - assert.throws(function() { osrm.route({coordinates: two_test_coordinates, skip_waypoints: null}, function(err, route) {}) }, - /skip_waypoints must be of type Boolean/); - }); + test(`table: ${ annotation } table in Monaco without hints`, (assert) => { + assert.plan(5); + const osrm = new OSRM(data_path); + const options = { + coordinates: two_test_coordinates, + generate_hints: false, // true is default + annotations: [annotation.slice(0,-1)] + }; + osrm.table(options, (err, table) => { + assert.ifError(err); - test('table: throws on invalid arguments', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - assert.throws(function() { osrm.table(null, function() {}); }, - /First arg must be an object/); - }); + // Helper function to verify waypoint has no hint data + function assertHasNoHints(waypoint) { + assert.strictEqual(waypoint.hint, undefined); + } - test('table: ' + annotation + ' table in Monaco with hints', function(assert) { - assert.plan(5); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - generate_hints: true, // true is default but be explicit here - annotations: [annotation.slice(0,-1)] - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - - // Helper function to verify waypoint contains hint data - function assertHasHints(waypoint) { - assert.notStrictEqual(waypoint.hint, undefined); - } - - table.sources.map(assertHasHints); - table.destinations.map(assertHasHints); - }); + table.sources.map(assertHasNoHints); + table.destinations.map(assertHasNoHints); }); + }); - test('table: ' + annotation + ' table in Monaco without hints', function(assert) { - assert.plan(5); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - generate_hints: false, // true is default - annotations: [annotation.slice(0,-1)] - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - - // Helper function to verify waypoint has no hint data - function assertHasNoHints(waypoint) { - assert.strictEqual(waypoint.hint, undefined); - } - - table.sources.map(assertHasNoHints); - table.destinations.map(assertHasNoHints); - }); + test(`table: ${ annotation } table in Monaco without waypoints`, (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + const options = { + coordinates: two_test_coordinates, + skip_waypoints: true, // false is default + annotations: [annotation.slice(0,-1)] + }; + osrm.table(options, (err, table) => { + assert.strictEqual(table.sources, undefined); + assert.strictEqual(table.destinations, undefined); }); + }); - test('table: ' + annotation + ' table in Monaco without waypoints', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - skip_waypoints: true, // false is default - annotations: [annotation.slice(0,-1)] - }; - osrm.table(options, function(err, table) { - assert.strictEqual(table.sources, undefined); - assert.strictEqual(table.destinations, undefined); - }); + test(`table: ${ annotation } table in Monaco without motorways`, (assert) => { + assert.plan(2); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: two_test_coordinates, + exclude: ['motorway'], + annotations: [annotation.slice(0,-1)] + }; + osrm.table(options, (err, response) => { + assert.equal(response[annotation].length, 2); + assert.strictEqual(response.fallback_speed_cells, undefined); }); + }); - test('table: ' + annotation + ' table in Monaco without motorways', function(assert) { - assert.plan(2); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: two_test_coordinates, - exclude: ['motorway'], - annotations: [annotation.slice(0,-1)] - }; - osrm.table(options, function(err, response) { - assert.equal(response[annotation].length, 2); - assert.strictEqual(response.fallback_speed_cells, undefined); - }); + test(`table: ${ annotation } table in Monaco with fallback speeds`, (assert) => { + assert.plan(2); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: two_test_coordinates, + annotations: [annotation.slice(0,-1)], + fallback_speed: 1, + fallback_coordinate: 'input' + }; + osrm.table(options, (err, response) => { + assert.equal(response[annotation].length, 2); + assert.equal(response['fallback_speed_cells'].length, 0); }); + }); - test('table: ' + annotation + ' table in Monaco with fallback speeds', function(assert) { - assert.plan(2); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: two_test_coordinates, - annotations: [annotation.slice(0,-1)], - fallback_speed: 1, - fallback_coordinate: 'input' - }; - osrm.table(options, function(err, response) { - assert.equal(response[annotation].length, 2); - assert.equal(response['fallback_speed_cells'].length, 0); - }); - }); + test(`table: ${ annotation } table in Monaco with invalid fallback speeds and fallback coordinates`, (assert) => { + assert.plan(4); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: two_test_coordinates, + annotations: [annotation.slice(0,-1)], + fallback_speed: -1 + }; - test('table: ' + annotation + ' table in Monaco with invalid fallback speeds and fallback coordinates', function(assert) { - assert.plan(4); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: two_test_coordinates, - annotations: [annotation.slice(0,-1)], - fallback_speed: -1 - }; + assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_speed must be > 0/, 'should throw on invalid fallback_speeds'); - assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_speed must be > 0/, "should throw on invalid fallback_speeds"); + options.fallback_speed = '10'; + assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_speed must be a number/, 'should throw on invalid fallback_speeds'); - options.fallback_speed = '10'; - assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_speed must be a number/, "should throw on invalid fallback_speeds"); + options.fallback_speed = 10; + options.fallback_coordinate = 'bla'; + assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_coordinate' param must be one of \[input, snapped\]/, 'should throw on invalid fallback_coordinate'); - options.fallback_speed = 10; - options.fallback_coordinate = 'bla'; - assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_coordinate' param must be one of \[input, snapped\]/, "should throw on invalid fallback_coordinate"); + options.fallback_coordinate = 10; + assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_coordinate must be a string: \[input, snapped\]/, 'should throw on invalid fallback_coordinate'); - options.fallback_coordinate = 10; - assert.throws(()=>osrm.table(options, (err, res) => {}), /fallback_coordinate must be a string: \[input, snapped\]/, "should throw on invalid fallback_coordinate"); + }); - }); - - test('table: ' + annotation + ' table in Monaco with invalid scale factor', function(assert) { - assert.plan(3); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: two_test_coordinates, - annotations: [annotation.slice(0,-1)], - scale_factor: -1 - }; + test(`table: ${ annotation } table in Monaco with invalid scale factor`, (assert) => { + assert.plan(3); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: two_test_coordinates, + annotations: [annotation.slice(0,-1)], + scale_factor: -1 + }; - assert.throws(()=>osrm.table(options, (err, res) => {}), /scale_factor must be > 0/, "should throw on invalid scale_factor value"); + assert.throws(()=>osrm.table(options, (err, res) => {}), /scale_factor must be > 0/, 'should throw on invalid scale_factor value'); - options.scale_factor = '-1'; - assert.throws(()=>osrm.table(options, (err, res) => {}), /scale_factor must be a number/, "should throw on invalid scale_factor value"); + options.scale_factor = '-1'; + assert.throws(()=>osrm.table(options, (err, res) => {}), /scale_factor must be a number/, 'should throw on invalid scale_factor value'); - options.scale_factor = 0; - assert.throws(()=>osrm.table(options, (err, res) => {}), /scale_factor must be > 0/, "should throw on invalid scale_factor value"); + options.scale_factor = 0; + assert.throws(()=>osrm.table(options, (err, res) => {}), /scale_factor must be > 0/, 'should throw on invalid scale_factor value'); - }); + }); }); -test('table: throws on disabled geometry', function (assert) { - assert.plan(1); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - }; - osrm.table(options, function(err, table) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); +test('table: throws on disabled geometry', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + }; + osrm.table(options, (err, table) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); }); -test('table: ok on disabled geometry', function (assert) { - assert.plan(4); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - skip_waypoints: true - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table.durations, 'distances table result should exist'); - assert.notok(table.sources) - assert.notok(table.destinations) - }); +test('table: ok on disabled geometry', (assert) => { + assert.plan(4); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + skip_waypoints: true + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table.durations, 'distances table result should exist'); + assert.notok(table.sources); + assert.notok(table.destinations); + }); }); -test('table: ok on disabled steps', function (assert) { - assert.plan(4); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - }; - osrm.table(options, function(err, table) { - assert.ifError(err); - assert.ok(table.durations, 'distances table result should exist'); - assert.ok(table.sources.length, 2) - assert.ok(table.destinations.length, 2) - }); +test('table: ok on disabled steps', (assert) => { + assert.plan(4); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + }; + osrm.table(options, (err, table) => { + assert.ifError(err); + assert.ok(table.durations, 'distances table result should exist'); + assert.ok(table.sources.length, 2); + assert.ok(table.destinations.length, 2); + }); }); - diff --git a/test/nodejs/tile.js b/test/nodejs/tile.js index fca80e71e83..402cff374d7 100644 --- a/test/nodejs/tile.js +++ b/test/nodejs/tile.js @@ -1,42 +1,41 @@ // Test tile service functionality for vector tile generation -import OSRM from '../../lib/index.js'; import test from 'tape'; -import { data_path, test_tile as tile } from './constants.js'; +import { OSRM, data_path, test_tile as tile } from './constants.js'; -test.test('tile check size coarse', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - osrm.tile(tile.at, function(err, result) { - assert.ifError(err); - assert.equal(result.length, tile.size); - }); +test.test('tile check size coarse', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + osrm.tile(tile.at, (err, result) => { + assert.ifError(err); + assert.equal(result.length, tile.size); + }); }); -test.test('tile interface pre-conditions', function(assert) { - assert.plan(6); - const osrm = new OSRM(data_path); +test.test('tile interface pre-conditions', (assert) => { + assert.plan(6); + const osrm = new OSRM(data_path); - assert.throws(function() { osrm.tile(null, function(err, result) {}) }, /must be an array \[x, y, z\]/); - assert.throws(function() { osrm.tile([], function(err, result) {}) }, /must be an array \[x, y, z\]/); - assert.throws(function() { osrm.tile([[]], function(err, result) {}) }, /must be an array \[x, y, z\]/); - assert.throws(function() { osrm.tile(undefined, function(err, result) {}) }, /must be an array \[x, y, z\]/); - assert.throws(function() { osrm.tile(17059, 11948, 15, function(err, result) {}) }, /must be an array \[x, y, z\]/); - assert.throws(function() { osrm.tile([17059, 11948, -15], function(err, result) {}) }, /must be unsigned/); + assert.throws(() => { osrm.tile(null, (err, result) => {}); }, /must be an array \[x, y, z\]/); + assert.throws(() => { osrm.tile([], (err, result) => {}); }, /must be an array \[x, y, z\]/); + assert.throws(() => { osrm.tile([[]], (err, result) => {}); }, /must be an array \[x, y, z\]/); + assert.throws(() => { osrm.tile(undefined, (err, result) => {}); }, /must be an array \[x, y, z\]/); + assert.throws(() => { osrm.tile(17059, 11948, 15, (err, result) => {}); }, /must be an array \[x, y, z\]/); + assert.throws(() => { osrm.tile([17059, 11948, -15], (err, result) => {}); }, /must be unsigned/); }); -test.test('tile fails to load with geometry disabled', function(assert) { - assert.plan(1); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - osrm.tile(tile.at, function(err, result) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); +test.test('tile fails to load with geometry disabled', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + osrm.tile(tile.at, (err, result) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); }); -test.test('tile ok with steps disabled', function(assert) { - assert.plan(2); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - osrm.tile(tile.at, function(err, result) { - assert.ifError(err); - assert.equal(result.length, tile.size); - }); +test.test('tile ok with steps disabled', (assert) => { + assert.plan(2); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + osrm.tile(tile.at, (err, result) => { + assert.ifError(err); + assert.equal(result.length, tile.size); + }); }); diff --git a/test/nodejs/trip.js b/test/nodejs/trip.js index 0363607bf0c..46c4aebf71f 100644 --- a/test/nodejs/trip.js +++ b/test/nodejs/trip.js @@ -1,431 +1,427 @@ // Test trip service functionality for solving traveling salesman problem -import OSRM from '../../lib/index.js'; -import test from 'tape'; -import { data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; import flatbuffers from 'flatbuffers'; -import { osrm } from '../../features/support/fbresult_generated.js'; - -const FBResult = osrm.engine.api.fbresult.FBResult; - -test('trip: trip in Monaco with flatbuffers format', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - osrm.trip({coordinates: two_test_coordinates, format: 'flatbuffers'}, function(err, trip) { - assert.ifError(err); - const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(trip)); - assert.equal(fb.routesLength(), 1); - }); +import test from 'tape'; +import { OSRM, FBResult, data_path, mld_data_path, three_test_coordinates, two_test_coordinates } from './constants.js'; + +test('trip: trip in Monaco with flatbuffers format', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + osrm.trip({coordinates: two_test_coordinates, format: 'flatbuffers'}, (err, trip) => { + assert.ifError(err); + const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(trip)); + assert.equal(fb.routesLength(), 1); + }); }); -test('trip: trip in Monaco', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - osrm.trip({coordinates: two_test_coordinates}, function(err, trip) { - assert.ifError(err); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(trip.trips[t].geometry); - } - }); +test('trip: trip in Monaco', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + osrm.trip({coordinates: two_test_coordinates}, (err, trip) => { + assert.ifError(err); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(trip.trips[t].geometry); + } + }); }); -test('trip: trip in Monaco as a buffer', function(assert) { - assert.plan(3); - const osrm = new OSRM(data_path); - osrm.trip({coordinates: two_test_coordinates}, { format: 'json_buffer' }, function(err, trip) { - assert.ifError(err); - assert.ok(trip instanceof Buffer); - trip = JSON.parse(trip); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(trip.trips[t].geometry); - } - }); +test('trip: trip in Monaco as a buffer', (assert) => { + assert.plan(3); + const osrm = new OSRM(data_path); + osrm.trip({coordinates: two_test_coordinates}, { format: 'json_buffer' }, (err, trip) => { + assert.ifError(err); + assert.ok(trip instanceof Buffer); + trip = JSON.parse(trip); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(trip.trips[t].geometry); + } + }); }); -test('trip: trip with many locations in Monaco', function(assert) { - assert.plan(2); +test('trip: trip with many locations in Monaco', (assert) => { + assert.plan(2); - const many = 5; + const many = 5; - const osrm = new OSRM(data_path); - const opts = {coordinates: three_test_coordinates.slice(0, many)}; - osrm.trip(opts, function(err, trip) { - assert.ifError(err); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(trip.trips[t].geometry); - } - }); + const osrm = new OSRM(data_path); + const opts = {coordinates: three_test_coordinates.slice(0, many)}; + osrm.trip(opts, (err, trip) => { + assert.ifError(err); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(trip.trips[t].geometry); + } + }); }); -test('trip: throws with too few or invalid args', function(assert) { - assert.plan(3); - const osrm = new OSRM(data_path); - assert.throws(function() { osrm.trip({coordinates: two_test_coordinates}) }, - /Two arguments required/); - assert.throws(function() { osrm.trip(null, function(err, trip) {}) }, - /First arg must be an object/); - assert.throws(function() { osrm.trip({coordinates: two_test_coordinates}, { format: 'invalid' }, function(err, trip) {}) }, - /format must be a string:/); +test('trip: throws with too few or invalid args', (assert) => { + assert.plan(3); + const osrm = new OSRM(data_path); + assert.throws(() => { osrm.trip({coordinates: two_test_coordinates}); }, + /Two arguments required/); + assert.throws(() => { osrm.trip(null, (err, trip) => {}); }, + /First arg must be an object/); + assert.throws(() => { osrm.trip({coordinates: two_test_coordinates}, { format: 'invalid' }, (err, trip) => {}); }, + /format must be a string:/); }); -test('trip: throws with bad params', function(assert) { - assert.plan(14); - const osrm = new OSRM(data_path); - assert.throws(function () { osrm.trip({coordinates: []}, function(err) {}) }); - assert.throws(function() { osrm.trip({}, function(err, trip) {}) }, - /Must provide a coordinates property/); - assert.throws(function() { osrm.trip({ - coordinates: null - }, function(err, trip) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - assert.throws(function() { osrm.trip({ - coordinates: three_test_coordinates[0] - }, function(err, trip) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - assert.throws(function() { osrm.trip({ - coordinates: [three_test_coordinates[0][0], three_test_coordinates[0][1]] - }, function(err, trip) {}) }, - /Coordinates must be an array of \(lon\/lat\) pairs/); - assert.throws(function() { osrm.trip({ - coordinates: two_test_coordinates, - hints: null - }, function(err, trip) {}) }, - /Hints must be an array of strings\/null/); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - hints: three_test_coordinates[0] - }; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /Hint must be null or string/); - options.hints = [null]; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /Hints array must have the same length as coordinates array/); - delete options.hints; - options.geometries = 'false'; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /'geometries' param must be one of \[polyline, polyline6, geojson\]/); - delete options.geometries; - options.source = false; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /Source must be a string: \[any, first\]/); - options.source = 'false'; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /'source' param must be one of \[any, first\]/); - delete options.source; - options.destination = true; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /Destination must be a string: \[any, last\]/); - options.destination = 'true'; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /'destination' param must be one of \[any, last\]/); - options.roundtrip = 'any'; - assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, - /'roundtrip' param must be a boolean/); +test('trip: throws with bad params', (assert) => { + assert.plan(14); + const osrm = new OSRM(data_path); + assert.throws(() => { osrm.trip({coordinates: []}, (err) => {}); }); + assert.throws(() => { osrm.trip({}, (err, trip) => {}); }, + /Must provide a coordinates property/); + assert.throws(() => { osrm.trip({ + coordinates: null + }, (err, trip) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + assert.throws(() => { osrm.trip({ + coordinates: three_test_coordinates[0] + }, (err, trip) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + assert.throws(() => { osrm.trip({ + coordinates: [three_test_coordinates[0][0], three_test_coordinates[0][1]] + }, (err, trip) => {}); }, + /Coordinates must be an array of \(lon\/lat\) pairs/); + assert.throws(() => { osrm.trip({ + coordinates: two_test_coordinates, + hints: null + }, (err, trip) => {}); }, + /Hints must be an array of strings\/null/); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + hints: three_test_coordinates[0] + }; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /Hint must be null or string/); + options.hints = [null]; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /Hints array must have the same length as coordinates array/); + delete options.hints; + options.geometries = 'false'; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /'geometries' param must be one of \[polyline, polyline6, geojson\]/); + delete options.geometries; + options.source = false; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /Source must be a string: \[any, first\]/); + options.source = 'false'; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /'source' param must be one of \[any, first\]/); + delete options.source; + options.destination = true; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /Destination must be a string: \[any, last\]/); + options.destination = 'true'; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /'destination' param must be one of \[any, last\]/); + options.roundtrip = 'any'; + assert.throws(() => { osrm.trip(options, (err, trip) => {}); }, + /'roundtrip' param must be a boolean/); }); -test('trip: routes Monaco using shared memory', function(assert) { - assert.plan(2); - const osrm = new OSRM(); - osrm.trip({coordinates: two_test_coordinates}, function(err, trip) { - assert.ifError(err); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(trip.trips[t].geometry); - } - }); +test('trip: routes Monaco using shared memory', (assert) => { + assert.plan(2); + const osrm = new OSRM(); + osrm.trip({coordinates: two_test_coordinates}, (err, trip) => { + assert.ifError(err); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(trip.trips[t].geometry); + } + }); }); -test('trip: routes Monaco with hints', function(assert) { - assert.plan(5); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - steps: false - }; - osrm.trip(options, function(err, first) { - assert.ifError(err); - for (let t = 0; t < first.trips.length; t++) { - assert.ok(first.trips[t].geometry); - } - const hints = first.waypoints.map(function(wp) { return wp.hint; }); - assert.ok(hints.every(function(h) { return typeof h === 'string'; })); - options.hints = hints; - - osrm.trip(options, function(err, second) { - assert.ifError(err); - assert.deepEqual(first, second); - }); +test('trip: routes Monaco with hints', (assert) => { + assert.plan(5); + const osrm = new OSRM(data_path); + const options = { + coordinates: two_test_coordinates, + steps: false + }; + osrm.trip(options, (err, first) => { + assert.ifError(err); + for (let t = 0; t < first.trips.length; t++) { + assert.ok(first.trips[t].geometry); + } + const hints = first.waypoints.map((wp) => { return wp.hint; }); + assert.ok(hints.every((h) => { return typeof h === 'string'; })); + options.hints = hints; + + osrm.trip(options, (err, second) => { + assert.ifError(err); + assert.deepEqual(first, second); }); + }); }); -test('trip: trip through Monaco with geometry compression', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]] - }; - osrm.trip(options, function(err, trip) { - assert.ifError(err); - for (let t = 0; t < trip.trips.length; t++) { - assert.equal('string', typeof trip.trips[t].geometry); - } - }); +test('trip: trip through Monaco with geometry compression', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]] + }; + osrm.trip(options, (err, trip) => { + assert.ifError(err); + for (let t = 0; t < trip.trips.length; t++) { + assert.equal('string', typeof trip.trips[t].geometry); + } + }); }); -test('trip: trip through Monaco without geometry compression', function(assert) { - assert.plan(2); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - geometries: 'geojson' - }; - osrm.trip(options, function(err, trip) { - assert.ifError(err); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(Array.isArray(trip.trips[t].geometry.coordinates)); - } - }); +test('trip: trip through Monaco without geometry compression', (assert) => { + assert.plan(2); + const osrm = new OSRM(data_path); + const options = { + coordinates: two_test_coordinates, + geometries: 'geojson' + }; + osrm.trip(options, (err, trip) => { + assert.ifError(err); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(Array.isArray(trip.trips[t].geometry.coordinates)); + } + }); }); -test('trip: trip through Monaco with speed annotations options', function(assert) { - assert.plan(12); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - steps: true, - annotations: ['speed'], - overview: 'false' - }; - osrm.trip(options, function(err, trip) { - assert.ifError(err); - assert.equal(trip.trips.length, 1); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(trip.trips[t]); - assert.ok(trip.trips[t].legs.every(function(l) { return l.steps.length > 0; }), 'every leg has steps') - assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation; }), 'every leg has annotations') - assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.speed; }), 'every leg has annotations for speed') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.weight; }), 'has no annotations for weight') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.datasources; }), 'has no annotations for datasources') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.duration; }), 'has no annotations for duration') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.distance; }), 'has no annotations for distance') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.nodes; }), 'has no annotations for nodes') - assert.notOk(trip.trips[t].geometry); - } - }); +test('trip: trip through Monaco with speed annotations options', (assert) => { + assert.plan(12); + const osrm = new OSRM(data_path); + const options = { + coordinates: two_test_coordinates, + steps: true, + annotations: ['speed'], + overview: 'false' + }; + osrm.trip(options, (err, trip) => { + assert.ifError(err); + assert.equal(trip.trips.length, 1); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(trip.trips[t]); + assert.ok(trip.trips[t].legs.every((l) => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(trip.trips[t].legs.every((l) => { return l.annotation; }), 'every leg has annotations'); + assert.ok(trip.trips[t].legs.every((l) => { return l.annotation.speed; }), 'every leg has annotations for speed'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.weight; }), 'has no annotations for weight'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.datasources; }), 'has no annotations for datasources'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.duration; }), 'has no annotations for duration'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.distance; }), 'has no annotations for distance'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.nodes; }), 'has no annotations for nodes'); + assert.notOk(trip.trips[t].geometry); + } + }); }); -test('trip: trip through Monaco with several (duration, distance, nodes) annotations options', function(assert) { - assert.plan(12); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - steps: true, - annotations: ['duration', 'distance', 'nodes'], - overview: 'false' - }; - osrm.trip(options, function(err, trip) { - assert.ifError(err); - assert.equal(trip.trips.length, 1); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(trip.trips[t]); - assert.ok(trip.trips[t].legs.every(function(l) { return l.steps.length > 0; }), 'every leg has steps') - assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation; }), 'every leg has annotations') - assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.duration; }), 'every leg has annotations for duration') - assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.distance; }), 'every leg has annotations for distance') - assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.nodes; }), 'every leg has annotations for nodes') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.weight; }), 'has no annotations for weight') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.datasources; }), 'has no annotations for datasources') - assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.speed; }), 'has no annotations for speed') - assert.notOk(trip.trips[t].geometry); - } - }); +test('trip: trip through Monaco with several (duration, distance, nodes) annotations options', (assert) => { + assert.plan(12); + const osrm = new OSRM(data_path); + const options = { + coordinates: two_test_coordinates, + steps: true, + annotations: ['duration', 'distance', 'nodes'], + overview: 'false' + }; + osrm.trip(options, (err, trip) => { + assert.ifError(err); + assert.equal(trip.trips.length, 1); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(trip.trips[t]); + assert.ok(trip.trips[t].legs.every((l) => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(trip.trips[t].legs.every((l) => { return l.annotation; }), 'every leg has annotations'); + assert.ok(trip.trips[t].legs.every((l) => { return l.annotation.duration; }), 'every leg has annotations for duration'); + assert.ok(trip.trips[t].legs.every((l) => { return l.annotation.distance; }), 'every leg has annotations for distance'); + assert.ok(trip.trips[t].legs.every((l) => { return l.annotation.nodes; }), 'every leg has annotations for nodes'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.weight; }), 'has no annotations for weight'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.datasources; }), 'has no annotations for datasources'); + assert.notOk(trip.trips[t].legs.every((l) => { return l.annotation.speed; }), 'has no annotations for speed'); + assert.notOk(trip.trips[t].geometry); + } + }); }); -test('trip: trip through Monaco with options', function(assert) { - assert.plan(6); - const osrm = new OSRM(data_path); - const options = { - coordinates: two_test_coordinates, - steps: true, - annotations: true, - overview: 'false' - }; - osrm.trip(options, function(err, trip) { - assert.ifError(err); - assert.equal(trip.trips.length, 1); - for (let t = 0; t < trip.trips.length; t++) { - assert.ok(trip.trips[t]); - assert.ok(trip.trips[t].legs.every(function(l) { return l.steps.length > 0; }), 'every leg has steps') - assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation; }), 'every leg has annotations') - assert.notOk(trip.trips[t].geometry); - } - }); +test('trip: trip through Monaco with options', (assert) => { + assert.plan(6); + const osrm = new OSRM(data_path); + const options = { + coordinates: two_test_coordinates, + steps: true, + annotations: true, + overview: 'false' + }; + osrm.trip(options, (err, trip) => { + assert.ifError(err); + assert.equal(trip.trips.length, 1); + for (let t = 0; t < trip.trips.length; t++) { + assert.ok(trip.trips[t]); + assert.ok(trip.trips[t].legs.every((l) => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(trip.trips[t].legs.every((l) => { return l.annotation; }), 'every leg has annotations'); + assert.notOk(trip.trips[t].geometry); + } + }); }); -test('trip: routes Monaco with null hints', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - const options = { - coordinates: [three_test_coordinates[0], three_test_coordinates[1]], - hints: [null, null] - }; - osrm.trip(options, function(err, second) { - assert.ifError(err); - }); +test('trip: routes Monaco with null hints', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + const options = { + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + hints: [null, null] + }; + osrm.trip(options, (err, second) => { + assert.ifError(err); + }); }); -test('trip: service combinations that are not implemented', function(assert) { - assert.plan(1); - const osrm = new OSRM(data_path); - - // no fixed start, no fixed end, non-roundtrip - const options = { - coordinates: two_test_coordinates, - source: 'any', - destination: 'any', - roundtrip: false - }; - osrm.trip(options, function(err, second) { - assert.equal('NotImplemented', err.message); - }); +test('trip: service combinations that are not implemented', (assert) => { + assert.plan(1); + const osrm = new OSRM(data_path); + + // no fixed start, no fixed end, non-roundtrip + const options = { + coordinates: two_test_coordinates, + source: 'any', + destination: 'any', + roundtrip: false + }; + osrm.trip(options, (err, second) => { + assert.equal('NotImplemented', err.message); + }); }); -test('trip: fixed start and end combinations', function(assert) { - assert.plan(21); - const osrm = new OSRM(data_path); - - const options = { - coordinates: two_test_coordinates, - source: 'first', - destination: 'last', - roundtrip: false, - geometries: 'geojson' - }; - - // variations of non roundtrip - const nonRoundtripChecks = function(options) { - osrm.trip(options, function(err, fseTrip) { - assert.ifError(err); - assert.equal(1, fseTrip.trips.length); - const coordinates = fseTrip.trips[0].geometry.coordinates; - assert.notEqual(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1])); - }); - }; - - // variations of roundtrip - const roundtripChecks = function(options) { - osrm.trip(options, function(err, trip) { - assert.ifError(err); - assert.equal(1, trip.trips.length); - const coordinates = trip.trips[0].geometry.coordinates; - assert.equal(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1])); - }); - }; - - // fixed start and end, non-roundtrip - nonRoundtripChecks(options); - - // fixed start, non-roundtrip - delete options.destination; - options.source = 'first'; - nonRoundtripChecks(options); - - // fixed end, non-roundtrip - delete options.source; - options.destination = 'last'; - nonRoundtripChecks(options); - - // roundtrip, source and destination not specified - roundtripChecks({coordinates: options.coordinates, geometries: options.geometries}); - - // roundtrip, fixed destination - options.roundtrip = true; - delete options.source; - options.destination = 'last'; - roundtripChecks(options); - - //roundtrip, fixed source - delete options.destination; - options.source = 'first'; - roundtripChecks(options); - - // roundtrip, non-fixed source, non-fixed destination - options.source = 'any'; - options.destination = 'any'; - roundtripChecks(options); +test('trip: fixed start and end combinations', (assert) => { + assert.plan(21); + const osrm = new OSRM(data_path); + + const options = { + coordinates: two_test_coordinates, + source: 'first', + destination: 'last', + roundtrip: false, + geometries: 'geojson' + }; + + // variations of non roundtrip + const nonRoundtripChecks = function(options) { + osrm.trip(options, (err, fseTrip) => { + assert.ifError(err); + assert.equal(1, fseTrip.trips.length); + const coordinates = fseTrip.trips[0].geometry.coordinates; + assert.notEqual(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1])); + }); + }; + + // variations of roundtrip + const roundtripChecks = function(options) { + osrm.trip(options, (err, trip) => { + assert.ifError(err); + assert.equal(1, trip.trips.length); + const coordinates = trip.trips[0].geometry.coordinates; + assert.equal(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1])); + }); + }; + + // fixed start and end, non-roundtrip + nonRoundtripChecks(options); + + // fixed start, non-roundtrip + delete options.destination; + options.source = 'first'; + nonRoundtripChecks(options); + + // fixed end, non-roundtrip + delete options.source; + options.destination = 'last'; + nonRoundtripChecks(options); + + // roundtrip, source and destination not specified + roundtripChecks({coordinates: options.coordinates, geometries: options.geometries}); + + // roundtrip, fixed destination + options.roundtrip = true; + delete options.source; + options.destination = 'last'; + roundtripChecks(options); + + //roundtrip, fixed source + delete options.destination; + options.source = 'first'; + roundtripChecks(options); + + // roundtrip, non-fixed source, non-fixed destination + options.source = 'any'; + options.destination = 'any'; + roundtripChecks(options); }); -test('trip: trip in Monaco without motorways', function(assert) { - assert.plan(3); - const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - const options = { - coordinates: two_test_coordinates, - exclude: ['motorway'] - }; - osrm.trip(options, function(err, response) { - assert.ifError(err); - assert.equal(response.waypoints.length, 2); - assert.equal(response.trips.length, 1); - }); +test('trip: trip in Monaco without motorways', (assert) => { + assert.plan(3); + const osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + const options = { + coordinates: two_test_coordinates, + exclude: ['motorway'] + }; + osrm.trip(options, (err, response) => { + assert.ifError(err); + assert.equal(response.waypoints.length, 2); + assert.equal(response.trips.length, 1); + }); }); -test('trip: throws on disabled geometry', function (assert) { - assert.plan(1); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.trip(options, function(err, route) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); +test('trip: throws on disabled geometry', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.trip(options, (err, route) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); }); -test('trip: ok on disabled geometry', function (assert) { - assert.plan(2); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); - const options = { - steps: false, - overview: 'false', - annotations: false, - skip_waypoints: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.trip(options, function(err, response) { - assert.ifError(err); - assert.equal(response.trips.length, 1); - }); +test('trip: ok on disabled geometry', (assert) => { + assert.plan(2); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']}); + const options = { + steps: false, + overview: 'false', + annotations: false, + skip_waypoints: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.trip(options, (err, response) => { + assert.ifError(err); + assert.equal(response.trips.length, 1); + }); }); -test('trip: throws on disabled steps', function (assert) { - assert.plan(1); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - steps: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.trip(options, function(err, route) { - console.log(err) - assert.match(err.message, /DisabledDatasetException/); - }); +test('trip: throws on disabled steps', (assert) => { + assert.plan(1); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + steps: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.trip(options, (err, route) => { + console.log(err); + assert.match(err.message, /DisabledDatasetException/); + }); }); -test('trip: ok on disabled steps', function (assert) { - assert.plan(8); - const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); - const options = { - steps: false, - overview: 'simplified', - annotations: true, - coordinates: three_test_coordinates.concat(three_test_coordinates), - }; - osrm.trip(options, function(err, response) { - assert.ifError(err); - assert.ok(response.waypoints); - assert.ok(response.trips); - assert.equal(response.trips.length, 1); - assert.ok(response.trips[0].geometry, "trip has geometry"); - assert.ok(response.trips[0].legs, "trip has legs"); - assert.notok(response.trips[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); - assert.ok(response.trips[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); - }); +test('trip: ok on disabled steps', (assert) => { + assert.plan(8); + const osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']}); + const options = { + steps: false, + overview: 'simplified', + annotations: true, + coordinates: three_test_coordinates.concat(three_test_coordinates), + }; + osrm.trip(options, (err, response) => { + assert.ifError(err); + assert.ok(response.waypoints); + assert.ok(response.trips); + assert.equal(response.trips.length, 1); + assert.ok(response.trips[0].geometry, 'trip has geometry'); + assert.ok(response.trips[0].legs, 'trip has legs'); + assert.notok(response.trips[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps'); + assert.ok(response.trips[0].legs.every(l => { return l.annotation;}), 'every leg has annotations'); + }); }); From 05bed214af06e0676c09d22f94b3171afa377e94 Mon Sep 17 00:00:00 2001 From: Marcello Perathoner Date: Thu, 5 Mar 2026 09:57:57 +0100 Subject: [PATCH 2/2] Bump node-tar AGAIN! now 7.4.0 --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 81d5a2adf72..559dd61a353 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13108,9 +13108,9 @@ } }, "node_modules/tar": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.9.tgz", - "integrity": "sha512-BTLcK0xsDh2+PUe9F6c2TlRp4zOOBMTkoQHQIWSIzI0R7KG46uEwq4OPk2W7bZcprBMsuaeFsqwYr7pjh6CuHg==", + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.10.tgz", + "integrity": "sha512-8mOPs1//5q/rlkNSPcCegA6hiHJYDmSLEI8aMH/CdSQJNWztHC9WHNam5zdQlfpTwB9Xp7IBEsHfV5LKMJGVAw==", "license": "BlueOak-1.0.0", "dependencies": { "@isaacs/fs-minipass": "^4.0.0",