/* eslint-disable @typescript-eslint/no-misused-promises */ /* eslint-disable jest/no-done-callback */ import http from "http"; import type { AddressInfo } from "net"; import { RosMasterClient } from "./RosMasterClient"; describe("RosMasterClient", () => { it("getPublishedTopics", (done) => { const server = http .createServer((_, res) => { res.writeHead(200, { "Content-Type": "text/xml" }); const data = ` 1 current topics /rosout rosgraph_msgs/Log /turtle1/pose turtlesim/Pose /turtle1/color_sensor turtlesim/Color /rosout_agg rosgraph_msgs/Log `; res.write(data); res.end(); }) .listen(undefined, "localhost", async () => { const port = (server.address() as AddressInfo).port; const client = new RosMasterClient(`http://localhost:${port}/`); const [status, msg, topics] = await client.getPublishedTopics("/test"); expect(status).toEqual(1); expect(msg).toEqual("current topics"); expect(topics).toEqual([ ["/rosout", "rosgraph_msgs/Log"], ["/turtle1/pose", "turtlesim/Pose"], ["/turtle1/color_sensor", "turtlesim/Color"], ["/rosout_agg", "rosgraph_msgs/Log"], ]); server.close(); done(); }); }); });