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
89 changes: 63 additions & 26 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions packages/modules/nats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
"build": "tsc --project tsconfig.build.json"
},
"devDependencies": {
"nats": "^2.28.0"
},
"dependencies": {
"testcontainers": "^10.27.0"
},
"devDependencies": {
"@nats-io/jetstream": "^3.0.2",
"@nats-io/transport-node": "^3.0.2"
}
}
12 changes: 6 additions & 6 deletions packages/modules/nats/src/nats-container.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { connect, StringCodec } from "nats";
import { jetstreamManager } from "@nats-io/jetstream";
import { connect } from "@nats-io/transport-node";
import { NatsContainer } from "./nats-container";

describe("NatsContainer", { timeout: 180_000 }, () => {
Expand All @@ -25,19 +26,18 @@ describe("NatsContainer", { timeout: 180_000 }, () => {

const container = await new NatsContainer().start();
const nc = await connect(container.getConnectionOptions());
const sc = StringCodec();

//----------------
const sub = nc.subscribe(SUBJECT);
(async () => {
for await (const m of sub) {
const actual: string = sc.decode(m.data);
const actual: string = m.string();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, Base64Codec static functions are provided by @nats-io/obj

Base64Codec.encode()
Base64Codec.decode()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NATS examples in their own documentation are out of date, but I found test cases which use string(), so I picked those. I do not think this PR should deviate to use the suggested Base64Codec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think toString is a suitable transport encoding to use even in an example.

expect(actual).toEqual(PAYLOAD);
}
})().then();

//----------------
nc.publish(SUBJECT, sc.encode(PAYLOAD));
nc.publish(SUBJECT, PAYLOAD);

//----------------
await nc.drain();
Expand Down Expand Up @@ -73,7 +73,7 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
const nc = await connect(container.getConnectionOptions());

// ensure JetStream is enabled, otherwise this will throw an error
await nc.jetstream().jetstreamManager();
await jetstreamManager(nc);

// close the connection
await nc.close();
Expand All @@ -90,7 +90,7 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
const nc = await connect(container.getConnectionOptions());

// ensure JetStream is not enabled, as this will throw an error
await expect(nc.jetstream().jetstreamManager()).rejects.toThrow("503");
await expect(jetstreamManager(nc)).rejects.toThrow("jetstream is not enabled");

// close the connection
await nc.close();
Expand Down