Skip to content

Commit b31eaca

Browse files
authored
NATS add codec, scratch compatibility (#1011)
1 parent b33050b commit b31eaca

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/modules/nats/src/nats-container.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,41 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
1919
});
2020
// }
2121

22+
it("should start, connect and close using scratch image", async () => {
23+
const container = await new NatsContainer("nats:2.11").start();
24+
25+
// establish connection
26+
const nc = await connect(container.getConnectionOptions());
27+
// close the connection
28+
await nc.close();
29+
// check if the close was OK
30+
const err = await nc.closed();
31+
expect(err).toBe(undefined);
32+
33+
await container.stop();
34+
});
35+
2236
// pubsub {
2337
it("should subscribe and receive one published message", async () => {
2438
const SUBJECT = "HELLO";
2539
const PAYLOAD = "WORLD";
2640

2741
const container = await new NatsContainer().start();
2842
const nc = await connect(container.getConnectionOptions());
43+
const TE = new TextEncoder();
44+
const TD = new TextDecoder();
2945

3046
//----------------
3147
const sub = nc.subscribe(SUBJECT);
3248
(async () => {
3349
for await (const m of sub) {
34-
const actual: string = m.string();
50+
const actual = TD.decode(m.data);
3551
expect(actual).toEqual(PAYLOAD);
3652
}
3753
})().then();
3854

3955
//----------------
40-
nc.publish(SUBJECT, PAYLOAD);
56+
nc.publish(SUBJECT, TE.encode(PAYLOAD));
4157

4258
//----------------
4359
await nc.drain();

packages/modules/nats/src/nats-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class NatsContainer extends GenericContainer {
8181
}
8282

8383
private getNormalizedCommand(): string[] {
84-
const result: string[] = ["nats-server"];
84+
const result: string[] = [];
8585
for (const arg of this.args) {
8686
result.push(arg);
8787
if (this.values.has(arg)) {

0 commit comments

Comments
 (0)