diff --git a/test/SocketAdapter.test.ts b/test/SocketAdapter.test.ts index 4aab9dac0..84f9166f2 100644 --- a/test/SocketAdapter.test.ts +++ b/test/SocketAdapter.test.ts @@ -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) => { diff --git a/test/examples/fibonacci.example.ts b/test/examples/fibonacci.example.ts index e9322cd07..c07514d5e 100644 --- a/test/examples/fibonacci.example.ts +++ b/test/examples/fibonacci.example.ts @@ -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( diff --git a/test/examples/params.example.ts b/test/examples/params.example.ts index 63fecaa18..e3c656551 100644 --- a/test/examples/params.example.ts +++ b/test/examples/params.example.ts @@ -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"; @@ -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), + ); + }, + ); }); diff --git a/test/examples/tf.example.ts b/test/examples/tf.example.ts index d94deb34a..17c26b16f 100644 --- a/test/examples/tf.example.ts +++ b/test/examples/tf.example.ts @@ -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", () => diff --git a/test/examples/tf_service.example.ts b/test/examples/tf_service.example.ts index 542808411..e74805c0b 100644 --- a/test/examples/tf_service.example.ts +++ b/test/examples/tf_service.example.ts @@ -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", () => diff --git a/test/setup/ros-backend.ts b/test/setup/ros-backend.ts index 3224c13a4..53d12c1c4 100644 --- a/test/setup/ros-backend.ts +++ b/test/setup/ros-backend.ts @@ -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) { diff --git a/test/urdf.test.ts b/test/urdf.test.ts index d99e7966b..001ca8441 100644 --- a/test/urdf.test.ts +++ b/test/urdf.test.ts @@ -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, ); }); diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100644 index 49c3f2443..000000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "compilerOptions": { - /* 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": ["./src"], -} diff --git a/tsconfig.json b/tsconfig.json index 851c3f1f0..19212b3fe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] } diff --git a/vite.config.ts b/vite.config.ts index 1991a51a6..a7f9b9777 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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 .",