Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aneuwald-ctw committed Aug 28, 2024
1 parent 23c72c6 commit ff9ae94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
4 changes: 1 addition & 3 deletions desktop/integration-test/open-extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { launchApp } from "./launchApp";

describe("websocket connection", () => {
it("should import .foxe extension correctly", async () => {
const app = await launchApp();
await using app = await launchApp();

await app.renderer.getByTestId("DataSourceDialog").getByTestId("CloseIcon").click();

Expand All @@ -25,7 +25,5 @@ describe("websocket connection", () => {
await app.renderer.getByText("Turtle [local]").click();

await expect(app.renderer.getByText("Turtle", { exact: true }).count()).resolves.toBe(1);

await app.main.close();
});
});
40 changes: 21 additions & 19 deletions desktop/integration-test/websocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ import { launchApp } from "./launchApp";
describe("websocket connection", () => {
let sysmonProcess: ChildProcess;

afterAll(async () => {
await new Promise<void>((resolve) => {
// Close all channels to ensure that there is no async leak
// Start the sysmon process using npx
function startWebSocketServer() {
sysmonProcess = spawn("npx", ["@foxglove/ws-protocol-examples@latest", "sysmon"]);
}

async function closeWebSocketServer() {
return await new Promise((resolve) => {

Check failure on line 18 in desktop/integration-test/websocket.test.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-20.04)

Delete `⏎`
// Close all channels to ensure that there is not any async leak
sysmonProcess.stdin?.end();
sysmonProcess.stdout?.destroy();
sysmonProcess.stderr?.destroy();

// Kill the process
sysmonProcess.kill();
sysmonProcess.kill('SIGINT');

Check failure on line 25 in desktop/integration-test/websocket.test.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-20.04)

Replace `'SIGINT'` with `"SIGINT"`

// Ensure Jest waits for the process to be fully closed
sysmonProcess.on("close", () => {
resolve();
});
resolve(1)

Check failure on line 27 in desktop/integration-test/websocket.test.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-20.04)

Insert `;`
});
});
}

it("should show correct attributes using sysmon ws and raw messages panel", async () => {
// Start the sysmon process using npx
sysmonProcess = spawn("npx", ["@foxglove/ws-protocol-examples@latest", "sysmon"]);
startWebSocketServer();

const app = await launchApp();
await using app = await launchApp();

await app.renderer.getByText("Open connection").click();
await app.renderer.getByText("Open", { exact: true }).click();
Expand All @@ -49,12 +51,12 @@ describe("websocket connection", () => {

// Select the topic
await app.renderer.getByPlaceholder("/some/topic.msgs[0].field").nth(0).click();
await app.renderer.getByTestId("autocomplete-item").getByText("system_stats").click();
await app.renderer.getByTestId("autocomplete-item").click();

const rawMessagesPanel = app.renderer.getByTestId(/RawMessages/);

// Check if message is correctly beeing displayed
const labelsToCheck = [
const attributesToCheck = [
"hostname",
"platform",
"type",
Expand All @@ -68,12 +70,12 @@ describe("websocket connection", () => {
"cpus",
];

for (const label of labelsToCheck) {
await expect(rawMessagesPanel.getByText(label, { exact: true }).innerText()).resolves.toBe(
label,
);
for (const attribute of attributesToCheck) {
await expect(
rawMessagesPanel.getByText(attribute, { exact: true }).innerText(),
).resolves.toBe(attribute);
}

await app.main.close();
await closeWebSocketServer();
});
});

0 comments on commit ff9ae94

Please sign in to comment.