Files
vibemake/tests/urdf-paths.test.js
T

58 lines
1.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { meshUrlCandidates, resolveUrdfResourcePath } from '../js/urdf-paths.js';
test('maps package references with a stale source directory prefix to uploaded paths', () => {
assert.equal(
resolveUrdfResourcePath(
'package://example-robot-data/robots/asr_twodof_description/meshes/arm.stl',
'robot.urdf',
['meshes/arm.stl'],
),
'meshes/arm.stl',
);
});
test('rewrites a package reference relative to a nested URDF file', () => {
assert.equal(
resolveUrdfResourcePath('package://robot/meshes/body.stl', 'urdf/robot.urdf', ['meshes/body.stl']),
'../meshes/body.stl',
);
});
test('uses uploaded paths to resolve ordinary relative references', () => {
assert.equal(
resolveUrdfResourcePath('../meshes/body.stl', 'urdf/robot.urdf', ['meshes/body.stl']),
'../meshes/body.stl',
);
});
test('leaves ambiguous filename-only matches unchanged', () => {
assert.equal(
resolveUrdfResourcePath('package://robot/legacy/body.stl', 'robot.urdf', ['left/body.stl', 'right/body.stl']),
null,
);
});
test('tries the resource-root URL first for stale robot source directory prefixes', () => {
assert.deepEqual(
meshUrlCandidates(
'https://oss.example/batch',
'https://oss.example/batch/robots/asr_twodof_description/meshes/arm.stl',
),
[
'https://oss.example/batch/meshes/arm.stl',
'https://oss.example/batch/robots/asr_twodof_description/meshes/arm.stl',
'https://oss.example/batch/asr_twodof_description/meshes/arm.stl',
'https://oss.example/batch/arm.stl',
],
);
});
test('keeps normal package mesh URLs first', () => {
assert.deepEqual(
meshUrlCandidates('https://oss.example/batch', 'https://oss.example/batch/meshes/body.stl'),
['https://oss.example/batch/meshes/body.stl', 'https://oss.example/batch/body.stl'],
);
});