Skip to content

Commit 9f6b9b1

Browse files
Merge branch 'main' into release-11.0.0
2 parents 9b57beb + b31eaca commit 9f6b9b1

File tree

4 files changed

+88
-36
lines changed

4 files changed

+88
-36
lines changed

package-lock.json

Lines changed: 61 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/modules/nats/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
2929
"build": "tsc --project tsconfig.build.json"
3030
},
31-
"devDependencies": {
32-
"nats": "^2.29.3"
33-
},
3431
"dependencies": {
3532
"testcontainers": "^10.27.0"
33+
},
34+
"devDependencies": {
35+
"@nats-io/jetstream": "^3.0.2",
36+
"@nats-io/transport-node": "^3.0.2"
3637
}
3738
}

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { connect, StringCodec } from "nats";
1+
import { jetstreamManager } from "@nats-io/jetstream";
2+
import { connect } from "@nats-io/transport-node";
23
import { NatsContainer } from "./nats-container";
34

45
const IMAGE = "nats:2.8.4-alpine";
@@ -20,26 +21,41 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
2021
});
2122
// }
2223

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

2843
const container = await new NatsContainer(IMAGE).start();
2944
const nc = await connect(container.getConnectionOptions());
30-
const sc = StringCodec();
45+
const TE = new TextEncoder();
46+
const TD = new TextDecoder();
3147

3248
//----------------
3349
const sub = nc.subscribe(SUBJECT);
3450
(async () => {
3551
for await (const m of sub) {
36-
const actual: string = sc.decode(m.data);
52+
const actual = TD.decode(m.data);
3753
expect(actual).toEqual(PAYLOAD);
3854
}
3955
})().then();
4056

4157
//----------------
42-
nc.publish(SUBJECT, sc.encode(PAYLOAD));
58+
nc.publish(SUBJECT, TE.encode(PAYLOAD));
4359

4460
//----------------
4561
await nc.drain();
@@ -75,7 +91,7 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
7591
const nc = await connect(container.getConnectionOptions());
7692

7793
// ensure JetStream is enabled, otherwise this will throw an error
78-
await nc.jetstream().jetstreamManager();
94+
await jetstreamManager(nc);
7995

8096
// close the connection
8197
await nc.close();
@@ -92,7 +108,7 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
92108
const nc = await connect(container.getConnectionOptions());
93109

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

97113
// close the connection
98114
await nc.close();

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)