Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/SocketAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("SocketAdapter fragment handling", () => {
client.isConnected = false;
client.emit("close", event);
},
onError: (event: ErrorEvent) => {
onError: (event: ErrorEvent | RTCErrorEvent) => {
client.emit("error", String(event.error));
},
onMessage: (message: RosbridgeMessage) => {
Expand Down
2 changes: 1 addition & 1 deletion test/examples/fibonacci.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ROSLIB from "../../src/RosLib.js";

// Noetic is the only version of ROS 1 we support, so we skip based on distro name
// instead of adding extra plumbing for ROS_VERSION.
describe.skipIf(process.env.ROS_DISTRO !== "noetic")(
describe.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
"ROS 1 Fibonacci Example",
function () {
it(
Expand Down
48 changes: 27 additions & 21 deletions test/examples/params.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it, expect, vi } from "vitest";
import * as ROSLIB from "../../src/RosLib.js";

const PARAM_NAME =
process.env.ROS_DISTRO === "noetic"
process.env["ROS_DISTRO"] === "noetic"
? "/test/foo"
: // Is it crazy to muck around with use_sim_time here? I feel like it shouldn't matter..
"/add_two_ints_server:use_sim_time";
Expand Down Expand Up @@ -50,26 +50,32 @@ describe("Param setting", function () {

// Known issue with getting params being able to hang in Humble because it had no timeout.
// This doesn't even work with `ros2 param list` at the CLI in our test environment :(
it.skipIf(process.env.ROS_DISTRO === "humble")("ros.getParams", async () => {
const callback = vi.fn();
ros.getParams(callback);
await vi.waitFor(() => {
expect(callback).toHaveBeenCalledOnce();
expect(callback.mock.calls[0][0]).to.include(PARAM_NAME);
});
});
it.skipIf(process.env["ROS_DISTRO"] === "humble")(
"ros.getParams",
async () => {
const callback = vi.fn();
ros.getParams(callback);
await vi.waitFor(() => {
expect(callback).toHaveBeenCalledOnce();
expect(callback.mock.calls[0][0]).to.include(PARAM_NAME);
});
},
);

// In ROS 2 we can't forcibly un-declare someone else's parameter
it.skipIf(process.env.ROS_DISTRO !== "noetic")("Param.delete", async () => {
const callback = vi.fn();
param.delete(callback);
await vi.waitFor(() => {
expect(callback).toHaveBeenCalled();
});
const getParamsCallback = vi.fn();
ros.getParams(getParamsCallback);
await vi.waitFor(() =>
expect(getParamsCallback.mock.calls[0][0]).to.not.include(PARAM_NAME),
);
});
it.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
"Param.delete",
async () => {
const callback = vi.fn();
param.delete(callback);
await vi.waitFor(() => {
expect(callback).toHaveBeenCalled();
});
const getParamsCallback = vi.fn();
ros.getParams(getParamsCallback);
await vi.waitFor(() =>
expect(getParamsCallback.mock.calls[0][0]).to.not.include(PARAM_NAME),
);
},
);
});
2 changes: 1 addition & 1 deletion test/examples/tf.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ROSLIB from "../../src/RosLib.js";

// Noetic is the only version of ROS 1 we support, so we skip based on distro name
// instead of adding extra plumbing for ROS_VERSION.
describe.skipIf(process.env.ROS_DISTRO !== "noetic")(
describe.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
"ROS 1 TF2 Republisher Example",
function () {
it("tf republisher", () =>
Expand Down
2 changes: 1 addition & 1 deletion test/examples/tf_service.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ROSLIB from "../../src/RosLib.js";

// Noetic is the only version of ROS 1 we support, so we skip based on distro name
// instead of adding extra plumbing for ROS_VERSION.
describe.skipIf(process.env.ROS_DISTRO !== "noetic")(
describe.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
"ROS 1 TF2 Republisher Service Example",
function () {
it("tf republisher", () =>
Expand Down
2 changes: 1 addition & 1 deletion test/setup/ros-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const docker = new Docker();
*/
function getRosDistro() {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- this might be an empty string, not undefined.
return process.env.ROS_DISTRO || "noetic";
return process.env["ROS_DISTRO"] || "noetic";
}

async function waitForRosConnection(ros: Ros, timeout = 5000) {
Expand Down
72 changes: 44 additions & 28 deletions test/urdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,54 +88,70 @@ describe("URDF", function () {
});

// Check all the visual elements
expect(urdfModel.links.link1.visuals.length).to.equal(1);
if (!(urdfModel.links.link1.visuals[0]?.geometry instanceof UrdfSphere)) {
expect(urdfModel.links["link1"].visuals.length).to.equal(1);
if (
!(urdfModel.links["link1"].visuals[0]?.geometry instanceof UrdfSphere)
) {
throw new Error("Expected geometry to be an instance of UrdfSphere");
}
expect(urdfModel.links.link1.visuals[0]?.geometry?.radius).to.equal(1.0);
if (!(urdfModel.links.link2.visuals[0]?.geometry instanceof UrdfBox)) {
expect(urdfModel.links["link1"].visuals[0]?.geometry?.radius).to.equal(
1.0,
);
if (!(urdfModel.links["link2"].visuals[0]?.geometry instanceof UrdfBox)) {
throw new Error("Expected geometry to be an instance of UrdfBox");
}
expect(urdfModel.links.link2.visuals[0]?.geometry?.dimension?.x).to.equal(
0.5,
);
expect(urdfModel.links.link2.visuals[0]?.geometry?.dimension?.y).to.equal(
0.5,
);
expect(urdfModel.links.link2.visuals[0]?.geometry?.dimension?.z).to.equal(
0.5,
);
expect(
urdfModel.links["link2"].visuals[0]?.geometry?.dimension?.x,
).to.equal(0.5);
expect(
urdfModel.links["link2"].visuals[0]?.geometry?.dimension?.y,
).to.equal(0.5);
expect(
urdfModel.links["link2"].visuals[0]?.geometry?.dimension?.z,
).to.equal(0.5);
if (
!(urdfModel.links.link3.visuals[0]?.geometry instanceof UrdfCylinder)
!(urdfModel.links["link3"].visuals[0]?.geometry instanceof UrdfCylinder)
) {
throw new Error("Expected geometry to be an instance of UrdfCylinder");
}
expect(urdfModel.links.link3.visuals[0]?.geometry?.length).to.equal(2.0);
expect(urdfModel.links.link3.visuals[0]?.geometry?.radius).to.equal(0.2);
expect(urdfModel.links["link3"].visuals[0]?.geometry?.length).to.equal(
2.0,
);
expect(urdfModel.links["link3"].visuals[0]?.geometry?.radius).to.equal(
0.2,
);

expect(urdfModel.links.link4.visuals.length).to.equal(1);
expect(urdfModel.links.link4.visuals[0]?.material?.name).to.equal("red");
expect(urdfModel.links.link4.visuals[0]?.material?.color?.r).to.equal(
expect(urdfModel.links["link4"].visuals.length).to.equal(1);
expect(urdfModel.links["link4"].visuals[0]?.material?.name).to.equal(
"red",
);
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.r).to.equal(
1.0,
);
expect(urdfModel.links.link4.visuals[0]?.material?.color?.g).to.equal(0);
expect(urdfModel.links.link4.visuals[0]?.material?.color?.b).to.equal(0);
expect(urdfModel.links.link4.visuals[0]?.material?.color?.a).to.equal(
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.g).to.equal(
0,
);
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.b).to.equal(
0,
);
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.a).to.equal(
1.0,
);

expect(urdfModel.links.link5.visuals.length).to.equal(2);
expect(urdfModel.links.link5.visuals[0]?.material?.name).to.equal("blue");
expect(urdfModel.links.link5.visuals[0]?.material?.color?.r).to.equal(
expect(urdfModel.links["link5"].visuals.length).to.equal(2);
expect(urdfModel.links["link5"].visuals[0]?.material?.name).to.equal(
"blue",
);
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.r).to.equal(
0.0,
);
expect(urdfModel.links.link5.visuals[0]?.material?.color?.g).to.equal(
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.g).to.equal(
0.0,
);
expect(urdfModel.links.link5.visuals[0]?.material?.color?.b).to.equal(
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.b).to.equal(
1.0,
);
expect(urdfModel.links.link5.visuals[0]?.material?.color?.a).to.equal(
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.a).to.equal(
1.0,
);
});
Expand Down
56 changes: 0 additions & 56 deletions tsconfig.build.json

This file was deleted.

66 changes: 57 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"noEmit": true
"noEmit": true,
/* Lib Options */
"target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es2022",
"DOM",
"DOM.Iterable"
] /* Specify library files to be included in the compilation. */,
"module": "esnext" /* Specify what module code is generated. */,
"moduleResolution": "bundler",

/* JavaScript Support */
"allowJs": false /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
"checkJs": false /* Enable error reporting in type-checked JavaScript files. */,

/* Build Options */
"rootDir": "." /* Specify the root folder within your source files. */,
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
"incremental": true /* Enable incremental compilation */,
"tsBuildInfoFile": "./node_modules/.cache/typescript/tsbuildinfo" /* Specify the folder for .tsbuildinfo incremental compilation files. */,
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"allowImportingTsExtensions": true,

/* Module Options */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,

/* Strict Type-Checking Options */
/* Gradually enable more of these until we can enable strict mode. */
"strict": false /* Enable all strict type-checking options. */,
/* Rules enabled so far */
"allowUnreachableCode": false /* Disable error reporting for unreachable code. */,
"allowUnusedLabels": false /* Disable error reporting for unused labels. */,
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements */,
"strictNullChecks": true /* When type checking, take into account `null` and `undefined`. */,
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noImplicitThis": true /* Enable error reporting when `this` is given the type `any`. */,
"noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type */,
"noUnusedLocals": true /* Enable error reporting when a local variable isn't read. */,
"noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
"strictBindCallApply": true /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */,
"strictBuiltinIteratorReturn": true /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */,
"useUnknownInCatchVariables": true /* Default catch clause variables as `unknown` instead of `any`. */,
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
"strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,

/* Rules to be enabled */
"exactOptionalPropertyTypes": false /* Differentiate between undefined and not present when type checking */,
"noImplicitAny": false /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
"noUncheckedIndexedAccess": false /* Add `undefined` to a type when accessed using an index. */,

"types": ["@types/node"]
},
"include": [
"vite.config.ts",
"./src",
"./test",
"eslint.config.ts",
"examples"
]
"exclude": ["docs"]
}
6 changes: 4 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import checker from "vite-plugin-checker";
export default defineConfig({
plugins: [
dts({
tsconfigPath: "tsconfig.build.json",
tsconfigPath: "tsconfig.json",
insertTypesEntry: true,
// Only generate types for our actual source code, obv
include: ["src"],
}),
checker({
typescript: {
tsconfigPath: "./tsconfig.build.json",
tsconfigPath: "./tsconfig.json",
},
eslint: {
lintCommand: "eslint .",
Expand Down