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
32 changes: 16 additions & 16 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"undici": "^6.19.0",
"winston": "^3.0.0",
"winston-transport": "^4.4.0",
"ws": "^7.5.10",
"ws": "^8.21.1",
"yaml": "^2.8.3",
"zod": "^4.0.0"
},
Expand Down Expand Up @@ -225,7 +225,7 @@
"@types/triple-beam": "^1.3.0",
"@types/universal-analytics": "^0.4.5",
"@types/update-notifier": "^5.1.0",
"@types/ws": "^7.2.3",
"@types/ws": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"astro": "^2.2.3",
Expand Down
53 changes: 53 additions & 0 deletions src/emulator/loggingEmulator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { expect } from "chai";
import { LogEntry } from "winston";
import * as WebSocket from "ws";
import { LoggingEmulator } from "./loggingEmulator";
import { logger } from "../logger";

describe("LoggingEmulator", () => {
let emulator: LoggingEmulator;
let client: WebSocket | undefined;
const port = 4501;

afterEach(async () => {
if (client) {
client.close();
client = undefined;
}
if (emulator) {
await emulator.stop();
}
});
Comment thread
joehan marked this conversation as resolved.

it("should start and broadcast log messages", async () => {
emulator = new LoggingEmulator({ port, host: "127.0.0.1" });
await emulator.start();

client = new WebSocket(`ws://127.0.0.1:${port}`);

const messagePromise = new Promise<LogEntry>((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error("Timeout waiting for message"));
}, 5000);

client!.on("message", (data) => {

Check warning on line 33 in src/emulator/loggingEmulator.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Forbidden non-null assertion
clearTimeout(timeout);
try {
resolve(JSON.parse(data.toString()) as LogEntry);
} catch (e) {
reject(e);
}
});
});

await new Promise<void>((resolve, reject) => {
client!.on("open", () => resolve());

Check warning on line 44 in src/emulator/loggingEmulator.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Forbidden non-null assertion
client!.on("error", (err) => reject(err));

Check warning on line 45 in src/emulator/loggingEmulator.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Forbidden non-null assertion
});

logger.info("Hello world from unit test!");

const receivedMessage = await messagePromise;
expect(receivedMessage.message).to.contain("Hello world from unit test!");
});
});
Loading